How do I make a combobox accept user input?

BlitzPlus Forums/BlitzPlus Programming/How do I make a combobox accept user input?

sswift(Posted 2005) [#1]
I need to know how to modify a combobox control in Blitz using Win32 commands to change it so that it allows the user to modify the text in the input box.

Basically, I want to allow the user to either pull down a list of numbers and select one, or type a number not in the list into the text entry box.

I'm pretty sure there's a style for this, but I'm not sure what it is or how to set it.


sswift(Posted 2005) [#2]
Still need help with this if possible!

Tried the following, but it didn't work:

Function SetReadOnly(Gadget, ReadOnly)
	
	Local EM_SETREADONLY = $CF
	Local ES_READONLY = $800 ; 2048
	Local NOT_ES_READONLY = -2049
	Local GWL_STYLE        = -16
	    
	Local Hwnd_Gadget
	Local Hwnd_Edit
	
	Local hWnd% = QueryObject(Gadget, 1)
	hWnd = GetParent(hWnd)
	
	; Get the handle of the gadget.
	;Hwnd_Gadget = QueryObject(Gadget, 1)
	
    ; Get the edit field handle.
   	Hwnd = FindWindowEx(Hwnd, 0, "", "")
    	
	SetWindowLong(Hwnd, GWL_STYLE, GetWindowLong(Hwnd, GWL_STYLE) And NOT_ES_READONLY)

	;If Hwnd_Edit <> 0 
		
		; Set or remove the read-only flag. (ES_ReadOnly)
     ;   SendMessage(Hwnd_Edit, EM_SETREADONLY, ReadOnly, 0)

	;End If

End Function



aab(Posted 2005) [#3]
Well, the only (be it ultimately insane) i can think of, is to check for the mouses coordinates:
if the mouse is hit over the text writing area, unhide a textfield underneath, to be placed over /in shown place of the combobox until eg:tab or return are hit, otherwise have this text field hidden. too wierd.

This is where i would give up and start making my own scratch gadgets out of canvases, temporary windows and the text command....


Andres(Posted 2005) [#4]
Another way is a textfield with a button next to it and when clicking on the button an Advanced PopupMenu will appear.

Advanced PopupMenu: http://www.blitzbasic.com/codearcs/codearcs.php?code=697


Sarge(Posted 2005) [#5]
You can use the SetWindowLong to change it from _

'ReadOnly
CBS_DROPDOWNLIST
to
'Editable
CBS_DROPDOWN


sswift(Posted 2005) [#6]
I'll keep that in mind and try it if I need a dropdown box in the future, but its much too late now to use that. :-)


JoshK(Posted 2005) [#7]
Sarge, how did you get that to work? This code doesn't do it. I really need this to work for my program:
Const GWL_STYLE=-16
Const CBS_SIMPLE=1
Const CBS_DROPDOWN=2
Const CBS_DROPDOWNLIST=3

window=CreateWindow( "ComboBox demo",300,200,160,120+80 )
combobox=CreateComboBox( ClientWidth(window)/2-64,ClientHeight(window)/2-12,128,60,window,2 )

For k=0 To 50
	AddGadgetItem combobox,"Item "+k
	Next
SelectGadgetItem combobox,0

hwnd=QueryObject(combobox,1)
flags=GetWindowLong(hwnd,GWL_STYLE)
flags=flags-CBS_DROPDOWNLIST
flags=flags+CBS_DROPDOWN
SetWindowLong hwnd,GWL_STYLE,flags

While WaitEvent()<>$803
Wend
End


I got this to work using a PureBasic combobox created in the Blitz window. Strangely, when I got the style of the PB combobox, and then set the Blitz combobox to that number, it had no effect.

I really think Blitz should support this on its own. If you have to use PureBasic every time you need something a little extra, what's the point of even using B+?

Seems like sooner or later, I always end up replacing Blitz commandsets with external libraries.


Snarty(Posted 2005) [#8]
The problem may lay with how Blitz handles gadgets/common controls. If you check any Blitz created common control they are all "Sub-Classed". This means, the more than likely have some form of control code, which forces styles and/or also filters messages.

The only way around this is to change the class back to default, but, this will stop BlitzPlus from receiving messages. Not much use, unless you provide your own control procedure which passes events to the parent window.

Without knowing Blitz's internal structure this is of course speculation.


Snarty(Posted 2005) [#9]
Scrub that, they are have the CBS_OWNERDRAWFIXED flag, meaning Blitz handles the rendering.


Sarge(Posted 2005) [#10]
Well i have no clue how to do it in Blitzplus because i cant use these type of thing using the demo but with my gui in blitzmax i have the Combobox flags like this

WS_VISIBLE|WS_CHILD|WS_CLIPSIBLINGS|CBS_DROPDOWN|WS_VSCROLL|WS_TABSTOP

and that allows user input but if i change the CBS_DROPDOWN to CBS_DROPDOWNLIST it dosent allow user input and then there is CBS_SIMPLE which is more like a listbox with a textbox at the top allowing user input.

sorry i coulnt help


JoshK(Posted 2005) [#11]
No, the BlitzPlus combobox does not have the CBS_OWNERDRAWFIXED style enabled:

flags=GetWindowLong(hwnd,GWL_STYLE)
Notify (CBS_OWNERDRAWFIXED And flags); says "0"

I tried using the flags you said, but it had no effect.


Arem(Posted 2005) [#12]
You could add text on keyhits... Pretty lame but it works!


Snarty(Posted 2005) [#13]
Strange, Spy++ gives the style as $56000413, no idea whats going on there. But yes, GetWindowLong returns $50000003. Very strange.