dro873
February 20th, 2005, 05:43 PM
I want my program to allow the user to save data using a Save As prompt. I declare a global variable OPENFILENAME ofn, and then when my window sends the WM_CREATE message, I set the various instance variables of ofn. Here's my code for the WM_CREATE case:
case WM_CREATE:
{
ofn.Flags = OFN_EXPLORER|OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT|OFN_FILEMUSTEXIST;
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = hwnd;
ofn.hInstance = GetModuleHandle(NULL);
ofn.lpstrFilter = "Data Files (.dat)\0*.dat\0\0";
ofn.lpstrCustomFilter = NULL;
ofn.nMaxCustFilter = 0;
ofn.nFilterIndex = 0;
ofn.lpstrFile = NULL;
ofn.nMaxFile = 256;
ofn.lpstrFileTitle = NULL;
ofn.lpstrInitialDir = NULL;
ofn.lpstrTitle = NULL;
ofn.lpstrDefExt = "dat";
} break;
Then, when the user clicks the "Save As..." option in my menu, it sends an ID_FILE_SAVE_AS message in the low end of the WPARAM variable, so I put this code in the WM_COMMAND case:
case WM_COMMAND:
{
switch(LOWORD(wParam))
{
case ID_FILE_SAVE_AS:
if (GetSaveFileName(&ofn))
SendMessage(hwnd,WM_SAVE_FILE,0,0); /*WM_SAVE_FILE is a constant that I define earlier in my program*/
break;
}
} break;
However, even though the Save As dialog displays correctly, and the GetSaveFileName returns a nonzero value (which I have been led to believe means that it executed correctly), the lpstrFile buffer is NULL. Can anyone tell me what is causing this? Thank you.
case WM_CREATE:
{
ofn.Flags = OFN_EXPLORER|OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT|OFN_FILEMUSTEXIST;
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = hwnd;
ofn.hInstance = GetModuleHandle(NULL);
ofn.lpstrFilter = "Data Files (.dat)\0*.dat\0\0";
ofn.lpstrCustomFilter = NULL;
ofn.nMaxCustFilter = 0;
ofn.nFilterIndex = 0;
ofn.lpstrFile = NULL;
ofn.nMaxFile = 256;
ofn.lpstrFileTitle = NULL;
ofn.lpstrInitialDir = NULL;
ofn.lpstrTitle = NULL;
ofn.lpstrDefExt = "dat";
} break;
Then, when the user clicks the "Save As..." option in my menu, it sends an ID_FILE_SAVE_AS message in the low end of the WPARAM variable, so I put this code in the WM_COMMAND case:
case WM_COMMAND:
{
switch(LOWORD(wParam))
{
case ID_FILE_SAVE_AS:
if (GetSaveFileName(&ofn))
SendMessage(hwnd,WM_SAVE_FILE,0,0); /*WM_SAVE_FILE is a constant that I define earlier in my program*/
break;
}
} break;
However, even though the Save As dialog displays correctly, and the GetSaveFileName returns a nonzero value (which I have been led to believe means that it executed correctly), the lpstrFile buffer is NULL. Can anyone tell me what is causing this? Thank you.