home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / COMMONDG.PAK / OPTDLG.C < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  3.6 KB  |  139 lines

  1. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  2. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  3. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  4. // PARTICULAR PURPOSE.
  5. //
  6. // Copyright (C) 1993-1995  Microsoft Corporation.  All Rights Reserved.
  7. //
  8. //  MODULE: optdlg.c
  9. //
  10. //  PURPOSE: To show the use of the fonts and colors common dialogs.
  11. //
  12. //
  13. //  FUNCTIONS:
  14. //    CmdFonts  - Change the current font using the fonts dialog box.
  15. //    CmdColors - Change the current color using the colors dialog box.
  16. //
  17. //  COMMENTS:
  18. //
  19. //
  20. //
  21. //  SPECIAL INSTRUCTIONS: N/A
  22. //
  23.  
  24. #include <windows.h>            // required for all Windows applications
  25. #ifdef WIN16
  26. #include "win16ext.h"           // required only for win16 applications
  27. #include "commdlg.h"           
  28. #endif
  29. #include "globals.h"            // prototypes specific to this application
  30.  
  31. //
  32. //  FUNCTION: CmdFonts(HWND, WORD, WORD, HWND)
  33. //
  34. //  PURPOSE: Change the current font using the fonts dialog box.
  35. //
  36. //  PARAMETERS:
  37. //    hwnd     - The window handle.
  38. //    wCommand - IDM_FONTS (Unused)
  39. //    wNotify   - Notification number (unused)
  40. //    hwndCtrl - NULL (Unused)
  41. //
  42. //  RETURN VALUE:
  43. //    Always returns 0 - Command handled.
  44. //
  45. //  COMMENTS:
  46. //
  47. //
  48.  
  49. #pragma argsused
  50. LRESULT CmdFonts(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
  51. {
  52.      CHOOSEFONT cf = {0};/* common dialog box structure */
  53.  
  54.      static LOGFONT lf = {0};         /* logical-font structure */
  55.      static DWORD rgbColors = RGB(0, 0, 0);
  56.      static BOOL  fInitLogFont = FALSE;
  57.  
  58.     // Initialize the ChooseFont structure.
  59.  
  60.     cf.lStructSize = sizeof (CHOOSEFONT);
  61.     cf.hwndOwner = hwnd;
  62.     cf.Flags =
  63.         CF_SCREENFONTS |
  64.         CF_EFFECTS |
  65.         (fInitLogFont ? CF_INITTOLOGFONTSTRUCT : 0);
  66.     cf.lpLogFont = &lf;
  67.     cf.rgbColors = rgbColors;
  68.     cf.nFontType = SCREEN_FONTTYPE;
  69.  
  70.      fInitLogFont = TRUE;
  71.  
  72.     // Display the dialog box, allow the user to choose a font, and
  73.     //   render the text in the window with that selection.
  74.  
  75.     if (ChooseFont(&cf))
  76.     {
  77.         rgbColors = cf.rgbColors;
  78.         SetCurrentFont(&lf, rgbColors);
  79.         InvalidateRect(hwnd, NULL, TRUE);
  80.     }
  81.     return 0;
  82. }
  83.  
  84.  
  85. //
  86. //  FUNCTION: CmdColors(HWND, WORD, WORD, HWND)
  87. //
  88. //  PURPOSE: Change the current color using the colors dialog box.
  89. //
  90. //  PARAMETERS:
  91. //    hwnd     - The window handle.
  92. //    wCommand - IDM_COLORS (Unused)
  93. //    wNotify   - Notification number (unused)
  94. //    hwndCtrl - NULL (Unused)
  95. //
  96. //  RETURN VALUE:
  97. //    Always returns 0 - Command handled.
  98. //
  99. //  COMMENTS:
  100. //
  101. //
  102.  
  103. #pragma argsused
  104. LRESULT CmdColors(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
  105. {
  106.      CHOOSECOLOR cc = {0};     /* common dialog box structure */
  107.      static DWORD rgbCurrent = RGB(0,0,0);
  108.  
  109.      static COLORREF acrCustClr[16] =
  110.      {
  111.           RGB(255, 255, 255), RGB(239, 239, 239),
  112.           RGB(223, 223, 223), RGB(207, 207, 207),
  113.           RGB(191, 191, 191), RGB(175, 175, 175),
  114.           RGB(159, 159, 159), RGB(143, 143, 143),
  115.           RGB(127, 127, 127), RGB(111, 111, 111),
  116.           RGB( 95,  95,  95), RGB( 79,  79,  79),
  117.           RGB( 63,  63,  63), RGB( 47,  47,  47),
  118.           RGB( 31,  31,  31), RGB( 15,  15,  15)
  119.      };
  120.  
  121.      // Initialize necessary members.
  122.  
  123.      cc.lStructSize = sizeof(CHOOSECOLOR);
  124.      cc.hwndOwner = hwnd;
  125.      cc.lpCustColors = (LPDWORD) acrCustClr;
  126.      cc.rgbResult = rgbCurrent;
  127.      cc.Flags = CC_RGBINIT | CC_SHOWHELP;
  128.  
  129.      /* Call the ChooseColor function. */
  130.  
  131.      if (ChooseColor(&cc))
  132.      {
  133.           rgbCurrent = cc.rgbResult;
  134.           SetCurrentColor(cc.rgbResult);
  135.           InvalidateRect(hwnd,NULL,TRUE);
  136.      }
  137.      return 0;
  138. }
  139.