Thread: API C Listbox

  1. #1
    Vicked
    Guest

    API C Listbox

    Hello

    I want a person to be able to click something in a listbox and as soon as he does the text in an edit box changes accordingly.

    All my controls are in the main window, I am using LB_SELCHANGE and
    HWND hList = GetDlgItem(hwnd, IDC_LIST);
    int count = SendMessage(hList, LB_GETCURSEL, 0, 0);

    can anyone give me a small example program so I can see where I am going wrong.

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    From a search of this board for LBN_SELCHANGE:

    http://www.cprogramming.com/cboard/s...t=LBNSELCHANGE

    Or, you could try something like (untested):

    Code:
    case WM_COMMAND:
      {
      WORD  wNotify;      /* notification code */
      WORD  wID;          /* control id */
      HWND  hCntrl;       /* control handle */
      int   nSelected;    /* zero-based index of selected listbox item */
      int   nLen;         /* listbox item number of TCHARS (ie str length) */
      TCHAR *chBuffer;    /* for listbox item text */
    
      wID=LOWORD(wParam);
      wNotify=HIWORD(wParam);
      hCntrl=(HWND)lParam;
    
      if (hCntrl && wNotify==LBN_SELCHANGE && wID==IDC_LIST)
        {
        nSelected=SendMessage(hCntrl, LB_GETCURSEL, 0, 0);
        nLen=SendMessage(hCntrl, LB_GETTEXTLEN, nSelected, 0);
        chBuffer=(TCHAR*)malloc((nLen+1)*sizeof(TCHAR));
        if (chBuffer)
          {
          SendMessage(hCntrl, LB_GETTEXT, nSelected, (LPARAM)chBuffer);
          /* 'hEdit' is handle to edit control*/
          SetWindowText(hEdit,chBuffer);
          free(chBuffer);
          }
        }
      return 0;
      }
    edit: editing
    Last edited by Ken Fitlike; 04-01-2003 at 06:51 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. ListBox Extra Data Storage
    By Welder in forum Windows Programming
    Replies: 1
    Last Post: 11-01-2007, 01:46 PM
  2. 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
  3. Listbox stealing focus
    By Calthun in forum Windows Programming
    Replies: 3
    Last Post: 09-12-2004, 04:36 PM
  4. FILES in WinAPI
    By Garfield in forum Windows Programming
    Replies: 46
    Last Post: 10-02-2003, 06:51 PM
  5. Getting FULL filename from listbox
    By Garfield in forum Windows Programming
    Replies: 8
    Last Post: 01-27-2002, 08:28 AM