switch to app

BlitzMax Forums/BlitzMax Programming/switch to app

Robert Cummings(Posted 2006) [#1]
Hi,

I'd like to order windows to switch back to my game. It has a valid mutex name but I do not know how to tell windows to switch back to the running task?


TartanTangerine (was Indiepath)(Posted 2006) [#2]
If you know the hWnd then you could use :-

ShowWindow(myHwnd,SW_SHOWNORMAL);


No idea what the Mac code would be.


Robert Cummings(Posted 2006) [#3]
Thank you very much!

How do I obtain myHwnd?


Diablo(Posted 2006) [#4]
Graphics 800, 600
global hWnd% = GetActiveWindow()
'...
' Later in code it losses focus
'...
' Bring back focus
ShowWindow(hWnd, SW_SHOWNORMAL)

should work

Edit ^


Grey Alien(Posted 2006) [#5]
Do you basically want to force the app to always be focused then? There is such a thing as making a window "modal" meaning always on top and you can't click anything else. You could look into that. Actually, thinking about it, that might only work *within* your app, e.g. if you had more than one window you can make it modal. Not sure.


Kanati(Posted 2006) [#6]
MS took out the option of making a program "system modal", but I know there's still a way to do it. Just not off the top of my head.


TartanTangerine (was Indiepath)(Posted 2006) [#7]
You need to change the style using SetWindowLong to WS_EX_TOPWINDOW


Robert Cummings(Posted 2006) [#8]
Think of this situation:

I am running Banana, and I want to close Banana and switch to Orange, and bring Orange in focus :)


Grey Alien(Posted 2006) [#9]
hmm so you need to get the handle of a different BMax program's window via the mutex name. Here's another possibility that works for me (in BlitzPlus):

In User32.decls (like doing an Extern)
User32_FindWindowA%(NullString,WindowText$):"FindWindowA"

Const FULLNAME = "Orange"
FindWindowA("",FULLNAME)		


this returns a handle ready for show window bababing!


Robert Cummings(Posted 2006) [#10]
What if there are two programs with the same name - can I return the HWND as well as the name (just so I can sort through several programs with the same name?)


Grey Alien(Posted 2006) [#11]
Hmm, I don't know if FindWindowA iterates through all possible windows, never tried it like that. If it did ... if two programs have the same name, you must know the current programs hWnd so could compare it against the one returned to see if it's different OR temporarily change your current app's name (just for a millisec) while you check for the other one :-)


TartanTangerine (was Indiepath)(Posted 2006) [#12]
Do they have different classes? ie. are they both BMAX?


TartanTangerine (was Indiepath)(Posted 2006) [#13]
Why don't you just get the two applications to swap handles via windows messages.


Robert Cummings(Posted 2006) [#14]
Both blitzmax apps... how would I get them to talk to each other?


TartanTangerine (was Indiepath)(Posted 2006) [#15]
Rob, if you would like to drop me a line via email I will give you some examples of how I do it with igLoader.


TartanTangerine (was Indiepath)(Posted 2006) [#16]
Rob, got your email and from what you are saying it's actually a lot easier than all that messaging stuff. The following code (Windows only) will prevent another instance of your application launching.

Extern "win32"
	Function Findwindow(lpClassName:Byte Ptr, lpWindowName:Byte Ptr) = "FindWindowA@8"
EndExtern

If FindWindow(Null,"Foo".tocstring())
	RuntimeError("Foo is already Running, this instance will now terminate")
EndIf

AppTitle = "Foo"
Graphics 200,200,0

WaitKey()



Robert Cummings(Posted 2006) [#17]
Thanks Tim! How do I switch to the other app though (bring it to full focus) and terminate this one?


TartanTangerine (was Indiepath)(Posted 2006) [#18]
1) Findwindow returns the handle of the other window
2) If a handle exists then Activate the other window by it's handle and terminate this instance, use the ShowWindow command.


Robert Cummings(Posted 2006) [#19]
Thanks - my thinking was pretty closed. I didn't think ShowWindow would work on anything but the current app for some daft reason :)