|
-
Sep 26th, 2000, 01:04 PM
#1
Thread Starter
Fanatic Member
Excuse my superior knowledge disguised as ignorance:
Code:
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?
-
Sep 26th, 2000, 01:33 PM
#2
Guru
Have you tried sending Combo1 a CB_SETDROPPEDWIDTH message?
Hmm, well, obviously you haven't. 
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!
-
Sep 26th, 2000, 01:36 PM
#3
Monday Morning Lunatic
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)
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Sep 26th, 2000, 03:22 PM
#4
Thread Starter
Fanatic Member
-
Sep 26th, 2000, 04:05 PM
#5
Guru
LIFE SUCKS! Get a resource script! (And stop using CreateWindow and/or CreateWindowEx!)
At least you spelled my name correctly. Not.
-
Sep 26th, 2000, 04:07 PM
#6
Monday Morning Lunatic
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.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Sep 27th, 2000, 01:55 PM
#7
Thread Starter
Fanatic Member
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]
-
Sep 27th, 2000, 02:11 PM
#8
-
Sep 28th, 2000, 12:52 PM
#9
Thread Starter
Fanatic Member
-
Sep 29th, 2000, 11:59 AM
#10
New Member
I have an idea
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.
You wouldn't know a joke if it got up and gave you a haircut.
-
Sep 29th, 2000, 12:27 PM
#11
Thread Starter
Fanatic Member
Oh, ,thanks. I thought that the height you set didn't have to include the dropdown area.
-
Aug 6th, 2001, 12:05 PM
#12
Lively Member
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
-
Aug 7th, 2001, 11:51 AM
#13
Lively Member
well holy cow. it worked!
thank you so very much man, i really appreciate the help!
-
Aug 14th, 2001, 03:59 PM
#14
Frenzied Member
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:
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?
-
Aug 14th, 2001, 04:21 PM
#15
Guru
Try this...
Code:
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
-
Aug 14th, 2001, 05:54 PM
#16
Frenzied Member
you can also get the text as it is changed:
Code:
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;
}
}
Last edited by wey97; Aug 14th, 2001 at 06:10 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|