Results 1 to 16 of 16

Thread: DropDownList ComboBox

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2000
    Location
    Whats a location?
    Posts
    516

    Red face

    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?
    Courgettes.

  2. #2
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892
    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!

  3. #3
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2000
    Location
    Whats a location?
    Posts
    516
    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.
    That sentence was quite good, heh?
    I should be an orator. (Look it up )
    Courgettes.

  5. #5
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892
    LIFE SUCKS! Get a resource script! (And stop using CreateWindow and/or CreateWindowEx!)
    At least you spelled my name correctly. Not.

  6. #6
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2000
    Location
    Whats a location?
    Posts
    516
    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]
    Courgettes.

  8. #8
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892
    Expert in ASM? Me???
    NEVER!
    Well, sometime in the future, maybe.
    But, resource scripts are fun! Use them!

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2000
    Location
    Whats a location?
    Posts
    516
    Originally posted by Yonatan
    Expert in ASM? Me???
    NEVER!
    Well, sometime in the future, maybe.
    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?
    Courgettes.

  10. #10
    New Member
    Join Date
    Sep 2000
    Location
    Hell
    Posts
    4

    Lightbulb 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.

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2000
    Location
    Whats a location?
    Posts
    516
    Oh, ,thanks. I thought that the height you set didn't have to include the dropdown area.
    Courgettes.

  12. #12
    Lively Member ExciteMouse's Avatar
    Join Date
    Jul 2000
    Location
    Dallas, TX
    Posts
    78
    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

  13. #13
    Lively Member ExciteMouse's Avatar
    Join Date
    Jul 2000
    Location
    Dallas, TX
    Posts
    78
    well holy cow. it worked!
    thank you so very much man, i really appreciate the help!

  14. #14
    Frenzied Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    1,276
    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?

  15. #15
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892

    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

  16. #16
    Frenzied Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    1,276
    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
  •  



Click Here to Expand Forum to Full Width