I get all the apps from AppsFolder:
`ShellObject appsFolder = (ShellObject)KnownFolderHelper.FromKnownFolderId(AppEntry.AppsKnownFolderId);`
```which I enumerate and display each app in a list (name and icon from the shell object). The user selects an app from this list.
Using the AppUserModelId for the app selected from the list above, I enumerate all the processes and call
```ruby
`GetApplicationUserModelId(process.Handle, ref length, sb);`
```If the app isn't running (list is empty), I launch it. This works.
If the app is running (list is NOT empty), I get all the windows for the processes in the list:
```sql
`var handles = EnumerateProcessWindowHandles(process.Id);`
```I add all these to a list of window handles.
If none of these windows matches the `GetForegroundWindow();` (or foreground window's process ID is NOT among the ids of processes in the list), I restore the app windows enumerated for the processes in the list if necessary and set those windows (or the owner window) to foreground. This also appears to work.
However, for some AppUserModelIds (e.g. Calculator), if this list DOES contain the process id of the foreground (there's no problem when the foreground window is in the list of window handles), I don't seem to be able to `ShowWindow(hwnd, SW_MINIMIZE);` for the windows found for the processes, whether hwnd is in the list of window hands or retrieved via `GetWindow(windowHandle, GetWindowType.GW_OWNER);` for the handles in the list of window handles. (For others, like Excel, this works, but not for what appear to be packaged apps like Calculator.)
If it matters, I'm on Win11 (I need a solution that also works on Win10), and the app is using WinUI/WinAppSDK in c#.
I've been chasing this problem for the better part of a week. Answers with "This worked for me..." are more useful than "Have you tried..." since I've already tried a dozen approaches.
Anyone know how to accomplish this?