home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / windows / graybutt.zip / GRAYBUTT.C next >
C/C++ Source or Header  |  1990-07-17  |  3KB  |  129 lines

  1. /*
  2.  *    Graybutt Graying Buttons Demo
  3.  *
  4.  *    Kraig Brockschmidt
  5.  *    Microsoft WinSDK Suport
  6.  *
  7.  *    (c)1990 Kraig Brockschmidt
  8.  *    All rights reserved.
  9.  *
  10.  */
  11.  
  12. #include <windows.h>
  13. #include "graybutt.h"
  14.  
  15.  
  16. HBRUSH      hBrush;
  17. HBITMAP     hBitmap;
  18. WORD        rgwBricks[]={0x0f, 0x8B, 0xDD, 0xB8, 0x70, 0xE8, 0xDD, 0x8E};
  19. char        szAppName[]="GrayButt";
  20.  
  21.  
  22.  
  23. int PASCAL WinMain (hInstance, hPrevInstance, lpszCmdLine, nCmdShow)
  24.     HANDLE    hInstance, hPrevInstance;
  25.     LPSTR    lpszCmdLine;
  26.     int     nCmdShow;
  27.     {
  28.     HWND        hWnd;
  29.     HWND        hWndEdit;
  30.     MSG         msg;
  31.     WNDCLASS    wndclass;
  32.  
  33.  
  34.     if (!hPrevInstance)
  35.         {
  36.         wndclass.style          = CS_HREDRAW | CS_VREDRAW;
  37.         wndclass.lpfnWndProc    = GrayWndProc;
  38.         wndclass.cbClsExtra     = 0;
  39.         wndclass.cbWndExtra     = 0;
  40.         wndclass.hInstance      = hInstance;
  41.         wndclass.hIcon          = LoadIcon(NULL, IDI_ASTERISK);
  42.         wndclass.hCursor        = LoadCursor(NULL, IDC_ARROW);
  43.         wndclass.hbrBackground  = GetStockObject(WHITE_BRUSH);
  44.         wndclass.lpszMenuName   = NULL;
  45.         wndclass.lpszClassName  = szAppName;
  46.  
  47.         if (!RegisterClass(&wndclass))
  48.             return FALSE;
  49.         }
  50.  
  51.     hWnd=CreateDialog(hInstance, szAppName, 0, NULL);
  52.  
  53.     /*
  54.      * This has to go here since Windows bombs if an edit is in a
  55.      * dialog statment and we use CreateDialog for the main Window.
  56.      */
  57.     hWndEdit=CreateWindow("edit", "Edit",
  58.                           WS_CHILD | ES_LEFT | WS_VISIBLE | WS_BORDER,
  59.                            7, 4, 50, 20, hWnd,
  60.                           ID_EDIT, hInstance, NULL);
  61.  
  62.     hBitmap=CreateBitmap(8,8,1,1, (LPSTR)rgwBricks);
  63.     hBrush=CreatePatternBrush(hBitmap);
  64.  
  65.  
  66.     ShowWindow(hWnd, nCmdShow);
  67.  
  68.     while (GetMessage(&msg, NULL, 0,0 ))
  69.         {
  70.         TranslateMessage(&msg);
  71.         DispatchMessage(&msg);
  72.         }
  73.  
  74.     DeleteObject(hBitmap);
  75.     DeleteObject(hBrush);
  76.  
  77.     return msg.wParam;
  78.     }
  79.  
  80.  
  81.  
  82. long FAR PASCAL GrayWndProc (hWnd, iMessage, wParam, lParam)
  83.     HWND          hWnd;
  84.     unsigned      iMessage;
  85.     WORD          wParam;
  86.     LONG          lParam;
  87.     {
  88.     short         nIndex;
  89.     static BOOL   bFirstPaint=TRUE;
  90.  
  91.  
  92.  
  93.     switch (iMessage)
  94.         {
  95.         case WM_DESTROY:
  96.             PostQuitMessage(0);
  97.             break;
  98.  
  99.         case WM_COMMAND:
  100.             if (wParam==ID_RADIO)
  101.                 {
  102.                 for (nIndex=ID_CHECK; nIndex<=ID_AUTO; nIndex++)
  103.                     EnableWindow(GetDlgItem(hWnd, nIndex), FALSE);
  104.                 }
  105.  
  106.             break;
  107.  
  108.         case WM_CTLCOLOR:
  109.             if (HIWORD(lParam)==CTLCOLOR_LISTBOX && bFirstPaint)
  110.                 {
  111.                 CheckDlgButton(hWnd, ID_RADIO, 2);
  112.                 CheckDlgButton(hWnd, ID_CHECK, 2);
  113.                 CheckDlgButton(hWnd, ID_AUTO,  0);
  114.                 bFirstPaint=FALSE;
  115.                 return (GetStockObject(LTGRAY_BRUSH));
  116.                 }
  117.             else
  118.                 if (HIWORD(lParam)==CTLCOLOR_SCROLLBAR)
  119.                     return hBrush;
  120.  
  121.             return (GetStockObject(WHITE_BRUSH));
  122.  
  123.  
  124.         default:
  125.             return (DefWindowProc(hWnd, iMessage, wParam, lParam));
  126.         }
  127.     return 0L;
  128.     }
  129.