Updated:ComboBox Edit (Windows Only)

Share your advanced PureBasic knowledge/code with the community.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Updated:ComboBox Edit (Windows Only)

Post by RASHAD »

Edit ComboBox Live:

Code: Select all

Global Pos

OpenWindow(0, 200, 100, 300, 100 , "Edit CB List Live", #PB_Window_SystemMenu |#PB_Window_SizeGadget|#PB_Window_ScreenCentered)
    CB_1 = ComboBoxGadget(1, 10, 30, 280, 21,#PB_ComboBox_Editable)
      For a = 1 To 5
        AddGadgetItem(1, -1,"ComboBox item " + Str(a))
      Next
Repeat

  Select WaitWindowEvent()
  
    Case #PB_Event_Gadget        
        
        Select EventGadget()
          
          Case 1
            Result = GetGadgetState(1)
            If Result >= 0
            Pos = Result            
            EndIf
                                        
        EndSelect        
        
    Case #WM_CHAR
        String$ = GetGadgetText(1)          
       If EventwParam() = 13                         ;Return to confirm
            SetGadgetItemText(1,Pos, String$)
       ElseIf EventwParam() = 27                     ;Escape to reset
            SetGadgetState(1,Pos)
       ElseIf EventwParam() = 19                     ;Ctrl + S (Add At Start)
            AddGadgetItem(1, 0, String$)       
       ElseIf EventwParam() = 5                      ;Ctrl + E (Add At End)
            AddGadgetItem(1,-1, String$)
       ElseIf EventwParam() = 4                      ;Ctrl + D Delete
            RemoveGadgetItem(1, Pos)            
       EndIf
     
    Case #PB_Event_CloseWindow
      Quit = #True
     
  EndSelect
Until Quit
End
Advancd Hand Made ComboBox:

No Ownerdrawn, No API just PureBasic Native commands

1- Any No. of items per line
2- Can insert Image / Icon / Text per one line
3- Color control For each item
4- Can disable any item (Color = $C2C2C2 )
5- Can Delete any row

No limit To your imagination
You can add what you want

Code: Select all

Global Pos,WFlag,LI_1,hwnd_1,hwnd_2,hwnd_3,BG_1,Image0,Lih

LoadFont(0, "Marlett",10)
LoadFont(1, "Arial",10,#PB_Font_HighQuality)


Procedure WndProc(hwnd, uMsg, wParam, lParam)
             rw.RECT
             GetWindowRect_(hwnd_1, rw)   
result = #PB_ProcessPureBasicEvents  
 Select uMsg
 
        Case #WM_GETMINMAXINFO       
            *pMinMax.MINMAXINFO = lParam
            *pMinMax\ptMinTrackSize\x=640
            *pMinMax\ptMinTrackSize\y=400
            *pMinMax\ptMaxTrackSize\x=GetSystemMetrics_(#SM_CXSCREEN)
            *pMinMax\ptMaxTrackSize\y=GetSystemMetrics_(#SM_CYSCREEN)
      
        Case #WM_MOVE,#WM_SIZE        
             MoveWindow_(hwnd_2,rw\right-310,rw\top+50,282,Lih+6,1)
             MoveWindow_(hwnd_3,rw\right-310,rw\top+Lih+55,282,402,1)            
             
   EndSelect   
  ProcedureReturn result 
EndProcedure

Procedure FCombo()
result = #PB_ProcessPureBasicEvents
             rw.RECT
             GetWindowRect_(hwnd_1, rw)       
 hwnd_2 =    OpenWindow(2,rw\right-310,rw\top+50,282,25,"",#PB_Window_BorderLess|#WS_BORDER,WindowID(0))                          
      LI_1 = ListIconGadget(1,0,0,260,24,"", 30,#PB_ListIcon_GridLines|#LVS_NOCOLUMNHEADER)
             SetGadgetColor(1,#PB_Gadget_BackColor,$D7FFFF)      
             AddGadgetColumn(1,1,"",150)
             AddGadgetColumn(1,2,"",75)
             AddGadgetItem(1, 0, ""+Chr(10)+""+Chr(10)+"")
             SetGadgetFont(1, FontID(1))
       Lih = SendMessage_(LI_1, #LVM_GETITEMSPACING, 1, 0) >> 16
             MoveWindow_(hwnd_2,rw\right-310,rw\top+50,282,Lih+5,1)
             MoveWindow_(LI_1,0,0,260,Lih+4,1)
      BG_1 = ButtonGadget(2,260,0,20,Lih+3,Chr(117),#PB_Button_Toggle)
             SetGadgetFont(2, FontID(0))  

             
 hwnd_3 =    OpenWindow(3,rw\right-310,rw\top+Lih+55,280,400,"",#PB_Window_BorderLess|#WS_BORDER,WindowID(0))
      LI_2 = ListIconGadget(10,0,0,280,400,"Test1",30,#PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect|#LVS_NOCOLUMNHEADER)
             SetGadgetColor(10,#PB_Gadget_BackColor,$D7FFFF)
             AddGadgetColumn(10,1,"",150)
             AddGadgetColumn(10,2,"",78)
             For i = 0 To 50
             AddGadgetItem(10,i,"test"+Chr(10)+"test"+Str(i)+Chr(10)+"test"+Str(i))
             Next
             SetGadgetFont(10, FontID(1))

 ProcedureReturn result 
EndProcedure

 hwnd_1 =    OpenWindow(0, 200, 100, 800, 500 , "Advanced ComboBox", #PB_Window_SystemMenu |#PB_Window_SizeGadget|#PB_Window_ScreenCentered) 
             SetWindowCallback(@WndProc())
             FCombo()
             SetGadgetItemColor(10,1,#PB_Gadget_FrontColor,$C2C2C2)
             SetGadgetItemColor(10,5,#PB_Gadget_FrontColor,$0303FC)
             SetGadgetItemColor(10,8,#PB_Gadget_FrontColor,$79FC86)            

WFlag = 1
HideWindow(3,WFlag)

Repeat
  Select WaitWindowEvent()
  
    Case #PB_Event_Gadget        
        
        Select EventGadget()

          Case 10
             
            Select EventType()
              
              Case #PB_EventType_LeftClick
                    Pos = GetGadgetState(10)
                    For i = 0 To 2
                    Color = GetGadgetItemColor(10,Pos,#PB_Gadget_FrontColor,i)
                    If Color = $C2C2C2
                    Goto noaction
                    EndIf
                    Text$ = GetGadgetItemText(10,Pos,i)                    
                    SetGadgetItemText(1,0,Text$,i)
                    SetGadgetItemColor(1,0,#PB_Gadget_FrontColor, Color ,i)
                    Next
noaction:
                    WFlag = WFlag!1
                    AnimateWindow_(hwnd_3,100,#AW_HIDE|#AW_BLEND)
                    SetActiveWindow(0)            
                            
              Case #PB_EventType_RightClick
                                        
              Case #PB_EventType_LeftDoubleClick
;                     Pos = GetGadgetState(10)
;                     For i = 0 To 2
;                     Color = GetGadgetItemColor(10,Pos,#PB_Gadget_FrontColor,i)
;                     If Color = $C2C2C2
;                     Goto noaction
;                     EndIf
;                     Text$ = GetGadgetItemText(10,Pos,i)                    
;                     SetGadgetItemText(1,0,Text$,i)
;                     SetGadgetItemColor(1,0,#PB_Gadget_FrontColor, Color ,i)
;                     Next
; noaction:
;                     WFlag = WFlag!1
;                     AnimateWindow_(hwnd_3,500,#AW_HIDE|#AW_BLEND)
                     
              Case #PB_EventType_RightDoubleClick
                  
          EndSelect
          
          Case 2
              WFlag = WFlag!1
              If Wflag = 1
              AnimateWindow_(hwnd_3,100,#AW_HIDE|#AW_BLEND)
              Else
              AnimateWindow_(hwnd_3,100,#AW_ACTIVATE|#AW_VER_POSITIVE)
              EndIf
              SetActiveWindow(0)
              
                                        
        EndSelect

     
    Case #PB_Event_CloseWindow
      Quit = #True
     
  EndSelect
Until Quit
End
Edit:Updated for speed and compatibility
Have fun
Last edited by RASHAD on Mon Sep 14, 2009 5:37 pm, edited 2 times in total.
Egypt my love
Little John
Addict
Addict
Posts: 4791
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: ComboBox.........ComboBox........ComboBox

Post by Little John »

RASHAD wrote:Advancd Hand Made ComboBox:

No Ownerdrawn, No API just PureBasic Native commands
RASHAD wrote:

Code: Select all

GetWindowRect_()   
GetSystemMetrics_()
MoveWindow_()
SendMessage_()
[...]
:?: :?:
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: ComboBox.........ComboBox........ComboBox

Post by RASHAD »

Hello Little John
I updated the post a little bit
You mean API
Yes but not big deal I mean not using API heavily or using rare API it is for compatibility bet different OS and to change font size if you want
You can use options for different OS and remove API
For windows limit size we can use WindowBounds(#Window, MinimalWidth, MinimalHeight, MaximalWidth, MaximalHeight)
Also we can use ResizeWindow() , ResizeGadget() and HideWindow()

Sorry mate
have fun
Egypt my love
User avatar
Rings
Moderator
Moderator
Posts: 1435
Joined: Sat Apr 26, 2003 1:11 am

Re: ComboBox Edit (Windows Only)

Post by Rings »

edited topic title
SPAMINATOR NR.1
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: ComboBox Edit (Windows Only)

Post by RASHAD »

Rings Hi
Windows only OK
But ComboBox Edit this is for the first snippet only
But why not you are the boss
Egypt my love
User avatar
Tomi
Enthusiast
Enthusiast
Posts: 270
Joined: Wed Sep 03, 2008 9:29 am

Re: ComboBox Edit (Windows Only)

Post by Tomi »

Thanks for share, that's nice :D
"Edit ComboBox Live"
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: ComboBox Edit (Windows Only)

Post by RASHAD »

Hi Tomi
Thanks
It is mainly for you
Have a look at the second code and post your comments freely

have a good day
Egypt my love
User avatar
Tomi
Enthusiast
Enthusiast
Posts: 270
Joined: Wed Sep 03, 2008 9:29 am

Re: ComboBox Edit (Windows Only)

Post by Tomi »

Hi
"second code" has a good idea for comboing i think.
i see your code always, you have a creativity in your coding really.

have best day
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: ComboBox.........ComboBox........ComboBox

Post by blueznl »

Little John wrote:
RASHAD wrote:Advancd Hand Made ComboBox:

No Ownerdrawn, No API just PureBasic Native commands
RASHAD wrote:

Code: Select all

GetWindowRect_()   
GetSystemMetrics_()
MoveWindow_()
SendMessage_()
[...]
:?: :?:
http://www.xs4all.nl/~bluez/datatalk/pu ... i_and_dlls
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: ComboBox Edit (Windows Only)

Post by RASHAD »

@blueznl Hi
I am so glad to have feedback from you mate
Most of the API in the snippet I can replace it with PureBasic native commands except one I think
What I am looking for right now is as long as that snippet is open so I want to add hyper text to
the subitems plus the associte files ext
So the user can run these files by clicking the right file name directly
Or open any web page as well

again thanks for your reply
I downloaded your files long time back do not worry

have a good day
Egypt my love
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: ComboBox Edit (Windows Only)

Post by RASHAD »

@Little John
As I said no single API

Code: Select all

Global Pos,WFlag,LI_1,hwnd_1,hwnd_2,hwnd_3,BG_1,xx,yy,WW,Fsize,FH

Fsize = 12
LoadFont(0, "Marlett",Fsize)
LoadFont(1, "Arial",Fsize,#PB_Font_HighQuality)

Procedure WndProc(hwnd, uMsg, wParam, lParam)
    xx = WindowX(0)
    yy = WindowY(0)
    WW = WindowWidth(0)
result = #PB_ProcessPureBasicEvents  
 Select uMsg
      
        Case #WM_MOVE,#WM_SIZE,#WM_PAINT,#WM_NCHITTEST
             ResizeWindow(2,xx+WW-295,yy+50,280,FH+5)
             ResizeGadget(0,261,1,18,FH+2)  
             ResizeGadget(1,0,0,280,FH+5)                         
             ResizeWindow(3,xx+WW-295,yy+58+FH,280,400)
             ResizeGadget(10,0,0,280,400)
             
   EndSelect   
  ProcedureReturn result 
EndProcedure

Procedure FCombo()
result = #PB_ProcessPureBasicEvents
    xx = WindowX(0)
    yy = WindowY(0)
    WW = WindowWidth(0)
 hwnd_2 =    OpenWindow(2,xx+WW-295,yy+50,280,FH+5,"",#PB_Window_BorderLess|#WS_BORDER,WindowID(0))
      BG_1 = ButtonGadget(0,261,1,18,FH+2,Chr(117),#PB_Button_Default)
             SetGadgetFont(0, FontID(0))               
      LI_1 = ListIconGadget(1,0,0,280,FH+5,"",30,#PB_ListIcon_GridLines|#LVS_NOCOLUMNHEADER)
             SetGadgetColor(1,#PB_Gadget_BackColor,$D7FFFF)      
             AddGadgetColumn(1,1,"",160)
             AddGadgetColumn(1,2,"",65)
             AddGadgetItem(1, 0, ""+Chr(10)+""+Chr(10)+"")
             SetGadgetFont(1, FontID(1))
               
             
 hwnd_3 =    OpenWindow(3,xx+WW-295,yy+58+FH,280,400,"",#PB_Window_BorderLess|#WS_BORDER,WindowID(0))
      LI_2 = ListIconGadget(10,0,0,280,400,"Test1",30,#PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect|#LVS_NOCOLUMNHEADER)
             SetGadgetColor(10,#PB_Gadget_BackColor,$D7FFFF)
             AddGadgetColumn(10,1,"",160)
             AddGadgetColumn(10,2,"",65)
             For i = 0 To 50
             AddGadgetItem(10,i,"test"+Chr(10)+"test"+Str(i)+Chr(10)+"test"+Str(i))
             Next
             SetGadgetFont(10, FontID(1)) 

 ProcedureReturn result 
EndProcedure

 hwnd_1 =    OpenWindow(0, 200, 100, 800, 500 , "Advanced ComboBox", #PB_Window_SizeGadget|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_ScreenCentered)
             WindowBounds(0, 640,400,#PB_Ignore,#PB_Ignore)
             StartDrawing(WindowOutput(0))
             DrawingFont(FontID(1))
             FH = TextHeight("W")
             StopDrawing()
             FCombo()             
             SetWindowCallback(@WndProc())
             SetGadgetItemColor(10,1,#PB_Gadget_FrontColor,$C2C2C2)
             SetGadgetItemColor(10,5,#PB_Gadget_FrontColor,$0303FC)
             SetGadgetItemColor(10,8,#PB_Gadget_FrontColor,$79FC86)            

WFlag = 1
HideWindow(3,WFlag)

Repeat
  Select WaitWindowEvent()
  
    Case #PB_Event_Gadget        
        
        Select EventGadget()

          Case 10
             
            Select EventType()
              
              Case #PB_EventType_LeftClick
                    Pos = GetGadgetState(10)
                    For i = 0 To 2
                    Color = GetGadgetItemColor(10,Pos,#PB_Gadget_FrontColor,i)
                    If Color = $C2C2C2
                    Goto noaction
                    EndIf
                    Text$ = GetGadgetItemText(10,Pos,i)                    
                    SetGadgetItemText(1,0,Text$,i)
                    SetGadgetItemColor(1,0,#PB_Gadget_FrontColor, Color ,i)
                    Next
noaction:
                    WFlag = WFlag!1
                    HideWindow(3,1)
                    SetActiveWindow(0)
                 
                            
              Case #PB_EventType_RightClick
                                        
              Case #PB_EventType_LeftDoubleClick
                     
              Case #PB_EventType_RightDoubleClick
                  
          EndSelect
          
          Case 0
              WFlag = WFlag!1
              If Wflag = 1
              HideWindow(3,1)
              Else
              HideWindow(3,0)
              EndIf
              SetActiveWindow(0)
              
                                        
        EndSelect

     
    Case #PB_Event_CloseWindow
      Quit = #True
     
  EndSelect
Until Quit
End
have fun
Egypt my love
Little John
Addict
Addict
Posts: 4791
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: ComboBox Edit (Windows Only)

Post by Little John »

Sorry, I don't know what you want to tell me with this reply. I know what (Win) API means.
Point was, that rashad wrote "No API", but did use several API calls in his respective code.

Regards, Little John
Post Reply