ComboBoxEx move Focus

I am creating an application using WINAPI. I need to use ComboBoxEx. So I used the CreateWindowEx API function and then applied sub-classing for this ComboBox. It was created properly and the sub-classing is functioning correctly as well. However, when the ComboBox has focus, and I need to do move focus by pressing "TAB", the focus is not moving because the focus is residing in the Edit Box of the Combo Box. I need to know where do I have to case the WM_CHAR holding the TAB value?
Please take into consideration that neither the sub-classing of the main Window nor that of the ComboBox is receiving the WM_CHAR holding the TAB.

Furthermore, I tried to do sub-classing for the Edit Box of the Combo Box, but it didn't work neither.

Thanks in advance.
Any update on this topic? I cant believe that no update till now!!!!
I found something that might be useful to you. On msdn window styles about WS_TABSTOP it says this"

WS_TABSTOP
0x00010000L

The window is a control that can receive the keyboard focus when the user presses the TAB key. Pressing the TAB key changes the keyboard focus to the next control with the WS_TABSTOP style.

You can turn this style on and off to change dialog box navigation. To change this style after a window has been created, use the SetWindowLong function. For user-created windows and modeless dialogs to work with tab stops, alter the message loop to call the IsDialogMessage function.


and on IsDialogMessage page it says:

Although the IsDialogMessage function is intended for modeless dialog boxes, you can use it with any window that contains controls, enabling the windows to provide the same keyboard selection as is used in a dialog box.

When IsDialogMessage processes a message, it checks for keyboard messages and converts them into selections for the corresponding dialog box. For example, the TAB key, when pressed, selects the next control or group of controls, and the DOWN ARROW key, when pressed, selects the next control in a group.
Last edited on
Thanks for your detailed update. however, in the past when I started Window development, i had tried the WS_TAPSTOP but it didn't work because I'm not using dialog boxes. Anyway, regarding moving focus from ComboBox, I had sub-classed the combobox edit field in order to receive the WM_KEYDOWN. Now the issue is done and I'm able to move focus according to the focus list that I have in my application.

Now, I am facing another issue while dropping down list of ComboBox.
In the comboBox control that I had created for testing, I had inserted 3 items representing the currency. However, upon dropping down the list, only the 1st item is shown while the other 2 items are created but not displayed. I can move through the list by pressing Up/Down Arrows. The Items count is 3 and they are highlighted properly "but the text is displayed only on the 1st item".

Below is the code of Inserting items, for sure there is a mistake somewhere:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
bool BsolComboBox::BsolCmBoxInsertItems (BsolLinkList * item_p, int iNum_p) {
	int i, iValue_v, size_v;
	wchar_t * wcText_v;
	wstring wsValue_v, wsText_v;
	long return_v;

	// Set the mask common to all items.
	this->cbItem.mask = CBEIF_TEXT 
			  | CBEIF_INDENT
			  | CBEIF_LPARAM
//			  | CBEIF_IMAGE
//			  | CBEIF_SELECTEDIMAGE
			  ;

	for(i = 0; i < iNum_p; i++) {
		wsValue_v = item_p[i][0]->ddValue;
		iValue_v = BsolWStringToNumber (wsValue_v);

		wsText_v = item_p[i][1]->ddText;
		size_v = wsValue_v.length();
		wcText_v = (wchar_t*)malloc(size_v * sizeof(wchar_t));
		BsolCopyWStringToWchar (wsText_v, wcText_v);

		// Initialize the COMBOBOXEXITEM struct (this->cbItem).
		this->cbItem.iItem          = i;
		this->cbItem.pszText        = wcText_v;
		this->cbItem.cchTextMax     = size_v;
		this->cbItem.iImage         = NULL;
		this->cbItem.iSelectedImage = NULL;
		this->cbItem.iIndent        = 0;
		this->cbItem.lParam			= iValue_v;

		// Tell the ComboBoxEx to add the item.
		// Return FALSE if this fails.
		return_v = SendMessage (this->cbhWnd, CBEM_INSERTITEM, 0, (LPARAM)&this->cbItem);

		// Set the mask common to all items.
//		this->cbItem.mask = CBEIF_DI_SETITEM;

		if (return_v == -1)
			return false;
	}
	return true;
}


Thanks in advance.
Ahmad
Last edited on
I found the mistake. It is in line 20 in the above code. I am setting the size to be the length of the Value while it must be the length of the Text. The correction is as below:

Line 20 with the bug:
size_v = wsValue_v.length();
It must be:
size_v = wsText_v.length();
After this correction the comboBox is functioning properly.

I still have another is related to changing the background and item color of the ListBox of the ComboBox. I had logged another thread in this regards.

Thanks anyway.
Topic archived. No new replies allowed.