程式語言 - Wine - C/C++ - Common Dialog - SaveFile



參考資訊:
http://www.winprog.org/tutorial/
http://winapi.freetechsecrets.com/win32/
https://github.com/gammasoft71/Examples_Win32
http://masm32.com/board/index.php?topic=3584.0
https://learn.microsoft.com/en-us/windows/win32/winmsg/window-styles

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] = "test";
    char pFilter[255] = {0};
    OPENFILENAME stSave = {0};

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

    stSave.lStructSize = sizeof(OPENFILENAME);
    stSave.lpstrFilter = pFilter;
    stSave.lpstrFile = pPath;
    stSave.lpstrDefExt = "txt";
    stSave.nMaxFile = sizeof(pPath);
    stSave.lpstrInitialDir = "/tmp";
    stSave.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST;
    if (GetSaveFileName(&stSave)) {
        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