Hi at all,
for my applikation I need on incoming message, if the window is in background, that it comes to foreground. The option if the window has come to front is changeable.
I tried it with SetForegroundWindow.
Following is happen.
If I start the applikation with the option is set, it works fine under XP, Vista, W2K3.
Now without starting the app new ich change the option and the window stays in background. Correct so far. Yet I switch the option back to bring the window to front.
Under Vista it works fine but under XP and W2K3 the applikation just blinking in the tastbar.
Now I tried to do it following:- Quote:
BOOL CMyViewClass::ForceForegroundWindow(HWND hWnd)
{
if(!hWnd || !::IsWindow(hWnd))
return FALSE;
HWND hWndCurrentWindow = ::GetForegroundWindow();
if(hWndCurrentWindow == NULL)
{
return ::SetForegroundWindow(hWnd);
}
DWORD dwCurProcId, dwCurThreadId = ::GetWindowThreadProcessId(hWndCurrentWindow, &dwCurProcId);
DWORD dwHWndProcId;
::GetWindowThreadProcessId(hWnd, &dwHWndProcId);
BOOL bReturn = FALSE;
if(dwHWndProcId == dwCurProcId)
{
bReturn = ::SetForegroundWindow(hWnd);
}
else
{
DWORD dwMyThreadId = ::GetCurrentThreadId();
if(::AttachThreadInput(dwMyThreadId, dwCurThreadId, TRUE))
{
//bReturn = ::SetForegroundWindow(hWnd);
HWND hActiveWnd = ::SetActiveWindow(hWnd);
if(hActiveWnd == NULL)
bReturn = ::SetForegroundWindow(hWnd);
else
bReturn = ::SetForegroundWindow(hActiveWnd);
//::SetFocus(hWnd);
::AttachThreadInput(dwMyThreadId, dwCurThreadId, FALSE);
}
else
{
bReturn = ::SetForegroundWindow(hWnd);
}
}
return bReturn;
}
|
The problem stays. With the Method SetActiveWindow nothing happens!
Now I have read that I could bring the window to front with SetWindowPos().
I´ve tried it in 3 ways:- Quote:
//1.)
this->SetWindowPos(&CWnd::wndTopMost, 0 ,0, 0, 0, SWP_SHOWWINDOW|SWP_NOREDRAW|SWP_NOSIZE|SWP_NOZORDE R);
//2.)
this->SetWindowPos(&CWnd::wndTopMost, 0 ,0, 0, 0, SWP_SHOWWINDOW|SWP_NOREDRAW|SWP_NOSIZE);
//3.)
this->SetWindowPos(&CWnd::wndTopMost, 0 ,0, 0, 0, SWP_SHOWWINDOW);
|
But with none of these tries the window come to front.
If it is really running to bring window to front with SetWindowPos can anyone explain me
how to use the method that it works???