home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 May / Pcwk5b98.iso / Borland / Cplus45 / BC45 / TODO.PAK / TODODLGS.CPP < prev    next >
C/C++ Source or Header  |  1995-08-29  |  7KB  |  264 lines

  1. //---------------------------------------------------------------------
  2. //
  3. //  TODODLGS.CPP - part of TODO example program
  4. //
  5. //      Copyright (c) 1991, 1993 by Borland International
  6. //      All Rights Reserved.
  7. //
  8. //---------------------------------------------------------------------
  9.  
  10. #define STRICT
  11.  
  12. #include <windows.h>
  13. #include <windowsx.h>
  14. #include <string.h>
  15.  
  16. #include "tododlgs.h"
  17. #include "tododefs.h"
  18.  
  19. //---------------------------------------------------------------------
  20. //
  21. //  member functions for class AboutBox.
  22. //
  23. //  not much needed here...
  24. //
  25. //---------------------------------------------------------------------
  26.  
  27. LPSTR AboutBox::GetDialogName()
  28. {
  29.     return "AboutBox";
  30. }
  31.  
  32. BOOL AboutBox::Dispatch( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam )
  33. {
  34.     switch( msg )
  35.         {
  36.  
  37.         case WM_INITDIALOG:
  38.  
  39.             return TRUE;                // no initialization.
  40.  
  41.         case WM_COMMAND:
  42.  
  43.             if( GET_WM_COMMAND_ID(wParam, lParam) == IDOK ||
  44.             GET_WM_COMMAND_ID(wParam, lParam) == IDCANCEL )
  45.             {
  46.             EndDialog( hDlg, TRUE );    // selecting OK or Cancel
  47.             return TRUE;                // terminates the dialog
  48.             }
  49.  
  50.         default:                        // if we don't handle it, pass it
  51.                                         // to our parent.
  52.  
  53.             return ModalDialog::Dispatch( hDlg, msg, wParam, lParam );
  54.  
  55.   }
  56. }
  57.  
  58. //---------------------------------------------------------------------
  59. //
  60. //  member functions for class FileBox.
  61. //
  62. //---------------------------------------------------------------------
  63.  
  64. BOOL FileBox::GetOpenFileName( HWND handle, char *fileName, char *titleName )
  65. {
  66.     ofn.hwndOwner = handle;
  67.     ofn.lpstrFile = fileName;
  68.     ofn.lpstrFileTitle = titleName;
  69.     ofn.Flags = OFN_FILEMUSTEXIST;
  70.     return ::GetOpenFileName( &ofn );
  71. }
  72.  
  73. BOOL FileBox::GetSaveFileName( HWND handle, char *fileName, char *titleName )
  74. {
  75.     ofn.hwndOwner = handle;
  76.     ofn.lpstrFile = fileName;
  77.     ofn.lpstrFileTitle = titleName;
  78.     ofn.Flags = OFN_OVERWRITEPROMPT;
  79.  
  80.     return ::GetOpenFileName( &ofn );
  81. }
  82.  
  83. OPENFILENAME FileBox::ofn =
  84. {
  85.     sizeof(OPENFILENAME),       // lStructSize
  86.     0,                          // hwndOwner
  87.     0,                          // hInstance
  88.     filters[0],                 // lpstrFilter
  89.     0,                          // lpstrCustomFilter
  90.     0,                          // nMaxCustFilter
  91.     0,                          // nFilterIndex
  92.     0,                          // lpstrFile
  93.     MAXPATH,                    // nMaxFile
  94.     0,                          // lpstrFileTitle
  95.     MAXFILE+MAXEXT,             // nMaxFileTitle
  96.     0,                          // lpstrInitialDir
  97.     0,                          // lpstrTitle
  98.     0,                          // Flags
  99.     0,                          // nFileOffset
  100.     0,                          // nFileExtension
  101.     "tdo",                      // lpstrDefExt
  102.     0,                          // lCustData
  103.     0,                          // lpfnHook
  104.     0                           // lpTemplateName
  105. };
  106.  
  107. char *FileBox::filters[] =
  108. {
  109.     "Todo Files (*.TDO)",   "*.tdo",
  110.     "All Files (*.*)",      "*.*",
  111.     ""
  112. };
  113.  
  114.  
  115. //---------------------------------------------------------------------
  116. //
  117. //  member functions for class EditBox.
  118. //
  119. //---------------------------------------------------------------------
  120.  
  121. LPSTR EditBox::GetDialogName()
  122. {
  123.     return "TodoEdit";
  124. }
  125.  
  126. //---------------------------------------------------------------------
  127. //
  128. //  void EditBox::InitDlg( HWND hDlg );
  129. //
  130. //  initializes the dialog box.
  131. //
  132. //---------------------------------------------------------------------
  133.  
  134. void EditBox::InitDlg( HWND hDlg )
  135. {
  136.     // set up the current date edit field.
  137.     SetDlgItemText( hDlg, IDE_DATEENT, 
  138.                     Current.DateCreated.AsString().c_str() );
  139.  
  140.     // set up the date due edit field.
  141.     SetDlgItemText( hDlg, IDE_DATEDUE, 
  142.                     Current.DateDue.AsString().c_str() );
  143.  
  144.     // set up the text edit field
  145.     SetDlgItemText( hDlg, IDE_TEXT, Current.Text.c_str() );
  146.  
  147.     // set up the correct radio button
  148.     Button = IDE_HIGH + 1 - Current.Priority;
  149.     CheckRadioButton( hDlg, IDE_LOW, IDE_HIGH, Button );
  150. }
  151.  
  152. //---------------------------------------------------------------------
  153. //
  154. //  void EditBox::CheckButton( HWND hDlg, WPARAM wParam );
  155. //
  156. //  called when the user selects one of the radio buttons.
  157. //
  158. //---------------------------------------------------------------------
  159.  
  160. void EditBox::CheckButton( HWND hDlg, WPARAM wParam )
  161. {
  162.     Button = wParam;
  163.     CheckRadioButton( hDlg, IDE_LOW, IDE_HIGH, Button );
  164. }
  165.  
  166. //---------------------------------------------------------------------
  167. //
  168. //  void EditBox::OkCmd( HWND hDlg );
  169. //
  170. //  called when the user selects the OK button.  Copies data from the
  171. //  dialog into the Todo entry and terminates the dialog.
  172. //
  173. //---------------------------------------------------------------------
  174.  
  175. void EditBox::OkCmd( HWND hDlg )
  176. {
  177.     char temp[100 ];
  178.  
  179.     //  copy date created from dialog.
  180.     GetDlgItemText( hDlg, IDE_DATEENT, temp, sizeof( temp ) );
  181.     {
  182.  
  183.     istrstream date( temp, sizeof( temp ) );
  184.     date >> Current.DateCreated;
  185.     }
  186.  
  187.     //  copy date due from dialog.
  188.     GetDlgItemText( hDlg, IDE_DATEDUE, temp, sizeof( temp ) );
  189.     {
  190.     istrstream date( temp, sizeof( temp ) );
  191.     date >> Current.DateDue;
  192.     }
  193.  
  194.     //  copy text from dialog
  195.     GetDlgItemText( hDlg, IDE_TEXT, temp, sizeof(temp) );
  196.     Current.Text = temp;
  197.  
  198.     //  copy priority from dialog.
  199.     Current.Priority = IDE_HIGH + 1 - Button;
  200.  
  201.     //  mark this entry as modified.
  202.     Current.Dirty = TRUE;
  203.  
  204.     EndDialog( hDlg, TRUE );
  205. }
  206.  
  207. //---------------------------------------------------------------------
  208. //
  209. //  void EditBox::CancelCmd( HWND hDlg );
  210. //
  211. //  called when the user selects the Cancel button.  Terminates the
  212. //  dialog without changing any fields in the entry.
  213. //
  214. //---------------------------------------------------------------------
  215.  
  216. void EditBox::CancelCmd( HWND hDlg )
  217. {
  218.     Result = 1;
  219.     EndDialog( hDlg, TRUE );
  220. }
  221.  
  222. //---------------------------------------------------------------------
  223. //
  224. //  BOOL EditBox::Dispatch( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam );
  225. //
  226. //  dispatches commands.
  227. //
  228. //---------------------------------------------------------------------
  229.  
  230. BOOL EditBox::Dispatch( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam )
  231. {
  232.     switch( msg )
  233.         {
  234.         case WM_INITDIALOG:
  235.  
  236.             InitDlg( hDlg );
  237.             return TRUE;
  238.  
  239.         case WM_COMMAND:
  240.  
  241.             switch( GET_WM_COMMAND_ID(wParam, lParam) )
  242.                 {
  243.                 case IDE_LOW:
  244.                 case IDE_MEDIUM:
  245.                 case IDE_HIGH:
  246.  
  247.                     CheckButton( hDlg, GET_WM_COMMAND_ID(wParam, lParam) );
  248.                     return TRUE;
  249.  
  250.                 case IDOK:
  251.  
  252.                     OkCmd( hDlg );
  253.                     return TRUE;
  254.  
  255.                 case IDCANCEL:
  256.  
  257.                     CancelCmd( hDlg );
  258.                     return TRUE;
  259.                 }
  260.         }
  261.  
  262.     return ModalDialog::Dispatch( hDlg, msg, wParam, lParam );
  263. }
  264.