Thread: Adding items to a Dialog Box

  1. #1
    Registered User
    Join Date
    Jan 2010
    Posts
    206

    Question Adding items to a Dialog Box

    Hi there,

    I was just curious as to how this is done? I'm working in Visual Studio (with C++) and I'm trying to follow an author's work on how he made a dialog box and then added content to it.

    Check out the following code he uses:

    Code:
    void AddItem(HWND hWnd, char *ch, void *pData)
    {
       WPARAM nI = (WPARAM)((int)(DWORD)SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)ch));
       SendMessage(hWnd,CB_SETITEMDATA, nI, (LPARAM)pData);
    }
    And here's an example of it being called:

    Code:
    AddItem(m_hADAPTER, m_xAdapterInfo[a].
                  d3dAdapterIdentifier.Description, 
                  &m_xAdapterInfo[a]);
    Which takes place inside an iteration loop where a is the incremented iterator.

    The function AddItem is a helper function which contains the native Win32 code that does the job. I was a bit confused though that it seems to use the function SendMessage twice? In the first part he uses SendMessage to make a WPARAM variable which is then passed into another call of SendMessage on the very next line.

    That's where I'm struggling, why use SendMessage twice? Maybe the first call is just to add a string to the combo box and maybe the next is to add the relevant data to its entry?

    I should add by the way that the HWND variable m_hADAPTER is a handle to the combo box control itself and not a HWND handle to the Dialog Box it's contained within.

    I hope that's made some sense, I'd appreciate anyone who can shed any light on this at all is it's got my head well and truly cornered

  2. #2
    Registered User
    Join Date
    Dec 2017
    Posts
    1,632
    Maybe the first call is just to add a string to the combo box and maybe the next is to add the relevant data to its entry?
    That's basically it.

    The CB_ADDSTRING message adds a new combo box entry and returns the index of the new entry.

    The CB_SETITEMDATA message sets a pointer associated with a combo box entry to point to arbitrary data. This requires the index from the first message.
    A little inaccuracy saves tons of explanation. - H.H. Munro

  3. #3
    Registered User
    Join Date
    Jan 2010
    Posts
    206
    That's great! Thanks very much John

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Adding items to a bounded buffer in C
    By brandon236 in forum C Programming
    Replies: 2
    Last Post: 02-07-2017, 02:57 AM
  2. Adding items to the beginning of a file
    By Dunners in forum C++ Programming
    Replies: 1
    Last Post: 02-20-2005, 09:13 AM
  3. Dialog items and hiding them
    By bman1176 in forum Windows Programming
    Replies: 3
    Last Post: 01-16-2002, 01:59 PM
  4. Adding Items to Combo Boxes
    By tenthirty in forum Windows Programming
    Replies: 10
    Last Post: 12-21-2001, 02:37 AM
  5. Menu Items in a dialog app MSVC++
    By jinx in forum Windows Programming
    Replies: 1
    Last Post: 10-19-2001, 01:44 AM

Tags for this Thread