Alter positions or sizes of windows

Win32API enables us to alter positions or sizes of windows.

Example.

100 CALL GetWindowRect(WINHANDLE("MAIN"),left,top,right,bottom)
110 PRINT left,top,right,bottom
120 CALL GetWindowRect(WINHANDLE("TEXT"),leftT,topT,rightT,bottomT)
130 CALL SetWindowPos(WinHandle("TEXT"),0,right,top,rightT-LeftT,Bottom-Top,0)
140 END
150 EXTERNAL SUB GetWindowRect(handle,left,top,right,bottom)
160 OPTION CHARACTER byte
170 FUNCTION GetWindowRectOrg(hwnd,p$)
180    ASSIGN "user32.dll","GetWindowRect"
190 END FUNCTION
200 LET p$=REPEAT$(CHR$(0),16)
210 IF GetWindowRectOrg(Handle,p$)<>0 THEN
220    LET left=ORD(p$(1:1))+256*ORD(p$(2:2))
230    LET top=ORD(p$(5:5))+256*ORD(p$(6:6))
240    LET right=ORD(p$(9:9))+256*ORD(p$(10:10))
250    LET bottom=ORD(p$(13:13))+256*ORD(p$(14:14))
260 END IF
270 END SUB
280 EXTERNAL SUB SetWindowPos(hwnd,HwndInsAfter,x,y,cx,cy,nFlags)
290 ASSIGN "user32.dll","SetWindowPos"
300 END SUB

External subprogram GetWindowRect defined at the line 150 gets the four coordinates of the four corners of the ondicated window.

External function SetWindowPos at the line 280 moves the left-top of the indicated window, and change the width into cx, the height into cx when nFlags is set 0. Normally HwndInsAfter is set 0.
The above program arranges the text output window stuck on the right edge of the main window.

Assigning nFlags with 1 enables only x and y, with 2 enables only the width and the height in SetWindowPos.

Show or hide of a window

The show state of a window can be altered by ShowWnd.

Example. Hide the graphics window and the text output window.

10 SUB ShowWnd(hWnd, nCmdShow)
20    ASSIGN "user32.dll","ShowWindow"
30 END SUB
40 CALL showWnd(winhandle("GRAPHICS"),0)
50 CALL showWnd(winhandle("TEXT"),0)
60 END
Conversely, assign the scond parameter with 5 to show the window.

WINHANDLE function

The parameter of WINHANDLE are currently one of followings.
"MAIN","TEXT","GRAPHICS","INPUT","CHARACTER INPUT","TRACE", "LOCATE", "TEXTWINDOW1", "TEXTWINDOW2"
"RICHEDIT" (RichEdit control of the text output window),
"RICHEDIT1" (RichEdit control of TextWindw1),
"RICHEDIT2" (RichEdit control of TextWindow2)



See also How to use Win32API


Back