DeferWindowPos

機能
親ウィンドウ内の指定した位置にある子ウィンドウのハンドル取得
Declare Function DeferWindowPos Lib "user32.dll"  _
(ByVal hWinPosInfo As Long, ByVal hWnd As Long, _
ByVal hWndInsertAfter As Long,ByVal x As Long, _
ByVal y As Long, ByVal cx As Long, ByVal cy As Long, _
ByVal uFalgs As Long) As Long
Declare Function DeferWindowPos Lib "user32.dll"  _
(ByVal hWinPosInfo As Integer, ByVal hWnd As Integer, _
ByVal hWndInsertAfter As Integer, ByVal x As Integer, _
ByVal y As Integer, ByVal cx As Integer, _
ByVal cy As Integer, ByVal uFalgs As Integer) As Integer

HDWP DeferWindowPos(
HDWP hWinPosInfo,
HWND hWnd,
HWND hWndInsertAfter,
int x,
int y,
int cx,
int cy,
UINT uFlags
);
引数
hWinPosInfo

データ構造体のハンドル
最初はBeginDeferWindowPos()関数によって取得したハンドル
二番目以降はDeferWindowPos()関数の戻り値
hWnd
ウィンドウのハンドル
hWndInsertAfter
hWndよりも前に置くウィンドウのハンドル or 定数
(uFlagsにSWP_NOZORDERを設定したときはこれらのフラッグは無視される)
x
新しいウィンドウの左上隅のx座標
y
同、Y座標
cx
新しいウィンドウの幅
cy
同、高さ
uFlags
ウィンドウの位置とサイズ指定する定数の組み合わせ
戻り値
正常終了のとき  データ構造体のハンドル
エラーのとき  0
hWndInsertAfterの定数

HWND_BOTTOM = 1                    ウィンドウ表示リストの最後に置く
HWND_NOTOPMOST = -2                トップ指定されたウィンドウの直後に置く
HWND_TOP = 0                       Zオーダーのトップに配置
HWND_TOPMOST = -1                  常に手前に表示
uFlagsの定数

SWP_FRAMECHANGED = &H20            再描画時に、ウィンドウを囲む枠を描画
SWP_DRAWFRAME = SWP_FRAMECHANGED
SWP_HIDEWINDOW = &H80              再描画時に、ウィンドウを非表示
SWP_NOACTIVE = &H10                ウィンドウをアクティブにしない
SWP_NOCOPYBITS = &H100             クライアント領域のないようを再描画しない
SWP_NOMOVE = &H2                   サイズを変更
SWP_NOOWNERZORDER = &H200          親ウィンドウのZオーダーを変更しない
SWP_NOREDRAW = &H8                 順序は変えるが、再描画しない
SWP_NOREPOSITION = SWP_NOOWNERZORDER
SWP_NOSIZE = &H1                   サイズを変更しない
SWP_NOZODER = &H4                  hWndInsertAfterを無視
SWP_NOSENDCHANGING = &H400         WM_WINDOWPOSCHANGINGを送らない
SWP_SHOWWINDOW = &H40              再描画時にウィンドウを再表示
サンプル
ダウンロード(DeferWindowPos.lzh 1.78KB)

Private Sub Command3_Click()
Dim rc As Long
Dim hWinPosInfo As Long, nNumWindows As Long

'操作対象のウインドウの数
nNumWindows = 2

'データ構造体のハンドルを得る
hWinPosInfo = BeginDeferWindowPos(nNumWindows)
  
'最初のウインドウ(Command1)の位置を変更
hWinPosInfo = DeferWindowPos(hWinPosInfo, Command1.hWnd, HWND_TOP, _
    10, 10, 40, 30, SWP_SHOWWINDOW Or SWP_NOSIZE)

'二番目のウインドウ(Command2)の位置とサイズを変更
hWinPosInfo = DeferWindowPos(hWinPosInfo, Command2.hWnd, Command1.hWnd, _
    10, 50, 80, 40, SWP_SHOWWINDOW)

'データ構造体のハンドルをクローズする
rc = EndDeferWindowPos(hWinPosInfo)

End Sub