home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / CPROG / WINPROGS.ZIP / BTNLOOK.ZIP / BTNLOOK.C next >
Text File  |  1990-12-21  |  5KB  |  182 lines

  1. /*   BTNLOOK.c   -   Button Look Program
  2.                      Petzold
  3. */
  4.  
  5. #include <windows.h>
  6. #include <stdio.h>
  7.  
  8.  
  9. struct 
  10.      {
  11.      long style;
  12.      char *text;
  13.      }
  14.      button[] =
  15.      {
  16.      BS_PUSHBUTTON,     "PUSHBUTTON",
  17.      BS_DEFPUSHBUTTON,  "DEFPUSHBUTTON",
  18.      BS_CHECKBOX,       "CHECKBOX",
  19.      BS_AUTOCHECKBOX,   "AUTOCHECKBOX",
  20.      BS_RADIOBUTTON,    "RADIOBUTTON",
  21.      BS_3STATE,         "3STATE",
  22.      BS_AUTO3STATE,     "AUTO3STATE",
  23.      BS_GROUPBOX,       "GROUPBOX",
  24.      BS_USERBUTTON,     "USERBUTTON",
  25.      BS_AUTORADIOBUTTON,"AUTORADIO",
  26.      BS_PUSHBOX,        "PUSHBOX"
  27.      };
  28.      
  29. #define NUM (sizeof button / sizeof button [0])
  30.      
  31.      
  32.  
  33. long FAR PASCAL WndProc (HWND, WORD, WORD, LONG);
  34.  
  35. int PASCAL WinMain (HANDLE hInstance,
  36.                     HANDLE hPrevInstance,
  37.                     LPSTR  lpszCmdParam,
  38.                     int    nCmdShow)
  39.                     
  40.   {
  41.   static char szAppName[] = "BtnLook";
  42.   HWND        hwnd;
  43.   MSG         msg;
  44.   WNDCLASS    wndclass;
  45.   
  46.   if (!hPrevInstance)
  47.      {
  48.      wndclass.style            = CS_HREDRAW | CS_VREDRAW;
  49.      wndclass.lpfnWndProc      = WndProc;
  50.      wndclass.cbClsExtra       = 0;
  51.      wndclass.cbWndExtra       = 0;
  52.      wndclass.hInstance        = hInstance;
  53.      wndclass.hIcon            = LoadIcon (NULL, IDI_APPLICATION);
  54.      wndclass.hCursor          = LoadCursor (NULL, IDC_ARROW);
  55.      wndclass.hbrBackground    = GetStockObject (WHITE_BRUSH);
  56.      wndclass.lpszMenuName     = NULL;
  57.      wndclass.lpszClassName    = szAppName;
  58.      
  59.      RegisterClass(&wndclass);
  60.      }
  61.      
  62.   hwnd = CreateWindow (szAppName,
  63.                        "Button Look",
  64.                        WS_OVERLAPPEDWINDOW, 
  65.                        CW_USEDEFAULT,   
  66.                        CW_USEDEFAULT,
  67.                        CW_USEDEFAULT,   
  68.                        CW_USEDEFAULT,   
  69.                        NULL,
  70.                        NULL,
  71.                        hInstance,
  72.                        NULL);
  73.                        
  74.   ShowWindow (hwnd, nCmdShow);
  75.   UpdateWindow (hwnd);
  76.   
  77.   while (GetMessage (&msg, NULL, 0, 0))
  78.     {
  79.     TranslateMessage (&msg);
  80.     DispatchMessage  (&msg);
  81.     }
  82.     
  83.   return msg.wParam;
  84.   }
  85.   
  86. long FAR PASCAL WndProc (HWND hwnd,
  87.                          WORD message,
  88.                          WORD wParam,
  89.                          LONG lParam)
  90.                          
  91.   {
  92.   static char szPrm[]    = "wParam       LOWORD(lParam)   HIWORD(lParam)",
  93.               szTop[]    = "Control ID   Window Handle    Notification",
  94.               szUnd[]    = "__________   _____________    ____________",
  95.               szFormat[] = "%5u          %4X              %5u",
  96.               szBuffer[50];
  97.   
  98.   static HWND hwndButton [NUM];
  99.  
  100.   static RECT rect;
  101.   static int  cxChar, cyChar;
  102.                           
  103.  
  104.   HDC          hdc;
  105.   PAINTSTRUCT  ps;
  106.   TEXTMETRIC   tm;
  107.   int          i;
  108.   
  109.     
  110.   
  111.   switch (message)
  112.     {
  113.     case WM_CREATE:
  114.       hdc = GetDC (hwnd);
  115.       SelectObject (hdc, GetStockObject (SYSTEM_FIXED_FONT));
  116.       GetTextMetrics (hdc, &tm);
  117.       cxChar = tm.tmAveCharWidth;
  118.       cyChar = tm.tmHeight + tm.tmExternalLeading;
  119.       
  120.       ReleaseDC (hwnd, hdc);
  121.       
  122.       for (i = 0; i < NUM; i++)
  123.       
  124.         hwndButton[i] = CreateWindow ("button", 
  125.                                       button[i].text,
  126.                                       WS_CHILD | WS_VISIBLE | button[i].style,
  127.                                       cxChar,
  128.                                       cyChar * (1 + 2 * i),
  129.                                       20 * cxChar,
  130.                                       7 * cyChar / 4,
  131.                                       hwnd, 
  132.                                       i,
  133.                                       ((LPCREATESTRUCT) lParam) -> hInstance, NULL);
  134.                                       
  135.          
  136.        return 0;
  137.        
  138.      case WM_SIZE:
  139.        rect.left   = 24 * cxChar;
  140.        rect.top    = 3 * cyChar;
  141.        rect.right  = LOWORD (lParam);
  142.        rect.bottom = HIWORD (lParam);
  143.        return 0;
  144.        
  145.      case WM_PAINT:
  146.        InvalidateRect (hwnd, &rect, TRUE);
  147.        
  148.        hdc = BeginPaint (hwnd, &ps);
  149.        SelectObject (hdc, GetStockObject (SYSTEM_FIXED_FONT));
  150.        SetBkMode (hdc, TRANSPARENT);
  151.        
  152.        TextOut (hdc,24 * cxChar, 1 * cyChar, szPrm, sizeof szPrm -1);
  153.        TextOut (hdc,24 * cxChar, 2 * cyChar, szTop, sizeof szTop -1);
  154.        TextOut (hdc,24 * cxChar, 2 * cyChar, szUnd, sizeof szUnd -1);
  155.        
  156.        EndPaint (hwnd, &ps);
  157.        return(0);
  158.        
  159.      case WM_COMMAND:
  160.        ScrollWindow(hwnd, 0, -cyChar, &rect, &rect);
  161.        hdc = GetDC (hwnd);
  162.        SelectObject (hdc, GetStockObject (SYSTEM_FIXED_FONT));
  163.        
  164.        TextOut (hdc, 24 * cxChar, cyChar * (rect.bottom / cyChar -1),
  165.                 szBuffer, sprintf (szBuffer, szFormat, wParam,
  166.                 LOWORD (lParam), HIWORD (lParam)));
  167.                 
  168.        ReleaseDC(hwnd,hdc);
  169.        ValidateRect (hwnd, NULL);
  170.        return(0);
  171.                 
  172.        return 0;
  173.                                                                                                
  174.     case WM_DESTROY:
  175.       PostQuitMessage (0);
  176.       return 0;
  177.     }
  178.     
  179.   return DefWindowProc (hwnd, message, wParam, lParam);
  180.   }
  181.                   
  182.