英文:
How to post a custom event of a wxWebview object to its parent in wxWidgets?
问题
我正在尝试将一个拖放事件发送给wxWebview对象的父对象。我知道wxWebView会消耗所有接收到的事件,所以我必须为其父对象创建一个自定义事件。我尝试了以下代码,但它不起作用:
void onNewWindow( wxWebViewEvent& evt )
{
wxString* files = new wxString[ 1 ];
files[ 0 ] = evt.GetURL();
wxDropFilesEvent dropEvent( wxEVT_DROP_FILES, 1, files );
dropEvent.SetEventObject( ctrl_->GetParent() );
dropEvent.m_pos.x = 0;
dropEvent.m_pos.y = 0;
ctrl_->GetParent()->GetEventHandler()->ProcessEvent( dropEvent );
// 我们不想打开新窗口,所以否决事件
evt.Veto();
}
当我将文件拖放到wxWebview中时,它不起作用,但如果我将其拖放到其父对象上,程序就按预期工作。我不确定发生了什么以及是否已为父对象设置了正确的拖放事件。
我还尝试在Windows的wxWebView子对象中为接收到的消息设置钩子,方法是重写MSWWindowProc
函数和SetWindowsHookEx
,但到目前为止我还没有成功。
我正在使用wxWidgets 3.2.2.1,使用Windows 10上的Edge后端,其他平台在这个时刻不重要。
英文:
I am trying to send a drop event to the parent of wxWebview object. I know that wxWebView consumes all received events and I have to create a custom event for its parent. I tried the following code but it does not work:
void onNewWindow( wxWebViewEvent& evt )
{
wxString* files = new wxString[ 1 ];
files[ 0 ] = evt.GetURL();
wxDropFilesEvent dropEvent( wxEVT_DROP_FILES, 1, files );
dropEvent.SetEventObject( ctrl_->GetParent() );
dropEvent.m_pos.x = 0;
dropEvent.m_pos.y = 0;
ctrl_->GetParent()->GetEventHandler()->ProcessEvent( dropEvent );
// we don't want to open a new window so veto the event
evt.Veto();
}
When I drop a file into the wxWebview, it does not work but if I drop it on its parent, program works as expected. I am not sure what's going on and whether I have set the correct drop event for the parent or not.
I also tried to set a hook for the message received in the child of wxWebView in Windows by overriding the MSWWindowProc
function and SetWindowsHookEx
but so far I have not succeeded.
I am using wxWidgets 3.2.2.1 with edge backend in Windows 10 and other platform are not important at this moment.
答案1
得分: 1
This depends on what do you mean by "work". If this just means "execute the handler bound to wxEVT_DROP_FILES
in the parent", then this should work, but I'm not sure how is it really useful considering that you could just bind the same handler to the same event on ctrl_
directly.
If you mean "do exactly the same thing as if the file were dropped on the parent", then you can't do this at wx level because part of this "thing" is what is done by Windows itself when it gets WM_DROPFILES
in DefWindowProc()
and, of course, you can't trigger execution of this code by sending wx events as Windows doesn't know anything about them. So to do this you would indeed need to forward the Windows message instead.
But it's still not clear at all why exactly do you think you need to do all this.
英文:
This depends on what do you mean by "work". If this just means "execute the handler bound to wxEVT_DROP_FILES
in the parent", then this should work, but I'm not sure how is it really useful considering that you could just bind the same handler to the same event on ctrl_
directly.
If you mean "do exactly the same thing as if the file were dropped on the parent", then you can't do this at wx level because part of this "thing" is what is done by Windows itself when it gets WM_DROPFILES
in DefWindowProc()
and, of course, you can't trigger execution of this code by sending wx events as Windows doesn't know anything about them. So to do this you would indeed need to forward the Windows message instead.
But it's still not clear at all why exactly do you think you need to do all this.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论