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.

GetWorkArea Window Resize

 Keywords: GetWorkArea Window Resize Place WinPlace X Y Coordinate MulDiv Calculation Pixel Height Width WinMetrics SysParamInfo 48 Task Bar

Question:

How do I get the Y-Coordinate for top of taskbar? I'm using the function WinPlace() to place and size a window. I want the top of the window to be at the top of the screen, and the bottom of the window to be at the top of the Windows task bar at the bottom. So, consider this command:
WinPlace(xulc, yulc, xbrc, ybrc, WinX)
If I set yulc = 0, my window's top is at the top of my screen. However, if I set ybrc = 1000 the bottom of my window is covered by the Windows taskbar. How can I find a value for ybrc that will make the bottom of my window go down exactly to the task bar?

Answer:

SysParamInfo 48 (GetWorkArea) Retrieves the size of the work area on the primary display monitor. The work area is the portion of the screen not obscured by the system taskbar or by application desktop toolbars. However this function returns comma-delimited coordinates of the work area, expressed in virtual screen pixel coordinates, in the format: "left,top,right,bottom". This will need to be converted to the virtual 1000x1000 screen coordinates expected by WinPlace.

The code might look something like this:

sWorkArea      = SysParamInfo(48, "", 0)
iLeft       = ItemExtract(1, sWorkArea, ",")
iTop       = ItemExtract(2, sWorkArea, ",")
iRight       = ItemExtract(3, sWorkArea, ",")
iBottom       = ItemExtract(4, sWorkArea, ",")

; Calculation : WorkArea multiplied by 1000 then divided by actual screen height.
; xulc = iLeft*1000/WinMetrics(0)
; yulc = iTop*1000/WinMetrics(1)
; xbrc = iRight*1000/WinMetrics(0)
; ybrc = iBottom*1000/WinMetrics(1)

; More Precise MulDiv Calculation
xulc  = DllCall(DirWindows(1):"kernel32.dll",long:"MulDiv",long:iLeft,long:1000,long:WinMetrics(0))
yulc = DllCall(DirWindows(1):"kernel32.dll",long:"MulDiv",long:iTop,long:1000,long:WinMetrics(1))
xbrc = DllCall(DirWindows(1):"kernel32.dll",long:"MulDiv",long:iRight,long:1000,long:WinMetrics(0))
ybrc = DllCall(DirWindows(1):"kernel32.dll",long:"MulDiv",long:iBottom,long:1000,long:WinMetrics(1))

Pause('GetWorkArea Window Resize Results',xulc:',':yulc:',':xbrc:',':ybrc)
title = '' ; Blank string refers to the Main WIL window
WinPlace( xulc, yulc, xbrc, ybrc,  title )
TimeDelay(5)
Exit

More

The above code might have some loss of precision because of the convertion to the 1000x1000 screen coordinates. The following code does not suffer from this problem because it uses pixel coordinates passed to SetWindowPos.
BoxOpen('GetWorkArea Window Resize','SysParamInfo(48, "", 0) Sample')
sWorkArea = SysParamInfo(48,"",0)
iLeft = ItemExtract(1, sWorkArea, ",")
iTop = ItemExtract(2, sWorkArea, ",")
iRight = ItemExtract(3, sWorkArea, ",")
iBottom = ItemExtract(4, sWorkArea, ",")

;Place the window using SetWindowPos
title = '' ;Blank string refers to the Main WIL window
DllCall(DirWindows(1):"user32.dll",long:"SetWindowPos",long:DllHwnd(title),long:0,long:iLeft,long:iTop,long:iRight-iLeft,long:iBottom-iTop,long:4|64)
TimeDelay(5)
Exit

Article ID:   W18459
Filename:   GetWorkArea Window Resize.txt
File Created: 2011:11:03:08:55:22
Last Updated: 2011:11:03:08:55:22