home *** CD-ROM | disk | FTP | other *** search
- /*
- Program to test the Choose Color common dialog box.
- */
-
- #include <owl\applicat.h>
- #include <owl\framewin.h>
- #include <owl\chooseco.h>
- #include "commdlg2.h"
- #include <stdio.h>
- #include <string.h>
-
- const int MaxStrLen = 31;
- const int MaxLongStrLen = 1024;
-
- // declare the custom application class as
- // a subclass of TApplication
- class TWinApp : public TApplication
- {
- public:
- TWinApp() : TApplication() {}
-
- protected:
- virtual void InitMainWindow();
- };
-
- // expand the functionality of TWindow by
- // deriving class TMainWindow
- class TMainWindow : public TWindow
- {
- public:
-
- TMainWindow();
-
- protected:
-
- // the data for the color dialog box
- TChooseColorDialog::TData ColorData;
-
- // handle invoking the color dialog box
- void CMColors();
-
- // handle exiting the program
- void CMExit();
-
- // handle closing the window
- virtual BOOL CanClose();
-
- // declare the message map macro
- DECLARE_RESPONSE_TABLE(TMainWindow);
-
- };
-
- DEFINE_RESPONSE_TABLE1(TMainWindow, TWindow)
- EV_COMMAND(CM_COLORCHANGE, CMColors),
- EV_COMMAND(CM_EXIT, CMExit),
- END_RESPONSE_TABLE;
-
- TMainWindow::TMainWindow()
- : TWindow(0, 0, 0)
- {
- }
-
- void TMainWindow::CMColors()
- {
- char ColorStr[MaxStrLen];
- static TColor CustColors[16] =
- {
- TColor(0,0,0), TColor(255, 255, 255), TColor(128, 128, 128),
- TColor(255, 0, 0), TColor(0, 255, 0), TColor(0, 0, 255),
- TColor(255, 128, 0), TColor(128, 255, 0), TColor(128, 0, 255),
- TColor(255, 0, 128), TColor(0, 255, 128), TColor(0, 128, 255),
- TColor(255, 128, 128), TColor(128, 255, 128),
- TColor(128, 128, 255), TColor(64, 64, 64)
- };
- TChooseColorDialog* ColorDialog;
-
- ColorData.Color = TColor(255, 0, 0);
- ColorData.Flags = CC_FULLOPEN | CC_SHOWHELP | CC_RGBINIT;
- ColorData.CustColors = CustColors;
- ColorDialog = new TChooseColorDialog(this, ColorData);
-
- if (ColorDialog->Execute() == IDOK) {
- sprintf(ColorStr,
- "Hexadecimal color code: %lX\nDecimal color code: %lu",
- COLORREF(ColorData.Color),
- COLORREF(ColorData.Color));
- MessageBox(ColorStr, "Color Metrics",
- MB_OK | MB_ICONINFORMATION);
- }
- }
-
- void TMainWindow::CMExit()
- {
- Parent->SendMessage(WM_CLOSE);
- }
-
- BOOL TMainWindow::CanClose()
- {
- return MessageBox("Want to close this application?",
- "Query", MB_YESNO | MB_ICONQUESTION) == IDYES;
- }
-
- void TWinApp::InitMainWindow()
- {
- MainWindow = new TFrameWindow(0, "Simple Colors Dialog Box Tester",
- new TMainWindow);
- // load the menu resource
- MainWindow->AssignMenu(TResId(IDM_MAINMENU));
- // enable the keyboard handler
- MainWindow->EnableKBHandler();
- }
-
- int OwlMain(int /* argc */, char** /*argv[] */)
- {
- TWinApp app;
- return app.Run();
- }
-
-