Access a Listbox

This is a discussion on Access a Listbox within the Windows Programming forums, part of the Platform Specific Boards category; Hello, i have this little problem. In my code, i create a listbox, which is a child window from the ...

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    17

    Access a Listbox

    Hello,
    i have this little problem.
    In my code, i create a listbox, which is a child window from the main window.
    Now, the problem is: how can i access the listbox in the MainWindowProc function?

    How can i set a ID to the ListBox, which will be passed as a message to the WindowProc?

    I would be very thankful if you could give me a short example, because i really have no idea how this works.

    Thank you very mutch.

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    When creating a child window, you can use the hMenu argument as a child window identifier. This example uses the identifier 0xED. In real code, you should use a constant, rather than a magic number.
    Code:
    			CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("EDIT"), TEXT("Write here!"), WS_CHILD | WS_VISIBLE,
    			               0, 0, 0, 0,
    			               hwnd, (HMENU) 0xED, GetModuleHandle(NULL), NULL);
    Once, you have a child window with an identifier, you can use the SendDlgItemMessage, GetDlgItemText and SetDlgItemText functions to interact with it:
    Code:
    SetDlgItemText(hwnd, 0xED, TEXT("Hello"));
    Alternatively, if you need its HWND, you can use the GetDlgItem function:
    Code:
    MoveWindow(GetDlgItem(hwnd, 0xED), rc.left, rc.top, rc.right, rc.bottom, TRUE);
    The alternative method to interact with a child window is to store its HWND when you create it. However, using an identifier is generally preferable.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Deal or No Deal listbox prob
    By kryptkat in forum Windows Programming
    Replies: 5
    Last Post: 03-30-2009, 06:53 PM
  2. Adding Strings to ListBox in a Dialog
    By kevins963 in forum C Programming
    Replies: 5
    Last Post: 09-10-2008, 04:36 PM
  3. cant load dialog with listbox, help
    By terracota in forum Windows Programming
    Replies: 2
    Last Post: 11-22-2004, 06:11 PM
  4. How to cast a ListBox item to an int for a switch statment?
    By Swaine777 in forum C++ Programming
    Replies: 8
    Last Post: 09-26-2004, 08:52 PM
  5. Getting FULL filename from listbox
    By Garfield in forum Windows Programming
    Replies: 8
    Last Post: 01-27-2002, 07:28 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21