Control the dimensions of DropDown List of ComboBox [Windows]

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

Control the dimensions of DropDown List of ComboBox [Windows]

Post by RASHAD »

Hi

Code: Select all

Dim iconhandle(2)
iconhandle(0)=CreateImage(0,20,20,32,#Red)
iconhandle(1)=CreateImage(1,20,20,32,#Blue)
iconhandle(2)=CreateImage(2,20,20,32,#Green)

LoadFont(0,"Tahoma",16)

OpenWindow(0,0,0,320,100,"...",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ComboBoxGadget(0,10,10,300,30,#PB_ComboBox_Editable|#PB_ComboBox_Image)
SetGadgetFont(0,FontID(0))

#CBEM_GETEDITCONTROL = 1031
Global hEdit = SendMessage_(GadgetID(0), #CBEM_GETEDITCONTROL, 0, 0)
Debug hEdit

For i=0 To 20
  AddGadgetItem(0,-1,"TEST "+Str(i),iconhandle(i&1))
Next i

dLhwnd = FindWindow_("ComboLBox",0)

h = SendMessage_(GadgetID(0), #CB_GETITEMHEIGHT, 0, 0)

GetWindowRect_(dLhwnd,r.RECT)
MoveWindow_(dLhwnd,r\left,r\top,r\right-r\left,h*22,1)

ComboBoxGadget(1,10,50,300,30,#PB_ComboBox_Editable|#PB_ComboBox_Image)
SetGadgetFont(1,FontID(0))

For i=0 To 30
  AddGadgetItem(1,-1,"TEST "+Str(i),iconhandle(i&1))
Next i

dLhwnd2 = FindWindow_("ComboLBox",0)
h = SendMessage_(GadgetID(1), #CB_GETITEMHEIGHT, 0, 0)

GetWindowRect_(dLhwnd2,r2.RECT)
MoveWindow_(dLhwnd2,r2\left,r2\top,r2\right-r2\left,h*32,1)
;SetActiveGadget(0)


Repeat
  EventID.l = WaitWindowEvent()
  Select EventID
      
    Case #PB_Event_CloseWindow
      End      
      
    Case #PB_Event_Gadget      
      Select EventGadget()
        Case 0
          
      EndSelect      
  EndSelect
ForEver

Egypt my love
hoangdiemtinh
User
User
Posts: 97
Joined: Wed Nov 16, 2022 1:51 pm

Re: Control the dimensions of DropDown List of ComboBox [Windows]

Post by hoangdiemtinh »

Thank man.
I will apply your code to my upcoming program.
PC: Windows 10 x64, 8GB RAM. PB ver: 6.x
--
I love PB5 vs PB6 :)
boddhi
Enthusiast
Enthusiast
Posts: 524
Joined: Mon Nov 15, 2010 9:53 pm

Re: Control the dimensions of DropDown List of ComboBox [Windows]

Post by boddhi »

Hi RASHAD,

I don't see any difference... normal?
(Win 10 x64 - PB 6.10 x64 - DPI 125%)

ImageImage
If my English syntax and lexicon are incorrect, please bear with Google translate and DeepL. They rarely agree with each other!
Except on this sentence...
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: Control the dimensions of DropDown List of ComboBox [Windows]

Post by RASHAD »

Hi boddhi
Just checked it with :
1- Windows 11 x64 - PB 6.10 x64 125% DPI
2- Windows 10 x64 (VM) - PB 6.10 x64 125% DPI
Both works as expected
Make sure that the handle of the DropDown list is OK and report
Thanks for reporting

And thanks for hoangdiemtinh too
Egypt my love
boddhi
Enthusiast
Enthusiast
Posts: 524
Joined: Mon Nov 15, 2010 9:53 pm

Re: Control the dimensions of DropDown List of ComboBox [Windows]

Post by boddhi »

No modification of the source except Debugs added:
DebuggerOutput wrote: hEdit : 2823766
dLhwnd : 35526464
h : 36
dLhwnd2 : 35526464
h : 36
It seems that the two combo get the same handle...
If my English syntax and lexicon are incorrect, please bear with Google translate and DeepL. They rarely agree with each other!
Except on this sentence...
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: Control the dimensions of DropDown List of ComboBox [Windows]

Post by RASHAD »

That is strange
See if the next snippet do it right

Code: Select all

Dim iconhandle(2)
iconhandle(0)=CreateImage(0,20,20,32,#Red)
iconhandle(1)=CreateImage(1,20,20,32,#Blue)
iconhandle(2)=CreateImage(2,20,20,32,#Green)

LoadFont(0,"Tahoma",16)

OpenWindow(0,0,0,320,100,"...",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ComboBoxGadget(0,10,10,300,30,#PB_ComboBox_Editable|#PB_ComboBox_Image)
SetGadgetFont(0,FontID(0))

For i=0 To 20
  AddGadgetItem(0,-1,"TEST "+Str(i),iconhandle(i&1))
Next i

ComboBoxGadget(1,10,50,300,30,#PB_ComboBox_Editable|#PB_ComboBox_Image)
SetGadgetFont(1,FontID(0))

For i=0 To 30
  AddGadgetItem(1,-1,"TEST "+Str(i),iconhandle(i&1))
Next i

Repeat
  EventID.l = WaitWindowEvent()
  Select EventID
      
    Case #PB_Event_CloseWindow
      End      
      
    Case #PB_Event_Gadget      
      Select EventGadget()
        Case 0
          dLhwnd = FindWindow_(@"ComboLBox",0)
          Debug dlhwnd          
          h = SendMessage_(GadgetID(0), #CB_GETITEMHEIGHT, 0, 0)          
          GetWindowRect_(dLhwnd,r.RECT)
          MoveWindow_(dLhwnd,r\left,r\top,r\right-r\left,h*(CountGadgetItems(0)+1),1)
          
        Case 1
          dLhwnd = FindWindow_(@"ComboLBox",0)
          h = SendMessage_(GadgetID(1), #CB_GETITEMHEIGHT, 0, 0)          
          GetWindowRect_(dLhwnd,r.RECT)
          MoveWindow_(dLhwnd,r\left,0,r\right-r\left,h*(CountGadgetItems(1)+1),1)
          
      EndSelect      
  EndSelect
ForEver


Egypt my love
boddhi
Enthusiast
Enthusiast
Posts: 524
Joined: Mon Nov 15, 2010 9:53 pm

Re: Control the dimensions of DropDown List of ComboBox [Windows]

Post by boddhi »

Hi,
RASHAD wrote: See if the next snippet do it right
It seems to be the expected behaviour but...
Image
as you can see, the first combo's dropdownlist (and probably for the second too if it had fewer items) is not always positioned at the same position, depending on whether it is the first click, the second click or whether the second combox was clicked before...
If my English syntax and lexicon are incorrect, please bear with Google translate and DeepL. They rarely agree with each other!
Except on this sentence...
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: Control the dimensions of DropDown List of ComboBox [Windows]

Post by RASHAD »

ComboBox with Image is a special class by PB
Next is my last run
Wish me luck :D

Code: Select all

Dim cblist(1,1)
Dim iconhandle(2)

iconhandle(0)=CreateImage(0,20,20,32,#Red)
iconhandle(1)=CreateImage(1,20,20,32,#Blue)
iconhandle(2)=CreateImage(2,20,20,32,#Green)

LoadFont(0,"Tahoma",16)

OpenWindow(0,0,0,320,100,"...",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ComboBoxGadget(0,10,10,300,30,#PB_ComboBox_Editable|#PB_ComboBox_Image)
SetGadgetFont(0,FontID(0))
dLhwnd = FindWindow_("ComboLBox",0)
h = SendMessage_(GadgetID(0), #CB_GETITEMHEIGHT, 0, 0)
cblist(0,0) = dLhwnd
cblist(0,1) = h

For i=0 To 20
  AddGadgetItem(0,-1,"TEST "+Str(i),iconhandle(i&1))
Next i

ComboBoxGadget(1,10,50,300,30,#PB_ComboBox_Editable|#PB_ComboBox_Image)
SetGadgetFont(1,FontID(0))
dLhwnd2 = FindWindow_("ComboLBox",0)
h = SendMessage_(GadgetID(1), #CB_GETITEMHEIGHT, 0, 0)
cblist(1,0) = dLhwnd2
cblist(1,1) = h

For i=0 To 30
  AddGadgetItem(1,-1,"TEST "+Str(i),iconhandle(i&1))
Next i

Repeat
  EventID.l = WaitWindowEvent()
  Select EventID
      
    Case #PB_Event_CloseWindow
      End      
      
    Case #PB_Event_Gadget      
      Select EventGadget()
        Case 0
          GetWindowRect_(cblist(0,0),r.RECT)
          MoveWindow_(cblist(0,0),r\left,r\top,r\right-r\left,cblist(0,1)*22,1)
          
        Case 1
          GetWindowRect_(cblist(1,0),r.RECT)
          MoveWindow_(cblist(1,0),r\left,0,r\right-r\left,cblist(1,1)*32,1)
          
      EndSelect      
  EndSelect
ForEver


Egypt my love
boddhi
Enthusiast
Enthusiast
Posts: 524
Joined: Mon Nov 15, 2010 9:53 pm

Re: Control the dimensions of DropDown List of ComboBox [Windows]

Post by boddhi »

Unfortunately, same result as your first code! :(
Thanks for your tries. :wink:

It was to move the schmilblick! :mrgreen:
If my English syntax and lexicon are incorrect, please bear with Google translate and DeepL. They rarely agree with each other!
Except on this sentence...
Post Reply