Change program's window start pos - is it poss?

BlitzMax Forums/BlitzMax Programming/Change program's window start pos - is it poss?

Chalky(Posted 2007) [#1]
Since it is apparently not possible to hack an exe to open 'hidden', and as I am trying to 'hide' my app's window on startup until I've made it borderless (I can already hide it via ShowWindow, but that results in an undesirable 'window flashes up then disappears' effect) I thought maybe I could make it open at an offscreen coordinate, apply the desired styles using SetWindowLongA, then move it into a visible position via SetWindowPos. I already know how to move a window after it's opened - what I would like to be able to do is have it open at coordinates specified by me so that users don't see it until I want them to.

All my compiled BlitzMax apps seem to open themselves at coords 29,3 on my system. Are these coordinates embedded in each program's exe - in which case is it possible to hack/change them - or do BlitzMax apps get their coordinates from somewhere else at runtime?


GfK(Posted 2007) [#2]
This centres the window on the desktop. I guess you could modify it so you can reposition the window anywhere you like. Don't think I ever found a way of creating a window at a specific position.
Function centreWindow(hWnd)
	?Win32
		Local desk[4]
		Local window[4]
	
		GetWindowRect(GetDesktopWindow(), desk)
		GetWindowRect(hWnd, window)
		
		'Centre Window
		SetWindowPos(hWnd, HWND_NOTOPMOST, (desk[2] - (window[2] - window[1])) / 2, (desk[3] - (window[3] - window[0])) / 2, 0, 0, SWP_NOSIZE)	
	?
End Function



Chalky(Posted 2007) [#3]
@Gfk - won't that move it after it's already opened? I can do that already - but I would like to have the window open off-screen automatically (instead of at 29,3) so that the user doesn't see it appear in one place, then immediately move somewhere else...


ChristianK(Posted 2007) [#4]
Just modify the module you are using ( brl.glmax2d or brl.d3d7max2d ). You will find the "CreateWindowEx" function where you can change the start position.
I think the coordinates 29, 3 are some Windows default values and are not embedded in the .exe file.


Chalky(Posted 2007) [#5]
@ChristianK - excellent - that did it. In case anyone else wants to do the same, and thus 'hide' the app window on startup [and hopefully I'm not telling people something they already know], I modified the following (truncated here) in d3d7graphics.bmx:

Function Create:TD3D7Graphics( width,height,depth,hertz,flags )

	[snip]

	Local hwnd

	If depth
		hwnd=CreateWindowExA( 0,_wndClass,title,WS_VISIBLE|WS_POPUP,0,0,width,height,0,0,hinst,Null )
	Else
		Local style=WS_VISIBLE|WS_CAPTION|WS_SYSMENU
		Local rect[]=[-width,0,width,height]
		AdjustWindowRect rect,style,0
		hwnd=CreateWindowExA( 0,_wndClass,title,style,rect[0],rect[1],rect[2]-rect[0],rect[3]-rect[1],0,0,hinst,Null )
		GetClientRect hwnd,rect
		width=rect[2]-rect[0]
		height=rect[3]-rect[1]
	EndIf

	[snip]

End Function

Now all my windows open 'width' pixels offscreen, so I can apply styles etc. before moving them into a viewable position...