switch to app
BlitzMax Forums/BlitzMax Programming/switch to app
| ||
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? |
| ||
If you know the hWnd then you could use :-ShowWindow(myHwnd,SW_SHOWNORMAL); No idea what the Mac code would be. |
| ||
Thank you very much! How do I obtain myHwnd? |
| ||
Graphics 800, 600 global hWnd% = GetActiveWindow() '... ' Later in code it losses focus '... ' Bring back focus ShowWindow(hWnd, SW_SHOWNORMAL) should work Edit ^ |
| ||
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. |
| ||
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. |
| ||
You need to change the style using SetWindowLong to WS_EX_TOPWINDOW |
| ||
Think of this situation: I am running Banana, and I want to close Banana and switch to Orange, and bring Orange in focus :) |
| ||
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! |
| ||
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?) |
| ||
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 :-) |
| ||
Do they have different classes? ie. are they both BMAX? |
| ||
Why don't you just get the two applications to swap handles via windows messages. |
| ||
Both blitzmax apps... how would I get them to talk to each other? |
| ||
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. |
| ||
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() |
| ||
Thanks Tim! How do I switch to the other app though (bring it to full focus) and terminate this one? |
| ||
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. |
| ||
Thanks - my thinking was pretty closed. I didn't think ShowWindow would work on anything but the current app for some daft reason :) |