Hello,
I have a question about bringing windows to the foreground.
My application enumerates all windows to find a window with a title that contains (parts of) a given title.
When a window is found, it must be brought to the foreground.
I use the following code to do this:
void __fastcall TForm1::Button2Click(TObject *Sender)
{
AnsiString sTest = "notepad";
char *cTest = sTest.c_str();
// enumerate windows
EnumWindows((WNDENUMPROC)ShowAllWindows, (LPARAM)cTest);
}
//----------------------------------------------------------
BOOL CALLBACK ShowAllWindows(HWND hwnd,LPARAM lParam)
{
if (!hwnd) return TRUE; // Not a window
if(!IsWindow(hwnd)) return TRUE;
char pcWinTitle[255];
char* cTitle = (char*)lParam;
AnsiString sTest = (AnsiString)cTitle;
//if(GetWindow(hwnd, GW_OWNER) != NULL)
{
GetWindowText(hwnd, pcWinTitle, 255);
AnsiString sTemp = (AnsiString)pcWinTitle;
if(sTemp.Pos(sTest) != 0)
{
if (IsIconic(hwnd) != 0)
{
ShowWindowAsync(hwnd, SW_RESTORE);
}
// bring it to the foreground
SetForegroundWindow(hwnd);
return false; //stop enumeration
}
}
//continue enumeration
return TRUE;
}
//---------------------------------------------------
This code works fine to show windows that were NOT created with CBuilder5. It does NOT work for all my other CBuilder-programs...
Can anybody tell me what might be the cause of this issue?
Thanks in advance,
nick;
I have a question about bringing windows to the foreground.
My application enumerates all windows to find a window with a title that contains (parts of) a given title.
When a window is found, it must be brought to the foreground.
I use the following code to do this:
void __fastcall TForm1::Button2Click(TObject *Sender)
{
AnsiString sTest = "notepad";
char *cTest = sTest.c_str();
// enumerate windows
EnumWindows((WNDENUMPROC)ShowAllWindows, (LPARAM)cTest);
}
//----------------------------------------------------------
BOOL CALLBACK ShowAllWindows(HWND hwnd,LPARAM lParam)
{
if (!hwnd) return TRUE; // Not a window
if(!IsWindow(hwnd)) return TRUE;
char pcWinTitle[255];
char* cTitle = (char*)lParam;
AnsiString sTest = (AnsiString)cTitle;
//if(GetWindow(hwnd, GW_OWNER) != NULL)
{
GetWindowText(hwnd, pcWinTitle, 255);
AnsiString sTemp = (AnsiString)pcWinTitle;
if(sTemp.Pos(sTest) != 0)
{
if (IsIconic(hwnd) != 0)
{
ShowWindowAsync(hwnd, SW_RESTORE);
}
// bring it to the foreground
SetForegroundWindow(hwnd);
return false; //stop enumeration
}
}
//continue enumeration
return TRUE;
}
//---------------------------------------------------
This code works fine to show windows that were NOT created with CBuilder5. It does NOT work for all my other CBuilder-programs...
Can anybody tell me what might be the cause of this issue?
Thanks in advance,
nick;