home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / c / coolcolr.zip / APPDLG.C < prev    next >
C/C++ Source or Header  |  1992-11-17  |  28KB  |  872 lines

  1. //****************************************************************************
  2. //      File:  APPDLG.C                                                    
  3. //                                                                         
  4. //   Purpose:  
  5. //                                                                         
  6. // Functions:  
  7. //             
  8. //                                                                         
  9. // Development Team:
  10. //
  11. //       Greg Keyser
  12. //
  13. // Written by Microsoft Product Support Services, Windows Developer Support
  14. // Copyright (c) 1992 Microsoft Corporation. All rights reserved.
  15. //****************************************************************************
  16.  
  17. #include "windows.h"
  18. #include "cpl.h"
  19. #include "commdlg.h"
  20. #include "colordlg.h"
  21. #include "dlgs.h"
  22. #define IN_INIT
  23. #include "global.h"
  24. #undef IN_INIT
  25.  
  26. //****************************************************************************
  27. // Function: InitializeStruct
  28. //
  29. // Purpose:  To initialize a structure for the current common dialog.    
  30. //           This routine is called just before the common dialogs       
  31. //           API is called.                                              
  32. //
  33. // Parameters:
  34. //    wCommDlgType == Indicates the type of common dialog we need to initialize
  35. //    lpStruct     == Long pointer to memory block for the structure
  36. //
  37. // Returns : Nothing
  38. //
  39. // Comments:
  40. //
  41. // History:  Date       Author        Reason
  42. //           2/19/92    gregk         Created
  43. //****************************************************************************
  44. void FAR PASCAL InitializeStruct(WORD wCommDlgType, LPSTR lpStruct)
  45. {
  46.  
  47.    LPCOLORSCHUNK       lpColorsChunk;
  48.    WORD                wCtr;
  49.    HDC                 hDC;
  50.    
  51.    switch (wCommDlgType)
  52.       {
  53.       case IDC_COLORS:
  54.  
  55.          lpColorsChunk = (LPCOLORSCHUNK)lpStruct;
  56.  
  57.          hDC = GetDC(ghWnd);
  58.          lpColorsChunk->dwCustClrs[0]=GetBkColor(hDC);
  59.          ReleaseDC(ghWnd, hDC);
  60.  
  61.          for (wCtr=1; wCtr<=15; wCtr++)
  62.             lpColorsChunk->dwCustClrs[wCtr]= lpColorsChunk->dwCustClrs[0];
  63.  
  64.          lpColorsChunk->chsclr.lStructSize    = sizeof(CHOOSECOLOR);  
  65.          lpColorsChunk->chsclr.hwndOwner      = ghWnd;
  66.          lpColorsChunk->chsclr.hInstance      = ghInst;
  67.          lpColorsChunk->chsclr.rgbResult      = (DWORD)(lpColorsChunk->dwColor);
  68.          lpColorsChunk->chsclr.lpCustColors   = (LPDWORD)(lpColorsChunk->dwCustClrs);
  69.          lpColorsChunk->chsclr.Flags          = CC_SHOWHELP | CC_ENABLEHOOK | CC_FULLOPEN | CC_ENABLETEMPLATE;
  70.          lpColorsChunk->chsclr.lCustData      = 0L;
  71.           lpColorsChunk->chsclr.lpfnHook       = (FARHOOK)ColorHook;
  72.          lpColorsChunk->chsclr.lpTemplateName = (LPSTR)"ChooseColor";
  73.          break;
  74.  
  75.       default:
  76.  
  77.          break;
  78.  
  79.       }
  80.  
  81.    return;
  82.  
  83. }
  84.  
  85.  
  86. //****************************************************************************
  87. // Function: AllocAndLockMem
  88. //
  89. // Purpose: To allocate and lock a chunk of memory for the CD structure
  90. //
  91. // Parameters:
  92. //    *hChunk == Pointer to handle of memory that will be allocated
  93. //    wSize   == Size of memory block to allocate
  94. //
  95. // Returns : LPSTR to block of memory allocated
  96. //
  97. // Comments:
  98. //
  99. // History:  Date       Author        Reason
  100. //           2/19/92    gregk         Created
  101. //****************************************************************************
  102. LPSTR FAR PASCAL AllocAndLockMem(HANDLE FAR *hChunk, WORD wSize)
  103. {
  104.    LPSTR lpChunk;
  105.  
  106.    *hChunk = GlobalAlloc(GMEM_FIXED, wSize);
  107.  
  108.    if (*hChunk)
  109.       {
  110.          lpChunk = GlobalLock(*hChunk);
  111.          if (!lpChunk)
  112.             {
  113.                GlobalFree(*hChunk);
  114.                ReportError(IDC_LOCKFAIL);
  115.                lpChunk=NULL;
  116.             }
  117.       }
  118.    else
  119.       {
  120.          ReportError(IDC_ALLOCFAIL);
  121.          lpChunk=NULL;
  122.       }
  123.    return(lpChunk);
  124. }
  125.  
  126. //****************************************************************************
  127. // Function: LaunchApplet
  128. //
  129. // Purpose:  Controls the processing to allocate memory for the dialog,  
  130. //           initialize the structure that will be passed to the         
  131. //           ChooseColor() API, call ChooseColor() and finally process   
  132. //           the return value.
  133. //
  134. // Parameters: None
  135. //
  136. // Returns : Nothing
  137. //
  138. // Comments:
  139. //
  140. // History:  Date       Author        Reason
  141. //           2/19/92    gregk         Created
  142. //****************************************************************************
  143. void FAR PASCAL LaunchApplet(void)
  144. {
  145.    WORD  wSize;
  146.    DWORD dwError;
  147.  
  148.    wSize=sizeof(COLORSCHUNK);
  149.  
  150.    if (!(glpColorsChunk=(LPCOLORSCHUNK)AllocAndLockMem(&ghColorsChunk, wSize)))
  151.       return;
  152.  
  153.    InitializeStruct(IDC_COLORS, (LPSTR)glpColorsChunk);
  154.  
  155.    if (ChooseColor( &(glpColorsChunk->chsclr) ))
  156.       {
  157.          SaveToWinIni();
  158.       }
  159.    else
  160.       {
  161.          dwError=CommDlgExtendedError();
  162.  
  163.          if (dwError == 0)  //the user hit CANCEL
  164.             {
  165.                if (gbSystemColorHasChanged)
  166.                   SetSysColors(NUMCOLORSSUPPORTED, (LPINT)&giSysColorArea,
  167.                                (COLORREF FAR*)&gdwOldSysColors);
  168.             }
  169.          else
  170.             ProcessCDError(dwError);
  171.       }
  172.  
  173.    return;
  174. }
  175.  
  176.  
  177. //****************************************************************************
  178. // Function: GetRGBValues
  179. //
  180. // Purpose:  This routine will grab the RGB values from the edit controls
  181. //           in the common dialog.                                       
  182. //
  183. // Parameters: 
  184. //      hDlg    == Handle to the ChooseColor dialog
  185. //     *wRed    == Pointer to value for Red
  186. //     *wGreen  == Pointer to value for Green
  187. //     *wBlue   == Pointer to value for Blue
  188. //
  189. //
  190. //
  191. // Returns : Nothing
  192. //
  193. // Comments:
  194. //
  195. // History:  Date       Author        Reason
  196. //           2/19/92    gregk         Created
  197. //****************************************************************************
  198. void FAR PASCAL GetRGBValues(HWND hDlg, WORD FAR *wRed, WORD FAR *wGreen,
  199.                              WORD FAR *wBlue)
  200. {
  201.    *wRed  =GetDlgItemInt(hDlg, COLOR_RED, NULL, FALSE);
  202.    *wGreen=GetDlgItemInt(hDlg, COLOR_GREEN, NULL, FALSE);
  203.    *wBlue =GetDlgItemInt(hDlg, COLOR_BLUE, NULL, FALSE);
  204.    return;
  205. }   
  206.  
  207.  
  208. //****************************************************************************
  209. // Function: LoadMyString(WORD)
  210. //
  211. // Purpose:  This routine will load a string.  Reports error on failure. 
  212. //
  213. //
  214. // Parameters: 
  215. //     szString == Buffer to contain the loaded string
  216. //    wStringID == ID value of string to be loaded
  217. //
  218. //
  219. // Returns : Nothing
  220. //
  221. // Comments:
  222. //
  223. // History:  Date       Author        Reason
  224. //           2/19/92    gregk         Created
  225. //****************************************************************************
  226. void FAR PASCAL LoadMyString(LPSTR szString, WORD wStringID)
  227. {
  228.    if (!LoadString(ghInst, wStringID, szString, MAXSTRINGDESCLEN))
  229.       {
  230.          ReportError(IDC_LOADSTRINGFAIL);
  231.          return;
  232.       }
  233.    
  234.    return;
  235. }
  236.  
  237. //****************************************************************************
  238. // Function: ColorHook(HWND, unsigned, WORD, LONG)
  239. //
  240. // Purpose:  This routine hooks all the messages being sent to the dialog.
  241. //           This is the heart of the application.
  242. //
  243. //
  244. // Parameters: 
  245. //         hDlg == Handle to the dialog window        
  246. //      message == Current message
  247. //       wParam == Varies, depending on message
  248. //       lParam == Varies, depending on message
  249. //
  250. //
  251. // Returns : TRUE, indicating message has been processed and COMMDLG.DLL
  252. //           should provide no further processing.  FALSE to indicate that
  253. //           COMMDLG.DLL should provide default processing for this message.
  254. //
  255. // Comments:
  256. //
  257. // History:  Date       Author        Reason
  258. //           2/19/92    gregk         Created
  259. //****************************************************************************
  260. BOOL FAR PASCAL ColorHook(HWND hDlg, unsigned message, WORD wParam, LONG lParam)
  261. {
  262.   static BOOL    bDragging=FALSE;
  263.   static HCURSOR hPaintCanCursor;    //Cursor used when dragging a color
  264.   static HWND    hWndSpecialIcon;    //Icon wnd representing active border, 
  265.                                      //disabled text, menu highlight and
  266.                                      //highlighted text.
  267.          WORD    wRed; 
  268.          WORD    wGreen;
  269.          WORD    wBlue;
  270.          LONG    lHitTestArea;
  271.          HWND    hCurrentWnd, hChild;
  272.          int     iSysArea=COLOR_ACTIVEBORDER;
  273.   static int     iLastSysArea=0;
  274.          DWORD   dwColor;
  275.          char    szClassName[64];               //Class name of window cursor is over
  276.          char    szAreaDesc[MAXSTRINGDESCLEN];  //Description of area cursor is over
  277.          BOOL    bUpdate=TRUE;
  278.  
  279.   switch (message)
  280.     {
  281.        case WM_INITDIALOG:
  282.       
  283.           hPaintCanCursor=LoadCursor(ghInst, "PaintCan");
  284.           ShowWindow(GetDlgItem(hDlg, COLOR_MIX), SW_HIDE);
  285.           LoadMyString(szAreaDesc, IDS_NOTHING);
  286.           SetDlgItemText(hDlg, stc2, (LPSTR)szAreaDesc);
  287.           LoadMyString(szAreaDesc, IDS_SYSTEMCOLORDROPPER);
  288.           SetWindowText(hDlg, szAreaDesc);
  289.           hWndSpecialIcon=GetDlgItem(hDlg, stc10);
  290.           gbSystemColorHasChanged=FALSE;
  291.  
  292. //The following line IS necessary....
  293.  
  294.           SendMessage(hWndSpecialIcon, STM_SETICON, 
  295.                       LoadIcon(ghInst, "SpecialArea"), 0L);
  296.  
  297.           return  (TRUE);
  298.  
  299.        case WM_LBUTTONDOWN:
  300.  
  301. //If we're over the Rainbow control.....
  302.  
  303.           if (GetDlgItem(hDlg, COLOR_RAINBOW)==ChildWindowFromPoint(hDlg, MAKEPOINT(lParam)))
  304.              break;
  305.  
  306. //..or the Lumoniscity control, don't capture the mouse.
  307.  
  308.           if (GetDlgItem(hDlg, COLOR_LUMSCROLL)==ChildWindowFromPoint(hDlg, MAKEPOINT(lParam)))
  309.              break;
  310.  
  311. //If we're over a color, capture the mouse, otherwise ignore this message
  312.  
  313.           if (GetDlgItem(hDlg, COLOR_BOX1)==
  314.                      ChildWindowFromPoint(hDlg,MAKEPOINT(lParam)) ||
  315.               GetDlgItem(hDlg, COLOR_CUSTOM1)==
  316.                      ChildWindowFromPoint(hDlg, MAKEPOINT(lParam)))
  317.           {
  318.              bDragging=TRUE;
  319.              SetCapture(hDlg);
  320.              SetCursor(hPaintCanCursor);
  321. //             do
  322. //             {
  323. //                MSG Msg;
  324. //
  325. //                while (PeekMessage(&Msg, NULL, NULL, NULL, PM_REMOVE))
  326. //                   DispatchMessage(&Msg);
  327. //             }
  328. //             while (GetAsyncKeyState(VK_LBUTTON) & 0x8000);
  329.           }
  330.           break;
  331.        
  332.        case WM_CANCELMODE:
  333.  
  334. //WM_CANCELMODE means that a dialog or some other modal process has started.
  335. //We must make sure that we release capture at this point.
  336.  
  337.           if (bDragging)
  338.           {
  339.              ReleaseCapture();
  340.              bDragging=FALSE;
  341.              return(TRUE);
  342.           }
  343.           break;
  344.  
  345.        case WM_MOUSEMOVE:
  346.  
  347.           if (bDragging)
  348.           {
  349.              ClientToScreen(hDlg, (LPPOINT)&lParam);
  350.              hCurrentWnd=WindowFromPoint(MAKEPOINT(lParam));
  351.  
  352. //This code determines if we are over a child window...
  353.  
  354.              for (;;)
  355.              {
  356.                 ScreenToClient(hCurrentWnd, (LPPOINT)&lParam);
  357.                 hChild=ChildWindowFromPoint(hCurrentWnd, MAKEPOINT(lParam));
  358.                 ClientToScreen(hCurrentWnd, (LPPOINT)&lParam);
  359.                 if (hChild && hChild != hCurrentWnd)
  360.                    hCurrentWnd=hChild;
  361.                 else
  362.                    break;
  363.              }
  364.  
  365.              GetClassName(hCurrentWnd, szClassName, sizeof(szClassName));
  366.  
  367. //Let Windows tell us where the cursor is...
  368.  
  369.              lHitTestArea=DefWindowProc(hCurrentWnd, WM_NCHITTEST, 0, lParam);
  370.  
  371. //
  372.              iSysArea=GetUpdateArea(hCurrentWnd, &bUpdate, lHitTestArea,
  373.                                     szClassName, szAreaDesc, lParam,
  374.                                     hWndSpecialIcon);
  375.  
  376.              if (iSysArea != iLastSysArea)
  377.              {
  378.                 iLastSysArea=iSysArea;
  379.                 SetDlgItemText(hDlg, stc2, szAreaDesc);
  380.              }
  381.           }
  382.           break;
  383.  
  384.        case WM_LBUTTONUP:
  385.  
  386.           if (bDragging)  
  387.           {
  388.              bUpdate=TRUE;
  389.  
  390.              ClientToScreen(hDlg, (LPPOINT)&lParam);
  391.              hCurrentWnd=WindowFromPoint(MAKEPOINT(lParam));
  392.  
  393.              for (;;)
  394.              {
  395.                 ScreenToClient(hCurrentWnd, (LPPOINT)&lParam);
  396.                 hChild=ChildWindowFromPoint(hCurrentWnd, MAKEPOINT(lParam));
  397.                 ClientToScreen(hCurrentWnd, (LPPOINT)&lParam);
  398.                 if (hChild && hChild != hCurrentWnd)
  399.                    hCurrentWnd=hChild;
  400.                 else
  401.                    break;
  402.              }
  403.  
  404.              GetClassName(hCurrentWnd, szClassName, sizeof(szClassName));
  405.              lHitTestArea=DefWindowProc(hCurrentWnd, WM_NCHITTEST, 0, lParam);
  406.  
  407.              iSysArea=GetUpdateArea(hCurrentWnd, &bUpdate, lHitTestArea,
  408.                                     szClassName, szAreaDesc, lParam,
  409.                                     hWndSpecialIcon);
  410.  
  411.              if (bUpdate)
  412.              {
  413.                 GetRGBValues(hDlg, &wRed, &wGreen, &wBlue);
  414.                 dwColor=RGB(wRed, wGreen, wBlue);
  415.                 gbSystemColorHasChanged=TRUE;
  416.  
  417.                 SetSysColors(1, (LPINT)&iSysArea, (COLORREF FAR*)&dwColor);
  418.              }  
  419.  
  420.              SetCursor(LoadCursor(NULL, IDC_ARROW));
  421.              ReleaseCapture();
  422.              bDragging=FALSE;
  423.              SetDlgItemText(hDlg, stc2, "Nothing");
  424.           }
  425.  
  426.           break;
  427.  
  428.        case WM_COMMAND:
  429.  
  430.           switch(wParam)
  431.           {
  432.              case pshHelp:
  433.  
  434.                 DialogBox(ghInst,             // current instance
  435.                           AboutBoxName,       // resource to use 
  436.                           hDlg,               // parent handle   
  437.                           AboutDlg);          // About() instance address
  438.                 break;
  439.  
  440.              default:
  441.                 break;
  442.           }
  443.  
  444.           break;
  445.  
  446.        default:
  447.           break;            
  448.     }  
  449.  
  450.   return  (FALSE);
  451. }
  452.  
  453. //****************************************************************************
  454. // Function: ProcessOverMenu(LPSTR, int *)
  455. //
  456. // Purpose:  This routine handles the processing to determine what portion
  457. //           of a menu we are over.  ie., Menu text or menu background
  458. //
  459. //
  460. // Parameters: 
  461. //   szAreaDesc == Buffer that will contain description of area we are over
  462. //    *iSysArea == Identifier indicating type of area we are over
  463. //          *pt == Point structure indicating location of cursor
  464. //
  465. // Returns : Nothing
  466. //
  467. // Comments:
  468. //
  469. // History:  Date       Author        Reason
  470. //           2/19/92    gregk         Created
  471. //****************************************************************************
  472. void FAR PASCAL ProcessOverMenu(LPSTR szAreaDesc, int FAR *iSysArea,
  473.                                 POINT FAR *pt)
  474. {
  475.    HDC   hDC;
  476.    DWORD dwPixelColor, dwTextColor;
  477.  
  478.    hDC=GetDC(NULL);
  479.    dwPixelColor=GetPixel(hDC, pt->x, pt->y);
  480.    dwTextColor=GetSysColor(COLOR_MENUTEXT);
  481.    ReleaseDC(NULL, hDC);
  482.  
  483.    if (dwTextColor==dwPixelColor)
  484.    {
  485.       LoadMyString(szAreaDesc, IDS_COLOR_MENUTEXT);
  486.       *iSysArea=COLOR_MENUTEXT;
  487.    }
  488.    else
  489.    {
  490.       LoadMyString(szAreaDesc, IDS_COLOR_MENU);
  491.       *iSysArea=COLOR_MENU;
  492.    }
  493.    return;
  494. }
  495.  
  496. //****************************************************************************
  497. // Function: ProcessOverCaption(LPSTR, int FAR *, POINT FAR *, HWND FAR *)
  498. //
  499. // Purpose:  This routine handles the processing to determine what portion
  500. //           of a caption we are over.
  501. //
  502. //
  503. // Parameters: 
  504. //   szAreaDesc == Buffer that will contain description of area we are over
  505. //    *iSysArea == Identifier indicating type of area we are over
  506. //          *pt == Point structure indicating location of cursor
  507. // *hCurrentWnd == Handle to window that the cursor is currently over
  508. //
  509. // Returns : Nothing
  510. //
  511. // Comments:
  512. //
  513. // History:  Date       Author        Reason
  514. //           2/19/92    gregk         Created
  515. //****************************************************************************
  516. void FAR PASCAL ProcessOverCaption(LPSTR szAreaDesc, int FAR *iSysArea,
  517.                                    POINT FAR *pt, HWND FAR *hCurrentWnd)
  518. {
  519.    HDC   hDC;
  520.    DWORD dwPixelColor, dwTextColor;
  521.  
  522.    hDC=GetDC(NULL);
  523.    dwPixelColor=GetPixel(hDC, pt->x, pt->y);
  524.    ReleaseDC(NULL, hDC);
  525.  
  526.    if (*hCurrentWnd==GetActiveWindow())
  527.       {
  528.          dwTextColor=GetSysColor(COLOR_CAPTIONTEXT);
  529.          if (dwTextColor==dwPixelColor)
  530.          {
  531.             LoadMyString(szAreaDesc, IDS_COLOR_CAPTIONTEXT);
  532.             *iSysArea=COLOR_CAPTIONTEXT;
  533.          }
  534.          else
  535.          {
  536.             LoadMyString(szAreaDesc, IDS_COLOR_ACTIVECAPTION);
  537.             *iSysArea=COLOR_ACTIVECAPTION;
  538.          }
  539.       }
  540.    else
  541.       {
  542.          dwTextColor=GetSysColor(COLOR_INACTIVECAPTIONTEXT);
  543.          if (dwTextColor==dwPixelColor)
  544.          {
  545.             LoadMyString(szAreaDesc, IDS_COLOR_INACTIVECAPTIONTEXT);
  546.             *iSysArea=COLOR_INACTIVECAPTIONTEXT;
  547.          }
  548.          else
  549.          {
  550.             LoadMyString(szAreaDesc, IDS_COLOR_INACTIVECAPTION);
  551.             *iSysArea=COLOR_INACTIVECAPTION;
  552.          }
  553.       }
  554.    return;
  555. }
  556.  
  557. //****************************************************************************
  558. // Function: ProcessOverButton(LPSTR, int FAR *, POINT FAR *, HWND FAR *)
  559. //
  560. // Purpose:  This routine handles the processing to determine what portion
  561. //           of a button we are over.
  562. //
  563. //
  564. // Parameters: 
  565. //   szAreaDesc == Buffer that will contain description of area we are over
  566. //    *iSysArea == Identifier indicating type of area we are over
  567. //          *pt == Point structure indicating location of cursor
  568. // *hCurrentWnd == Handle to window that the cursor is currently over
  569. //
  570. // Returns : Nothing
  571. //
  572. // Comments:
  573. //
  574. // History:  Date       Author        Reason
  575. //           2/19/92    gregk         Created
  576. //****************************************************************************
  577. void FAR PASCAL ProcessOverButton(LPSTR szAreaDesc, int FAR *iSysArea,
  578.                                   POINT FAR *pt, HWND FAR *hCurrentWnd)
  579. {
  580.    RECT r;
  581.    HDC  hDC;
  582.    DWORD dwPixelColor, dwTextColor;
  583.  
  584.    GetWindowRect(*hCurrentWnd, &r);
  585.  
  586. //If we're over the left or top side, then set button highlight...
  587.  
  588.    if ( ((r.top+4) > pt->y) || ((r.left+4) > pt->x) )
  589.       {
  590.          LoadMyString(szAreaDesc, IDS_COLOR_BTNHIGHLIGHT);
  591.          *iSysArea=COLOR_BTNHIGHLIGHT;
  592.       }
  593.  
  594. //otherwise, check for button shadow...
  595.  
  596.    else
  597.       if ( ((r.bottom-4) < pt->y) || ((r.right-4) < pt->x) )
  598.          {
  599.             LoadMyString(szAreaDesc, IDS_COLOR_BTNSHADOW);
  600.             *iSysArea=COLOR_BTNSHADOW;
  601.          }
  602.  
  603. //otherwise, we're over the button.  Check to see if we are over button text
  604.  
  605.    else
  606.       {
  607.          ScreenToClient(*hCurrentWnd, pt);
  608.          hDC=GetDC(*hCurrentWnd);
  609.          dwPixelColor=GetPixel(hDC, pt->x, pt->y);
  610.          ReleaseDC(*hCurrentWnd, hDC);
  611.          dwTextColor=GetSysColor(COLOR_BTNTEXT);
  612.  
  613.          if (dwPixelColor==dwTextColor)
  614.             {
  615.                LoadMyString(szAreaDesc, IDS_COLOR_BTNTEXT);
  616.                *iSysArea=COLOR_BTNTEXT;
  617.             }
  618.          else
  619.             {
  620.                LoadMyString(szAreaDesc, IDS_COLOR_BTNFACE);
  621.                *iSysArea=COLOR_BTNFACE;
  622.             }
  623.       }  
  624.    return;
  625. }
  626.  
  627.  
  628. //****************************************************************************
  629. // Function: ProcessOverStatic(LPSTR, int FAR *, POINT FAR *,
  630. //                             HWND FAR *, HWND FAR *, BOOL FAR *)
  631. //
  632. // Purpose:  This routine handles the processing to determine if the static
  633. //           window we are over contains any text.
  634. //
  635. //
  636. // Parameters: 
  637. //   szAreaDesc == Buffer that will contain description of area we are over
  638. //    *iSysArea == Identifier indicating type of area we are over
  639. //          *pt == Point structure indicating location of cursor
  640. // *hCurrentWnd == Handle to window that the cursor is currently over
  641. // *hWndSpecialIcon == Handle to SpecialIcon window contained in the dlg
  642. //     *bUpdate == Boolean indicating whether or not to update the status
  643. //                 window in the dialog
  644. //
  645. // Returns : Nothing
  646. //
  647. // Comments:
  648. //
  649. // History:  Date       Author        Reason
  650. //           2/19/92    gregk         Created
  651. //****************************************************************************
  652. void FAR PASCAL ProcessOverStatic(LPSTR szAreaDesc, int FAR *iSysArea,
  653.                                   POINT FAR *pt, HWND FAR *hCurrentWnd,
  654.                                   HWND FAR *hWndSpecialIcon,
  655.                                   BOOL FAR *bUpdate)
  656. {
  657.    RECT r;
  658.    char szText[128];
  659.  
  660.    if (*hCurrentWnd == *hWndSpecialIcon)  //are we over the special icon?
  661.    {
  662.       GetWindowRect(*hWndSpecialIcon, &r);
  663.       if (pt->y < r.top+10)                 //Active border area
  664.       {
  665.          LoadMyString(szAreaDesc, IDS_COLOR_ACTIVEBORDER);
  666.          *iSysArea=COLOR_ACTIVEBORDER;
  667.       }
  668.       else
  669.          if (pt->y < r.top+20)              //Disabled text area
  670.          {
  671.             LoadMyString(szAreaDesc, IDS_COLOR_GRAYTEXT);
  672.             *iSysArea=COLOR_GRAYTEXT;
  673.          }
  674.       else                                 //Highlight/text area
  675.          {
  676.             if (pt->x < r.left+16)          //Highlight area
  677.             {
  678.                LoadMyString(szAreaDesc, IDS_COLOR_HIGHLIGHT);
  679.                *iSysArea=COLOR_HIGHLIGHT;
  680.             }
  681.             else                           //Highlight text area
  682.             {
  683.                LoadMyString(szAreaDesc, IDS_COLOR_HIGHLIGHTTEXT);
  684.                *iSysArea=COLOR_HIGHLIGHTTEXT;
  685.             }
  686.          }
  687.    }  
  688.    else
  689.       if (SendMessage(*hCurrentWnd, WM_GETTEXT, (WORD)sizeof(szText),
  690.                       (LONG)(LPSTR)szText))
  691.       {
  692.          LoadMyString(szAreaDesc, IDS_COLOR_WINDOWTEXT);
  693.          *iSysArea=COLOR_WINDOWTEXT;
  694.       }
  695.       else  //were over some random static window, so don't update
  696.       {
  697.          LoadMyString(szAreaDesc, IDS_NOTHING);
  698.          *bUpdate=FALSE;
  699.       }
  700.    return;
  701. }
  702.  
  703. //****************************************************************************
  704. // Function: GetUpdateArea(HWND, BOOL FAR *, LONG, LPSTR, LPSTR, LONG,
  705. //                         HWND)    
  706. //
  707. // Purpose:  This routine is passed, among other things, the hit test  
  708. //           area that the cursor is currently over.  Given this info, 
  709. //           we probe further to determine the exact system area that  
  710. //           will be updated if the user were to drop the color.  For  
  711. //           example, lHitTestArea may be something like HT_MENU.  This
  712. //           routine will determine if the cursor is over menu text or 
  713. //           just a random menu area.                                  
  714. //
  715. // Parameters: 
  716. // *hCurrentWnd == Handle to window that the cursor is currently over
  717. //     *bUpdate == Boolean indicating whether or not to update the status
  718. //                 window in the dialog
  719. // lHitTestArea == Long defining the area the cursor is currently over
  720. //  szClassName == Class name of the window the cursor is currently over
  721. //   szAreaDesc == Buffer that will contain description of area we are over
  722. //       lParam == Point of the cursor
  723. // *hWndSpecialIcon == Handle to SpecialIcon window contained in the dlg
  724. //
  725. // Returns : Nothing
  726. //
  727. // Comments:
  728. //
  729. // History:  Date       Author        Reason
  730. //           2/19/92    gregk         Created
  731. //****************************************************************************
  732. int FAR PASCAL GetUpdateArea(HWND hCurrentWnd, BOOL FAR *bUpdate, LONG lHitTestArea,
  733.                              LPSTR szClassName, LPSTR szAreaDesc, LONG lParam,
  734.                              HWND hWndSpecialIcon)
  735. {
  736.    int   iSysArea=0;
  737.    POINT pt;
  738.  
  739.    pt=MAKEPOINT(lParam);
  740.  
  741.    if (lHitTestArea!=HTCLIENT)  //Check system area's first
  742.       {
  743.          switch (lHitTestArea)
  744.          {
  745.             case HTMENU:
  746.                ProcessOverMenu(szAreaDesc, &iSysArea, &pt);
  747.                break;
  748.  
  749.             case HTCAPTION:
  750.                ProcessOverCaption(szAreaDesc, &iSysArea, &pt, &hCurrentWnd);
  751.                break;
  752.  
  753.             case HTBORDER:
  754.                LoadMyString(szAreaDesc, IDS_COLOR_WINDOWFRAME);
  755.                iSysArea=COLOR_WINDOWFRAME;
  756.                break;
  757.  
  758.             case HTBOTTOMLEFT:  
  759.             case HTBOTTOMRIGHT:
  760.             case HTBOTTOM:
  761.             case HTTOPLEFT:
  762.             case HTTOPRIGHT:
  763.             case HTTOP:
  764.             case HTLEFT:
  765.             case HTRIGHT:
  766.     
  767.                LoadMyString(szAreaDesc, IDS_COLOR_INACTIVEBORDER);
  768.                iSysArea=COLOR_INACTIVEBORDER;
  769.                break;  
  770.            
  771.             case HTHSCROLL:
  772.             case HTVSCROLL:
  773.                LoadMyString(szAreaDesc, IDS_COLOR_SCROLLBAR);
  774.                iSysArea=COLOR_SCROLLBAR;
  775.                break;
  776.  
  777.             case HTTRANSPARENT:
  778.             case HTERROR:
  779.             case HTNOWHERE:
  780.             case HTSIZE:
  781.             case HTREDUCE:
  782.             case HTZOOM:
  783.             default:
  784.                lstrcpy(szAreaDesc, "Nothing");
  785.                iSysArea=-1;
  786.                *bUpdate=FALSE;
  787.                break;
  788.          }
  789.       }
  790.    else  //were in someone elses client area, probe a little further
  791.       {
  792.          if (!lstrcmp(szClassName, "Button"))  //there equal
  793.             {
  794.                ProcessOverButton(szAreaDesc, &iSysArea, &pt, &hCurrentWnd);
  795.             }  
  796.          else
  797.             if (!lstrcmp(szClassName, "Static"))    //there equal
  798.             {
  799.                ProcessOverStatic(szAreaDesc, &iSysArea, &pt, &hCurrentWnd, 
  800.                                  &hWndSpecialIcon, bUpdate);
  801.             }
  802.          else
  803.             if (!lstrcmp(szClassName, "#32770"))  //Dialog class
  804.             {
  805.                LoadMyString(szAreaDesc, IDS_COLOR_WINDOW);
  806.                iSysArea=COLOR_WINDOW;
  807.             }
  808.          else
  809.             if (!lstrcmp(szClassName, "#32769"))  //Desktop window
  810.             {
  811.                LoadMyString(szAreaDesc, IDS_COLOR_BACKGROUND);
  812.                iSysArea=COLOR_BACKGROUND;
  813.             }
  814.          else
  815.             if (!lstrcmp(szClassName, "MDIClient"))  //MDI client window
  816.             {
  817.                LoadMyString(szAreaDesc, IDS_COLOR_APPWORKSPACE);
  818.                iSysArea=COLOR_APPWORKSPACE;
  819.             }
  820.          else
  821.             {
  822.                LoadMyString(szAreaDesc, IDS_NOTHING);
  823.                iSysArea=-1;
  824.                *bUpdate=FALSE;
  825.             }
  826.       }  
  827.  
  828.    return(iSysArea);
  829. }
  830.  
  831. //****************************************************************************
  832. // Function: AboutDlg
  833. //
  834. // Purpose: Called by DoCommands() when want About dialog box.
  835. //
  836. // Parameters:
  837. //    hDlg    == Handle to _this_ window.
  838. //    message == Message to process.
  839. //    wParam  == WORD parameter -- depends on message
  840. //    lParam  == LONG parameter -- depends on message
  841. //
  842. // Returns: Depends on message.
  843. //
  844. // Comments:
  845. //
  846. // History:  Date       Author        Reason
  847. //           1/27/92                  Created
  848. //****************************************************************************
  849.  
  850. BOOL FAR PASCAL AboutDlg (HWND hDlg,
  851.                           unsigned message,
  852.                           WORD wParam,
  853.                           LONG lParam)
  854. {
  855.    switch (message)
  856.    {
  857.       case WM_INITDIALOG:
  858.          return (TRUE);
  859.  
  860.       case WM_COMMAND:
  861.          if ((wParam == IDOK) ||       // "OK" box selected?        
  862.              (wParam == IDCANCEL))     // System menu close command?
  863.          {
  864.             EndDialog(hDlg, TRUE);     // Exits the dialog box 
  865.             return (TRUE);
  866.          }
  867.          break;
  868.    }
  869.  
  870.    return (FALSE); // Didn't process a message
  871. }
  872.