GetOpenFileName
-
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { static HINSTANCE hInstance; static OPENFILENAME ofn; static TCHAR szFile[100]; switch (message) { case WM_CREATE: hInstance = ((LPCREATESTRUCT) lParam)->hInstance; ofn.lStructSize = sizeof (OPENFILENAME) ; ofn.hwndOwner = hwnd ; ofn.hInstance = NULL ; ofn.lpstrFilter = TEXT("All\0*.*\0\0Text\0*.TXT\0\0"); ofn.lpstrCustomFilter = NULL ; ofn.nMaxCustFilter = 0 ; ofn.nFilterIndex = 0 ; ofn.lpstrFile = NULL ; // Bei Öffnen bzw. Schließen gesetzt ofn.nMaxFile = MAX_PATH ; ofn.lpstrFileTitle = NULL ; // Bei Öffnen bzw. Schließen gesetzt ofn.nMaxFileTitle = MAX_PATH ; ofn.lpstrInitialDir = NULL ; ofn.lpstrTitle = NULL ; ofn.Flags = 0 ; // Bei Öffnen bzw. Schließen gesetzt ofn.nFileOffset = 0 ; ofn.nFileExtension = 0 ; ofn.lpstrDefExt = TEXT ("txt") ; ofn.lCustData = 0L ; ofn.lpfnHook = NULL ; ofn.lpTemplateName = NULL ; return 0 ; case WM_COMMAND: switch(LOWORD(wParam)) { case ID_ANDERES_\1: DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), hwnd, AboutProc); break; case ID_ANDERES_ASKABOUTSAVE: ofn.hwndOwner = hwnd ; ofn.lpstrFile = szFile ; ofn.lpstrFileTitle = TEXT ("Dialoge1") ; ofn.Flags = OFN_HIDEREADONLY | OFN_CREATEPROMPT ; GetOpenFileName(&ofn); break; } return 0; case WM_DESTROY: PostQuitMessage (0) ; return 0 ; } return DefWindowProc (hwnd, message, wParam, lParam) ; }Hallo ich wollte mit GetOPenFileName arbeiten, aber nachdem ich die Datei ausgewählt habe und auf Öffnen klicke stürzt das Programm ab?
-
szFile ist nur 100 Zeichen lang und nicht MAX_PATH. Ist der ausgewählte Dateiname länger als 100 Zeichen?
-
da ändert sich nix
-
lpstrFileTitle
Pointer to a buffer that receives the file name and extension (without path information) of the selected file. This member can be NULL.
-
yahu vielen dank