One-day training of Windows APIs (37) movewindow Function

Source: Internet
Author: User
One-day training of Windows APIs (37) movewindow Function
When you design a dialog box window, you need to layout all buttons, text display boxes, and so on. Because each button is a window, you need to move these windows to the appropriate position, in this case, you need to use the movewindow function. Or when you need to dynamically modify the button position on the interface, for example, if the window is enlarged, the button needs to be moved. Otherwise, the button is still in the original position, and the button will not be zoomed in, in this case, you also need to use the movewindow function to reset the button position. You can use this function to move the window.
 
The movewindow function declaration is as follows:
Winuserapi
Bool
Winapi
Movewindow (
_ In hwnd,
_ In int X,
_ In int y,
_ In int nwidth,
_ In int nheight,
_ In bool brepaint );
Hwnd is the handle of the window.
X is the position of the window on the X axis.
Y is the position of the window in Y.
Nwidth indicates the window width.
Nheight is the window height.
Brepaint is used to set whether to redraw the window and parent window. If this parameter is set to true, the image is repainted. If this parameter is set to false, the image is not repainted. You need to update the specified region by hand.
 
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 else
#033 {
#034 // set the text of the button.
#035 setwindowtext (m_hbtn, _ T ("button "));
#036
#037 // change the position and size of the button window.
#038 movewindow (m_hbtn, 50,50, 100,32, true );
#039}
#040
#041 // changes each time.
#042 bchangetext =! Bchangetext;
#043}
#044 break;
#045 default:
#046 return ccaiwin: oncommand (NID, nevent );
#047}
#048
#049 return 1;
#050}

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.