Thread: Creating/Adding to listboxes

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    6

    Creating/Adding to listboxes

    Hey guys

    Im having a problem adding strings to a listbox. ive tried many different variants, from other peoples code, but while most do compile fine, the listbox always remains empty...

    If you could help me i'd much appreciate it... Ive spent so much time on this...

    Also... what im trying to do is create a report with column values and data, but unable to do that (same problems as this), ive tried to set my sights lower and do this.. Any tips on inserting columns and stuff would be much appareciated...

    Thanx in advance

    Code:
    #include <windows.h>
    #include <commctrl.h>
    #include <stdio.h>
    #include <iostream.h>
    #include "resource.h" 
    
    BOOL CALLBACK DlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
    {
        switch(Message)
        {
    		
    
            case WM_INITDIALOG:
    		{
    
    		HWND hListView = GetDlgItem(hwnd, IDC_LIST_CTRL); 
    
    		SendMessage(hListView,LB_ADDSTRING, 0, (LPARAM)"Data");
    		SendMessage(hListView, LB_SETITEMDATA, 0, (LPARAM) 0); 
     		SendMessage(hListView,LB_ADDSTRING, 0, (LPARAM)"Data2");
    		SendMessage(hListView, LB_SETITEMDATA, 1, (LPARAM) 1); 
    
    	    return FALSE;
    		}
    
            case WM_CREATE:
            break;
    
    		case WM_CLOSE:
    		EndDialog(hwnd,0);
    		break;
    
    		default:
    		//return DefWindowProc(hwnd, Message, wParam, lParam);
    		return FALSE;
    	}
    
        return TRUE;
    }
    
     /* Main function (starting point) */
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
        LPSTR lpCmdLine, int nCmdShow)
    {
    
    	DialogBox(hInstance,MAKEINTRESOURCE(IDD_DIALOG1), NULL, (DLGPROC)DlgProc);
    
    		return TRUE;
    
    }

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Works ok for me, whats the problem exactly?
    Just re-read your post and I see that you say you aren't getting the strings in the listbox. I'm not sure unless you didn't create the listbox correctly in the editor.

    Zip up your entire project and I will look at it.

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    6
    The problem is for me, is that when the dialog box is loaded, the listbox is empty

    if my code is fine, is there any ListBox properties i should check?

    Also... 2 small points ive noticed since ive posted this:

    1. putting MSgBoxes around the item adding section.. both msgboxs appear before the dialog box... is timing the problem?

    2. running the debugger, i get the following error: "CXX0017" Error: this not found... in the "this" section of the DGB context

    Heres what i think is my entire project.. if there is anything missing please let me know..

  4. #4
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Apparently you are running an older version of Visual Studio then I am. It converted your project to the older version but I am now not even seeing the dialog box! I will look it over and let you know what I find out.

  5. #5
    Registered User
    Join Date
    Mar 2003
    Posts
    6
    Yup... im using Studio 97... although the current set of functions im using came with the MSDN disk.. (one reason im so puzzled as to why it wont add the strings)

    Weird, your getting more problems with it.. ive noticed that with VC++.. its so random... one program i wrote, intermittantly came up with compile errors... compile once, it failed, compile it again, it compiled... bloody microsoft

    I do try and use DevC++ (www.bloodshed.net) with Ming compiler where possible, but I cant get my listbox to work properly there either.. its really bugging me

    Thanx for helping.. i appreciate it :o)
    Last edited by punky; 03-02-2003 at 09:27 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Storing more data in ListBoxes in C
    By Welder in forum Windows Programming
    Replies: 1
    Last Post: 10-30-2007, 12:55 AM
  2. Replies: 2
    Last Post: 12-22-2006, 11:50 PM
  3. retrieving data from listboxes
    By luddeb in forum Windows Programming
    Replies: 6
    Last Post: 01-10-2006, 04:08 AM
  4. Listboxes
    By Zionaster in forum C++ Programming
    Replies: 3
    Last Post: 04-15-2003, 08:17 PM
  5. ListBoxes with MFC
    By omeydhomey in forum C++ Programming
    Replies: 1
    Last Post: 03-25-2003, 03:09 PM