Duilib Advanced Tutorial--Responding to Windows native messages and custom messages (13) One, Windows native message
Similarly, the Getting Started tutorial just gives a way to respond to Windows native messages, and does not give an example of the adaptive screen resolution. Although the Thunder player can automatically adjust the window size when it starts, but when the screen resolution changes in real time does not adjust the window, so we give the player to adjust the size of the real-time function, it is obvious that should respond to the wm_displaychange message, and Duilib's own function to handle Windows messages is in Handlemessage, so let's reload the Handlemessage function and add the following code:
LRESULT cduiframewnd::handlemessage (UINT umsg, WPARAM WPARAM, LPARAM LPARAM)
{
LRESULT lres = __super::handlemessage (umsg, WParam, LParam);
Switch (umsg)
{
Handle_msg (*this, Wm_displaychange, Ondisplaychange);
}
return lres;
}
So we can respond to the message of resolution change in the Ondisplaychange function, remember include header file # #
void Cduiframewnd::ondisplaychange (HWND hwnd, UINT bitsperpixel, uint cxscreen, uint cyscreen)
{
:: SetWindowPos (M_paintmanager.getpaintwindow (), NULL, 0, 0, Cxscreen, Cyscreen, swp_framechanged| swp_nozorder| Swp_noactivate);
}
II. Custom Messages
Custom messages are also often used, so here's a look, like Windows programming, to define the message ID and function, just to move the message processing to the Handlemessage function.
The player's time and file progress is always updated, so here's a custom message to handle the player's notifications.
1. Define Message ID
#define Wm_user_pos_changed Wm_user + 2//file playback position changed
2. Respond to Custom messages:
Add the following code to the switch branch of the Handlemessage function:
Case wm_user_pos_changed:
Return onposchanged (*this, WParam, LParam);
So we can process the wm_user_pos_changed message in the Onposchanged function.
3. Send a custom message:
Called where the message needs to be sent::P ostmessage (*this, wm_user_pos_changed, WParam, LParam);
Yes, same as Windows (of course, SendMessage OK, see the situation use)
In the introductory tutorial, it has been stressed many times that Duilib is just a UI library, other places are still windows programming, after so many examples of the explanation, now should know about it ~o (∩_∩) o~
Duilib Advanced Tutorials-Responding to Windows native messages and custom messages (13)