home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_122 / 7.ddi / OWLDEMOS.ZIP / PALTEST.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  3.1 KB  |  113 lines

  1. // ObjectWindows - (C) Copyright 1992 by Borland International
  2. //
  3. // paltest.cpp
  4.  
  5. #include <alloc.h>
  6. #include <owl.h>
  7. #include <window.h>
  8. #include "paltest.h"
  9.  
  10. const NumColors = 8;
  11. const BYTE RedVals[NumColors] =   {0, 0, 0, 0, 0xFF, 0xFF, 0xFF, 0xFF};
  12. const BYTE GreenVals[NumColors] = {0, 0, 0xFF, 0xFF, 0, 0, 0xFF, 0xFF};
  13. const BYTE BlueVals[NumColors] =  {0, 0xFF, 0, 0xFF, 0, 0xFF, 0, 0xFF};
  14.  
  15. class TTestApp : public TApplication
  16. {
  17. public:
  18.   TTestApp(LPSTR AName, HINSTANCE hInstance, HINSTANCE hPrevInstance,
  19.     LPSTR lpCmdLine, int nCmdShow)
  20.     : TApplication(AName, hInstance, hPrevInstance, lpCmdLine, nCmdShow) {};
  21.   virtual void InitMainWindow();
  22. };
  23.  
  24. class TTestWindow : public TWindow
  25. {
  26. public:
  27.   LPLOGPALETTE MyLogPalette;
  28.   TTestWindow(PTWindowsObject AParent, LPSTR ATitle);
  29.   ~TTestWindow();
  30.   virtual void WMLButtonDown(RTMessage Msg) =
  31.     [WM_FIRST + WM_LBUTTONDOWN];
  32.   virtual void WMRButtonDown(RTMessage Msg) =
  33.     [WM_FIRST + WM_RBUTTONDOWN];
  34.   virtual void CMAbout(RTMessage  Msg) =
  35.     [CM_FIRST + CM_ABOUT];
  36. };
  37.  
  38. TTestWindow::TTestWindow(PTWindowsObject AParent, LPSTR ATitle) :
  39.   TWindow(AParent, ATitle)
  40. {
  41.   AssignMenu("PALTEST_MENU");
  42.   MyLogPalette = (LPLOGPALETTE)
  43.     farmalloc(sizeof(LOGPALETTE) + sizeof(PALETTEENTRY) * NumColors);
  44.   MyLogPalette->palVersion = 0x300;
  45.   MyLogPalette->palNumEntries = NumColors;
  46.   for (int i = 0; i < NumColors; ++i)
  47.   {
  48.     MyLogPalette->palPalEntry[i].peRed = RedVals[i];
  49.     MyLogPalette->palPalEntry[i].peGreen = GreenVals[i];
  50.     MyLogPalette->palPalEntry[i].peBlue = BlueVals[i];
  51.     MyLogPalette->palPalEntry[i].peFlags = PC_RESERVED;
  52.   }
  53. }
  54.  
  55. TTestWindow::~TTestWindow()
  56. {
  57.   farfree(MyLogPalette);
  58. }
  59.  
  60. void TTestWindow::WMLButtonDown(RTMessage)
  61. {
  62.   HBRUSH ABrush, OldBrush;
  63.   HPALETTE ThePalette, OldPalette;
  64.   HDC TheDC;
  65.  
  66.   ThePalette = CreatePalette(MyLogPalette);
  67.   TheDC = GetDC(HWindow);
  68.   OldPalette = SelectPalette(TheDC, ThePalette, FALSE);
  69.   RealizePalette(TheDC);
  70.   for (int i = 0; i < NumColors; ++i)
  71.   {
  72.     ABrush = CreateSolidBrush(PALETTEINDEX(i));
  73.     OldBrush = (HBRUSH)SelectObject(TheDC, ABrush);
  74.     Rectangle(TheDC, i * 25, i * 25, i * 25 + 20, i * 25 + 20);
  75.     SelectObject(TheDC, OldBrush);
  76.     DeleteObject(ABrush);
  77.   }
  78.   SelectPalette(TheDC, OldPalette, FALSE);
  79.   ReleaseDC(HWindow, TheDC);
  80.   DeleteObject(ThePalette);
  81. }
  82.  
  83. void TTestWindow::WMRButtonDown(RTMessage)
  84. {
  85.   PALETTEENTRY APaletteEntry;
  86.  
  87.   APaletteEntry = MyLogPalette->palPalEntry[0];
  88.   for (int i = 0; i < NumColors-1; i++)
  89.   {
  90.     MyLogPalette->palPalEntry[i] = MyLogPalette->palPalEntry[i + 1] ;
  91.   }
  92.   MyLogPalette->palPalEntry[i] = APaletteEntry;
  93. }
  94.  
  95. void TTestWindow::CMAbout(RTMessage)
  96. {
  97.   GetApplication()->ExecDialog(new TDialog(this, "ABOUT"));
  98. }
  99.  
  100. void TTestApp::InitMainWindow()
  101. {
  102.   MainWindow = new TTestWindow(NULL, "Palette Tester");
  103. }
  104.  
  105. int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  106.   LPSTR lpCmdLine, int nCmdShow)
  107. {
  108.   TTestApp TestApp("Palette Tester", hInstance, hPrevInstance,
  109.     lpCmdLine, nCmdShow);
  110.   TestApp.Run();
  111.   return TestApp.Status;
  112. }
  113.