Duilib Advanced Tutorials-Responding to Windows native messages and custom messages (13)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.