Subversion Repositories Games.Chess Giants

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  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.  
  19.    _beginthread (StartThread_ThisDialog, 0, NULL); // fire up a new one
  20.  
  21.    return; // return as soon as the thread is fired up
  22. }
  23.  
  24.  
  25. void DialogBox_SavePosition_Validated (void)
  26. {
  27.    // callback function called by the main game thread when the dialog box is validated
  28.  
  29.    // remember this callback is no longer to be called
  30.    is_dialogbox_saveposition_validated = false;
  31.  
  32.    // save the requested FEN file
  33.    if (!FENFile_Save (saveposition_pathname, the_board.moves[the_board.viewed_move].fen_string))
  34.    {
  35.       messagebox.hWndParent = hMainWnd;
  36.       wcscpy_s (messagebox.title, WCHAR_SIZEOF (messagebox.title), LOCALIZE (L"ImportantMessage"));
  37.       wcscpy_s (messagebox.text, WCHAR_SIZEOF (messagebox.text), LOCALIZE (L"Error_SaveFailed"));
  38.       messagebox.flags = MB_ICONWARNING | MB_OK;
  39.       DialogBox_Message (&messagebox); // on error, display a modeless error message box
  40.    }
  41.  
  42.    return; // finished, FEN position has been saved
  43. }
  44.  
  45.  
  46. static void StartThread_ThisDialog (void *thread_parms)
  47. {
  48.    // this function runs in a separate thread, for that's the only way (seemingly)
  49.    // to implement a non-modal Save dialog box using the Common Controls library.
  50.  
  51.    OPENFILENAME ofn;
  52.  
  53.    // reset and prepare the open file name structure
  54.    memset (&ofn, 0, sizeof (ofn));
  55.    ofn.lStructSize = sizeof (ofn);
  56.    ofn.hwndOwner = hMainWnd;
  57.    ofn.lpstrFilter = LOCALIZE (L"PositionFileFilter");
  58.    ofn.lpstrDefExt = L"fen"; // default extension will be .fen
  59.    ofn.nFilterIndex = 1; // first filter (list is 1-based)
  60.    ofn.lpstrCustomFilter = ofn_customfilter;
  61.    ofn.nMaxCustFilter = WCHAR_SIZEOF (ofn_customfilter);
  62.    ofn.lpstrFile = saveposition_pathname;
  63.    ofn.nMaxFile = WCHAR_SIZEOF (saveposition_pathname);
  64.    ofn.Flags = OFN_ENABLESIZING | OFN_EXPLORER | OFN_ENABLEHOOK | OFN_OVERWRITEPROMPT;
  65.  
  66.    // display the dialog box and get the file name
  67.    if (GetSaveFileName (&ofn) != 0)
  68.       is_dialogbox_saveposition_validated = true;
  69.  
  70.    return; // _endthread() implied
  71. }
  72.