The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Veki on April 03, 2009, 11:37:57 AM

Title: Combo box cue banner
Post by: Veki on April 03, 2009, 11:37:57 AM
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?
Title: Re: Combo box cue banner
Post by: akane on April 03, 2009, 12:01:08 PM
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.
Title: Re: Combo box cue banner
Post by: Veki on April 03, 2009, 12:31:27 PM
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?
Title: Re: Combo box cue banner
Post by: akane on April 03, 2009, 03:10:24 PM
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
Title: Re: Combo box cue banner
Post by: Veki on April 06, 2009, 06:25:56 AM
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