Windows API function (6) in VCL: begindeferwindowpos

Source: Internet
Author: User
Begindeferwindowpos, deferwindowpos, and enddeferwindowpos are functions used together to adjust the position, size, and Z sequence of a set of windows. They are useful in extctrls units.

Next, adjust a group of buttons in Panel1 using the conventional method, and then implement them again using the above three functions.

In this example:


Code File:
Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls, extctrls; Type tform1 = Class (tform) Panel1: tpanel; button1: tbutton; button2: tbutton; button3: tbutton; button4: tbutton; identifier: identifier; identifier: tradiobutton; Procedure identifier (Sender: tobject); end; vaR form1: tform1; implementation {$ R *. DFM} procedure tform1.radiobutton1click (Sender: tobject); var num, I: integer; BTN: tbutton; L, t, W, H: integer; begin num: = panel1.controlcount; l: = 10; T: = 10; W: = (panel1.clientwidth-L * (Num + 1) Div num; H: = (panel1.clientheight-T * (Num + 1 )) div num; for I: = 0 to num-1 do begin if panel1.controls [I] Is tbutton then begin BTN: = tbutton (panel1.controls [I]); BTN. left: = L; BTN. top: = (H + T) * I + T; BTN. width: = W; BTN. height: = H; end; Procedure tform1.radiobutton2click (Sender: tobject); var num, I: integer; BTN: tbutton; L, t, W, H: integer; begin num: = panel1.controlcount; L: = 10; T: = 10; W: = (panel1.clientwidth-L * (Num + 1) Div num; h: = (panel1.clientheight-T * (Num + 1) Div num; for I: = 0 to num-1 do begin if panel1.controls [I] Is tbutton then begin BTN: = tbutton (panel1.controls [I]); BTN. left: = (W + l) * I + L; BTN. top: = T; BTN. width: = W; BTN. height: = H; end.
 
   
 

Form file:

Object form1: tform1 left = 0 Top = 0 caption = 'form1' clientheight = 220 clientwidth = 307 color = clbtnface font. charset = default_charset font. color = clwindowtext font. height =-11 font. name = 'tahoma 'font. style = [] oldcreateorder = false pixelsperinch = 96 textheight = 13 object Panel1: tpanel left = 8 Top = 8 width = 289 Height = 161 caption = 'panel1' taborder = 0 object button1: tbutton left = 152 Top = 72 width = 75 Height = 25 caption = 'button1' taborder = 0 end object button2: tbutton left = 160 Top = 80 width = 75 Height = 25 caption = 'button2' taborder = 1 end object button3: tbutton left = 168 Top = 88 width = 75 Height = 25 caption = 'button3' taborder = 2 end object button4: tbutton left = 176 Top = 96 width = 75 Height = 25 caption = 'button4' taborder = 3 end object radiobutton1: tradiobutton left = 50 top = 183 width = 113 Height = 17 caption = 'radiobutton1' taborder = 1 onclick = radiobutton1click end object radiobutton2: tradiobutton left = 184 Top = 183 width = 113 Height = 17 caption = 'radiobutton2' taborder = 2 onclick = radiobutton2click endend
 
   
 

Code re-implemented with begindeferwindowpos, deferwindowpos, and enddeferwindowpos (the form and running effect are the same ):

Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls, extctrls; Type tform1 = Class (tform) Panel1: tpanel; button1: tbutton; button2: tbutton; button3: tbutton; button4: tbutton; identifier: identifier; identifier: tradiobutton; Procedure identifier (Sender: tobject); end; vaR form1: tform1; implementation {$ R *. DFM} procedure tform1.radiobutton1click (Sender: tobject); var num, I: integer; BTN: tbutton; L, t, W, H: integer; deferhandle: thandle; begin num: = panel1.controlcount; L: = 10; T: = 10; W: = (panel1.clientwidth-L * (Num + 1) Div num; h: = (panel1.clientheight-T * (Num + 1) Div num; deferhandle: = begindeferwindowpos (Num); {prepare to adjust a set of Windows} For I: = 0 to num-1 do begin if panel1.controls [I] Is tbutton then begin BTN: = tbutton (panel1.controls [I]); deferhandle: = deferwindowpos (deferhandle, BTN. handle, hwnd_top, {This parameter determines the Z order} l, (H + T) * I + T, W, H, {new position and size} swp_nozorder {more control, currently, the Z sequence is not changed}); end; enddeferwindowpos (deferhandle); {implementation adjustment} end; Procedure tform1.radiobutton2click (Sender: tobject); var num, I: integer; BTN: tbutton; L, t, W, H: integer; deferhandle: thandle; begin num: = panel1.controlcount; L: = 10; T: = 10; W: = (panel1.clientwidth-L * (Num + 1) Div num; H: = (panel1.clientheight-T * (Num + 1) Div num; deferhandle: = begindeferwindowpos (Num ); for I: = 0 to num-1 do begin if panel1.controls [I] Is tbutton then begin BTN: = tbutton (panel1.controls [I]); deferhandle: = deferwindowpos (deferhandle, BTN. handle, hwnd_top, (W + l) * I + L, t, W, H, swp_nozorder); end; enddeferwindowpos (deferhandle); end.
 
  
 

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.