-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfile_dialog.cc
More file actions
40 lines (33 loc) · 993 Bytes
/
file_dialog.cc
File metadata and controls
40 lines (33 loc) · 993 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include "file_dialog.h"
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int open_file_dialog(char *rom_name, char *filters) {
/* open file dialogue */
char cwd[MAX_PATH];
GetCurrentDirectory(MAX_PATH, cwd);
OPENFILENAME ofn;
char szFile[MAX_PATH];
/* open a file name */
ZeroMemory( &ofn , sizeof( ofn));
ofn.lStructSize = sizeof ( ofn );
ofn.hwndOwner = NULL ;
ofn.lpstrFile = szFile ;
ofn.lpstrFile[0] = '\0';
ofn.nMaxFile = sizeof( szFile );
ofn.lpstrFilter = "Chip8\0*.ch8\0All\0*.*\0";
ofn.nFilterIndex =1;
ofn.lpstrFileTitle = NULL ;
ofn.nMaxFileTitle = 0 ;
ofn.lpstrInitialDir=NULL ;
ofn.Flags = OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST ;
/* change current working directory back to location of executable */
SetCurrentDirectory(cwd);
if (!GetOpenFileName( &ofn)) {
/* user hit cancel */
return 1;
}
strcpy(rom_name, szFile);
return 0;
}