How can I make a modeless topmost for the desktop ?
-
I've got an application where I want a modeless dialog to stay on top of other applications. When I call SetWindowPos for the main window, this window stays on top of the others but when I try the same code for the modeless it just stay on top of its parent. The code is just basic SetWindowPos:
SetWindowPos(m_hWnd, NULL, 0, 0, 0, 0, HWND_TOPMOST);
Is there a trick or a way to make that modeless topmost ? or is it a problem from my program ? :) Yarp http://www.senosoft.com/ -
I've got an application where I want a modeless dialog to stay on top of other applications. When I call SetWindowPos for the main window, this window stays on top of the others but when I try the same code for the modeless it just stay on top of its parent. The code is just basic SetWindowPos:
SetWindowPos(m_hWnd, NULL, 0, 0, 0, 0, HWND_TOPMOST);
Is there a trick or a way to make that modeless topmost ? or is it a problem from my program ? :) Yarp http://www.senosoft.com/Just a guess, but you need to make the parent of your modeless dialog be the desktop, rather than your main window. You can se the *owner* of your dialog to be your main window... Iain.
-
Just a guess, but you need to make the parent of your modeless dialog be the desktop, rather than your main window. You can se the *owner* of your dialog to be your main window... Iain.
Sure, this is a good idea. If I can't find a clean solution I will try this. Doesn't mean your solution is a dirty one, just looking for the perfect one if any ;) Yarp http://www.senosoft.com/
-
I've got an application where I want a modeless dialog to stay on top of other applications. When I call SetWindowPos for the main window, this window stays on top of the others but when I try the same code for the modeless it just stay on top of its parent. The code is just basic SetWindowPos:
SetWindowPos(m_hWnd, NULL, 0, 0, 0, 0, HWND_TOPMOST);
Is there a trick or a way to make that modeless topmost ? or is it a problem from my program ? :) Yarp http://www.senosoft.com/ -
I've got an application where I want a modeless dialog to stay on top of other applications. When I call SetWindowPos for the main window, this window stays on top of the others but when I try the same code for the modeless it just stay on top of its parent. The code is just basic SetWindowPos:
SetWindowPos(m_hWnd, NULL, 0, 0, 0, 0, HWND_TOPMOST);
Is there a trick or a way to make that modeless topmost ? or is it a problem from my program ? :) Yarp http://www.senosoft.com/yarp wrote:
The code is just basic SetWindowPos: SetWindowPos(m_hWnd, NULL, 0, 0, 0, 0, HWND_TOPMOST); Is there a trick or a way to make that modeless topmost ?
Try this instead. SetWindowPos(&wndTopMost, 0, 0, 0, 0, SWP_NOSIZE); CWnd::SetWindowPos[^]
DEBUGGING : Removing the needles from the haystack.
-
I've got an application where I want a modeless dialog to stay on top of other applications. When I call SetWindowPos for the main window, this window stays on top of the others but when I try the same code for the modeless it just stay on top of its parent. The code is just basic SetWindowPos:
SetWindowPos(m_hWnd, NULL, 0, 0, 0, 0, HWND_TOPMOST);
Is there a trick or a way to make that modeless topmost ? or is it a problem from my program ? :) Yarp http://www.senosoft.com/I found a solution as suggested by Iain. The other ways din't work: Here's the function that makes it :
void CfrmImg::EnableStayOnTop(bool bDesktop) { // Desktop topmost if (bDesktop) { ::SetWindowLongPtr(m_hWnd, GWL_HWNDPARENT, NULL); ::SetWindowPos(m_hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); } // Application topmost else { if (::GetParent(m_hWnd)==NULL) ::SetWindowLongPtr(m_hWnd, GWL_HWNDPARENT, (LONG_PTR)frmMain->m_hWnd); ::SetWindowPos(m_hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); } }
I recall this is for a modeless dialog - don't know if it makes sense for modals. The SetWindowLongPtr with GWL_HWNDPARENT parameter is a dirty hack. MSDN says SetParent should be used instead, but with SetParent it didn't work (I presume I have to change the windows style as suggested by MSDN - this is a later clean up work). At the moment I'm happy with my stay on top function. Thanks all for your assistance. Yarp http://www.senosoft.com/