void BringWindowToFront(HWND hWnd)
{
bool Result;
DWORD ForegroundWindowThreadID;
DWORD WindowThreadID;
if(hWnd != GetForegroundWindow())
{
ForegroundWindowThreadID = GetWindowThreadProcessId(GetForegroundWindow(), NULL);
WindowThreadID = GetWindowThreadProcessId(hWnd, NULL);
if(ForegroundWindowThreadID != WindowThreadID)
{
AttachThreadInput(ForegroundWindowThreadID, WindowThreadID, true);
SetForegroundWindow(hWnd);
AttachThreadInput(ForegroundWindowThreadID, WindowThreadID, false);
}
else
SetForegroundWindow(hWnd);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
HWND hWnd = FindWindow(L"QWidget", L"Panel Kontrolny Vidalii");
if(hWnd == NULL) ShowMessage("Nie odnaleziono okna!");
TRect wRect;
GetWindowRect(hWnd, &wRect);
BringWindowToFront(hWnd);
POINT cP;
GetCursorPos(&cP);
int dx = wRect.Left + 215;
int dy = wRect.Top + 245;
SetCursorPos(dx, dy);
mouse_event( MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0 );
mouse_event( MOUSEEVENTF_LEFTUP, 0, 0, 0, 0 );
SetCursorPos(cP.x, cP.y);
BringWindowToFront(this->Handle);
}