Protected check boxes for ListIconGadget

Windows specific forum
Lord
Enthusiast
Enthusiast
Posts: 744
Joined: Tue May 26, 2009 2:11 pm

Protected check boxes for ListIconGadget

Post by Lord »

Maybe this can be handy:

Code: Select all

; Protected check boxes

EnableExplicit

Enumeration
  #MainWindow
EndEnumeration
Enumeration
  #LIG
  #Protect
  #Disable
EndEnumeration


Procedure myWndProc(hwnd, uMsg, wParam, lParam)
  Protected Result
  Result = #PB_ProcessPureBasicEvents 
  Select uMsg   
    Case #WM_NOTIFY     
      Protected *nmhdr.NMHDR = lParam     
      If *nmhdr\hwndFrom=GadgetID(#LIG)
        Select *nmhdr\code
          Case #LVN_ITEMCHANGING
            Protected *nmlv.NM_LISTVIEW = lParam           
            If *nmlv\uChanged=#LVIF_STATE
              Select *nmlv\uNewState
                Case 4096, 8192 ; try to uncheck/check list item
                  If GetGadgetState(#Protect); if #True -> protect
                    Result = #True
                  EndIf
              EndSelect
            EndIf
        EndSelect     
      EndIf 
  EndSelect
  ProcedureReturn Result
EndProcedure
Procedure LIGEvents()
  Debug "Still receive events while check boxes are protected"
EndProcedure
Procedure DisableLIG()
  DisableGadget(#LIG, GetGadgetState(#Disable))
EndProcedure

; Example

Define Row

OpenWindow(#Mainwindow, 10, 10, 320, 240, "Protected Check Boxes", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) 

ListIconGadget(#LIG, 10, 10, WindowWidth(#MainWindow)-20, WindowHeight(0)-60, "Column 1", 160,
               #PB_ListIcon_CheckBoxes|#PB_ListIcon_FullRowSelect|#PB_ListIcon_MultiSelect|#PB_ListIcon_GridLines)
BindGadgetEvent(#LIG, @LIGEvents())
ButtonGadget(#Protect, WindowWidth(#MainWindow)/3-25, WindowHeight(#MainWindow)-40, 50, 24, "Protect",#PB_Button_Toggle)
ButtonGadget(#Disable, WindowWidth(#MainWindow)/3*2-25, WindowHeight(#MainWindow)-40, 50, 24, "Disable",#PB_Button_Toggle)
BindGadgetEvent(#Disable, @DisableLIG())

For Row = 1 To 50
  AddGadgetItem(0,-1,"Row "+RSet(Str(Row),2,"0"))   
Next


SetWindowCallback(@myWndProc())   

Repeat
Until WaitWindowEvent()= #PB_Event_CloseWindow 
But my question is:
What are the constant names for 4096 and 8192 (List-View Item States)?

They are not mentioned here:
https://msdn.microsoft.com/de-de/librar ... 85%29.aspx

But they should be found there according to here:
https://msdn.microsoft.com/de-de/librar ... 85%29.aspx
Image
RSBasic
Moderator
Moderator
Posts: 1119
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

Re: Protected check boxes for ListIconGadget

Post by RSBasic »

Code: Select all

#LVIS_UNCHECKED = $1000
#LVIS_CHECKED = $2000
ImageImageImageImage Image
Lord
Enthusiast
Enthusiast
Posts: 744
Joined: Tue May 26, 2009 2:11 pm

Re: Protected check boxes for ListIconGadget

Post by Lord »

RSBasic wrote:

Code: Select all

#LVIS_UNCHECKED = $1000
#LVIS_CHECKED = $2000
Thanks for answering.
But where can I read this info on MSDN?
Image
RSBasic
Moderator
Moderator
Posts: 1119
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

Re: Protected check boxes for ListIconGadget

Post by RSBasic »

MSDN isn't always up to date.
But the user "Aezay" wrote a comment: https://msdn.microsoft.com/de-de/librar ... 85%29.aspx
ImageImageImageImage Image
Lord
Enthusiast
Enthusiast
Posts: 744
Joined: Tue May 26, 2009 2:11 pm

Re: Protected check boxes for ListIconGadget

Post by Lord »

Hm, I can't see any comment here?
Image
RSBasic
Moderator
Moderator
Posts: 1119
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

Re: Protected check boxes for ListIconGadget

Post by RSBasic »

I'm not logged in MSDN.
You can't see the comments below?
Image

Do you use NoScript or other add-ons for your browser?
I don't know.
ImageImageImageImage Image
Lord
Enthusiast
Enthusiast
Posts: 744
Joined: Tue May 26, 2009 2:11 pm

Re: Protected check boxes for ListIconGadget

Post by Lord »

Yes I'm using NoScript.
I did allow MSDN and its dependencies some time ago, but
it looks they changed some since then.

Now I can see the comments of "rostom lemmouchi" and "Aezay".

Thanks for pointing this out to me.
Image
Lord
Enthusiast
Enthusiast
Posts: 744
Joined: Tue May 26, 2009 2:11 pm

Re: Protected check boxes for ListIconGadget

Post by Lord »

Hello!

Sorry for diggin' up this old topic, but I'm curious if it
is possible to protect check boxes for a TreeGadget
in the same way as for the ListIconGadget?

Any info appreciated.
Image
Lord
Enthusiast
Enthusiast
Posts: 744
Joined: Tue May 26, 2009 2:11 pm

Re: Protected check boxes for ListIconGadget

Post by Lord »

Has nobody any idea how to protect and unprotect
checkboxes on TreeGadget during runtime as shown
for ListIconGadged in first posting?
Image
User avatar
chi
Addict
Addict
Posts: 829
Joined: Sat May 05, 2007 5:31 pm
Location: Linz, Austria

Re: Protected check boxes for ListIconGadget

Post by chi »

This should get you started... (Tested on WinXp, Win7 and Win10) For Xp, you'll need to investigate the keyboard part (Space key) by yourself ;)

Code: Select all

Global protect

#TVM_GETITEMSTATE = #TV_FIRST + 39

Procedure WndProc(hwnd, uMsg, wParam, lParam)
  Protected Result
  Result = #PB_ProcessPureBasicEvents
  Select uMsg
    Case #WM_NOTIFY
      If protect
        Protected *nmt.NMTREEVIEW = lParam
        Protected tvhti.TV_HITTESTINFO
        If *nmt\hdr\hwndFrom = GadgetID(0)
          If *nmt\hdr\code = #NM_CLICK ;mouse select
            GetCursorPos_(@tvhti\pt)
            ScreenToClient_(*nmt\hdr\hwndFrom, @tvhti\pt)
            If SendMessage_(*nmt\hdr\hwndFrom, #TVM_HITTEST, 0, @tvhti)
              If tvhti\hItem
                If tvhti\flags = #TVHT_ONITEMSTATEICON
                  ProcedureReturn 1
                EndIf
              EndIf
            EndIf
          ElseIf *nmt\hdr\code = -24 ;keyboard select (not working on WinXp...)
            ProcedureReturn 1
          EndIf
        EndIf
      EndIf
  EndSelect
  ProcedureReturn Result
EndProcedure

OpenWindow(0, 0, 0, 300, 500, "Protected Tree Checkboxes", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered|#PB_Window_Invisible)

TreeGadget(0, 10, 10, 180, 480, #PB_Tree_CheckBoxes)
For i=0 To 99
  AddGadgetItem(0, -1, "Item " + Str(i), 0, Random(2))
Next

ButtonGadget(1, 200, 10, 90, 30, "Protect", #PB_Button_Toggle)
ButtonGadget(2, 200, 50, 90, 30, "Disable", #PB_Button_Toggle)

SetWindowCallback(@WndProc())

HideWindow(0, #False)

Repeat
  event = WaitWindowEvent()
  Select event
    Case #PB_Event_Gadget
      Select EventGadget()
          
        Case 1
          protect = GetGadgetState(1)
          
        Case 2
          DisableGadget(0, GetGadgetState(2))
          
      EndSelect
  EndSelect
Until event = #PB_Event_CloseWindow
Et cetera is my worst enemy
Lord
Enthusiast
Enthusiast
Posts: 744
Joined: Tue May 26, 2009 2:11 pm

Re: Protected check boxes for ListIconGadget

Post by Lord »

Hi chi!

That's what I was looking for. :idea:
Thank you very much for your help!
Image
User avatar
chi
Addict
Addict
Posts: 829
Joined: Sat May 05, 2007 5:31 pm
Location: Linz, Austria

Re: Protected check boxes for ListIconGadget

Post by chi »

Lord wrote:Hi chi!

That's what I was looking for. :idea:
Thank you very much for your help!
You're welcome :D
Et cetera is my worst enemy
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4040
Joined: Sun Apr 12, 2009 6:27 am

Re: Protected check boxes for ListIconGadget

Post by RASHAD »

Enable/Disable icon , state & Buttons
Edit :
- chi is using window callback
- next using subclass

Code: Select all

Global oldTreeProc,iicon,istate,ibutton

Procedure TreeProc(hwnd, uMsg, wParam, lParam)
  Protected result, HitTest.TV_HITTESTINFO, item, tvitem.TV_ITEM
  Select uMsg 
      Case #WM_LBUTTONDOWN
          HitTest\pt\x = lParam & $FFFF
          HitTest\pt\y = (lParam >> 16) & $FFFF
          If SendMessage_(hwnd, #TVM_HITTEST, 0, HitTest)
              tvitem\mask = #TVIF_PARAM   
              tvitem\hItem = HitTest\hItem
              SendMessage_(hwnd, #TVM_GETITEM, 0, tvitem)
              item = tvitem\lParam
            If (HitTest\flags = #TVHT_ONITEMICON Or HitTest\flags = #TVHT_ONITEMLABEL) And iicon = 1 And (item = 0 Or item = 1)
              result = 1
            ElseIf HitTest\flags = #TVHT_ONITEMSTATEICON And istate = 1 And (item = 0 Or item = 1)
              result = 1
            ElseIf HitTest\flags = #TVHT_ONITEMBUTTON And ibutton = 1 And (item = 1 Or item = 15)
              result = 1
            Else                 
              result = CallWindowProc_(oldTreeProc, hwnd, uMsg, wParam, lParam) 
            EndIf             
          EndIf 
          
       Case #WM_LBUTTONDBLCLK
           result = 1
          
      Case #WM_KEYDOWN
        If wParam <> #VK_SPACE Or GetGadgetState(0) <> 0 Or GetGadgetState(0) <> 3
          result = CallWindowProc_(oldTreeProc, hwnd, uMsg, wParam, lParam)
        EndIf
        
      Default
        result = CallWindowProc_(oldTreeProc, hwnd, uMsg, wParam, lParam)
    EndSelect
  ProcedureReturn result
EndProcedure

If OpenWindow(0, 0, 0, 350, 250, "Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  TreeGadget(0, 10, 10, 330, 180, #PB_Tree_CheckBoxes)
  AddGadgetItem (0, -1, "Normal Item "+Str(a), 0, 0)
    AddGadgetItem (0, -1, "Node "+Str(a), 0, 0)
    AddGadgetItem(0, -1, "Sub-Item 1", 0, 1)
    AddGadgetItem(0, -1, "Sub-Item 2", 0, 1)
    AddGadgetItem(0, -1, "Sub-Item 3", 0, 1)
    AddGadgetItem(0, -1, "Sub-Item 4", 0, 1)
    AddGadgetItem (0, -1, "File "+Str(a), 0, 0)
  For a = 0 To 4     
    AddGadgetItem (0, -1, "Node "+Str(a), 0, 0)
    AddGadgetItem(0, -1, "Sub-Item 1", 0, 1)
    AddGadgetItem(0, -1, "Sub-Item 2", 0, 1)
    AddGadgetItem(0, -1, "Sub-Item 3", 0, 1)
    AddGadgetItem(0, -1, "Sub-Item 4", 0, 1)
    AddGadgetItem (0, -1, "File "+Str(a), 0, 0)
  Next
  
  ButtonGadget(1,10,210,60,25,"iicon")
  ButtonGadget(2,80,210,60,25,"istate")
  ButtonGadget(3,150,210,60,25,"ibutton")
  
  oldTreeProc = SetWindowLongPtr_(GadgetID(0), #GWL_WNDPROC, @TreeProc())

  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        Quit = 1        
      
      Case #PB_Event_Gadget
        Select EventGadget()
          Case 1
            iicon ! 1
          Case 2
            istate ! 1
          Case 3
            ibutton ! 1            
        EndSelect
    EndSelect   
  Until Quit = 1 
EndIf 
Egypt my love
Lord
Enthusiast
Enthusiast
Posts: 744
Joined: Tue May 26, 2009 2:11 pm

Re: Protected check boxes for ListIconGadget

Post by Lord »

Thanks Rashad for your version, but I'm already using Chi's example.
However, it's always interesting to see alternative approaches.
Image
Post Reply