我有EDIT
一个分配了 ID ( IDC_FILE_NAME_INPUT
) 的 Win32 控件,我希望在单击此控件时打开保存对话框。我WM_COMMAND
在窗口处理器的消息中处理这个:
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;
当我单击EDIT
控件时,对话框会打开,但当我关闭它(Cancel、Save或X)时,它会再次出现。只有这一次,当我再次关闭它时,它保持关闭状态。如果我删除该SetFocus(hWnd);
部分,它只会继续打开,直到我关闭整个应用程序。我需要知道如何EDIT
在对话框打开后立即失去焦点,或者我应该使用另一条消息而不是WM_COMMAND