Page 1 of 1

IsHideWindow

Posted: Sun Aug 09, 2015 5:52 pm
by User_Russian
I propose to add a function IsHideWindow, that would be similar to WinAPI functions IsWindowVisible.
Now in PB can not be determined visible window.

Re: IsHideWindow

Posted: Sun Aug 09, 2015 8:27 pm
by BasicallyPure
I would vote for this feature.
+1

Re: IsHideWindow

Posted: Sun Aug 09, 2015 8:40 pm
by davido
+1

Re: IsHideWindow

Posted: Sun Aug 09, 2015 8:52 pm
by RSBasic
+1

Re: IsHideWindow

Posted: Sun Aug 09, 2015 10:37 pm
by minimy
+1

Re: IsHideWindow

Posted: Mon Aug 10, 2015 12:28 am
by Amilcar Matos
+1

Re: IsHideWindow

Posted: Mon Aug 10, 2015 11:24 am
by Karellen
Yes, this would be usefull! Instead of adding another command I suggest to add #PB_Window_Hidden to Set/GetWindowState() and declare HideWindow() deprecated.

Re: IsHideWindow

Posted: Mon Aug 10, 2015 4:39 pm
by BasicallyPure
Karellen wrote:Yes, this would be usefull! Instead of adding another command I suggest to add #PB_Window_Hidden to Set/GetWindowState() and declare HideWindow() deprecated.
I had this same thought as well but after thinking about it further I decided it would not work.
That is why my post above shows two edits.
Here is why I think it will not work.
GetWindowState() returns a single value.
This is fine as it is now because the window can be in one of three states, normal, maximized, or minimized.
These states are exclusive, the window cannot be in two of these states at one time.
Now if you add "Hidden" to the mix the states are no longer exclusive.
The window can be (normal hidden),( maximized not hidden), (minimized hidden) etc.
The state can no longer be expressed by returning a single value.

It could be made to work if different bits of the return value are used to indicate the states.
You would have to decode the return value using the bitwise and operator '&' with the constant indicating the state of interest.
This would be similar to the way GetGadgetItemState() works.

Re: IsHideWindow

Posted: Mon Aug 10, 2015 4:48 pm
by oreopa
This would be nice for crossplatform. I concur. +1

Re: IsHideWindow

Posted: Mon Aug 10, 2015 5:57 pm
by Karellen
BasicallyPure wrote:
Karellen wrote:These states are exclusive, the window cannot be in two of these states at one time.
True, you're right! Should think longer before posting a suggestion... :oops:
Sounds like that IsWindowHidden() seems to be the way!

+1 anyway

Re: IsHideWindow

Posted: Mon Aug 10, 2015 7:54 pm
by Trond
But you hid it, so you know it's hidden. No need to check. Use a variable to keep track of it, if needed.

Re: IsHideWindow

Posted: Mon Aug 10, 2015 8:55 pm
by User_Russian
Trond, If we follow your logic, then the PB need to remove function GetWindowState, GetWindowColor, WindowX, WindowY, and many others, because you can use a variable. But will it be convenient?

Re: IsHideWindow

Posted: Tue Aug 11, 2015 8:27 am
by mestnyi
+1

Code: Select all

CompilerIf Not Defined(IsHideWindow, #PB_Function)
  CompilerIf #PB_Compiler_OS =#PB_OS_Linux And  Not Defined(gtk_widget_get_visible, #PB_Procedure)
    ImportC ""
      gtk_widget_get_visible(*widget.GtkWidget)
    EndImport
  CompilerEndIf
  
  ProcedureDLL IsHideWindow(Window, State = -1, Flags = 0) ;Returns TRUE is window (from number or handle) hidden
    If IsWindow(Window)
      If State = -1
        CompilerIf #PB_Compiler_OS = #PB_OS_Windows 
          If Not IsWindowVisible_(WindowID(Window))
            ProcedureReturn #True
          EndIf
        CompilerElseIf #PB_Compiler_OS = #PB_OS_Linux
          If Not gtk_widget_get_visible(WindowID(Window))
            ProcedureReturn #True
          EndIf 
        CompilerElseIf #PB_Compiler_OS = #PB_OS_MacOS
          If Not CocoaMessage(0, WindowID(Window), "isVisible")
            ProcedureReturn #True
          EndIf 
        CompilerEndIf
      Else
        HideWindow(Window, State, Flags)
      EndIf
    EndIf
  EndProcedure :Macro HideWindow( Window, State = -1, Flags = 0 ) :IsHideWindow( Window, State, Flags ) :EndMacro
CompilerEndIf

CompilerIf #PB_Compiler_IsMainFile
  Window = OpenWindow(#PB_Any,0,0,200,40,"Show Window_0",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
  ShowHide = ButtonGadget(#PB_Any,5,5,190,30,"Hide Window_0?")
  
  Window_0 = OpenWindow(#PB_Any,20,10,250,200,"Show Window_0",#PB_Window_SystemMenu|#PB_Window_NoActivate)
  Window_1 = OpenWindow(#PB_Any,320,10,250,200,"Show Window_1",#PB_Window_SystemMenu|#PB_Window_Invisible|#PB_Window_NoActivate)
  StickyWindow(Window,#True)
  
  Repeat 
    Event = WaitWindowEvent()
    If Event = #PB_Event_Gadget And EventGadget() = ShowHide
      If HideWindow(Window_1)
        HideWindow(Window_1, #False, #PB_Window_NoActivate)
        HideWindow(Window_0, #True)
        SetGadgetText(ShowHide, "Hide Window_1?")
        SetWindowTitle(Window, "Show Window_1")
      Else
        HideWindow(Window_0, #False, #PB_Window_NoActivate)
        HideWindow(Window_1, #True)
        SetGadgetText(ShowHide,"Hide Window_0?")
        SetWindowTitle(Window,"Show Window_0")
      EndIf  
    EndIf 
  Until Event = #PB_Event_CloseWindow
CompilerEndIf

; IDE Options = PureBasic 5.24 LTS (Windows - x64)
; CursorPosition = 46
; FirstLine = 17
; Folding = 8-
; EnableUnicode
; EnableXP
wilbert thank :)

Re: IsHideWindow

Posted: Tue Aug 18, 2015 11:21 am
by minimy
very good mestnyi! very clever! :D
Thanks for that!

Re: IsHideWindow

Posted: Tue Aug 18, 2015 11:30 am
by wilbert
@mestnyi, for OSX you can get the info like this

Code: Select all

If Not CocoaMessage(0, WindowID(Window), "isVisible")