Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to insert data into ListBox(Something Different)

How to insert data into ListBox(Something Different)

Scheduled Pinned Locked Moved C / C++ / MFC
c++tutorialquestionlearning
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    ashishbhatt 0
    wrote on last edited by
    #1

    Hi All, I am using Win32 Application. In that I have created resource as Dialog and also in this Dialog I have added onr ListBox control. Now I want to insert data in to this Dialog. In this I have added one C++ class in which I am using like below to open Dialog..... void CCurrentWnd::Open() { DialogBoxParam(hAppInstance,MAKEINTRESOURCE(IDD_CURWND),NULL,(DLGPROC)CurrntWndDlgProc,(LONG)this); } As shown in above code my CurrentDlgProc is shown as below.... BOOL CCurrentWnd::CurrntWndDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { CCurrentWnd * _this = (CCurrentWnd *)GetWindowLong(hwnd,GWL_USERDATA); switch(uMsg) { case WM_INITDIALOG: { HWND m_list1; m_list1 = GetDlgItem(hwnd,IDC_WNDLIST); //Now here I got the handle of the ListBox // Now How to insert data in //this ListBox from here within this class. } //Any code } } Here IDC_WNDLIST is the ID of the ListBox control. Is there any method for ListBox control as in Tab control like TabCtrl_InsertItem().? If you know any other alternative then plz reply me. Thanks in Advance.

    Ashish Bhatt

    H 1 Reply Last reply
    0
    • A ashishbhatt 0

      Hi All, I am using Win32 Application. In that I have created resource as Dialog and also in this Dialog I have added onr ListBox control. Now I want to insert data in to this Dialog. In this I have added one C++ class in which I am using like below to open Dialog..... void CCurrentWnd::Open() { DialogBoxParam(hAppInstance,MAKEINTRESOURCE(IDD_CURWND),NULL,(DLGPROC)CurrntWndDlgProc,(LONG)this); } As shown in above code my CurrentDlgProc is shown as below.... BOOL CCurrentWnd::CurrntWndDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { CCurrentWnd * _this = (CCurrentWnd *)GetWindowLong(hwnd,GWL_USERDATA); switch(uMsg) { case WM_INITDIALOG: { HWND m_list1; m_list1 = GetDlgItem(hwnd,IDC_WNDLIST); //Now here I got the handle of the ListBox // Now How to insert data in //this ListBox from here within this class. } //Any code } } Here IDC_WNDLIST is the ID of the ListBox control. Is there any method for ListBox control as in Tab control like TabCtrl_InsertItem().? If you know any other alternative then plz reply me. Thanks in Advance.

      Ashish Bhatt

      H Offline
      H Offline
      Hamid Taebi
      wrote on last edited by
      #2

      You can use of these messages LB_ADDSTRING or LB_INSERTSTRING.

      A 2 Replies Last reply
      0
      • H Hamid Taebi

        You can use of these messages LB_ADDSTRING or LB_INSERTSTRING.

        A Offline
        A Offline
        ashishbhatt 0
        wrote on last edited by
        #3

        Ya You are absolutely right. Using these messages I can add String to ListBox. But my problem is that how to insert string in to ListBox??

        Ashish Bhatt

        A 1 Reply Last reply
        0
        • A ashishbhatt 0

          Ya You are absolutely right. Using these messages I can add String to ListBox. But my problem is that how to insert string in to ListBox??

          Ashish Bhatt

          A Offline
          A Offline
          ashishbhatt 0
          wrote on last edited by
          #4

          Sorry, I tried as you told and I got the solution. If I will get some problem then I will contact you. Thank you very much.

          Ashish Bhatt

          1 Reply Last reply
          0
          • H Hamid Taebi

            You can use of these messages LB_ADDSTRING or LB_INSERTSTRING.

            A Offline
            A Offline
            ashishbhatt 0
            wrote on last edited by
            #5

            Hi,, I got little much problem with same.I am using SendMessage() function to set the value for the ListBox using LB_ADDSTRING message. But I got not perfect value as pass here in the parameter lParam of Sendmessage() function. I am passing such like this. char *str ="Desktop"; SendMessage(m_list1,LB_ADDSTRING,NULL,(LPARAM)(str)); And I got undefined value in listbox like square rectangles. If you have any other way to pass then tell me. Thanks.

            Ashish Bhatt

            H 1 Reply Last reply
            0
            • A ashishbhatt 0

              Hi,, I got little much problem with same.I am using SendMessage() function to set the value for the ListBox using LB_ADDSTRING message. But I got not perfect value as pass here in the parameter lParam of Sendmessage() function. I am passing such like this. char *str ="Desktop"; SendMessage(m_list1,LB_ADDSTRING,NULL,(LPARAM)(str)); And I got undefined value in listbox like square rectangles. If you have any other way to pass then tell me. Thanks.

              Ashish Bhatt

              H Offline
              H Offline
              Hamid Taebi
              wrote on last edited by
              #6

              TCHAR str[120] =_T("Desktop"); ::SendMessage(GetDlgItem(IDC_LIST1)->m_hWnd,LB_ADDSTRING,0,(LPARAM)(str));

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups