I want to write a program where it can help me maximize a window that has been minimized into the taskbar and bring it forward. Here is my current code:
procedure TryDisplayWindows;
var
indicator: HWND;
begin
indicator := FindWindow(nil, PChar('Untitled - Notepad'));
ShowMessage(Cardinal(indicator).toString);
if (indicator <> 0) then
begin
ShowWindow(indicator, SW_SHOWNORMAL);
SetForegroundWindow(indicator);
end
else
MessageDlg('This application might be running on other user', mtError,
[mbOk], 0, mbRetry);
end;
This existing code helps me to maximize a window by finding it's title name. However, this code only works if the program is running under the same user account. I'm looking for a code that can help me maximize the window even if it's running under local system account (SYSTEM). I have an external application with UI that tends to run under SYSTEM when I allow it to make changes to my PC during a UAC prompt.
Is there a way to maximize a window by using its process ID, or any other ways?
ShowWindow
and all the other window-related functions afterCreateWindow
. – Ken White Dec 4 '20 at 1:29CreateWindow
part. – EllynLyn Dec 4 '20 at 1:34CreateWindow
is used to create a window (as its name would indicate). It's how a window handle is first created. After that, all functions related to a window require that window handle in order to identify the window. So, as I said, except forCreateWindow
(which creates the window handle in the first place), all window-related functions require a window handle. – Ken White Dec 4 '20 at 1:38EnumWindows()
andGetWindowThreadProcessId()
to find top-levelHWND
(s) that belong to a given process ID. – Remy Lebeau Dec 4 '20 at 1:49ShowWindow
will always return me a false value" - per the documentation : "If the window was previously visible, the return value is nonzero. If the window was previously hidden, the return value is zero." So it is not a success/fail kind of return value, like you are probably thinking. – Remy Lebeau Dec 4 '20 at 15:33