News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Combo box cue banner

Started by Veki, April 03, 2009, 11:37:57 AM

Previous topic - Next topic

Veki

First, hi all.

I'm doing a small application in MASM and I have a combo box in it. I would like to add a cue banner to combo box, but don't know how to do it.

Is it possible to do that?

akane

Sure, you'll need the handle to the child edit control, and send them a EM_SETCUEBANNER message (at least XP) or subclass it and implement custom cue by just drawing gray text if the control is empty and is not focused.

Veki

Thanks for the quick reply, but I still can't make it work (I'm running Win XP SP3).

I use this code to create combo box (copied it from here, hope you don't mind :red)

invoke CreateWindowEx, WS_EX_CLIENTEDGE,ADDR cbClass,NULL,WS_VISIBLE or WS_CHILD or WS_VSCROLL or
CBS_DROPDOWNLIST or CBS_HASSTRINGS or CBS_SORT,10,10,150,100,hWin,IDCB,hInstance,NULL


And I use this code to try to add cue banner to combo box

;str_item0 contains the text I would like to write
invoke SendDlgItemMessage, hWin, 1001, EM_SETCUEBANNER , 0, ADDR str_item0


As far as "subclassing it" that could be problem for me since I'm new to MASM. :red

And what would happen if my application is run on Win98 with EM_SETCUEBANNER? Would it crash or would it refuse to run?

akane

You can't use CBS_DROPDOWNLIST because it does not create the child edit control required for EM_SETCUEBANNER.
invoke CreateWindowEx, WS_EX_CLIENTEDGE,ADDR cbClass,NULL,WS_VISIBLE or WS_CHILD or WS_VSCROLL or
CBS_DROPDOWN or CBS_HASSTRINGS or CBS_SORT,10,10,150,100,hWin,IDCB,hInstance,NULL

invoke GetWindow, eax, GW_CHILD
invoke SendMessage, eax, EM_SETCUEBANNER, 0, ADDR wstr_item0 ; unicode string!


On win98, EM_SETCUEBANNER will be ignored, old edit controls do not implement this message.

If you are accepting the CBS_DROPDOWN style and want your cue to be working on win95, you'll need to subclass the window which handle returns the GetWindow function. If you prefer the CBS_DROPDOWNLIST style, you'll better use owner drawn combobox (CBS_OWNERDRAWFIXED style bit set) and handle the more advanced WM_MEASUREITEM and WM_DRAWITEM messages passed to your window callback procedure.

For subclassing related examples just search for GWL_WNDPROC and SetWindowLong. For example: http://win32assembly.online.fr/tut20.html

Veki

#4
Sorry for a late reply, was out of town for the weekend.

The reason I use CBS_DROPDOWNLIST is that it doesn't allow the user to enter something into the combo box.

If cue banner can't be used with CBS_DROPDOWNLIST, can one print the first choice of the combo box so that combo box is not empty (not sure if I explained it well)?

And thanks for the link, bookmarked. :U

EDIT :

Managed to print first choice of the combo box. :dance:

First, after I created Combo box I used CB_SETCURSEL to set and display default choice.

Case WM_CREATE
invoke CreateWindowEx, WS_EX_CLIENTEDGE,ADDR cbClass,NULL,WS_VISIBLE or WS_CHILD or WS_VSCROLL or
CBS_DROPDOWNLIST or CBS_HASSTRINGS or CBS_SORT,10,10,150,100,hWin,IDCB,hInstance,NULL

invoke SendDlgItemMessage, hWin, 1001, CB_ADDSTRING, 0, ADDR str_item1
invoke SendDlgItemMessage, hWin, 1001, CB_SETCURSEL, 0, 0


After the control has been selected fill it up with choices and display default choice again because the control is refreshed.

Case WM_COMMAND
invoke SendDlgItemMessage, hWin, 1001, CB_ADDSTRING, 0, ADDR str_item1
invoke SendDlgItemMessage, hWin, 1001, CB_ADDSTRING, 0, ADDR str_item2
invoke SendDlgItemMessage, hWin, 1001, CB_ADDSTRING, 0, ADDR str_item3
.
.
.
invoke SendDlgItemMessage, hWin, 1001, CB_SETCURSEL, 0, 0


Thanks again for help. :U