Click to See Complete Forum and Search --> : DropDownList ComboBox
V(ery) Basic
Sep 26th, 2000, 01:04 PM
Excuse my superior knowledge disguised as ignorance:
Combo1 = CreateWindowEx(WS_EX_CLIENTEDGE, "ComboBox", "", WS_CHILD | CBS_DROPDOWNLIST, 115, 30, 50, 30, hWnd, 0, hInst, NULL);
HFONT hFont;
CHAR* Tahoma = "Tahoma";
hFont = (HFONT) CreateFont( 18 , 0, 0, 0, FW_NORMAL, 0, 0, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, 0, Tahoma);
SendMessage(Combo1, WM_SETFONT, (WPARAM)hFont, (LPARAM)true);
SendMessage(Combo1, CB_ADDSTRING, 0, (WPARAM) "+");
SendMessage(Combo1, CB_ADDSTRING, 0, (WPARAM) "-");
SendMessage(Combo1, CB_ADDSTRING, 0, (WPARAM) "x");
SendMessage(Combo1, CB_ADDSTRING, 0, (WPARAM) "/");
ShowWindow(Combo1, nCmdShow);
The code executes fine, and if you use the up/down keys, the different symbols appear in the combo, but if you press that down button, it shows a little grey line about 2 pixels high instead of the list. Do I have to set each item's height or what?
Yonatan
Sep 26th, 2000, 01:33 PM
Have you tried sending Combo1 a CB_SETDROPPEDWIDTH message?
Hmm, well, obviously you haven't. :rolleyes:
Originally written in MSDN
CB_SETDROPPEDWIDTH
An application sends the CB_SETDROPPEDWIDTH message to set the maximum allowable width, in pixels,
of the list box of a combo box with the CBS_DROPDOWN or CBS_DROPDOWNLIST style.
CB_SETDROPPEDWIDTH
wParam = (WPARAM) wWidth // width of list box, in pixels
lParam = 0 // not used, must be zero
Parameters
wWidth
Specifies the width of the list box, in pixels.
Return Values
If the message is successful, The return value is the new width of the list box.
If the message fails, the return value is CB_ERR.
Happy? Good! :rolleyes:
parksie
Sep 26th, 2000, 01:36 PM
Or also try CB_SETITEMHEIGHT:
CB_SETITEMHEIGHT
An application sends a CB_SETITEMHEIGHT message to set the height of list items or the selection field in a combo box.
To send this message, call the SendMessage function with the following parameters.
SendMessage(
(HWND) hWnd, // handle to destination window
CB_SETITEMHEIGHT, // message to send
(WPARAM) wParam, // item index
(LPARAM) lParam // item height
);
Parameters
wParam
Specifies the component of the combo box for which to set the height.
This parameter must be –1 to set the height of the selection field. It must be zero to set the height of list items, unless the combo box has the CBS_OWNERDRAWVARIABLE style. In that case, the wParam parameter is the zero-based index of a specific list item.
lParam
Specifies the height, in pixels, of the combo box component identified by wParam.
Return Values
If the index or height is invalid, the return value is CB_ERR.
Remarks
The selection field height in a combo box is set independently of the height of the list items. An application must ensure that the height of the selection field is not smaller than the height of a particular list item.
...from MSDN (again)
V(ery) Basic
Sep 26th, 2000, 03:22 PM
I've already tried SetItemHeight, parksie, and the width is fine, Yanoton. ;) , it's just that each item isn't high enough.
Do I have to set another parameter like CB_REMEMBERTOSHOWLISTBOX or something. Are you seriously telling me you've never made a ComboBox the non-MFC way? Please? I appreciate the replies, but I would prefer an answer.
:cool: That sentence was quite good, heh?
I should be an orator. (Look it up :o )
Yonatan
Sep 26th, 2000, 04:05 PM
LIFE SUCKS! Get a resource script! (And stop using CreateWindow and/or CreateWindowEx!)
At least you spelled my name correctly. Not. :rolleyes:
parksie
Sep 26th, 2000, 04:07 PM
Unfortunately, when using dialogues and resource scripts you lose a large level of control.
Although that's probably to be expected considering how easy it is to make a dialogue in
the resource editor.
V(ery) Basic
Sep 27th, 2000, 01:55 PM
Originally posted by Yonatan
LIFE SUCKS! Get a resource script! (And stop using CreateWindow and/or CreateWindowEx!)
That's rich: Somebody who's an expert in asm telling me that I want too much control.
[Edited by V(ery) Basic on 09-27-2000 at 02:57 PM]
Yonatan
Sep 27th, 2000, 02:11 PM
Expert in ASM? Me???
NEVER! :mad:
Well, sometime in the future, maybe. :rolleyes:
But, resource scripts are fun! Use them!
V(ery) Basic
Sep 28th, 2000, 12:52 PM
Originally posted by Yonatan
Expert in ASM? Me???
NEVER! :mad:
Well, sometime in the future, maybe. :rolleyes:
But, resource scripts are fun! Use them!
Comparatively expert ;)
But I don't really want to use a resource script. I really want to make this with CreateWindow(Ex)
Any help?
Pls?
V(ery) Basics Helper
Sep 29th, 2000, 11:59 AM
What might be happening is that the combo might not have enough space for dropping down, so change the nHeight parameter in CreateWindowEx to something bigger.
V(ery) Basic
Sep 29th, 2000, 12:27 PM
Oh, :o ,thanks. I thought that the height you set didn't have to include the dropdown area.
ExciteMouse
Aug 6th, 2001, 12:05 PM
Ok im going to bring this thread back from the dead.
I am having the same problem here. and nothing in this thread does anything for me.
Hasnt anyone had this problem before? you add a combo box to a form, you add a bunch of data to the combo box. You run the program and when you want to drop the combo box down, the list only shows about 2 pixels worth. the Width is fine, the height isnt.
This has to be a common problem, if you havent played with a combo box before, try it now and see if it happens to you also
anyways, anyone know how to get this to work correctly?
thanks
ExciteMouse
Aug 7th, 2001, 11:51 AM
well holy cow. it worked!
thank you so very much man, i really appreciate the help!
wey97
Aug 14th, 2001, 03:59 PM
You also need to make sure you add WS_VSCROLL to the dwStyle
parameter in case you list becomes longer than the list height you
set.
I also have a question. Here is my code:
#include <windows.h>
#define WIN32_LEAN_AND_MEAN
#define IDC_COMBO 1001
static HINSTANCE hInstance = NULL;
char szClassName[] = "Combo";
static HWND hwndCombo;
void SetDefaultFont(int identifier, HWND hwnd){
SendDlgItemMessage(
hwnd,
identifier,
WM_SETFONT,
(WPARAM)GetStockObject(DEFAULT_GUI_FONT),
MAKELPARAM(TRUE, 0));
}
HWND CreateCombo(char* tempText, int x, int y, int width, int height,
int identifier, HWND hwnd){
HWND hComboTemp;
hComboTemp = CreateWindowEx(
WS_EX_CLIENTEDGE,
"COMBOBOX",
tempText,
WS_CHILD | CBS_DROPDOWNLIST | WS_VSCROLL,
x, y, width, height,
hwnd, (HMENU)identifier, hInstance, NULL);
return hComboTemp;
}
LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam){
switch(message){
case WM_CREATE:
hwndCombo = CreateCombo("Combo", 10, 10, 150, 100, IDC_COMBO, hwnd);
SetDefaultFont(IDC_COMBO, hwnd);
ShowWindow(hwndCombo, SW_SHOWNORMAL);
SendMessage(hwndCombo, CB_ADDSTRING, 0, (LPARAM) "Item 1");
SendMessage(hwndCombo, CB_ADDSTRING, 0, (LPARAM) "Item 2");
SendMessage(hwndCombo, CB_ADDSTRING, 0, (LPARAM) "Item 3");
SendMessage(hwndCombo, CB_ADDSTRING, 0, (LPARAM) "Item 4");
break;
case WM_COMMAND:
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
break;
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpszArgument, int nCmdShow){
HWND hwnd;
MSG messages;
WNDCLASSEX wincl;
wincl.hInstance = hInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure;
wincl.style = CS_DBLCLKS;
wincl.cbSize = sizeof(WNDCLASSEX);
wincl.hIcon = LoadIcon(NULL, IDI_WINLOGO);
wincl.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
wincl.hCursor = LoadCursor(NULL, IDC_ARROW);
wincl.lpszMenuName = NULL;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.hbrBackground = (HBRUSH)COLOR_BTNSHADOW;
if(!RegisterClassEx(&wincl)) return 0;
hwnd = CreateWindowEx(
0,
szClassName,
"ComboBox",
WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU,
CW_USEDEFAULT,
CW_USEDEFAULT,
200,
100,
HWND_DESKTOP,
NULL,
hInstance,
NULL
);
ShowWindow(hwnd, nCmdShow);
while(GetMessage(&messages, NULL, 0, 0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
return messages.wParam;
}
?? - How do you check the WM_COMMAND message after a list
item is clicked to get the index of the item and the list text that
was clicked?
Yonatan
Aug 14th, 2001, 04:21 PM
case WM_COMMAND:
// Check if the selection changed in IDC_COMBO:
if(wParam == MAKEWPARAM(IDC_COMBO, CBN_SELENDOK)) {
HWND ComboBox = (HWND)lParam;
UINT CurrentItemIndex = SendMessage(ComboBox, CB_GETCURSEL, NULL, NULL);
LPTSTR ItemText;
UINT TextLength;
// Get the text length of the currently selected item
TextLength = SendMessage(ComboBox, CB_GETLBTEXTLEN, CurrentItemIndex, NULL);
// Allocate a buffer for the text
ItemText = new TCHAR[TextLength + 1];
// Get the text
SendMessage(ComboBox, CB_GETLBTEXT, CurrentItemIndex, (LPARAM)ItemText);
// Do something with the text
MessageBox(hwnd, ItemText, TEXT("ComboBox Selection Changed"), MB_ICONINFORMATION);
// Deallocate the buffer
delete[] ItemText;
}
break;
Enjoy :rolleyes:
wey97
Aug 14th, 2001, 05:54 PM
you can also get the text as it is changed:
if(HIWORD(wParam) == CBN_EDITCHANGE) {
switch(LOWORD(wParam)){
case IDC_COMBO:
LPTSTR ItemText;
const TextLength = GetWindowTextLength(hwndCombo);
ItemText = new TCHAR[TextLength+1];
GetWindowText(hwndCombo, ItemText, TextLength+1);
MessageBox(hwnd, ItemText, "The text entered is:", NULL);
delete[] ItemText;
break;
}
}
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.