I have an Win32 EDIT
control with an assigned ID (IDC_FILE_NAME_INPUT
) and I want the Save Dialog to open up when this control is clicked.
I handle this in the WM_COMMAND
message of the window processor:
case WM_COMMAND:
{
switch (LOWORD(wParam))
{
case IDC_FILE_NAME_INPUT:
{
SetFocus(hWnd); // If I remove this the dialog opens every time it's closed
OPENFILENAME ofn;
wchar_t szFileName[MAX_PATH] = TEXT("");
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hWnd;
ofn.lpstrFilter = TEXT("Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0");
ofn.lpstrFile = szFileName;
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_EXPLORER | OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY;
ofn.lpstrDefExt = TEXT("txt");
if (GetSaveFileName(&ofn))
{
}
break;
}
}
}
break;
When I click on the EDIT
control, the dialog opens up but when I close it (Cancel, Save or X), it shows up again. Only this time, when I close it again, it stays closed. If I remove the SetFocus(hWnd);
part, it just keeps opening itself until I close the entire application. I need to know how to make the EDIT
lose focus as soon as the dialog is open, or maybe I should do this with another message than WM_COMMAND