How to make BlitzMax app Always on Top
Archives Forums/Win32 Discussion/How to make BlitzMax app Always on Top
| ||
I have a full screen BlitzMax app that has to use system_() to call ghostscript to print a PDF. The problem is that it cases the shell window to pop up over the app while it runs. Is there a way to either force the app to be on top always or force the other one to be minimized when ran? |
| ||
I was trying to do exactly that a few days ago, and came up with this code quick & dirty snippet:?Win32 Extern "os" Function win32_LoadLibrary:Int(lpFileName$z) = "LoadLibraryA@4" Function win32_GetProcAddress:Byte Ptr(hModule:Int, lpProcName$z) = "GetProcAddress@8" End Extern ? Function SetAlwaysOnTop(win:TGadget, bState:Int = True) ?Win32 Local hModule:Int = win32_LoadLibrary("user32.dll") If hModule = 0 Then Return EndIf Local SetWindowPos:Int(hWnd:Int, hWndInsertAfter:Int, X:Int, Y:Int, cx:Int, cy:Int, uFlags:Int) "os" = win32_GetProcAddress(hModule, "SetWindowPos") Const HWND_TOPMOST = -1 Const HWND_NOTOPMOST = -2 Const SWP_NOSIZE = $0001 Const SWP_NOMOVE = $0002 'Const SWP_NOZORDER = $0004 'Const SWP_NOREDRAW = $0008 Const SWP_NOACTIVATE = $0010 Local hwnd% = QueryGadget(win, QUERY_HWND) If hwnd <> 0 Then If bState SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE) Else SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE) EndIf EndIf ? End Function I didn't even check yet if passing false actually makes it normal again. NOTE: the forum is buggy, it adds a "\" before "LoadLibraryA@4" and "GetProcAddress@8". They're not in the original code. |
| ||
Where is the TGadget type defined? |
| ||
Okay, so found the TGadget stuff (it is part of MaxGUI which I haven't ever used). I will do some reading into MaxGUI now ;) |
| ||
Well, doesn't look like MaxGUI is going to work for me. This is a full screen app that uses a lot of the Max2D functions. Or ist here a way to use MaxGUI along with that? |
| ||
You can use a canvas in a MaxGUI window, but not in fullscreen. If your window is fullscreen and your having problems with it not being "always on top" then theres no way to fix that. Technically when your program is full screen, it is "always on top" - unless an important window interrupts it (which is what I would assume is happening here). EDIT: Take a look at this (for always on top MaxGUI windows): automax.mod It contains a function for doing it, which you can just snag from the source if thats all you need. |
| ||
You can use the GetActiveWindow() command to get the HWND of the window created by the Graphics function and set it topmost that way. |
| ||
I've found that calling "ShowGadget()" Keeps a gadget on top. (This is for MaxGUI) If the window hides only after particular actions, just call "ShowGadget" on it, and it will remain on top of everything. If the hiding is occurring due to popups etc, I suppose you could call ShowGadget once every flip (assuming canvas-based graphics)... but I have no idea if this is a costly operation. |