Make Window Stay On Top
-
I'm not too saavy in Visual C++ programming as most of my C/CPP has been in embedded platforms. I'm working on a host application which is a VC++ window. Essentially, for this one particular window I want it to stay on top all the time. I have added some code that was given to me by someone who has done it in another application before, but it does not seem to be working in mine. Can anyone help? Here is what I have:
CWnd appWnd; // the application CWnd CWnd *pAppWnd; // a pointer to CWnd pAppWnd = & appWnd; pAppWnd = AfxGetMainWnd(); if (NULL != pAppWnd) { HWND appHandle; // window handle appHandle = pAppWnd->GetSafeHwnd(); if (NULL != appHandle) { targetObj.m_pAppWnd = pAppWnd; } } // Cause window to stay on top targetObj.m_bWindowStayOnTop = TRUE;
targetObj is another class which is essentially being called by this (no "gui" elements in that class) and in that class, inside of a loop that he is in, I have this part:
// Used to keep parent window (test module) on top if (TRUE == this->m_bWindowStayOnTop) { BOOL bReturn = FALSE; if (NULL != this->m_pAppWnd) { bReturn = this->m_pAppWnd->SetForegroundWindow(); } }
It seems that the return from SetForegroundWindow() is 0 which means it is failing. But I don't know why! Any ideas?
There are only 10 types of people in this world....those that understand binary, and those that do not.
-
I'm not too saavy in Visual C++ programming as most of my C/CPP has been in embedded platforms. I'm working on a host application which is a VC++ window. Essentially, for this one particular window I want it to stay on top all the time. I have added some code that was given to me by someone who has done it in another application before, but it does not seem to be working in mine. Can anyone help? Here is what I have:
CWnd appWnd; // the application CWnd CWnd *pAppWnd; // a pointer to CWnd pAppWnd = & appWnd; pAppWnd = AfxGetMainWnd(); if (NULL != pAppWnd) { HWND appHandle; // window handle appHandle = pAppWnd->GetSafeHwnd(); if (NULL != appHandle) { targetObj.m_pAppWnd = pAppWnd; } } // Cause window to stay on top targetObj.m_bWindowStayOnTop = TRUE;
targetObj is another class which is essentially being called by this (no "gui" elements in that class) and in that class, inside of a loop that he is in, I have this part:
// Used to keep parent window (test module) on top if (TRUE == this->m_bWindowStayOnTop) { BOOL bReturn = FALSE; if (NULL != this->m_pAppWnd) { bReturn = this->m_pAppWnd->SetForegroundWindow(); } }
It seems that the return from SetForegroundWindow() is 0 which means it is failing. But I don't know why! Any ideas?
There are only 10 types of people in this world....those that understand binary, and those that do not.
::SetWindowPos(HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); If that works, I am a superman, seeing as I've done nothing like this for years. It's damn close though. setwindowpos takes as it's first parameter a value that allows you to make a window move to the top or bottom, or make it topmost (i.e. top and stay there ). You pass whatever you like for the position and size, and use flags to make them irrelevant. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
-
::SetWindowPos(HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); If that works, I am a superman, seeing as I've done nothing like this for years. It's damn close though. setwindowpos takes as it's first parameter a value that allows you to make a window move to the top or bottom, or make it topmost (i.e. top and stay there ). You pass whatever you like for the position and size, and use flags to make them irrelevant. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
You are my superman! ;) It wasn't exactly right, but (hang on..moving window now in my way)....it was damn close! :) Appreciated!
There are only 10 types of people in this world....those that understand binary, and those that do not.
-
You are my superman! ;) It wasn't exactly right, but (hang on..moving window now in my way)....it was damn close! :) Appreciated!
There are only 10 types of people in this world....those that understand binary, and those that do not.
KingTermite wrote: hang on..moving window now in my way).... LOL - brilliant. And you're welcome :-) Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder