Win32 SDK - 打开文件对话框

 

OPENFILENAME ofn;     // common dialog box structure
TCHAR szFile[MAX_PATH];  // buffer for file name

// Initialize OPENFILENAME
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hwndDlg;
ofn.lpstrFile = szFile;
ofn.lpstrFile[0] = '\0';    //
               // Set lpstrFile[0] to '\0' so that GetOpenFileName does not
               // use the contents of szFile to initialize itself.
               //
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrFilter = _T("Text files (*.txt)\0*.txt\0\0");
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
ofn.lpstrTitle = _T("打开");  // set the dialog box title

if (GetOpenFileName(&ofn))
{
  SetDlgItemText(hwndDlg, IDC_EDIT1, szFile);
}

 

 

posted @ 2014-12-18 11:43  huhu0013  阅读(3168)  评论(0编辑  收藏  举报