Page 1 of 1

IsIconic_() fails for UWP windows

Posted: Fri Dec 13, 2019 1:26 pm
by BarryG
[Edit] My mistake. See my other post further below.

Original post:

This is strange. Press Win+I to open Win 10's "Settings" app, then run this code. It'll show 0. Then minimize the "Settings" window, and run this again. It still shows 0, as if the window isn't minimized. So how do we tell when a UWP window is actually minimized?

Note: The opposite API call of IsZoomed_() works perfectly to detect maximized UWP windows.

Code: Select all

hWnd=FindWindow_(0,"Settings")
Debug IsIconic_(hWnd)

Re: IsIconic_() fails for UWP windows

Posted: Fri Dec 13, 2019 4:36 pm
by RASHAD
Hi BarryG
Adapt it for your needs

Code: Select all

Prototype DwmGetWindowAttribute(hWnd,dwAttribute.l,*pvAttribute,cbAttribute.l)
Global DwmGWA.DwmGetWindowAttribute,hWnd,title${#MAX_PATH},class${#MAX_PATH}
#DWMWA_CLOAKED = 14

Procedure GetWinState()
  hWnd = FindWindow_(0, 0)
  Repeat
    hWnd = GetWindow_(hWnd, #GW_HWNDNEXT)
    If hWnd And IsWindowVisible_(hWnd) And GetWindowLongPtr_(hWnd, #GWL_HWNDPARENT) = 0
      GetWindowText_(hWnd, @title$, #MAX_PATH)
      GetClassName_(hWnd,@class$,#MAX_PATH)
       If class$ = "ApplicationFrameWindow" Or class$ = "Windows.UI.Core.CoreWindow"
        dll = OpenLibrary(#PB_Any,"DWMAPI.DLL")
        If dll
          DwmGWA = GetFunction(dll,"DwmGetWindowAttribute")
          If DwmGWA
            DwmGWA(hWnd,#DWMWA_CLOAKED,@Cloaked,SizeOf(Cloaked))
            If Cloaked = 0 And title$ = "Settings"
              If IsIconic_(hwnd)
                Debug "Minimized"
              ElseIf IsZoomed_(hwnd)
                Debug "Maximized"
              Else
                Debug "Normal"
              EndIf 
            EndIf
          EndIf
          CloseLibrary(dll)
        EndIf
      EndIf
    EndIf
  Until hWnd = 0
  ProcedureReturn #False
EndProcedure

GetWinState()

Re: IsIconic_() fails for UWP windows

Posted: Sat Dec 14, 2019 1:27 am
by BarryG
Thanks for your quick reply, Rashad. But I'm sorry to report it was a mistake on my part. Turns out there must be another (and invisible!) window on my PC called "Settings" that FindWindow_() has found, because when I check IsIconic_() with the following code, it works. Sorry to have wasted your time, but your code is still useful for me in other ways.

Code: Select all

Macro WaitForCtrlPress()
  Repeat : Sleep_(1) : Until GetAsyncKeyState_(#VK_CONTROL) & $8000 ; Is down.
  Repeat : Sleep_(1) : Until GetAsyncKeyState_(#VK_CONTROL)=0 ; Now wait for up.
EndMacro

Debug "Open Settings with Win+I, click it, then hit Ctrl"

WaitForCtrlPress()
hWnd=GetForegroundWindow_()
cap$=Space(100) : GetWindowText_(hWnd,cap$,100)
Debug "Got hWnd of: "+cap$
Debug "Now minimize it and hit Ctrl again"

WaitForCtrlPress()
Debug "IsIconic: "+Str(IsIconic_(hWnd))