PanelGadget Tab Focus Event

Just starting out? Need help? Post your questions and find answers here.
SniffTheGlove
Enthusiast
Enthusiast
Posts: 122
Joined: Sat Nov 19, 2011 6:51 pm

PanelGadget Tab Focus Event

Post by SniffTheGlove »

Hi,

Looking for a way to detect when and what tab is clicked on a PanelGadget. ie the point when the tab gets the focus.

I came across this thread from 2007 http://www.purebasic.fr/english/viewtop ... ab+clicked

I prefer the NetMaestro code in the 3rd post over akj's 4th post as akj code detects the tab focus multiple times whereas NetMaestro code does the single detection.

I have a 4 tab PanelGadget. On Tab 3 I have a combobox that contains a list of files in a directory. To refresh this file list I have been using a separate button to reload the files into the combobox.

What I am trying to do is run the reload code when the Tab 3 get focus, thus getting rid of the reload button.

However I am not sure after hours of testing how to actually fire the reload code once the tab 3 is selected. The Netmaestro code is this...The change is detected in the procedure where is fires off a Debug, but I am not sure how to get it to fire an event that can detected with EventType

Code: Select all

Global oldproc, lastgadget, lastitem

Procedure WindowProc(hwnd, msg, wparam, lparam)
  Select msg
    Case #TCM_GETITEM

      gadget = GetDlgCtrlID_(hwnd)
      item = wparam
      If gadget<>lastgadget Or item<>lastitem
        lastgadget = gadget
        lastitem = item
        Debug "Gadget: "+Str(gadget)+", item: "+Str(item)
      EndIf

  EndSelect
       
 ProcedureReturn CallWindowProc_(oldproc, hwnd, msg, wparam, lparam)
EndProcedure


  If OpenWindow(0, 0, 0, 322, 220, "PanelGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) 
       PanelGadget (1, 10, 20, 290, 180)
          AddGadgetItem(1, -1, "Sub-Panel 1")
          AddGadgetItem(1, -1, "Sub-Panel 2")
          AddGadgetItem(1, -1, "Sub-Panel 3")
          AddGadgetItem(1, -1, "Sub-Panel 4")
        CloseGadgetList()
 
    oldproc = SetWindowLong_(GadgetID(1), #GWL_WNDPROC, @WindowProc())
    Repeat 
;*********************************
 Until WaitWindowEvent() = #PB_Event_CloseWindow
  EndIf
ie, what code to replace the asterisks to detect tab 3 and run some code.

eg

PS, as this code is from 2007, has things become easier in the last 10 years at detect a PanelGadget Tab Event

Thanks really much if you can answer.
User avatar
kenmo
Addict
Addict
Posts: 2032
Joined: Tue Dec 23, 2003 3:54 am

Re: PanelGadget Tab Focus Event

Post by kenmo »

#PB_EventType_Change and GetGadgetState()

Code: Select all

If OpenWindow(0, 0, 0, 322, 220, "PanelGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  PanelGadget (1, 10, 20, 290, 180)
    AddGadgetItem(1, -1, "Sub-Panel 1")
    AddGadgetItem(1, -1, "Sub-Panel 2")
    AddGadgetItem(1, -1, "Sub-Panel 3")
    AddGadgetItem(1, -1, "Sub-Panel 4")
  CloseGadgetList()
  
  Repeat
    Event = WaitWindowEvent()
    If (Event = #PB_Event_Gadget) And (EventType() = #PB_EventType_Change)
      Debug "Gadget: "+Str(EventGadget())+", item: "+Str(GetGadgetState(EventGadget()))
    EndIf
  Until Event = #PB_Event_CloseWindow
EndIf
SniffTheGlove
Enthusiast
Enthusiast
Posts: 122
Joined: Sat Nov 19, 2011 6:51 pm

Re: PanelGadget Tab Focus Event

Post by SniffTheGlove »

Thank you for your help :-)
Post Reply