News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

GetWindowPos

Started by guga, May 20, 2012, 12:54:17 AM

Previous topic - Next topic

guga

RosAsm Syntax



;;
    GetWindowPos v 1.0
   
    This functions retrieves the x, y, width and heigth of any window.

    Arguments:
   
        hWnd(in): A handle to the window. The window can be a child, overlapped, a dialog a control etc.
        PosStruct(out): A pointer to a WINPOS structure to rceive the values found.

    Returned Value: If the window is a child window, the return value is a handle to the parent window. If the window is a top-level window with the WS_POPUP style, the return value is a handle to the owner window.
                    If the function fails, the return value is NULL. To get extended error information, call GetLastError.
                    This function typically fails for one of the following reasons:
                        *The window is a top-level window that is unowned or does not have the WS_POPUP style.
                        •The owner window has WS_POPUP style.

    Remarks:
        The WINPOS structure have the following format and specifications:

        [WINPOS:
         WINPOS.cx: D$ 0 ; The initial horizontal position of the window. For an overlapped or pop-up window, the x parameter is
                         ; the initial x-coordinate of the window's upper-left corner, in screen coordinates. For a child window,
                         ; x is the x-coordinate of the upper-left corner of the window relative to the upper-left corner of the
                         ; parent window's client area.

         WINPOS.cy: D$ 0 ; The initial vertical position of the window. For an overlapped or pop-up window, the y parameter is
                         ; the initial y-coordinate of the window's upper-left corner, in screen coordinates. For a child window,
                         ; y is the initial y-coordinate of the upper-left corner of the child window relative to the upper-left
                         ; corner of the parent window's client area. For a list box y is the initial y-coordinate of the upper-left
                         ; corner of the list box's client area relative to the upper-left corner of the parent window's client area.


         WINPOS.width: D$ 0 ; The width, in device units, of the window.
         WINPOS.height: D$ 0; The height, in device units, of the window.
         ]       
       

    Usage example:

    [WINPOS:
     WINPOS.cx: D$ 0
     WINPOS.cy: D$ 0
     WINPOS.width: D$ 0
     WINPOS.height: D$ 0]
   
   
    call 'USER32.GetDlgItem' D@hWnd, 156
    call GetWindowPos eax, WINPOS


    Author: Gustavo Trigueiros (aka: Beyond2000!)
    Build Date: 19/05/2012 (v 1.0)

;;


Proc GetWindowPos:
    Arguments @hWnd, @PosStruct
    Local @width, @height, @hParent
    Structure @WINDOWINFO 64, @WINDOWINFO.cbSizeDis 0,  @WINDOWINFO.rcWindow_leftDis 4,  @WINDOWINFO.rcWindow_topDis 8,
                              @WINDOWINFO.rcWindow_rightDis 12,  @WINDOWINFO.rcWindow_bottomDis 16,  @WINDOWINFO.rcClient_leftDis 20,
                              @WINDOWINFO.rcClient_topDis 24,  @WINDOWINFO.rcClient_rightDis 28,  @WINDOWINFO.rcClient_bottomDis 32,
                              @WINDOWINFO.dwStyleDis 36,  @WINDOWINFO.dwExStyleDis 40,  @WINDOWINFO.dwWindowStatusDis 44,  @WINDOWINFO.cxWindowBordersDis 48,
                              @WINDOWINFO.cyWindowBordersDis 52,  @WINDOWINFO.atomWindowTypeDis 56,  @WINDOWINFO.wCreatorVersionDis 60
    Uses esi, ecx, edx

    call 'user32.GetParent' D@hWnd
    On eax = 0, ExitP
    mov D@hParent eax
    call 'USER32.MapWindowPoints' D@hWnd, eax, D@PosStruct, 2

    call ZeroMemory D@WINDOWINFO, 64
    mov D@WINDOWINFO.cbSizeDis 64
    call 'USER32.GetWindowInfo' D@hWnd, D@WINDOWINFO
    mov esi D@PosStruct
    mov eax D@WINDOWINFO.rcWindow_rightDis | sub eax D@WINDOWINFO.rcWindow_leftDis | mov D$esi+WINPOS.widthDis eax
    mov eax D@WINDOWINFO.rcWindow_bottomDis | sub eax D@WINDOWINFO.rcWindow_topDis | mov D$esi+WINPOS.heightDis eax

    mov eax D@WINDOWINFO.cxWindowBordersDis | sub D$esi+WINPOS.cxDis eax
    mov eax D@WINDOWINFO.cyWindowBordersDis | sub D$esi+WINPOS.cyDis eax

    mov eax D@hParent

EndP


dedndave

couldn't you use GetWindowRect ?
http://msdn.microsoft.com/en-us/library/windows/desktop/ms633519%28v=vs.85%29.aspx

also - be aware that, when a window is minimized to the taskbar, the height is a negative value as i recall   :P