Win32: How to position a window at CW_USEDEFAULT?

BlitzMax Forums/BlitzMax Programming/Win32: How to position a window at CW_USEDEFAULT?

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Not sure what you mean by system default?!?


You can position the app window using this code.

Just save the xy position set at the end of the program.
And read it from a file at start up.

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%//
' // BlitzMax Window Framework by Eikon
' //                                    modified by Grisu
' // BMX 1.14
' //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%//
Strict

' // Framework & Modules //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%//
Framework BRL.GLMax2D
Import BRL.Basic
Import BRL.System

' // Win32 API //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%//
Extern "win32"
   Function GetActiveWindow%()
   Function GetDesktopWindow%()
   Function GetWindowRect%(hWnd%, lpRect:Byte Ptr)
   Function SetWindowText%(hWnd%, lpString$z) = "SetWindowTextA@8"
   Function SetWindowPos%(hWnd%, after%, x%, y%, w%, h%, flags%)
End Extern

Type lpRECT
   Field l%, t%, r%, b%
End Type

' // Create Window %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%//
Const GFX_WIDTH = 320, GFX_HEIGHT = 200, BIT_DEPTH = 0, HERTZ = -1

Graphics GFX_WIDTH, GFX_HEIGHT, BIT_DEPTH, HERTZ
Local hWnd% = GetActiveWindow()
Local desk_hWnd% = GetDesktopWindow(), l:lpRect = New lpRECT

GetWindowRect desk_hWnd, l:lpRECT ' Get Desktop Dimensions
SetWindowText hWnd, "My Window"  ' Set Window Text

' Center Window
SetWindowPos hWnd, -2, (l.r / 2) - (GFX_WIDTH / 2), (l.b / 2) - (GFX_HEIGHT / 2), 0, 0, 1

l:lpRECT = Null ' Mark for garbage collection
GCCollect() ' Do collection :)

Repeat;

Flip; Until KeyDown(KEY_ESCAPE) Or (AppTerminate()=True) ' also exit if windowbutton is used!!!