home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / mag&info / msjv7_6.zip / TOPTEN.ARJ / ETO.ARJ / ETO.C < prev    next >
Text File  |  1992-10-01  |  7KB  |  271 lines

  1. #include <windows.h>
  2.  
  3. #include "basedefs.h"
  4. #include "eto.h"
  5.  
  6. WINPROC WndProc     ( WINDOWS_PARAMS );
  7.  
  8. void TestIDM_RECT_FILLRECT ( HWND hWnd );
  9. void TestIDM_RECT_ETO      ( HWND hWnd );
  10. void TestIDM_TEXT_TEXTOUT  ( HWND hWnd );
  11. void TestIDM_TEXT_ETO      ( HWND hWnd );
  12.  
  13. /**************************************************************
  14. *                                                             *
  15. *                   Global Variables                          *
  16. *                                                             *
  17. **************************************************************/
  18.  
  19. HANDLE   ghInst;
  20. HWND     ghWnd;
  21. char     szNullString[] = "";
  22. char     szAppName[] = "ETO";
  23. HBRUSH   hRGBBrush[16];
  24. COLORREF dwRGB[16];
  25.  
  26. /**************************************************************
  27. *                                                             *
  28. *                      WinMain                                *
  29. *                                                             *
  30. **************************************************************/
  31.  
  32. int PASCAL WinMain (HANDLE hInstance,  HANDLE hPrevInstance, 
  33.                     LPSTR lpszCmdLine, int    nCmdShow       )
  34. {
  35.   MSG         msg       ;
  36.   WNDCLASS    wndclass  ;
  37.   int         i;
  38.  
  39.   if (!hPrevInstance) 
  40.     {
  41.     // Register the Parent Window
  42.  
  43.     wndclass.style         = CS_BYTEALIGNCLIENT;
  44.     wndclass.lpfnWndProc   = (WNDPROC)WndProc ;
  45.     wndclass.cbClsExtra    = 0 ;
  46.     wndclass.cbWndExtra    = 0 ;
  47.     wndclass.hInstance     = hInstance ;
  48.     wndclass.hIcon         = NULL;
  49.     wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
  50.     wndclass.hbrBackground = GetStockObject ( LTGRAY_BRUSH ) ;
  51.     wndclass.lpszMenuName  = (LPSTR)"PlainMenu" ;
  52.     wndclass.lpszClassName = szAppName ;
  53.  
  54.     if (!RegisterClass (&wndclass))
  55.          return FALSE;
  56.  
  57.     }
  58.  
  59.   // Generate sixteen cached brushes, for each of the solid colors,
  60.   // and fill in the dwRGB array
  61.  
  62.   for ( i = 0; i < 16; i++ )
  63.     hRGBBrush[i] = CreateSolidBrush ( dwRGB[i] =
  64.                                        RGB
  65.                                            ( 
  66.                                              min ((((i%8)&4)/4)*(((i%16)/8)+1)*128, 255),
  67.                                              min ((((i%8)&2)/2)*(((i%16)/8)+1)*128, 255),
  68.                                              min ((((i%8)&1)/1)*(((i%16)/8)+1)*128, 255)
  69.                                            )
  70.                                      );
  71.  
  72.   ghInst   = hInstance;
  73.  
  74.  
  75.   ghWnd =        CreateWindow (szAppName, "Tiny Windows App",
  76.                                WS_OVERLAPPEDWINDOW,
  77.                                CW_USEDEFAULT, 0,
  78.                                CW_USEDEFAULT, 0,
  79.                                NULL, NULL, hInstance, NULL) ;
  80.  
  81.  
  82.   ShowWindow ( ghWnd, nCmdShow );
  83.   UpdateWindow ( ghWnd );
  84.  
  85.   while (GetMessage((LPMSG)&msg, NULL, 0, 0))
  86.     {
  87.     TranslateMessage(&msg);
  88.     DispatchMessage(&msg);
  89.     }
  90.  
  91.   for ( i = 0; i < 16; i++ )
  92.     DeleteObject ( hRGBBrush[i] );
  93.  
  94.   return msg.wParam ;
  95. }
  96.  
  97. /*********************************************************************
  98. *                                                                    *
  99. *                       WndProc: Main Message Translator             *
  100. *                                                                    *
  101. *********************************************************************/
  102.  
  103. WINPROC WndProc ( WINDOWS_PARAMS )
  104. {
  105.   switch ( msg )
  106.     {
  107.     case WM_COMMAND :
  108.  
  109.       switch ( wParam )
  110.         {
  111.         case IDM_RECT_FILLRECT: TestIDM_RECT_FILLRECT ( hWnd ); break;
  112.         case IDM_RECT_ETO     : TestIDM_RECT_ETO      ( hWnd ); break;
  113.         case IDM_TEXT_TEXTOUT : TestIDM_TEXT_TEXTOUT  ( hWnd ); break;
  114.         case IDM_TEXT_ETO     : TestIDM_TEXT_ETO      ( hWnd ); break;
  115.         }
  116.       break;
  117.  
  118.     case WM_CREATE  :
  119.  
  120.       break;
  121.  
  122.     case WM_DESTROY :
  123.  
  124.       PostQuitMessage (0) ;
  125.       break ;
  126.  
  127.     default :
  128.  
  129.       return DefWindowProc ( hWnd, msg, wParam, lParam );
  130.  
  131.     }
  132.   return 0L ;
  133. }
  134. //*************************************************************************
  135. //
  136. //
  137. //
  138. //*************************************************************************
  139.  
  140. void TestIDM_RECT_FILLRECT ( HWND hWnd )
  141. {
  142.   RECT r;
  143.   int  i, j;
  144.   HDC  hDC;
  145.  
  146.   GetClientRect ( hWnd, &r );
  147.  
  148.   hDC = GetDC ( hWnd );
  149.  
  150.   for ( j = 0; j < 3; j++ )
  151.     for ( i = 0; i < 16; i++ )
  152.       FillRect ( hDC, &r, hRGBBrush[i] );
  153.  
  154.   ReleaseDC ( hWnd, hDC );
  155.   
  156. }
  157.  
  158. //*************************************************************************
  159. //
  160. //
  161. //
  162. //*************************************************************************
  163.  
  164. void TestIDM_RECT_ETO      ( HWND hWnd )
  165. {
  166.   RECT r;
  167.   int  i, j;
  168.   HDC  hDC;
  169.  
  170.   GetClientRect ( hWnd, &r );
  171.  
  172.   hDC = GetDC ( hWnd );
  173.  
  174.   for ( j = 0; j < 3; j++ )
  175.     for ( i = 0; i < 16; i++ )
  176.       {
  177.       SetBkColor ( hDC, dwRGB[i] );
  178.       ExtTextOut ( hDC, 0, 0, ETO_OPAQUE, &r, NULL, NULL, NULL );
  179.       }
  180.  
  181.   ReleaseDC ( hWnd, hDC );
  182. }
  183.  
  184. //*************************************************************************
  185. //
  186. //
  187. //
  188. //*************************************************************************
  189.  
  190. void TestIDM_TEXT_TEXTOUT  ( HWND hWnd )
  191. {
  192.   RECT r;
  193.   int  i, j, k;
  194.   HDC  hDC;
  195.   int  iNumLines;
  196.   WORD wCharHeight;
  197.   char szTest[] = "This is a test!!!! ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  198.   int  cbTest = lstrlen ( szTest );
  199.  
  200.   GetClientRect ( hWnd, &r );
  201.  
  202.   hDC = GetDC ( hWnd );
  203.  
  204.   wCharHeight = HIWORD (GetTextExtent(hDC, szTest, cbTest));
  205.  
  206.   r.left = LOWORD (GetTextExtent(hDC, szTest, cbTest));
  207.  
  208.   iNumLines = r.bottom / wCharHeight;
  209.  
  210.   for ( j = 0; j < 3; j++ )
  211.     for ( i = 0; i < 16; i++ )
  212.       {
  213.       SetBkColor   ( hDC, dwRGB[i]    );
  214.       SetTextColor ( hDC, dwRGB[15-i] );
  215.  
  216.       for ( k = 0; k < iNumLines; k++ )
  217.         {
  218.         r.top    = k*wCharHeight;
  219.         r.bottom = r.top + wCharHeight;
  220.         TextOut ( hDC, 0, k*wCharHeight, szTest, cbTest ); 
  221.         FillRect ( hDC, &r, hRGBBrush[i] );
  222.         }
  223.       
  224.       }
  225.  
  226.   ReleaseDC ( hWnd, hDC );
  227. }
  228.  
  229. //*************************************************************************
  230. //
  231. //
  232. //
  233. //*************************************************************************
  234.  
  235. void TestIDM_TEXT_ETO      ( HWND hWnd )
  236. {
  237.   RECT r;
  238.   int  i, j, k;
  239.   HDC  hDC;
  240.   int  iNumLines;
  241.   WORD wCharHeight;
  242.   char szTest[] = "This is a test!!!! ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  243.   int  cbTest = lstrlen ( szTest );
  244.  
  245.   GetClientRect ( hWnd, &r );
  246.  
  247.   hDC = GetDC ( hWnd );
  248.  
  249.   wCharHeight = HIWORD (GetTextExtent(hDC, szTest, cbTest));
  250.  
  251.   iNumLines = r.bottom / wCharHeight;
  252.  
  253.   for ( j = 0; j < 3; j++ )
  254.     for ( i = 0; i < 16; i++ )
  255.       {
  256.       SetBkColor   ( hDC, dwRGB[i]    );
  257.       SetTextColor ( hDC, dwRGB[15-i] );
  258.  
  259.       for ( k = 0; k < iNumLines; k++ )
  260.         {
  261.         r.top    = k*wCharHeight;
  262.         r.bottom = r.top + wCharHeight;
  263.         ExtTextOut ( hDC, 0, k*wCharHeight, ETO_OPAQUE, &r, szTest, cbTest, NULL ); 
  264.         }
  265.       
  266.       }
  267.  
  268.   ReleaseDC ( hWnd, hDC );
  269. }
  270.  
  271.