Skip to content

Instantly share code, notes, and snippets.

@ktye
Created August 4, 2022 05:15
Show Gist options
  • Save ktye/cea01aad213facba185b5e583b7a45fb to your computer and use it in GitHub Desktop.
Save ktye/cea01aad213facba185b5e583b7a45fb to your computer and use it in GitHub Desktop.
show windows 3.1 file open dialog
// this program opens an old win 3.1 file-open dialog.
//
// it works if OFN_EXPLORER is missing AND a hook is used.
//
// compile with msys2/mingw:
// gcc fileopen.c -lcomdlg32 -o fileopen
#include<windows.h>
#include<commdlg.h>
#include<stdio.h>
UINT_PTR CALLBACK hook(_In_ HWND hdlg, _In_ UINT uiMsg, _In_ WPARAM wParam, _In_ LPARAM lParam){ return 0; }
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){
OPENFILENAME ofn;
char szFile[260];
HWND hwnd=NULL;
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hwnd;
ofn.lpstrFile = szFile;
ofn.lpstrFile[0] = '\0';
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrFilter = "All\0*.*\0Text\0*.TXT\0";
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.lpfnHook = hook;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_ENABLEHOOK ;
if (GetOpenFileName(&ofn))
printf("%s\n", ofn.lpstrFile);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment