SRL Archive - Help and Support

ActivateClient flashes target but doesn't pop up


riwu

2015-02-25 02:11:23


processes:= GetProcesses();
for i:= 0 to High(processes) do
if Pos(toStr(TS.ID), Processes[i].Title) > 0 then
begin
SetTarget(processes[i]);
ActivateClient();
end;
I have the above code to bring the current SMART to the front (i.e. pop up if it's minimized), sometimes it worked, but sometimes SMART just flashed orange in taskbar but refused to pop up, any idea why?

Olly

2015-02-27 14:56:07

Indeed, It doesn't bring minimized windows to the front.

CynicRus

2015-02-27 15:43:28

From: riwu

processes:= GetProcesses();
for i:= 0 to High(processes) do
if Pos(toStr(TS.ID), Processes[i].Title) > 0 then
begin
SetTarget(processes[i]);
ActivateClient();
end;
I have the above code to bring the current SMART to the front (i.e. pop up if it's minimized), sometimes it worked, but sometimes SMART just flashed orange in taskbar but refused to pop up, any idea why?

This can help you with a window control. Maybe.

https://villavu.com/forum/showthread.php?t=99380&highlight=Bottinghelper

Brandon

2015-02-27 19:30:56

From: riwu
I have the above code to bring the current SMART to the front (i.e. pop up if it's minimized), sometimes it worked, but sometimes SMART just flashed orange in taskbar but refused to pop up, any idea why?


http://blogs.msdn.com/b/oldnewthing/archive/2009/02/20/9435239.aspx


^That's why it happens. In Windows, you cannot just "steal focus". You need to "request" it. If you need to force the stealing of focus, use:


ShowWindow(hwnd, SW_HIDE); //minimise the window.
ShowWindow(hwnd, SW_SHOW); //restore it.

SetWindowPos(hwnd, HWND_TOPMOST, NULL, NULL, NULL, NULL, SWP_NOMOVE | SWP_NOSIZE); //set the top most window.
SetWindowPos(hwnd, HWND_NOTOPMOST, NULL, NULL, NULL, NULL, SWP_NOMOVE | SWP_NOSIZE); /lock it at the top.
SetForegroundWindow(hwnd); //set it as the fore-ground window.

You only need to minimise and restore it IF you don't plan on alt-tabbing to it. Otherwise the alternative is to just alt-tab to the specified window. You MIGHT be able to get away with out the first two lines.

You can see the Simba devs using only SetForegroundWindow here: https://github.com/MerlijnWajer/Simba/blob/master/Units/MMLCore/os_windows.pas#L298