奇怪问题,郁闷,请教高手。(打开文件对话框没有响应)
CString OpenFile()
{
OPENFILENAME ofn; // common dialog box structure
char szFile[256]; // buffer for file name
// Initialize OPENFILENAME
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = AfxGetMainWnd()->GetSafeHwnd();
ofn.lpstrFile = szFile;
//
// Set lpstrFile[0] to '\0' so that GetOpenFileName does not
// use the contents of szFile to initialize itself.
//
ofn.lpstrFile[0] = '\0';
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrFilter = "画像(*.bmp)\0*.bmp\0画像(*.jpg)\0*.jpg\0";
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
// Display the Open dialog box.
if (GetOpenFileName(&ofn) == TRUE)
{
return ofn.lpstrFile;
}
return "";
}
不知道是上面代码问题不是,一调用这个函数 GetOpenFileName(&ofn) ,对话框就出来了,这点没问题。
也可以选择文件和文件类型,但是只要一点OK,或是别的任何按钮,就失去响应了,好像是传过去消息没有返回。debug这个该死的 GetOpenFileName(&ofn) 函数又跟不进去,比较郁闷,请教高手指点。
顺便:
CFileDialog dlg1;
CColorDialog dlg2;
CFontDialog dlg3;
唯独 CFileDialog 说没有这个类,include什么头文件也没用,就是说没有,也比较郁闷。