home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / bc45 / owlsrc.pak / CHOOSECO.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-24  |  1.9 KB  |  67 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // (C) Copyright 1992, 1994 by Borland International, All Rights Reserved
  4. //
  5. //   Implementation of Choose Color Common Dialog class
  6. //----------------------------------------------------------------------------
  7. #include <owl/owlpch.h>
  8. #include <owl/chooseco.h>
  9.  
  10. uint TChooseColorDialog::SetRGBMsgId = 0;
  11.  
  12. DEFINE_RESPONSE_TABLE1(TChooseColorDialog, TCommonDialog)
  13. END_RESPONSE_TABLE;
  14.  
  15. IMPLEMENT_CASTABLE(TChooseColorDialog);
  16.  
  17. TChooseColorDialog::TChooseColorDialog(TWindow*        parent,
  18.                                        TData&          data,
  19.                                        TResId          templateId,
  20.                                        const char far* title,
  21.                                        TModule*        module)
  22. :
  23.   TCommonDialog(parent, title, module), 
  24.   Data(data)
  25. {
  26.   if (!SetRGBMsgId)
  27.     SetRGBMsgId = ::RegisterWindowMessage(SETRGBSTRING);
  28.  
  29.   memset(&cc, 0, sizeof(CHOOSECOLOR));
  30.   cc.lStructSize = sizeof(CHOOSECOLOR);
  31.   cc.hwndOwner = Parent ? Parent->HWindow : 0;
  32.   (HINSTANCE)(cc.hInstance) = *GetModule();
  33.   cc.Flags = CC_ENABLEHOOK | Data.Flags;
  34.   if (templateId) {
  35.     cc.lpTemplateName = templateId;
  36.     cc.Flags |= CC_ENABLETEMPLATE;
  37.   }
  38.   else
  39.     cc.Flags &= ~CC_ENABLETEMPLATE;
  40.   cc.lpfnHook = 0;
  41.  
  42.   cc.rgbResult = Data.Color;
  43.   cc.lpCustColors = (COLORREF far*)Data.CustColors;
  44. }
  45.  
  46. bool
  47. TChooseColorDialog::DialogFunction(uint msg, WPARAM wParam, LPARAM lParam)
  48. {
  49.   return TCommonDialog::DialogFunction(msg, wParam, lParam);
  50. }
  51.  
  52. int
  53. TChooseColorDialog::DoExecute()
  54. {
  55.   (DLGPROC)cc.lpfnHook = (DLGPROC)(FARPROC)StdDlgProcInstance;
  56.   int ret = ::ChooseColor(&cc);
  57.   if (ret) {
  58.     Data.Flags = cc.Flags;
  59.     Data.Error = 0;
  60.     Data.Color = cc.rgbResult;
  61.   }
  62.   else {
  63.     Data.Error = ::CommDlgExtendedError();
  64.   }
  65.   return ret ? IDOK : IDCANCEL;
  66. }
  67.