One-day Windows API training (38) setwindowpos Function

Source: Internet
Author: User
One-day Windows API training (38) setwindowpos Function
One day, the user suddenly said to me, can you put this window at the top, it is very inconvenient to operate and open the file. This function requires changing the properties of the window. For example, when you use QQ, there is a function that sets the QQ window to the top, no matter what window you choose, the QQ interface will always be at the top. Another example is the flash get status display window, which is always at the front end of the window, allowing you to see the current download stream range. Now the stock is so popular that many people view the stock while working. If they miss the opportunity, they lose a lot of money! In the face of such requirements, we need to always put some windows at the forefront, so as to serve as a reminder to users. Therefore, learning to use the setwindowpos function becomes the key to meeting customers' requirements. Compared with the movewindow function, the setwindowpos function is more powerful.
 
The setwindowpos function declaration is as follows:
Winuserapi
Bool
Winapi
Setwindowpos (
_ In hwnd,
_ In_opt hwnd hwndinsertafter,
_ In int X,
_ In int y,
_ In int CX,
_ In int cy,
_ In uint uflags );
Hwnd is the handle of the window.
Hwndinsertafter is the Z sequence attribute of the window.
X is the position of the window on the X axis.
Y is the position of the window in Y.
CX is the window width.
Cy is the window height.
Uflags is the flag for selecting settings.
 
An example of calling this function is as follows:
#001 //
#002 // response command.
#003 // Cai junsheng 2007/09/16 QQ: 9073204
#004 //
#005 lresult ccaiwinmsg: oncommand (int nid, int nevent)
#006 {
#007 // menu option command response:
#008 switch (NID)
#009 {
#010 case idc_createbtn:
#011 // display a button.
#012 if (! M_hbtn)
#013 {
#014 m_hbtn = createwindow (_ T ("button"), _ T ("button "),
#015 ws_visible | ws_child | bs_pushbutton,
#016 50,50, 100,32,
#017 m_hwnd, (hmenu) idc_btn, m_hinstance, null );
#018}
#019 break;
#020 case idc_btn:
#021 outputdebugstring (_ T ("click/R/N "));
#022 {
#023 static bool bchangetext = true;
#024 if (bchangetext)
#025 {
#026 // set the text of the button.
#027 setwindowtext (m_hbtn, _ T ("change it "));
#028
#029 // change the position and size of the button window.
#030 movewindow (m_hbtn, 10, 10, 100,32, true );
#031
#032 // change the main window to the top window.
#033 setwindowpos (m_hwnd, hwnd_topmost, 0, 0, 0, swp_nomove | swp_nosize );
#034}
#035 else
#036 {
#037 // set the text of the button.
#038 setwindowtext (m_hbtn, _ T ("button "));
#039
#040 // change the position and size of the button window.
#041 movewindow (m_hbtn, 50,50, 100,32, true );
#042
#043 // change the main window to a normal window.
#044 setwindowpos (m_hwnd, hwnd_notopmost, 0, 0, 0, swp_nomove | swp_nosize );
#045}
#046
#047 // changes each time.
#048 bchangetext =! Bchangetext;
#049}
#050 break;
#051 default:
#052 return ccaiwin: oncommand (NID, nevent );
#053}
#054
#055 return 1;
#056}
Related Article

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.