The SetWindowPos function changes the size, position, and Z order of a child, pop-up, or top-level window. Child, pop-up, and top-level windows are ordered according to their appearance on the screen. The topmost window receives the highest rank and is the first window in the Z order.
BOOL SetWindowPos( HWND hWnd, // handle to window HWND hWndInsertAfter, // placement-order handle int X, // horizontal position int Y, // vertical position int cx, // width int cy, // height UINT uFlags // window-positioning flags );
SAMPLE CODE ========================================
LRESULT CALLBACK WndProc(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam) { HDC hdc; PAINTSTRUCT ps; char Mes[]="왼쪽=위치 변경, 오른쪽=항상 위 옵션 변경"; static BOOL bTopMost=FALSE;
switch(iMessage) { case WM_LBUTTONDOWN: SetWindowPos(hWnd, HWND_NOTOPMOST, rand()%640, rand()%480, 0, 0, SWP_NOSIZE); return 0; case WM_RBUTTONDOWN: if (bTopMost) { SetWindowPos(hWnd,HWND_NOTOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE); } else { SetWindowPos(hWnd,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE); } bTopMost=~bTopMost; return 0; case WM_PAINT: hdc=BeginPaint(hWnd, &ps); TextOut(hdc,10,10,Mes,lstrlen(Mes)); EndPaint(hWnd, &ps); return 0; case WM_DESTROY: PostQuitMessage(0); return 0; } return(DefWindowProc(hWnd,iMessage,wParam,lParam)); } |