Demo to adjust the size of a window according to the desired client area size.
nomainwin
UpperLeftX=30:UpperLeftY=50
struct rect, left as long, top as long,_
right as long, bottom as long
'desired client size - 250x250:
rect.left.struct=0
rect.top.struct=0
rect.right.struct=250
rect.bottom.struct=250
Open "user32" For DLL As #user
statictext #1.s, "", 10,10,200,200
Open "I'm a test window" for window_nf as #1
#1 "trapclose [quit]"
h=hwnd(#1)
'get style of window for use
'with AdjustWindowRect:
style=GetWindowLong(h, _GWL_STYLE)
'get coords into struct rect:
call AdjustWindowRect style, 0
'rect now holds coords
nLeft=rect.left.struct
nTop=rect.top.struct
nRight=rect.right.struct
nBottom=rect.bottom.struct
'get proper width and height
width=nRight-nLeft
height=nBottom-nTop
call MoveWindow h, UpperLeftX, UpperLeftY, width, height
'now see if we got it right:
call GetClientRect h
nLeft=rect.left.struct
nTop=rect.top.struct
nRight=rect.right.struct
nBottom=rect.bottom.struct
width=nRight-nLeft
height=nBottom-nTop
msg$="Client dimensions are: "
msg$=msg$+str$(width)+" X "+str$(height)
#1.s msg$
wait
[quit]
Close #user:close #1:end
Sub AdjustWindowRect dwStyle, isMenu
'isMenu=1 for window with menu, 0 for no menu
calldll #user, "AdjustWindowRect",_
rect as struct, dwStyle as long,_
isMenu as boolean, re as boolean
End Sub
Sub MoveWindow hWnd,x,y,w,h
CallDLL #user, "MoveWindow",hWnd As ulong,_
x As long, y As long,_
w As long, h As long,_
1 As boolean, r As boolean
End Sub
Sub GetClientRect hW
CallDLL #user, "GetClientRect",_
hW As ulong, rect As struct,r As long
End Sub
Function GetWindowLong(hW, type)
CallDLL #user, "GetWindowLongA", _
hW As ulong, type As long,_
re As long
GetWindowLong=re
End Function