Thread: I can't init that combo box!

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    87

    Lightbulb I can't init that combo box!

    Hi and thanks for reading this.

    I want to initialize a combo box.When I create the dialog, in which the box will be, I send CB_ADDSTRING to the box, but it doesn't works

    Here is the code:

    Code:
    theWnd=CreateDialog(hInst,MAKEINTRESOURCE(IDD_PROB
    A),NULL,DlgProc);
    i=GetLastError();
    SendDlgItemMessage(theWnd,IDC_COMBO1,CB_ADDSTRING,
    0,(LPARAM) "some text");
    ShowWindow(theWnd, SW_SHOW);
    I have tried to put the code in the WM_INITDIALOG or WM_CREATE message-handlers of the windows procedure:


    Code:
    BOOL CALLBACK DlgProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)
    {
    switch(uMsg)	{
    case WM_CREATE:
    SendDlgItemMessage(hwndDlg,IDC_COMBO1,CB_ADDSTRING,0,(LPARAM) "some text");
    break;
    case WM_INITDIALOG:
    SendDlgItemMessage(hwndDlg,IDC_COMBO1,CB_ADDSTRING,0,(LPARAM) "some text");
    ....................

    If somebody can tell me where the problem is, please tell me!

  2. #2
    Registered User Dante Shamest's Avatar
    Join Date
    Apr 2003
    Posts
    970
    Your code seems fine to me (I think). Did you return TRUE when handling WM_INITDIALOG?

  3. #3
    Registered User lobo's Avatar
    Join Date
    Oct 2001
    Posts
    71
    Try checking out return value... what styles do you specify for that combobox?

  4. #4
    Registered User
    Join Date
    Sep 2003
    Posts
    87
    I've created the combo box with a resource editor and the styles that I've specified are: Visible,Tabstop, Type:dropdown, Owner draw: no, sort and Vertical scroll.
    Last edited by Gravedigga; 10-03-2003 at 12:17 PM.

  5. #5
    Registered User lobo's Avatar
    Join Date
    Oct 2001
    Posts
    71
    Well, this piece of code along with bare bone winmain & procedure works fine for me:

    static HWND cb;
    ..
    case WM_CREATE:
    cb = CreateWindow("COMBOBOX", "", WS_VISIBLE | WS_CHILD | WS_TABSTOP | CBS_DROPDOWN | CBS_SORT | WS_VSCROLL, 0, 0, 200, 200, hwnd, 0, (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE), NULL);

    SendMessage(cb, CB_ADDSTRING, 0, (LPARAM) "1. lobo");
    SendMessage(cb, CB_ADDSTRING, 0, (LPARAM) "2. is");
    SendMessage(cb, CB_ADDSTRING, 0, (LPARAM) "3. testing");
    SendMessage(cb, CB_ADDSTRING, 0, (LPARAM) "4. cbox");
    break;

    I'm not qiute sure about need of that WS_VSCROLL, but it works even with it. So i can only recommend you to check carefully all return values and validity of objects you've created.

  6. #6
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Originally posted by Gravedigga
    Owner draw
    Which means you have to draw the contents yourself by handling the control parent's WM_DRAWITEM message. If you don't need to do this then remove the owner draw style and it will work as expected.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  7. #7
    Registered User lobo's Avatar
    Join Date
    Oct 2001
    Posts
    71
    2Ken

    originally posted by Gravedigga
    Owner draw: no

    If i get this right, this should mean Gravedigga does not use ownerdraw style

  8. #8
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    I am assuming the combo creates and displays.

    Can you click on it and catch a message to it?


    lobo

    You have set the combo to a child but not given it a resource ID number.

    cb = CreateWindow("COMBOBOX", "", WS_VISIBLE | WS_CHILD | WS_TABSTOP | CBS_DROPDOWN | CBS_SORT | WS_VSCROLL, 0, 0, 200, 200, hwnd, 0 , (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE), NULL);

    All child windows have to have an individual int ID number. Cast the HMENU param)
    ie
    ,(HMENU)ID_CHILD_CTRL,
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  9. #9
    Registered User lobo's Avatar
    Join Date
    Oct 2001
    Posts
    71
    novacain:

    All child windows have to have an individual int ID number. Cast the HMENU param)

    ..if you want to be able to retrieve their handles using GetDlgItem() and so. Or you can use static handle to window like i did in my example (which was nothing more then demonstration of functionality, anyway)

  10. #10
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    "The application determines the child-window identifier; it must be unique for all child windows with the same parent window. " MSDN

    That is all controls which are created with the same hwnd MUST have different resource ID values. Not if you feel like it.


    >>Or you can use static handle to window like i did in my example

    At no point do you explain that you are using a static hwnd.

    And Gravedigga DOES use a function that requires the resource ID.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  11. #11
    Registered User lobo's Avatar
    Join Date
    Oct 2001
    Posts
    71
    novacain:

    0 is unique

    My example above does contain declaration of static variable cb, if you look there.

    And, at no point i wrote my example is code Gravedigga should use .

    I agree, using non-unique ID's is dirty. However, according to my little test and experience, system itself does not seem to have any problems with that. Only problem i'd see would be handling of messages like WM_COMMAND. But in cases you are not using items that are of interest? Like certain statics? Laziness is terrible disease , i know...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Create new combo boxes based on items selected in preview combo box
    By RealityFusion in forum Windows Programming
    Replies: 2
    Last Post: 01-10-2007, 09:50 AM
  2. No data showing in combo box
    By PJYelton in forum Windows Programming
    Replies: 6
    Last Post: 04-29-2005, 07:20 PM
  3. How to program a "back" button with MFC
    By 99atlantic in forum Windows Programming
    Replies: 3
    Last Post: 04-26-2005, 08:34 PM
  4. New Theme
    By XSquared in forum A Brief History of Cprogramming.com
    Replies: 160
    Last Post: 04-01-2004, 08:00 PM
  5. SkyLock tech demo (GUI - DX combo box)
    By jdinger in forum Game Programming
    Replies: 4
    Last Post: 07-14-2002, 09:04 PM