It is currently Sat Oct 19, 2019 6:17 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 14 posts ] 
Author Message
 Post subject: Protected check boxes for ListIconGadget
PostPosted: Thu Oct 22, 2015 5:11 pm 
Offline
Enthusiast
Enthusiast

Joined: Tue May 26, 2009 2:11 pm
Posts: 599
Maybe this can be handy:
Code:
; 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


Top
 Profile  
Reply with quote  
 Post subject: Re: Protected check boxes for ListIconGadget
PostPosted: Thu Oct 22, 2015 6:08 pm 
Offline
Moderator
Moderator
User avatar

Joined: Thu Dec 31, 2009 11:05 pm
Posts: 1102
Location: Germany::Berlin()
Code:
#LVIS_UNCHECKED = $1000
#LVIS_CHECKED = $2000

_________________
ImageImageImageImage Image


Top
 Profile  
Reply with quote  
 Post subject: Re: Protected check boxes for ListIconGadget
PostPosted: Fri Oct 23, 2015 11:38 am 
Offline
Enthusiast
Enthusiast

Joined: Tue May 26, 2009 2:11 pm
Posts: 599
RSBasic wrote:
Code:
#LVIS_UNCHECKED = $1000
#LVIS_CHECKED = $2000

Thanks for answering.
But where can I read this info on MSDN?

_________________
Image


Top
 Profile  
Reply with quote  
 Post subject: Re: Protected check boxes for ListIconGadget
PostPosted: Fri Oct 23, 2015 12:07 pm 
Offline
Moderator
Moderator
User avatar

Joined: Thu Dec 31, 2009 11:05 pm
Posts: 1102
Location: Germany::Berlin()
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Protected check boxes for ListIconGadget
PostPosted: Sat Oct 24, 2015 10:40 am 
Offline
Enthusiast
Enthusiast

Joined: Tue May 26, 2009 2:11 pm
Posts: 599
RSBasic wrote:

Hm, I can't see any comment here?

_________________
Image


Top
 Profile  
Reply with quote  
 Post subject: Re: Protected check boxes for ListIconGadget
PostPosted: Sat Oct 24, 2015 11:44 am 
Offline
Moderator
Moderator
User avatar

Joined: Thu Dec 31, 2009 11:05 pm
Posts: 1102
Location: Germany::Berlin()
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Protected check boxes for ListIconGadget
PostPosted: Sun Oct 25, 2015 10:35 am 
Offline
Enthusiast
Enthusiast

Joined: Tue May 26, 2009 2:11 pm
Posts: 599
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Protected check boxes for ListIconGadget
PostPosted: Mon Feb 25, 2019 3:38 pm 
Offline
Enthusiast
Enthusiast

Joined: Tue May 26, 2009 2:11 pm
Posts: 599
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Protected check boxes for ListIconGadget
PostPosted: Sun Mar 03, 2019 10:30 am 
Offline
Enthusiast
Enthusiast

Joined: Tue May 26, 2009 2:11 pm
Posts: 599
Has nobody any idea how to protect and unprotect
checkboxes on TreeGadget during runtime as shown
for ListIconGadged in first posting?

_________________
Image


Top
 Profile  
Reply with quote  
 Post subject: Re: Protected check boxes for ListIconGadget
PostPosted: Sun Mar 03, 2019 1:36 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat May 05, 2007 5:31 pm
Posts: 623
Location: Linz, Austria
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:
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Protected check boxes for ListIconGadget
PostPosted: Sun Mar 03, 2019 3:09 pm 
Offline
Enthusiast
Enthusiast

Joined: Tue May 26, 2009 2:11 pm
Posts: 599
Hi chi!

That's what I was looking for. :idea:
Thank you very much for your help!

_________________
Image


Top
 Profile  
Reply with quote  
 Post subject: Re: Protected check boxes for ListIconGadget
PostPosted: Sun Mar 03, 2019 4:19 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat May 05, 2007 5:31 pm
Posts: 623
Location: Linz, Austria
Lord wrote:
Hi chi!

That's what I was looking for. :idea:
Thank you very much for your help!
You're welcome :D


Top
 Profile  
Reply with quote  
 Post subject: Re: Protected check boxes for ListIconGadget
PostPosted: Sun Mar 03, 2019 4:42 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3428
Enable/Disable icon , state & Buttons
Edit :
- chi is using window callback
- next using subclass
Code:
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Protected check boxes for ListIconGadget
PostPosted: Mon Mar 04, 2019 9:07 am 
Offline
Enthusiast
Enthusiast

Joined: Tue May 26, 2009 2:11 pm
Posts: 599
Thanks Rashad for your version, but I'm already using Chi's example.
However, it's always interesting to see alternative approaches.

_________________
Image


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

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


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