home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / tybc4 / commdlg2.cpp < prev    next >
C/C++ Source or Header  |  1997-07-29  |  3KB  |  119 lines

  1. /*
  2.   Program to test the Choose Color common dialog box.
  3. */
  4.  
  5. #include <owl\applicat.h>
  6. #include <owl\framewin.h>
  7. #include <owl\chooseco.h>
  8. #include "commdlg2.h"
  9. #include <stdio.h>
  10. #include <string.h>
  11.  
  12. const int MaxStrLen = 31;
  13. const int MaxLongStrLen = 1024;
  14.  
  15. // declare the custom application class as
  16. // a subclass of TApplication
  17. class TWinApp : public TApplication
  18. {
  19. public:
  20.   TWinApp() : TApplication() {}
  21.  
  22. protected:
  23.   virtual void InitMainWindow();
  24. };
  25.  
  26. // expand the functionality of TWindow by
  27. // deriving class TMainWindow
  28. class TMainWindow : public TWindow
  29. {
  30. public:
  31.  
  32.   TMainWindow();
  33.  
  34. protected:
  35.  
  36.   // the data for the color dialog box
  37.   TChooseColorDialog::TData ColorData;
  38.  
  39.   // handle invoking the color dialog box
  40.   void CMColors();
  41.  
  42.   // handle exiting the program
  43.   void CMExit();
  44.  
  45.   // handle closing the window
  46.   virtual BOOL CanClose();
  47.  
  48.   // declare the message map macro
  49.   DECLARE_RESPONSE_TABLE(TMainWindow);
  50.  
  51. };
  52.  
  53. DEFINE_RESPONSE_TABLE1(TMainWindow, TWindow)
  54.   EV_COMMAND(CM_COLORCHANGE, CMColors),
  55.   EV_COMMAND(CM_EXIT, CMExit),
  56. END_RESPONSE_TABLE;
  57.  
  58. TMainWindow::TMainWindow()
  59.   : TWindow(0, 0, 0)
  60. {
  61. }
  62.  
  63. void TMainWindow::CMColors()
  64. {
  65.   char ColorStr[MaxStrLen];
  66.   static TColor CustColors[16] =
  67.     {
  68.       TColor(0,0,0), TColor(255, 255, 255), TColor(128, 128, 128),
  69.       TColor(255, 0, 0), TColor(0, 255, 0), TColor(0, 0, 255),
  70.       TColor(255, 128, 0), TColor(128, 255, 0), TColor(128, 0, 255),
  71.       TColor(255, 0, 128), TColor(0, 255, 128), TColor(0, 128, 255),
  72.       TColor(255, 128, 128), TColor(128, 255, 128),
  73.       TColor(128, 128, 255), TColor(64, 64, 64)
  74.     };
  75.   TChooseColorDialog* ColorDialog;
  76.  
  77.   ColorData.Color = TColor(255, 0, 0);
  78.   ColorData.Flags = CC_FULLOPEN | CC_SHOWHELP | CC_RGBINIT;
  79.   ColorData.CustColors = CustColors;
  80.   ColorDialog = new TChooseColorDialog(this, ColorData);
  81.  
  82.   if (ColorDialog->Execute() == IDOK) {
  83.      sprintf(ColorStr,
  84.         "Hexadecimal color code: %lX\nDecimal color code: %lu",
  85.         COLORREF(ColorData.Color),
  86.         COLORREF(ColorData.Color));
  87.      MessageBox(ColorStr, "Color Metrics",
  88.                     MB_OK | MB_ICONINFORMATION);
  89.   }
  90. }
  91.  
  92. void TMainWindow::CMExit()
  93. {
  94.   Parent->SendMessage(WM_CLOSE);
  95. }
  96.  
  97. BOOL TMainWindow::CanClose()
  98. {
  99.   return MessageBox("Want to close this application?",
  100.             "Query", MB_YESNO | MB_ICONQUESTION) == IDYES;
  101. }
  102.  
  103. void TWinApp::InitMainWindow()
  104. {
  105.   MainWindow = new TFrameWindow(0, "Simple Colors Dialog Box Tester",
  106.                 new TMainWindow);
  107.   // load the menu resource
  108.   MainWindow->AssignMenu(TResId(IDM_MAINMENU));
  109.   // enable the keyboard handler
  110.   MainWindow->EnableKBHandler();
  111. }
  112.  
  113. int OwlMain(int /* argc */, char** /*argv[] */)
  114. {
  115.   TWinApp app;
  116.   return app.Run();
  117. }
  118.  
  119.