代码之家  ›  专栏  ›  技术社区  ›  Svisstack

win32函数到openfiledialog?

  •  11
  • Svisstack  · 技术社区  · 14 年前

    我的搜索功能是 OpenFileDialog .NET 但关于 win32 ,在此名称上找不到此函数 MSDN 我记得这个函数存在。

    有人能告诉我名字吗?

    问候语,

    2 回复  |  直到 14 年前
        1
  •  18
  •   YWE    14 年前

    我相信你在找 GetOpenFileName .

        2
  •  2
  •   Artem Moroz    6 年前
    //make sure this is commented out in all code (usually stdafx.h)
    // #define WIN32_LEAN_AND_MEAN 
    
    #include <windows.h>
    
    OPENFILENAME ofn;       // common dialog box structure
    TCHAR szFile[260] = { 0 };       // if using TCHAR macros
    
    // Initialize OPENFILENAME
    ZeroMemory(&ofn, sizeof(ofn));
    ofn.lStructSize = sizeof(ofn);
    ofn.hwndOwner = hWnd;
    ofn.lpstrFile = szFile;
    ofn.nMaxFile = sizeof(szFile);
    ofn.lpstrFilter = _T("All\0*.*\0Text\0*.TXT\0");
    ofn.nFilterIndex = 1;
    ofn.lpstrFileTitle = NULL;
    ofn.nMaxFileTitle = 0;
    ofn.lpstrInitialDir = NULL;
    ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
    
    if (GetOpenFileName(&ofn) == TRUE)
    {
        // use ofn.lpstrFile
    }
    

    取自 Displaying Open File Dialog using WinApi