well im trying to create a notepad in the win32 Api with C++ and at the moment im trying to set up the Open and Save As dialogs but the open Dialog works and the Save As doesn't, yet when i comment out the Open Dialog the Save Dialog works

Im using dev C++
Heres the code:

case IDM_OPEN:
//Open Dialog
OPENFILENAME openFileDialog;
char szFileName[MAX_PATH];
ZeroMemory(&openFileDialog, sizeof(openFileDialog));
openFileDialog.lStructSize= sizeof(openFileDialog);
openFileDialog.hwndOwner = hwnd;
openFileDialog.lpstrFilter = "Demonic Text (*.Dtxt)\0*.Dtxt\0Text Files (*.txt)\0*txt\0All Files (*.*)\0*.*\0";
openFileDialog.lpstrFile = szFileName;
openFileDialog.nMaxFile = MAX_PATH;
openFileDialog.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
openFileDialog.lpstrDefExt = "Dtxt";

if(GetOpenFileName(&openFileDialog)){

}
break;



case IDM_SAVE:
break;
case IDM_SAVE_AS:
//Save Dialog
OPENFILENAME saveFileDialog;
char szSaveFileName[MAX_PATH];
ZeroMemory(&saveFileDialog, sizeof(saveFileDialog));
saveFileDialog.lStructSize= sizeof(saveFileDialog);
saveFileDialog.hwndOwner = hwnd;
saveFileDialog.lpstrFilter = "Demonic Text (*.Dtxt)\0*.Dtxt\0Text Files (*.txt)\0*txt\0All Files (*.*)\0*.*\0";
saveFileDialog.lpstrFile = szSaveFileName;
saveFileDialog.nMaxFile = MAX_PATH;
saveFileDialog.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY |OFN_OVERWRITEPROMPT;
saveFileDialog.lpstrDefExt = "Dtxt";

if(GetSaveFileName(&saveFileDialog)){

}
break;

I'm using Windows 7 and I can't make GetOpenFileDlg() to work. Maybe its deprecated because Microsoft recommends using IFileOpenDialog now. But I'm certain that GetOpenFileDlg() is still support otherwise no program written before Vista would work on Vista or Win7.

I'm using Windows 7 and I can't make GetOpenFileDlg() to work. Maybe its deprecated because Microsoft recommends using IFileOpenDialog now. But I'm certain that GetOpenFileDlg() is still support otherwise no program written before Vista would work on Vista or Win7.

well i got Mine working and tested on windows 7, xp, and 2000 and my code works the only thing i had to do different is take the two dialogs( Open and Save dialogs) and make them the same, so you just use the same declaration for both opening and saving

I think ... though i haven't tried it out yet ... that you may well need a "switch(LOWORD (Param))" statement in there. Also, i use DevC++ with Win32 and find that it consistently goes a bit silly after you've compiled a win32 project a few times. The other day i accidently commented out the brackets on the main func and the project compiled just fine!! madness!

Opps, didnt note that thread solved

add this after you declare the szSaveFileName:

memset(szSaveFileName, 0, MAX_PATH);

Or just char szFileName[MAX_PATH] = {0}; . In that case memset() is not needed.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.