It is currently Tue Nov 12, 2019 7:41 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: IsHwndVisible() for Win 10 compatibilty
PostPosted: Mon Jun 03, 2019 3:38 am 
Offline
Enthusiast
Enthusiast

Joined: Thu Apr 18, 2019 8:17 am
Posts: 381
Just discovered today that invisible Windows 10 UWP windows (like Calculator, Microsoft Store, Settings, Xbox, and such) can return non-zero with IsWindowVisible_(), which is obviously NOT the desired result. I did some research and came up with this procedure that will correctly return 0 if any window is invisible, 1 if it's visible, or -1 if not found or unable to be determined.

I purposely named it IsHwndVisible() so as not to clash with IsWindowVisible_() when searching/replacing your sources.

Code:
Prototype DwmGetWindowAttribute_(hWnd,dwAttribute.l,*pvAttribute,cbAttribute.l)
Procedure IsHwndVisible(hWnd)
  vis=-1 ; Means hWnd not found or couldn't determine visibility status.
  c$=Space(999)
  GetClassName_(hWnd,c$,999)
  If c$<>"ApplicationFrameWindow" And c$<>"Windows.UI.Core.CoreWindow" ; Normal Win32 window.
    vis=IsWindowVisible_(hWnd)
    If vis<>0 : vis=1 : EndIf
  Else ; Windows 10 UWP window, which can return non-zero for IsWindowVisible_() despite not shown!
    Define DwmGetWindowAttribute_.DwmGetWindowAttribute_
    #DWMWA_CLOAKED=14
    DWMAPIDLL=OpenLibrary(#PB_Any,"DWMAPI.DLL")
    If DWMAPIDLL
      DwmGetWindowAttribute_=GetFunction(DWMAPIDLL,"DwmGetWindowAttribute")
      If DwmGetWindowAttribute_ And DwmGetWindowAttribute_(hWnd,#DWMWA_CLOAKED,@Cloaked,SizeOf(Cloaked))=#S_OK
        If Cloaked=0
          vis=1
        Else
          vis=0
        EndIf
      EndIf
      CloseLibrary(DWMAPIDLL)
    EndIf
  EndIf
  ProcedureReturn vis
EndProcedure

Debug IsHwndVisible(FindWindow_(0,"Untitled - Notepad")) ; Standard Win32 window.
Debug IsHwndVisible(FindWindow_(0,"Microsoft Store"))    ; Windows 10 UWP window.


Top
 Profile  
Reply with quote  
 Post subject: Re: IsHwndVisible() for Win 10 compatibilty
PostPosted: Mon Jun 03, 2019 6:59 am 
Offline
Moderator
Moderator
User avatar

Joined: Thu Dec 31, 2009 11:05 pm
Posts: 1105
Location: Germany::Berlin()
Image

_________________
ImageImageImageImage Image


Top
 Profile  
Reply with quote  
 Post subject: Re: IsHwndVisible() for Win 10 compatibilty
PostPosted: Mon Jun 03, 2019 7:05 am 
Offline
Enthusiast
Enthusiast

Joined: Thu Apr 18, 2019 8:17 am
Posts: 381
Thanks RSBasic. :)

Here's one of the pages I found that led me to the solution:

https://social.msdn.microsoft.com/Forums/vstudio/en-US/0d7419a7-1d25-40bc-909e-a0db33b109a8/iswindowvisible-fails-to-detect-if-store-app-is-visible

It's pretty shocking that IsWindowVisible_() can't be relied on anymore. Really bad move, Microsoft - this will break a LOT of window-management tools.


Top
 Profile  
Reply with quote  
 Post subject: Re: IsHwndVisible() for Win 10 compatibilty
PostPosted: Thu Aug 22, 2019 11:27 am 
Offline
Enthusiast
Enthusiast

Joined: Thu Apr 18, 2019 8:17 am
Posts: 381
BTW, does the Prototype command have to go inside the procedure in my code? Or is it okay to stay outside? Are prototypes global?


Top
 Profile  
Reply with quote  
 Post subject: Re: IsHwndVisible() for Win 10 compatibilty
PostPosted: Thu Aug 22, 2019 4:09 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 07, 2007 3:25 pm
Posts: 3699
Location: Berlin, Germany
Prototypes have a global scope, like e.g. structures:

Code:
EnableExplicit

Procedure.d CalcAdd (value1.d, value2.d)
   ProcedureReturn value1 + value2
EndProcedure

Procedure.d CalcMul (value1.d, value2.d)
   ProcedureReturn value1 * value2
EndProcedure

Prototype.d ProtoCalc (value1.d, value2.d)


Procedure Main (value1.d, value2.d)
   Protected Calc.ProtoCalc
   
   Calc = @ CalcAdd()
   Debug Calc(value1, value2)
   
   Calc = @ CalcMul()
   Debug Calc(value1, value2)
EndProcedure


Main(2.5, 3.0)

_________________
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups


Top
 Profile  
Reply with quote  
 Post subject: Re: IsHwndVisible() for Win 10 compatibilty
PostPosted: Thu Aug 22, 2019 10:10 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu Apr 18, 2019 8:17 am
Posts: 381
Thanks, LJ!


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 12 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye