ListIconGadget with checkboxes

Just starting out? Need help? Post your questions and find answers here.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

ListIconGadget with checkboxes

Post by PB »

If I create a ListIconGadget with the #PB_ListIcon_CheckBoxes flag, is there
a way to have some items without a checkbox? I only want some to have a
checkbox, rather than all.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

There might be a better way, but these 2 methods work for me on WinXPhome with PB3.92.
Remove ListIconGadget checkboxes in WaitWindowEvent()

Code: Select all

If OpenWindow(0, 0, 0, 270, 150, #PB_Window_SystemMenu | #PB_Window_ScreenCentered, "ListIconGadget") And CreateGadgetList(WindowID(0)) 
  ListIconGadget(0, 10, 10, 250, 125, "Testing", 200, #PB_ListIcon_CheckBoxes)
  For a = 0 To 12 
    addtext$ = "Item index #" + Str(a) +  " in the ListIconGadget"
    AddGadgetItem(0, -1, addtext$)
  Next 
  ; --> Remove checkboxes for items 2, 3, 4
  For i = 2 To 4
  lv.LV_ITEM\mask = #LVIF_STATE
  lv\iItem = i
  lv\state = 0 << 12
  lv\stateMask = #LVIS_STATEIMAGEMASK
  SendMessage_(GadgetID(0), #LVM_SETITEMSTATE, i, lv)
  Next
  Repeat
    event = WaitWindowEvent()
    Select event
      Case #PB_EventGadget
        Select EventGadgetID()
          Case 0
            ; --> Remove checkboxes for items 2, 3, 4
            For i = 2 To 4
              SendMessage_(GadgetID(0), #LVM_SETITEMSTATE, i, lv)
            Next
        EndSelect
    EndSelect
  Until event =# PB_Event_CloseWindow 
EndIf 
End

Remove ListIconGadget checkboxes with SetWindowCallback()

Code: Select all

Procedure myWindowCallback(hwnd, msg, wparam, lparam)
  result = #PB_ProcessPureBasicEvents
  Select msg
    Case #WM_NOTIFY
      *nmNMHDR.NMHDR = lparam
      If *nmNMHDR\code = #LVN_ITEMCHANGED
        *lvm.NMLISTVIEW = *nmNMHDR
        ; --> Remove checkboxes for items 2, 3, 4
        If *lvm\iItem > 1 And *lvm\iItem < 5
          lv.LV_ITEM\mask = #LVIF_STATE
          lv\state = 0 << 12
          lv\stateMask = #LVIS_STATEIMAGEMASK
          SendMessage_(GadgetID(0), #LVM_SETITEMSTATE, *lvm\iItem, lv)
        EndIf
      EndIf
  EndSelect
  ProcedureReturn result
EndProcedure

If OpenWindow(0, 0, 0, 270, 150, #PB_Window_SystemMenu | #PB_Window_ScreenCentered, "ListIconGadget") And CreateGadgetList(WindowID(0)) 
  SetWindowCallback(@myWindowCallback())
  ListIconGadget(0, 10, 10, 250, 125, "Testing", 200, #PB_ListIcon_CheckBoxes)
  For a = 0 To 12 
    addtext$ = "Item index #" + Str(a) +  " in the ListIconGadget"
    AddGadgetItem(0, -1, addtext$)
  Next 
  Repeat
    event = WaitWindowEvent()
  Until event = #PB_Event_CloseWindow 
EndIf 
End
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

Thanks Sparkie! :)
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
TerryHough
Enthusiast
Enthusiast
Posts: 781
Joined: Fri Apr 25, 2003 6:51 pm
Location: NC, USA
Contact:

Post by TerryHough »

Nice, Sparkie!

One more question about the checkboxes.

Is it possible to change the character shown in a selected checkbox. For example, instead of showing a checkmark can that be an X instead?

Terry
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Thanks guys, glad to hear it works for you. :)

As for using x's in place of checkmarks, this seems to work ok. I'm not very good with 2DDrawing so I'm sure this can be optimized. If nothing else, it gives you a start in the right direction ;)

Code: Select all

If OpenWindow(0, 0, 0, 270, 150, #PB_Window_SystemMenu | #PB_Window_ScreenCentered, "ListIconGadget") And CreateGadgetList(WindowID(0)) 
  ListIconGadget(0, 10, 10, 250, 125, "Testing", 200, #PB_ListIcon_CheckBoxes)
  For a = 0 To 12 
    addtext$ = "Item index #" + Str(a) +  " in the ListIconGadget"
    AddGadgetItem(0, -1, addtext$)
  Next 
  ; --> Create our checked checkbox image with red x
  itemChecked = CreateImage(0, 16, 16)
  StartDrawing(ImageOutput())
  Box(0, 0, 16, 16, RGB(255, 255, 255))
  Box(1, 1, 14, 14, RGB(0, 0, 0))
  Box(3, 3, 10, 10, RGB(255, 255, 255))
  ; --> red line top left to bottom right
  LineXY(4, 4, 11, 11, RGB(255, 0, 0))
  LineXY(5, 4, 11, 10, RGB(255, 0, 0))
  LineXY(4, 5, 10, 11, RGB(255, 0, 0))
  ; --> red line bottom left to top right
  LineXY(4, 11, 11, 4, RGB(255, 0, 0))
  LineXY(4, 10, 10, 4, RGB(255, 0, 0))
  LineXY(5, 11, 11, 5, RGB(255, 0, 0))
  StopDrawing()
  ; --> Create our un-checked checkbox image with no red x
  itemUnchecked = CreateImage(1, 16, 16)
  StartDrawing(ImageOutput())
  Box(0, 0, 16, 16, RGB(255, 255, 255))
  Box(1, 1, 14, 14, RGB(0, 0, 0))
  Box(3, 3, 10, 10, RGB(255, 255, 255))
  StopDrawing()
  ; --> Create our new state imagelist for ListIconGadget 
  stateImageList= ImageList_Create_(16, 16, #ILC_COLOR32, 0, 2) 
  ImageList_Add_(stateImageList, itemUnchecked, 0)
  ImageList_Add_(stateImageList, itemChecked, 0)
  SendMessage_(GadgetID(0), #LVM_SETIMAGELIST, #LVSIL_STATE, stateImageList)
  ; --> Remove checkboxes for items 2, 3, 4
  For i = 2 To 4
    lv.LV_ITEM\mask = #LVIF_STATE
    lv\iItem = i
    lv\state = 0 << 12
    lv\stateMask = #LVIS_STATEIMAGEMASK
    SendMessage_(GadgetID(0), #LVM_SETITEMSTATE, i, lv)
  Next
  Repeat
    event = WaitWindowEvent()
    Select event
      Case #PB_EventGadget
        Select EventGadgetID()
          Case 0
            ; --> Remove checkboxes for items 2, 3, 4
            For i = 2 To 4
              SendMessage_(GadgetID(0), #LVM_SETITEMSTATE, i, lv)
            Next
        EndSelect
    EndSelect
  Until event =# PB_Event_CloseWindow 
EndIf 
End

What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
TerryHough
Enthusiast
Enthusiast
Posts: 781
Joined: Fri Apr 25, 2003 6:51 pm
Location: NC, USA
Contact:

Post by TerryHough »

Sparkie wrote: it gives you a start in the right direction ;)
Thanks Sparkie!

I played with a bit and ende up with this...

Code: Select all


  FontID1 = LoadFont(3, "Arial", 8, #PB_Font_Bold)
------------
  ; --> Create our checked checkbox image with an X 
  itemChecked = CreateImage(0, 16, 16) 
  StartDrawing(ImageOutput()) 
    Box(1, 1, 14, 14, RGB(255, 255, 255)) 
    DrawingFont(FontID1)  ; Select a drawing font
    FrontColor(255, 0, 0) ; Choose the color of the X here
    Locate(5, 1)          ; Locate the cursor and
    DrawText("X")         ; draw the X using the chosen drawing font
  StopDrawing() 

  ; --> Create our un-checked checkbox image
  itemUnchecked = CreateImage(1, 16, 16) 
  StartDrawing(ImageOutput()) 
    Box(1, 1, 14, 14, RGB(255, 255, 255)) 
  StopDrawing() 
which was exactly how I wanted it to appear.

That will get some users off my back as soon as I can implement this in
three programs.

Tnanks for your suggestions and ideas,
Terry
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Very nice Terry :)

I was so into drawing my pretty little red x's that I overlooked the fact that there was one sitting right in front of me on my keyboard. 8O :oops: :twisted:
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Post Reply