Wine >> C/C++ >> Dialog >> Common Dialog

OpenFile


參考資訊:
1. win32
2. petzold
3. tutorial
4. examples_win32

main.c

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine, int nCmdShow)
{
    int len = 0;
    char pPath[255] = {0};
    char pFilter[255] = {0};
    OPENFILENAME stOpen = {0};

    strcpy(pFilter, "MyFilter(*.TXT;*.DOC)");
    len = strlen(pFilter) + 1;
    strcat(&pFilter[len], "*.TXT;*.DOC");

    stOpen.lStructSize = sizeof(OPENFILENAME);
    stOpen.lpstrFilter = pFilter;
    stOpen.lpstrFile = pPath;
    stOpen.nMaxFile = sizeof(pPath);
    stOpen.lpstrInitialDir = "/tmp";
    stOpen.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST;
    if (GetOpenFileName(&stOpen)) {
        char buf[255] = {0};
        sprintf(buf, "path=%s", pPath);
        MessageBox(NULL, buf, "main", MB_OK);
    }
    ExitProcess(0);
    return 0;
}

編譯、執行

$ winegcc main.c -o main -lcomdlg32
$ wine ./main.exe



返回上一頁