home *** CD-ROM | disk | FTP | other *** search
/ Black Box 4 / BlackBox.cdr / w3_scrn / clrbut.arj / DEMO.ZIP / DEMO.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-01-21  |  5.0 KB  |  186 lines

  1. /****************************************************************************
  2.  
  3.     PROGRAM: Demo.c
  4.  
  5. ****************************************************************************/
  6.  
  7. #include "windows.h"
  8. #include "clrbuttn.h"
  9. #include "demo.h"
  10.  
  11. HBRUSH hFaceBrush, hShadowBrush;
  12. LOGBRUSH bsBr;
  13. HFONT hFixFont;
  14.  
  15. WORD hDlgItem;
  16. int iButtonClr;
  17. int iLabelClr;
  18. int iLabelTxt;
  19. int iLabelFnt;
  20. int iLabelSty;
  21. int iButtonSiz;
  22. int iOn;
  23.  
  24. char szLabel1[] = "Color Button Text";
  25. char szLabel2[] = "Button Label";
  26.  
  27. long lBaseUnits;
  28. WORD wBUHi;
  29. WORD wBUWi;
  30.  
  31. BOOL FAR PASCAL TestProc(HWND, unsigned, WORD, LONG);
  32.  
  33. int PASCAL WinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow)
  34. HANDLE hInstance;
  35. HANDLE hPrevInstance;
  36. LPSTR lpCmdLine;
  37. int nCmdShow;
  38. {
  39.  
  40.    HWND hWnd;
  41.    FARPROC lpTestProc;
  42.    BOOL bRtn;
  43.  
  44.    lpTestProc = MakeProcInstance(TestProc, hInstance);
  45.    lBaseUnits = GetDialogBaseUnits();
  46.    wBUHi = HIWORD(lBaseUnits) / 8;
  47.    wBUWi = LOWORD(lBaseUnits) / 4;
  48.    DialogBox(hInstance, "TESTBOX", NULL, lpTestProc);
  49.    FreeProcInstance(lpTestProc);
  50.  
  51.    return (TRUE);
  52. }
  53.  
  54. /****************************************************************************/
  55.  
  56. BOOL FAR PASCAL TestProc(hDlg, message, wParam, lParam)
  57. HWND hDlg;
  58. unsigned message;
  59. WORD wParam;
  60. LONG lParam;
  61. {
  62.     switch (message) {
  63.    case WM_INITDIALOG:
  64.  
  65.       // Create Face Brush
  66.          bsBr.lbStyle = BS_SOLID;
  67.          bsBr.lbColor = RGB(255,130,120);
  68.          hFaceBrush = CreateBrushIndirect(&bsBr);
  69.       // Create Shadow Brush
  70.          bsBr.lbColor = RGB(255,0,0);
  71.          hShadowBrush = CreateBrushIndirect(&bsBr);
  72.          iOn = iButtonClr = iLabelClr = iLabelSty = iLabelTxt = iLabelFnt = iButtonSiz = 0;
  73.          hDlgItem = GetDlgItem(hDlg, TEST);
  74.          hFixFont = GetStockObject(SYSTEM_FIXED_FONT);
  75.       
  76.       return (TRUE);
  77.  
  78.    case WM_COMMAND:
  79.        if (wParam == IDOK) {
  80.           EndDialog(hDlg, TRUE);
  81.           return (TRUE);
  82.        }
  83.  
  84.        if (wParam == BUTTON_COLOR) {
  85.           iButtonClr++;
  86.           if (iButtonClr > 1)
  87.             iButtonClr = 0;
  88.           if (iButtonClr) {
  89.              SendMessage(hDlgItem, CRBM_SETFACEBRUSH, hFaceBrush, 0L);
  90.              SendMessage(hDlgItem, CRBM_SETSHADOWBRUSH, hShadowBrush, 0L);
  91.           }
  92.           else {
  93.              SendMessage(hDlgItem, CRBM_SETFACEBRUSH, 0, 0L);
  94.              SendMessage(hDlgItem, CRBM_SETSHADOWBRUSH, 0, 0L);
  95.           }
  96.          InvalidateRect(hDlgItem, NULL, FALSE);
  97.        }
  98.  
  99.        if (wParam == LABEL_COLOR) {
  100.           iLabelClr++;
  101.           if (iLabelClr > 1)
  102.             iLabelClr = 0;
  103.           if (iLabelClr)
  104.              SendMessage(hDlgItem, CRBM_SETTEXTCOLOR, TRUE, RGB(255, 0, 0));
  105.           else
  106.              SendMessage(hDlgItem, CRBM_SETTEXTCOLOR, FALSE, 0L);
  107.          InvalidateRect(hDlgItem, NULL, FALSE);
  108.        }
  109.  
  110.        if (wParam == LABEL_TEXT) {
  111.           iLabelTxt++;
  112.           if (iLabelTxt > 1)
  113.             iLabelTxt = 0;
  114.           if (iLabelTxt)
  115.             SetDlgItemText(hDlg, TEST, (LPSTR) szLabel2);
  116.           else
  117.             SetDlgItemText(hDlg, TEST, (LPSTR) szLabel1);
  118.          InvalidateRect(hDlgItem, NULL, FALSE);
  119.        }
  120.  
  121.        if (wParam == LABEL_STYLE) {
  122.           iLabelSty++;
  123.           if (iLabelSty > 1)
  124.             iLabelSty = 0;
  125.           if (iLabelSty)
  126.              SendMessage(hDlgItem, CRBM_SETDRAWTEXTSTYLE, (DT_LEFT   | DT_WORDBREAK), 0L);
  127.           else
  128.              SendMessage(hDlgItem, CRBM_SETDRAWTEXTSTYLE, (DT_CENTER | DT_WORDBREAK), 0L);
  129.          InvalidateRect(hDlgItem, NULL, FALSE);
  130.        }
  131.  
  132.        if (wParam == BUTTON_SIZE) {
  133.           iButtonSiz++;
  134.           if (iButtonSiz > 1)
  135.             iButtonSiz = 0;
  136.             if (iButtonSiz)
  137.              // increase width, decrease height
  138.                 MoveWindow(hDlgItem, 
  139.                            (16 * wBUWi), 
  140.                            (30 * wBUHi),
  141.                            (90 * wBUWi),
  142.                            (15 * wBUHi), TRUE);
  143.             else
  144.              // increase height, decrease width
  145.                 MoveWindow(hDlgItem,
  146.                            (16 * wBUWi), 
  147.                            (30 * wBUHi),
  148.                            (40 * wBUWi),
  149.                            (35 * wBUHi), TRUE);
  150.        }
  151.  
  152.        if (wParam == LABEL_FONT) {
  153.           iLabelFnt++;
  154.           if (iLabelFnt > 1)
  155.             iLabelFnt = 0;
  156.           if (iLabelFnt)
  157.             SendMessage(hDlgItem, CRBM_SETLABELFONT, hFixFont, 0L);
  158.           else
  159.             SendMessage(hDlgItem, CRBM_SETLABELFONT, 0, 0L);
  160.           InvalidateRect(hDlgItem, NULL, FALSE);
  161.        }
  162.  
  163.        if (wParam == ON_OFF) {
  164.           iOn++;
  165.           if (iOn > 1)
  166.             iOn = 0;
  167.           if (iOn) 
  168.              EnableWindow(hDlgItem, FALSE);
  169.           else
  170.              EnableWindow(hDlgItem, TRUE);
  171.        }
  172.  
  173.        return (TRUE);
  174.  
  175.    case WM_DESTROY:
  176.          DeleteObject(hFaceBrush);
  177.          DeleteObject(hShadowBrush);
  178.          return (TRUE);
  179.     }
  180.     return (FALSE);
  181.  
  182. }
  183.  
  184.  
  185.  
  186.