WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Window Manipulation

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Active Window Height and Width in Pixels


Question:

Is there a way to determine the height and width of the active window in pixels?

Answer:

Yes. You can get pretty close by doing a WinPlaceGet, and then picking apart the numbers (ItemExtract) then "converting the numbers to absolute coordinates with from fractions. From WinMetrics you know the pixel size of the entire screen. And the numbers returned from WinPlaceGet assume it is a 1000x1000 screen so you have to convert it. Alternatively some DllCall or other like GetWindowRect might do it. Pick the numbers apart with ItemExtract, using a comma as a delimiter.
a = ItemExtract( 1, rect, "," )


;--------------------------------------------------------------------------------;
;GetWindowPos : Gets window position in real screen x,y                          ;
;--------------------------------------------------------------------------------;
;handle : dialog handle of window                                                ;
;--------------------------------------------------------------------------------;
;Returns: string = "xpos,ypos,widht,height"                                      ;
;--------------------------------------------------------------------------------;
#DefineFunction GetWindowPos(handle)
   user32=StrCat(DirWindows(1),"user32.dll")
   lpRect = BinaryAlloc(16)
   ret = -1
   If DllCall(user32,long:"GetWindowRect",long:handle,lpbinary:lpRect) Then
      ret = StrCat(BinaryPeek4(lpRect,0),",",BinaryPeek4(lpRect,4),",",BinaryPeek4(lpRect,8),",",BinaryPeek4(lpRect,12))
   EndIf
   BinaryFree(lpRect)
   Return ret
#EndFunction


handle=DllHwnd("Untitled - Notepad") ; 
rect=GetWindowPos(handle)
Message("numbers",rect)


Article ID:   W16748
File Created: 2005:02:18:12:22:14
Last Updated: 2005:02:18:12:22:14