63
Visual Basic 6 Black Book:Connecting To The Windows API And Visual C++
cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Here’s what the arguments to this function mean:
• hwnd—Handle of the window to work with.
• hWndInsertAfter—Handle to the window that will precede this window in the Z-order. This parameter
can be a window handle set to one of the following values: HWND_BOTTOM (= 1; places the window at
the bottom of the Z-order), HWND_TOP (= 0; places the window at the top of the Z-order),
HWND_TOPMOST (= –1; places the window above all non-topmost windows), or
HWND_NOTOPMOST (= –2; repositions the window to the top of all non-topmost windows).
• x—Specifies the new position of the left side of the window.
• y—Specifies the new position of the top of the window.
• cx—Specifies the new width of the window.
• cy—Specifies the new height of the window.
• wFlags—Specifies sizing and positioning options, as shown in Table 23.5.
Table 23.5SetWindowPos flags.
Constant
Meaning
SWP_DRAWFRAME (= &H20)
Draws a frame (defined when the window was
created) around the window.
SWP_FRAMECHANGED (= &H20)
Sends a WM_NCCALCSIZE message to the
window, even if the window’s size is not being
changed. If this flag is not specified,
WM_NCCALCSIZE is sent only when the
window’s size is being changed.
SWP_HIDEWINDOW (=&H80)
Hides the window.
SWP_NOACTIVATE (= &H10)
Does not activate the window. If this flag is not set,
the window is activated and moved to the top of
either the topmost or the non-topmost group
(depending on the setting of the hWndInsertAfter
parameter).
SWP_NOCOPYBITS (= &H100)
Discards the entire contents of the client area. If this
flag is not specified, the valid contents of the client
area are saved and copied back into the client area
after the window is sized or repositioned.
SWP_NOMOVE (= 2)
Retains current position (ignores the x and y
parameters).
SWP_NOOWNERZORDER (= &H200)
Does not change the owner window’s position in the
Z-order.
SWP_NOREDRAW (= 8)
Does not redraw changes. If this flag is set, no
repainting of any kind occurs.
SWP_NOREPOSITION (= &H200)
Same as SWP_NOOWNERZORDER.
SWP_NOSIZE (= 1)
Retains current size (ignores the cx and cy
parameters).
SWP_NOZORDER (= 4)
Retains current ordering (ignores hWndInsertAfter).
SWP_SHOWWINDOW (=&H40)
Displays the window.
Let’s see an example. Here, we’ll size a window to 100 x 100 pixels and make it a topmost window. We start by
declaring SetWindowPos in our program, as well as the constants we’ll use, SWP_SHOWWINDOW,
SWP_DRAWFRAME, and HWND_TOPMOST:
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, _
ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long,
file:///E|/Program%20Files/KaZaA/My%20Shared%...Basic%20-%20%20Black%20Book/ch23/806-812.html (3 of 4) [7/31/2001 9:04:09 AM]