I'm creating a basic notepad program, and when the user clicks close, I want it to ask the user if they want to save the current document opened. I'm using a tabbed interface, and trying to retrieve the filename ( text on tab ) so I have a MessageBox that says "Would you like to save: untitled.txt" or similar. I'm having trouble getting the file name. This is what I currently have:
case ID_FILE_CLOSE: // When the close button is clicked
{
HWND hEdit, hTabs;
hTabs = GetDlgItem( hwnd, IDC_MAIN_TAB );
int curTab = TabCtrl_GetCurSel( hTabs );
TCITEM curtitem;
TabCtrl_GetItem( hTabs, curTab, &curtitem );
// Check for file name
MessageBox( hwnd, curtitem.pszText, "Test", MB_OK );
}
break;
This is the error I keep getting in a popup box with Break, Continue, Ignore buttons:
Unhandled exception at 0x7597d298 in notepadpremium.exe: 0xC0000005: Access violation reading location 0xcccccccc.
I'm using MS Visual C++ Express 2010.
I also have a listbox with the filenames that also show the extension ( almost like notepad++ document switcher ) and tried LB_GETITEMDATA through a message, but that always returned blank. I think that was because I use LB_ADDSTRING to add it to the listbox. ( the listbox and tabs are interconnected, when you click on a file in the listbox, it changes to the corresponding tab ). Why isnt my code working the way it should?
Read the documentation:
You are not initializing the
TCITEMat all. You need to tellTabCtrl_GetItem()what data to retrieve, and more importantly what buffer you provide to receive that data into. You are not doing any of that, you are passing random data toTabCtrl_GetItem(), which is why it crashes.Try this instead:
As for your ListBox issue, you said you are using
LB_ADDSTRINGto add strings to the ListBox, but are usingLB_GETITEMDATAto retrieve them. That is wrong. You need to useLB_GETTEXTLENandLB_GETTEXTinstead.LB_GETITEMDATAis used to retrieve user-defined data that was added to the ListBox usingLB_SETITEMDATA.