ListIconGadget - resizing columns

Just starting out? Need help? Post your questions and find answers here.
Holly
User
User
Posts: 10
Joined: Sat May 24, 2003 6:05 am
Location: Tampa, Florida

ListIconGadget - resizing columns

Post by Holly »

Hi. I recently purchased PureBasic and am new to programming. Is there a way to lock the width of the columns in a ListIconGadget so that users cannot resize the width with their mouse? If not, what would be the best way of displaying information in columns and rows in which each item could be a clickable link and the width of the column could not be resized? Thanks.
Denis
Enthusiast
Enthusiast
Posts: 779
Joined: Fri Apr 25, 2003 5:10 pm
Location: Doubs - France

Post by Denis »

; Hi Holly,
;
; Here is an exemple with the second size column (index 1) locked.
; Second exemple locks all size columns (4 columns --> index 0 to 3).
;
; When you resize a column, there is many messages sending by the system
; and in particular HDN_... msg.
; Those msg are sending as WM_NOTIFY msg.
; After many tries, i get good result with HDN_ITEMCHANGING msg to lock size column..
; According MS doc, Return Value of HDN_ITEMCHANGING msg must be :

; FALSE To allow the changes

; TRUE To prevent them.

; So, to lock one or more size column, you must test in the window Callback procedure :

; if msg is WM_NOTIFY
; if so, if the value msg is HDN_ITEMCHANGING
; if so, you must detect wich column has been modified.
; if this or those columns must be locked, the callback have to retunr #true
; else the callback have to retunr #PB_ProcessPureBasicEvents
; in the first exemple, i test only the second column (index 1) to lock only size of column 2
; to get thoses values, you must use a var based on NMHEADER structure
; lParam from Callback function is a pointer to an NMHDR structure that contains
; the notification code and additional informations.
; HDN_ITEMCHANGING notification message notifies a header control's parent window
; that the attributes of a header item are about to change.


Code: Select all

; windows contants

#WM_NOTIFY              = $4E
#HDN_ITEMCHANGING       = #HDN_FIRST
; #HDN_ITEMCHANGINGW    = #HDN_FIRST - 20
; #HDN_ITEMCHANGED      = #HDN_FIRST - 1
; #HDN_ITEMCHANGEDW     = #HDN_FIRST - 21
; #HDN_ITEMCLICK        = #HDN_FIRST - 2
; #HDN_ITEMCLICKW       = #HDN_FIRST - 22
; #HDN_ITEMDBLCLICK     = #HDN_FIRST - 3
; #HDN_ITEMDBLCLICKW    = #HDN_FIRST - 23
; #HDN_DIVIDERDBLCLICK  = #HDN_FIRST - 5
; #HDN_DIVIDERDBLCLICKW = #HDN_FIRST - 25
; #HDN_BEGINTRACK       = #HDN_FIRST - 6
; #HDN_BEGINTRACKW      = #HDN_FIRST - 26
; #HDN_ENDTRACK         = #HDN_FIRST - 7
; #HDN_ENDTRACKW        = #HDN_FIRST - 27
; #HDN_TRACK            = #HDN_FIRST - 8
; #HDN_TRACKW           = #HDN_FIRST - 28

#true                   = 1
#false                  = 0

;PB ID constants
#MainWindow = 0
#ListIconGadget1 = 1


; Windows Structures 

Structure  NMHEADER  ; same structure as HD_NOTIFY
  hdr.NMHDR 
  iItem.l
  iButton.l
  pitem.l
EndStructure


;;========================================================================================================================  
;;========================================================================================================================  

Procedure WindowCallBack(Window, Message, wParam, lParam)
  ReturnValue = #PB_ProcessPureBasicEvents

  Select Message

      Case #WM_NOTIFY               ; test if message is a WM_NOTIFY one
      *NotifyMsgInfos.NMHEADER = lParam

            If  *NotifyMsgInfos\hdr\code = #HDN_ITEMCHANGING  ; test if value of msg is HDN_ITEMCHANGING

               If *NotifyMsgInfos\iItem = 1    ; first column with index 0
                   ReturnValue = #true
               EndIf
            EndIf
  EndSelect 
  ProcedureReturn ReturnValue
EndProcedure 



;;*****************************************************************************************************
;;*****************************************************************************************************

If OpenWindow(#MainWindow,0,0,320,300,#PB_Window_ScreenCentered |#PB_Window_SystemMenu,"")
   If CreateGadgetList(WindowID()) And ListIconGadget(#ListIconGadget1,1,1,299,299,"Colonne 1", 298/4 ,#PB_ListIcon_MultiSelect)
      AddGadgetColumn(#ListIconGadget1, 1, "Colonne 2",298/4)
      AddGadgetColumn(#ListIconGadget1, 2, "Colonne 3",298/4)
      AddGadgetColumn(#ListIconGadget1, 3, "Colonne 4",298/4)
   EndIf

   For i.b = 1 To 10
       AddGadgetItem(#ListIconGadget1, -1, "111"+Chr(10)+ "222"+Chr(10)+"333"+Chr(10)+ "444")
   Next i
   SetWindowCallback(@WindowCallBack())
EndIf 



;; PB event Loop
  Repeat
  Until WaitWindowEvent() = #PB_EventCloseWindow



;; second exemple, all size columns are locked

Code: Select all

;;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
;;\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
#WM_NOTIFY              = $4E
#HDN_ITEMCHANGING       = #HDN_FIRST
; #HDN_ITEMCHANGINGW    = #HDN_FIRST - 20
; #HDN_ITEMCHANGED      = #HDN_FIRST - 1
; #HDN_ITEMCHANGEDW     = #HDN_FIRST - 21
; #HDN_ITEMCLICK        = #HDN_FIRST - 2
; #HDN_ITEMCLICKW       = #HDN_FIRST - 22
; #HDN_ITEMDBLCLICK     = #HDN_FIRST - 3
; #HDN_ITEMDBLCLICKW    = #HDN_FIRST - 23
; #HDN_DIVIDERDBLCLICK  = #HDN_FIRST - 5
; #HDN_DIVIDERDBLCLICKW = #HDN_FIRST - 25
; #HDN_BEGINTRACK       = #HDN_FIRST - 6
; #HDN_BEGINTRACKW      = #HDN_FIRST - 26
; #HDN_ENDTRACK         = #HDN_FIRST - 7
; #HDN_ENDTRACKW        = #HDN_FIRST - 27
; #HDN_TRACK            = #HDN_FIRST - 8
; #HDN_TRACKW           = #HDN_FIRST - 28

#true                   = 1
#false                  = 0

;PB ID constants
#MainWindow             = 0
#ListIconGadget1        = 1


; Windows Structures 

Structure  NMHEADER
  hdr.NMHDR 
  iItem.l
  iButton.l
  pitem.l
EndStructure


;;========================================================================================================================  
;;========================================================================================================================  

Procedure WindowCallBack(Window, Message, wParam, lParam)
  ReturnValue = #PB_ProcessPureBasicEvents

  Select Message

      Case #WM_NOTIFY               ; test if message is a WM_NOTIFY one
      *NotifyMsgInfos.NMHEADER = lParam

            If  *NotifyMsgInfos\hdr\code = #HDN_ITEMCHANGING  ; test if value of msg is HDN_ITEMCHANGING

               If *NotifyMsgInfos\iItem >= 0  And  *NotifyMsgInfos\iItem < 4 ; all columns index (4 columns, index 0 to 3)
                   ReturnValue = #true
               EndIf
            EndIf
  EndSelect 
  ProcedureReturn ReturnValue
EndProcedure 



;;*****************************************************************************************************
;;*****************************************************************************************************

If OpenWindow(#MainWindow,0,0,300,300,#PB_Window_ScreenCentered |#PB_Window_SystemMenu,"")
   If CreateGadgetList(WindowID()) And ListIconGadget(#ListIconGadget1,1,1,299,299,"Colonne 1", 298/4 ,#PB_ListIcon_MultiSelect)
      AddGadgetColumn(#ListIconGadget1, 1, "Colonne 2",298/4)
      AddGadgetColumn(#ListIconGadget1, 2, "Colonne 3",298/4)
      AddGadgetColumn(#ListIconGadget1, 3, "Colonne 4",298/4)
   EndIf

   For i.b = 1 To 10
       AddGadgetItem(#ListIconGadget1, -1, "111"+Chr(10)+ "222"+Chr(10)+"333"+Chr(10)+ "444")
   Next i
   SetWindowCallback(@WindowCallBack())
EndIf 




  Repeat
  Until WaitWindowEvent() = #PB_EventCloseWindow


Denis
A+
Denis
Denis
Enthusiast
Enthusiast
Posts: 779
Joined: Fri Apr 25, 2003 5:10 pm
Location: Doubs - France

Post by Denis »

A liitle bit error in my comment (because i was trying with different columns):

If *NotifyMsgInfos\iItem = 1 ; first column with index 0

it's a comment error.

You must read :


If *NotifyMsgInfos\iItem = 1 ; second column with index 1
A+
Denis
Holly
User
User
Posts: 10
Joined: Sat May 24, 2003 6:05 am
Location: Tampa, Florida

Post by Holly »

Hi Denis,

Thank you so much for the detailed explanation. I appreciate all your effort. I will study your examples when I get home tonight.


Holly
Post Reply