I'm trying to make a generic procedure to Center any Window on the computer screen but I can't seem to 'extract' the WinAPI RECT structure to get the proper Windows coordinates.
Here's what I have so far:
Code: Select all
;
; ------------------------------------------------------------
;
; Center the Main Menu Screen
; aug.18,2001
; ------------------------------------------------------------
;
Global hWnd.l ; a handle for each window
Procedure.l CenterWindow(hWnd)
; Generic routine to center any window given its handle.
;
; Structure is already declared (must be in library info?)
; Structure RECT
; Left.l
; Top.l
; Right.l
; Bottom.l
; EndStructure
*RECT = GetWindowRect_(hWnd, RECT)
;-------------------------------------------------
;Original stuff
;x.w = (GetSystemMetrics_((SM_CXSCREEN) - (WndRect\Right-WndRect\Left)))/2
;y.w = (GetSystemMetrics_((SM_CYSCREEN)- (WndRect\Bottom-WndRect\Top + GetSystemMetrics_(SM_CYCAPTION)))/2
;SetWindowPos_(hWnd, NULL, x, y, 0, 0, SWP_NOSIZE Or SWP_NOZORDER)
;------------------------------------------------
;x.w = GetSystemMetrics_((SM_CXSCREEN))
x = *RECT\Right
result = messagerequester("title", str(x), 0)
SetWindowPos_(hWnd, NULL, x, y, 0, 0, SWP_NOSIZE Or SWP_NOZORDER)
EndProcedure
result = GetWindow_(hWnd, NULL)
If OpenWindow(hWnd, 100, 150, 450, 400, #PB_Window_SystemMenu, "System - Main Menu Screen")
CenterWindow(hWnd)
If CreateStatusBar(0, WindowID())
AddStatusBarField(100)
AddStatusBarField(250)
AddStatusBarField(100)
EndIf
Prog.s = "Power is in the programmer"
SetStatusBarText(0, 0, "Area 1", 0)
SetStatusBarText(0, 1, Prog, 0)
SetStatusBarText(0, 2, "Area 3", 0)
Repeat
Until WaitWindowEvent() = #PB_EventCloseWindow
EndIf