How do I know what a gadget is displayed?

Just starting out? Need help? Post your questions and find answers here.
mestnyi
Addict
Addict
Posts: 999
Joined: Mon Nov 25, 2013 6:41 am

How do I know what a gadget is displayed?

Post by mestnyi »

That is, I need an event after the gadget is displayed.
Here is an example of what I need but only more correct.
Can anyone help me? Thank you in advance.
And it is very desirable cross-platform.

Code: Select all

; Module
#PB_EventType_Show = #PB_EventType_FirstCustomValue

Procedure CallBack()
  
  Select EventType()
    Case #PB_EventType_Show
      Debug "show"
  EndSelect
  
EndProcedure

Procedure TimerCallBack()
  
  If IsWindowVisible_(GadgetID(0))
    RemoveWindowTimer(0, EventTimer())
    PostEvent(#PB_Event_Gadget, 0,0, #PB_EventType_Show)
  EndIf
  
EndProcedure

Procedure Gadget(Window, Gadget, X.l, Y.l, Width.l, Height.l)
  AddWindowTimer(Window, 1, 10)
  CanvasGadget(Gadget, X, Y, Width, Height) 
  
  BindGadgetEvent(Gadget, @CallBack())
  BindEvent(#PB_Event_Timer, @TimerCallBack(), Window)
EndProcedure

; EndModule



If OpenWindow(0, 0, 0, 220, 220, "CanvasGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  
  Gadget(0, 0, 10, 10, 200, 200)
  
  ;   HideGadget(0,1)
  
  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow
EndIf
mestnyi
Addict
Addict
Posts: 999
Joined: Mon Nov 25, 2013 6:41 am

Re: How do I know what a gadget is displayed?

Post by mestnyi »

Do not pass by write do not hesitate. :D Here's another version without using the window id (which is important).
This option would suit me more only there is no cross-platform.

Code: Select all

; Module
Enumeration  #PB_EventType_FirstCustomValue
  #PB_EventType_Show
  #PB_EventType_Timer
EndEnumeration

Procedure TimerStart(hWnd, TimerId, Delay, ProcedureAdress)
  SetTimer_(hWnd,TimerId,Delay,ProcedureAdress)
EndProcedure

Procedure TimerKill(hWnd, TimerId)
  KillTimer_(hWnd, TimerId)
EndProcedure

Procedure CallBack()
  
  Select EventType()
    Case #PB_EventType_Show
      Debug "show"
    Case #PB_EventType_Timer
      Debug "Timer"
  EndSelect
  
EndProcedure

Procedure TimerCallBack(hwnd.l, uMsg.l, *idEvent, dwTime.w); 
  
  If *idEvent = 0 And IsWindowVisible_(hwnd)
    PostEvent(#PB_Event_Gadget, GetProp_(GetParent_(hwnd), "PB_WindowID")-1, GetDlgCtrlID_(hwnd), #PB_EventType_Show)
    TimerKill(hWnd,*idEvent)
  Else
    PostEvent(#PB_Event_Gadget, GetProp_(GetParent_(hwnd), "PB_WindowID")-1, GetDlgCtrlID_(hwnd), #PB_EventType_Timer)
  EndIf
  
EndProcedure 

Procedure Gadget(Gadget, X.l, Y.l, Width.l, Height.l, time=0)
  CanvasGadget(Gadget, X, Y, Width, Height) 
  
  TimerStart(GadgetID(Gadget), 0, 1, @TimerCallBack())
  
  If time
    TimerStart(GadgetID(Gadget), 1, time, @TimerCallBack())
  EndIf
  
  BindGadgetEvent(Gadget, @CallBack())
EndProcedure

; EndModule



If OpenWindow(10, 0, 0, 220, 220, "CanvasGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  
  Gadget(10, 10, 10, 200, 200, 500)
  
  ;   HideGadget(0,1)
  
  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow
EndIf
mestnyi
Addict
Addict
Posts: 999
Joined: Mon Nov 25, 2013 6:41 am

Re: How do I know what a gadget is displayed?

Post by mestnyi »

Code: Select all

EnableExplicit

Global GadgetCB

Procedure ButtonCB(hWnd, Message, wParam, lParam)
  Select Message
    Case 133
      If IsWindowVisible_(hwnd)
        Debug "Show"
      EndIf
  EndSelect
  
  ProcedureReturn CallWindowProc_(GadgetCB, hWnd, Message, wParam, lParam)
EndProcedure

If OpenWindow(0, 0, 0, 500, 400, "Window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  CanvasGadget(1, 10, 10, 100, 20)
  
  ;HideGadget(1,1)
  GadgetCB = SetWindowLongPtr_(GadgetID(1), #GWL_WNDPROC, @ButtonCB())
  
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        End
    EndSelect
  ForEver
EndIf
Post Reply