home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0040 - 0049 / ibm0040-0049 / ibm0040.tar / ibm0040 / BCPPOWL1.ZIP / OWLDEMOS.ZIP / PALTEST.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-28  |  3.1 KB  |  112 lines

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