MSWMessageHandler example
MSWMessageHandler example
I've been trying to register a windows message handler with no luck. I think it needs a pointer but I can't make it work, and there seems to be no examples in google either. Can someone give me an example how to use it?
-
- Super wx Problem Solver
- Posts: 469
- Joined: Tue Jun 20, 2006 6:47 pm
- Contact:
Re: MSWMessageHandler example
If you want to handle messages on windows, you should derive a class from whatever wwWidgets object you are using and override MSWOnNotify or MSWHandleMessage.
Re: MSWMessageHandler example
Thanks for your input, I made a little function like this:New Pagodi wrote: ↑Fri Mar 19, 2021 8:36 pm If you want to handle messages on windows, you should derive a class from whatever wwWidgets object you are using and override MSWOnNotify or MSWHandleMessage.
Code: Select all
bool MainWindow::MSWHandleMessage(WXLRESULT res, WXUINT msg, WXWPARAM wParam, WXLPARAM lParam)
{
wxLogDebug(wxString("Message ID: ") + wxString(std::to_string(msg)));
return false;
}
Re: MSWMessageHandler example
It expects a function pointer with the following signature:but I don't know what to pass as second parameter which asks for a "wxWindow::MSWMessageHandler" object
Code: Select all
typedef bool (*MSWMessageHandler)(wxWindowMSW *win,
WXUINT nMsg,
WXWPARAM wParam,
WXLPARAM lParam);
Code: Select all
WXLRESULT mainFrame::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
{
if( nMsg == WM_DEVICECHANGE )
{
wxLogDebug(wxT("WM_DEVICECHANGE %x %x"), wParam, lParam);
if( wParam==DBT_DEVICEARRIVAL || wParam==DBT_DEVICEREMOVECOMPLETE )
{
// update device list
}
}
return wxFrame::MSWWindowProc(nMsg, wParam, lParam);
}
Use the source, Luke!
Re: MSWMessageHandler example
Thank you! I tried something like this with no luck:doublemax wrote: ↑Sat Mar 20, 2021 12:29 pmIt expects a function pointer with the following signature:but I don't know what to pass as second parameter which asks for a "wxWindow::MSWMessageHandler" objectAlternatively you can override wxWindow::MSWWindowProcCode: Select all
typedef bool (*MSWMessageHandler)(wxWindowMSW *win, WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
Code: Select all
WXLRESULT mainFrame::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) { if( nMsg == WM_DEVICECHANGE ) { wxLogDebug(wxT("WM_DEVICECHANGE %x %x"), wParam, lParam); if( wParam==DBT_DEVICEARRIVAL || wParam==DBT_DEVICEREMOVECOMPLETE ) { // update device list } } return wxFrame::MSWWindowProc(nMsg, wParam, lParam); }
I can't understand how to pass a function pointer correctly so I used MSWWindowProc and now it works perfectly now!
Re: MSWMessageHandler example
As i'm seeing the WM_POWERBROADCAST in your code, maybe you missed wxPowerEvent ?
https://docs.wxwidgets.org/trunk/classw ... event.html
https://docs.wxwidgets.org/trunk/classw ... event.html
Use the source, Luke!
Re: MSWMessageHandler example
Oh I had no idea about this! Thank you very much!doublemax wrote: ↑Sat Mar 20, 2021 1:07 pm As i'm seeing the WM_POWERBROADCAST in your code, maybe you missed wxPowerEvent ?
https://docs.wxwidgets.org/trunk/classw ... event.html