Bring graphics window to front ?

Archives Forums/Win32 Discussion/Bring graphics window to front ?

EOF(Posted 2010) [#1]
I am trying to bring the BlitzMax (GL) graphics window to the front but none of the API window-related commands seem to help. Any thoughts?

SetGraphicsDriver GLMax2DDriver()
Graphics 400,300,0


' ways to get the graphics window
hWnd=GetActiveWindow()        ' straight after calling Graphics()
hWnd=FindWindowA("BlitzMax GLGraphics",AppTitle)
DebugLog hWnd


' API calls attempted

SetActiveWindow(Proc.hWnd)				 'no
BringWindowToTop(Proc.hWnd)				 ' no
SetWindowPos Proc.hWnd,0 , 0,0,0,0 , 2|1|$40|$200		 ' no
SetForegroundWindow(Proc.hWnd)				 ' flashes the window only
SetFocus Proc.hWnd					'no



BlitzSupport(Posted 2010) [#2]
SetForegroundWindow doesn't actually do what it sounds like it does -- see the Remarks section here for the 'rules' on getting to the front:

http://msdn.microsoft.com/en-us/library/ms633539(VS.85).aspx

In short, your program isn't allowed to steal focus from the current foreground app, just bring one of its own windows up-front if it is the foreground app.

See the code at the bottom of the link below for use of AttachThreadInput to cheat, which is apparently quite a common way to do this... but it's very much frowned upon to force your way to the front -- and I'd be one of the frowners!

http://www.drdobbs.com/cpp/184405755;jsessionid=DW11B2SQ11DP3QE1GHPCKH4ATMY32JVN


EOF(Posted 2010) [#3]
.. use of AttachThreadInput to cheat, which is apparently quite a common way to do this... but it's very much frowned upon to force your way to the front -- and I'd be one of the frowners!

I agree but in my case it's a legitimate cause ..

The graphics (game window) is permanently running. I also have the BlitzMax IDE running. The game window monitors changes to script code (*Lua) being saved from the IDE. It then auto-reloads and plays the new code

The problem is, the IDE is usually covering most of the game window and maintains focus for keyboard input. I want the running game window to regain control as well as come to the front of the IDE (or indeed any other window such as NotePad)

From what I see in the AttachThreadInput trick there is one area I am not clear on:

	HWND hOtherWnd = FindWindow( ... );
	if (hOtherWnd)
	{
		DWORD hMyThread = GetWindowThreadProcessId( m_hWnd,NULL );
		DWORD hOtherThread = GetWindowThreadProcessId( hOtherWnd,NULL);

Ok, I can find the game window but I don't know what the m_hWnd refers to?
The running game would only know about it's own window created by Graphics() ??


BlitzSupport(Posted 2010) [#4]
That would be the *current* foreground window (you're kinda trying to share its thread) -- here's someone else's (PureBasic) code that does what you want:

http://www.purebasic.fr/english/viewtopic.php?f=12&t=7424


EOF(Posted 2010) [#5]
Thanks James

I get the idea and now have the desired effect working. The game (graphics) window pops to the front in an activated state with keyboard focus

However, something is not quite right ...

It does not correctly lose focus when I click away from it. If I click the desktop the game window remains active. I have to click the previous threads window (the editor for example), then the game window, finally the previous threads window again

There is something missing in the chain and I guess BlitzMax is monitoring for a specific sequence messages ???

I have tried issuing various "SendMessage" options such as mouse clicks, mouse down, mouse up, activate, activateapp, but I am at a loss at the moment


_PJ_(Posted 2010) [#6]
I admit I'm nowhere near as knowledgeable in this stuff, and certainly don't have BMax, but perhaps you ened a combination of James' sugegstion to 'grab' focus, and something else (I've seen examples around at least for BB/B3D) to check if focus is 'lost'

Also if it helps,
Windows API has a flag for NOT_TOPMOST.