Actually if i understand correctly, what you trying to do is this...
You want to bring the window to front when another window has the foreground focus...
Regarding this matter Micro$oft, from version 98 of Windows and on decided to restrict the accessibility of this function, and now it should only work for windows that belong to the same thread...
This modification to the API was made due to the rise of adware, viruses, etc that would insert code to
STEAL the foreground window...
Therefore in order to successfully acheive stilling the foreground you must use the followin function i found in the web... it is in c++ but some one can translate it for you if you can't
code:
void ReallySetForegroundWindow( HWND hWnd )
{
DWORD foregroundThreadID; // foreground window thread
DWORD ourThreadID; // our active thread
// If the window is in a minimized state, maximize now
if (GetWindowLong(hWnd, GWL_STYLE) & WS_MINIMIZE)
{
ShowWindow(hWnd, SW_MAXIMIZE);
UpdateWindow(hWnd);
}
// Check to see if we are the foreground thread
foregroundThreadID = GetWindowThreadProcessId(GetForegroundWindow(),
NULL);
ourThreadID = GetCurrentThreadId();
// If not, attach our thread's 'input' to the foreground thread's
if (foregroundThreadID != ourThreadID)
AttachThreadInput(foregroundThreadID, ourThreadID, TRUE);
// Bring our window to the foreground
SetForegroundWindow(hWnd);
// If we attached our thread, detach it now
if (foregroundThreadID != ourThreadID)
AttachThreadInput(foregroundThreadID, ourThreadID, FALSE);
// Force our window to redraw
InvalidateRect(hWnd, NULL, TRUE);
}
What the code does is actually sends input to the thread that has the focus, and makes it think that the window belongs in that thread, thus successfully brings the window in front