Rev 124 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | pmbaty | 1 | // dialog_save.cpp |
2 | |||
3 | #include "../common.h" |
||
4 | |||
5 | |||
6 | // global variables used in this module only |
||
7 | static wchar_t ofn_customfilter[256] = L""; |
||
8 | static wchar_t saveposition_pathname[MAX_PATH]; |
||
9 | |||
10 | |||
11 | // local prototypes |
||
12 | static void StartThread_ThisDialog (void *thread_parms); |
||
13 | |||
14 | |||
15 | void DialogBox_SavePosition (void) |
||
16 | { |
||
17 | // helper function to fire up the modeless Save dialog box |
||
18 | |||
140 | pmbaty | 19 | is_dialogbox_displayed = true; |
1 | pmbaty | 20 | _beginthread (StartThread_ThisDialog, 0, NULL); // fire up a new one |
21 | |||
22 | return; // return as soon as the thread is fired up |
||
23 | } |
||
24 | |||
25 | |||
26 | void DialogBox_SavePosition_Validated (void) |
||
27 | { |
||
28 | // callback function called by the main game thread when the dialog box is validated |
||
29 | |||
30 | // remember this callback is no longer to be called |
||
31 | is_dialogbox_saveposition_validated = false; |
||
32 | |||
33 | // save the requested FEN file |
||
34 | if (!FENFile_Save (saveposition_pathname, the_board.moves[the_board.viewed_move].fen_string)) |
||
35 | { |
||
36 | messagebox.hWndParent = hMainWnd; |
||
37 | wcscpy_s (messagebox.title, WCHAR_SIZEOF (messagebox.title), LOCALIZE (L"ImportantMessage")); |
||
38 | wcscpy_s (messagebox.text, WCHAR_SIZEOF (messagebox.text), LOCALIZE (L"Error_SaveFailed")); |
||
39 | messagebox.flags = MB_ICONWARNING | MB_OK; |
||
40 | DialogBox_Message (&messagebox); // on error, display a modeless error message box |
||
41 | } |
||
42 | |||
43 | return; // finished, FEN position has been saved |
||
44 | } |
||
45 | |||
46 | |||
47 | static void StartThread_ThisDialog (void *thread_parms) |
||
48 | { |
||
49 | // this function runs in a separate thread, for that's the only way (seemingly) |
||
50 | // to implement a non-modal Save dialog box using the Common Controls library. |
||
51 | |||
52 | OPENFILENAME ofn; |
||
53 | |||
54 | // reset and prepare the open file name structure |
||
55 | memset (&ofn, 0, sizeof (ofn)); |
||
56 | ofn.lStructSize = sizeof (ofn); |
||
57 | ofn.hwndOwner = hMainWnd; |
||
58 | ofn.lpstrFilter = LOCALIZE (L"PositionFileFilter"); |
||
59 | ofn.lpstrDefExt = L"fen"; // default extension will be .fen |
||
60 | ofn.nFilterIndex = 1; // first filter (list is 1-based) |
||
61 | ofn.lpstrCustomFilter = ofn_customfilter; |
||
62 | ofn.nMaxCustFilter = WCHAR_SIZEOF (ofn_customfilter); |
||
63 | ofn.lpstrFile = saveposition_pathname; |
||
64 | ofn.nMaxFile = WCHAR_SIZEOF (saveposition_pathname); |
||
65 | ofn.Flags = OFN_ENABLESIZING | OFN_EXPLORER | OFN_ENABLEHOOK | OFN_OVERWRITEPROMPT; |
||
66 | |||
67 | // display the dialog box and get the file name |
||
68 | if (GetSaveFileName (&ofn) != 0) |
||
69 | is_dialogbox_saveposition_validated = true; |
||
140 | pmbaty | 70 | is_dialogbox_displayed = false; |
1 | pmbaty | 71 | |
124 | pmbaty | 72 | the_board.reevaluate = true; // refresh the GUI buttons if needed |
1 | pmbaty | 73 | return; // _endthread() implied |
74 | } |