Resume UWP app in Windows 10

delphi package - easy access to kernel objects etc.
Post Reply
giociampa
Posts: 3
Joined: Tue Jan 04, 2022 11:02 am

Resume UWP app in Windows 10

Post by giociampa »

Our (Delphi 11) app allows the user to trigger the Windows calculator from the menu, and once open to restore it to the foreground using the same menu item, using the following (where wnd is the window handle of the app)

Code: Select all

ShowWindow(wnd, SW_SHOWNORMAL);
SetForegroundWindow(wnd);
However, if the calculator is minimised (or closed) then that fails to restore the calculator to the foreground as the Windows 10 calculator is a UWP app which is in a suspended state.

As I understand it - the process needs to be resumed from the suspended state before it can be brought to the foreground, so I first tried to resume the process as a whole (pid is the process ID):

Code: Select all

processList := Processes();
for processIndex := 0 to processList.ItemCount - 1 do begin
  processItem := processList.Items[processIndex];
  if processItem.ID = pid then
    processItem.Resume;
  end;
end;
and, when that failed to work, attempting to resume the constituent threads individually (in addition to the process):

Code: Select all

processList := Processes();
for processIndex := 0 to processList.ItemCount - 1 do begin
  processItem := processList.Items[processIndex];
  if processItem.ID = pid then begin
    threadList := processItem.Threads;
    for threadIndex := 0 to threadList.ItemCount - 1 do begin
      threadItem := threadList.Items[threadIndex];
      if threadItem.IsSuspended then
        threadItem.Resume();
    end;
    processItem.Resume;
  end;
end;
Neither variation has been successful, so the obvious question is "What have I done wrong?"
madshi
Site Admin
Posts: 10820
Joined: Sun Mar 21, 2004 5:25 pm

Re: Resume UWP app in Windows 10

Post by madshi »

Good question, I wish I knew. Unfortunately, Microsoft doesn't really offer any APIs to resume suspended UWP apps. If you have a valid window handle, I suppose you could try send a WM_SYSCOMMAND / SC_RESTORE message to it, but I've no idea if that works.
giociampa
Posts: 3
Joined: Tue Jan 04, 2022 11:02 am

Re: Resume UWP app in Windows 10

Post by giociampa »

madshi wrote: Tue Jan 04, 2022 1:18 pm Good question, I wish I knew. Unfortunately, Microsoft doesn't really offer any APIs to resume suspended UWP apps. If you have a valid window handle, I suppose you could try send a WM_SYSCOMMAND / SC_RESTORE message to it, but I've no idea if that works.
Cheers - I'll try looking at that angle (I don't think I've seen it mentioned anywhere else)
giociampa
Posts: 3
Joined: Tue Jan 04, 2022 11:02 am

Re: Resume UWP app in Windows 10

Post by giociampa »

Looks like I've been applying ShowWindow and/or SetForegroundWindow to the wrong window handle as this code works, whether the window is open, closed, or minimised. (I found a reference to 'ApplicationFrameWindow' in another Delphi forum)

Code: Select all

wnd := FindWindow('ApplicationFrameWindow','Calculator');
if wnd = 0 then
  WinExec('calc.exe', SW_NORMAL)
else begin
  ShowWindow(wnd, SW_SHOWNORMAL);
  SetForegroundWindow(wnd);
end;
This does mean that the calls to the madKernel functions are redundant - making this query likewise so - apologies for taking up your time
Post Reply