Manually adding controls to a wnd and their functions.

This is a discussion on Manually adding controls to a wnd and their functions. within the Windows Programming forums, part of the Platform Specific Boards category; Hi, I'm trying to make a File->Open type of a window to pop up from my main dialog. I've made ...

  1. #1
    Registered User
    Join Date
    May 2005
    Location
    Toronto, Canada
    Posts
    257

    Manually adding controls to a wnd and their functions.

    Hi,
    I'm trying to make a File->Open type of a window to pop up from my main dialog. I've made it manually. I connect to an FTP server and spit out the folders in the current directory into a ListBox. Now I want to add an OnSelchange() function that will go into the selected folder, open it and put the contents into the list box.
    I can't do the message map properly.
    Code:
    BEGIN_MESSAGE_MAP(CTestDialog, CDialog) 
    
    // Message map macros for CTestDialog will go here 
    ON_COMMAND(IDB_CONNECT, OnConnect) 
    ON_LB_SELCHANGE(IDLB_MAINDIR, OnSelchangeMainDir)
    
    END_MESSAGE_MAP()
    and the error:
    Code:
    error C2065: 'ON_LB_SELCHANGE' : undeclared identifier
    the function is declared in the class and the definition is in the .cpp file. I'm not sure where to declare the message.
    Everything is relative...

  2. #2
    Registered User
    Join Date
    May 2005
    Location
    Toronto, Canada
    Posts
    257
    ok, If I change the message to ON_LBN_SELCHANGE(IDLB_MAINDIR, OnSelchangeMainDir) it compiles without errors, This message is used for another listbox clicking function. The problem now is a "Memory could not be read" at run-time when I click on an item in the listbox. I guess it's the function, here it is:
    Code:
    afx_msg void CTestDialog::OnSelchangeMainDir()
    {
    	CFtpFileFind finder(gpConnect);
    
    	CString fname;
    	CListBox* pListMain = (CListBox*)GetDlgItem(IDLB_MAINDIR); 
    	CListBox* pListSub = (CListBox*)GetDlgItem(IDLB_SUBDIR);
    
    	BOOL bWorking = finder.FindFile(_T("*"));
    
    	pListMain->GetText(pListMain->GetCurSel(), fname);
    	gpConnect->SetCurrentDirectory(fname);
    					
    	bWorking = finder.FindFile(_T("*"));
    
    	pListMain->ResetContent( );
    	pListSub->ResetContent( );
    
    	while (bWorking)
    	{
    		bWorking = finder.FindNextFile();
    		fname = finder.GetFileName();
    		//fprintf(out,"%s\n", fname ); 
    
    		if( strchr(fname,'.') )  //strstr(fname,".txt")  ||
    			pListSub->AddString(fname);
    		else
    			pListMain->AddString(fname);  
    	}
    		
    }
    and gpConnect is a gloal variable CFtpConnection* gpConnect; I establish a connection by a different function and make that connection pointer equal to the global one.
    Everything is relative...

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    EDIT: misread the code....

    try using NULL in the find file.

    >>GetCurSel(),
    will return LB_ERR == -1 if selection has not yet been set, ie if you are processing msg before the calling the default handler.


    What IDE do you use?


    Learn to debug...
    In MSVC (looks like MFC) add a break point with F9, run with F5 and it will stop on the break point. F10 to move one line at a time.

    Or add MessageBoxes to show how far the app has run (with network problems).
    Last edited by novacain; 08-21-2005 at 06:54 AM.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  4. #4
    Registered User
    Join Date
    May 2005
    Location
    Toronto, Canada
    Posts
    257
    >>GetCurSel(),
    will return LB_ERR == -1 if selection has not yet been set
    The function describes an event to be carried out when a user selects something from the list. So GetCurSel() will have to return a proper index. If there is no selection this function is not run. I can't even test it now, because there is something wrong with the ftp connection. I get an erro msg that The Connection to the Server has been Reset or somehting very close to it. Any ideas?

    and I use MS visual C++ 6.0. I've tried the debugger on this.
    Everything is relative...

  5. #5
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    MSDN
    "LBN_SELCHANGE notification message when the selection in a list box is about to change."

    So it is possible that the selection has not yet changed.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

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