home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 2002 December (Special) / DOSV2002_12.iso / utility / tcl230ja95.lzh / source.lzh / dll / traynotify.c < prev    next >
C/C++ Source or Header  |  2001-02-15  |  5KB  |  188 lines

  1. /*-------------------------------------------
  2.   traynotify.c
  3.     Customize the tray in taskbar
  4.     Kazubon 2001
  5. ---------------------------------------------*/
  6. #include "tcdll.h"
  7.  
  8. LRESULT CALLBACK WndProcTrayNotify(HWND, UINT, WPARAM, LPARAM);
  9. void InitTrayNotify(HWND hwnd);
  10. void EndTrayNotify(void);
  11. BOOL bFillTray = FALSE;
  12. static HWND hwndTrayNotify = NULL, hwndToolbar = NULL;
  13. static WNDPROC oldWndProcTrayNotify = NULL;
  14. static LONG oldClassStyleTrayNotify;
  15. static LONG oldStyleTrayNotify;
  16. static LONG oldExStyleTrayNotify;
  17. static BOOL bFlatTray = FALSE;
  18. static HWND s_hwndClock;
  19.  
  20. /*--------------------------------------------------
  21.   initialize
  22. ----------------------------------------------------*/
  23. void InitTrayNotify(HWND hwndClock)
  24. {
  25.     HWND hwnd;
  26.     char classname[80];
  27.     
  28.     EndTrayNotify();
  29.     
  30.     bFillTray = GetMyRegLong(NULL, "FillTray", FALSE);
  31.     bFlatTray = GetMyRegLong(NULL, "FlatTray", FALSE);
  32.     
  33.     if(!bFillTray && !bFlatTray) return ;
  34.     
  35.     // get window handle of TrayNotifyWnd
  36.     hwndTrayNotify = GetParent(hwndClock);  // TrayNotifyWnd
  37.     
  38.     // search toolbar
  39.     if(bFillTray)
  40.     {
  41.         hwndToolbar = NULL;
  42.         hwnd = GetWindow(hwndTrayNotify, GW_CHILD);
  43.         while(hwnd)
  44.         {
  45.             GetClassName(hwnd, classname, 80);
  46.             if(lstrcmpi(classname, "ToolbarWindow32") == 0)
  47.             {
  48.                 hwndToolbar = hwnd;
  49.                 break;
  50.             }
  51.             hwnd = GetWindow(hwnd, GW_HWNDNEXT);
  52.         }
  53.         if(hwndToolbar == NULL)
  54.             bFillTray = FALSE;
  55.     }
  56.     
  57.     if(bFillTray)
  58.     {
  59.         s_hwndClock = hwndClock;
  60.         
  61.         oldClassStyleTrayNotify = GetClassLong(hwndTrayNotify, GCL_STYLE);
  62.         SetClassLong(hwndTrayNotify, GCL_STYLE,
  63.             oldClassStyleTrayNotify|CS_HREDRAW|CS_VREDRAW);
  64.         
  65.         oldWndProcTrayNotify = 
  66.             (WNDPROC)GetWindowLong(hwndTrayNotify, GWL_WNDPROC);
  67.         SetWindowLong(hwndTrayNotify, GWL_WNDPROC, (LONG)WndProcTrayNotify);
  68.         
  69.         oldStyleTrayNotify = GetWindowLong(hwndTrayNotify, GWL_STYLE);
  70.         SetWindowLong(hwndTrayNotify, GWL_STYLE,
  71.             oldStyleTrayNotify & ~(WS_CLIPCHILDREN|WS_CLIPSIBLINGS));
  72.     }
  73.     
  74.     if(bFlatTray)
  75.     {
  76.         oldExStyleTrayNotify = GetWindowLong(hwndTrayNotify, GWL_EXSTYLE);
  77.         SetWindowLong(hwndTrayNotify, GWL_EXSTYLE,
  78.             oldExStyleTrayNotify & ~WS_EX_STATICEDGE);
  79.         SetWindowPos(hwndTrayNotify, NULL, 0, 0, 0, 0,
  80.             SWP_DRAWFRAME|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER);
  81.     }
  82.     
  83.     if(bFillTray || bFlatTray)
  84.         InvalidateRect(hwndTrayNotify, NULL, TRUE);
  85.     if(bFillTray)
  86.         SendMessage(hwndToolbar, WM_SYSCOLORCHANGE, 0, 0);
  87. }
  88.  
  89. /*--------------------------------------------------
  90.   undo
  91. ----------------------------------------------------*/
  92. void EndTrayNotify(void)
  93. {
  94.     if(bFillTray && hwndTrayNotify && IsWindow(hwndTrayNotify))
  95.     {
  96.         SetWindowLong(hwndTrayNotify, GWL_STYLE, oldStyleTrayNotify);
  97.         if(oldWndProcTrayNotify)
  98.             SetWindowLong(hwndTrayNotify, GWL_WNDPROC,
  99.                 (LONG)oldWndProcTrayNotify);
  100.         
  101.         SetClassLong(hwndTrayNotify, GCL_STYLE, oldClassStyleTrayNotify);
  102.         
  103.         InvalidateRect(hwndTrayNotify, NULL, TRUE);
  104.         SendMessage(hwndToolbar, WM_SYSCOLORCHANGE, 0, 0);
  105.         InvalidateRect(hwndToolbar, NULL, TRUE);
  106.     }
  107.     
  108.     if(bFlatTray && hwndTrayNotify && IsWindow(hwndTrayNotify))
  109.     {
  110.         SetWindowLong(hwndTrayNotify, GWL_EXSTYLE, oldExStyleTrayNotify);
  111.         SetWindowPos(hwndTrayNotify, NULL, 0, 0, 0, 0,
  112.             SWP_DRAWFRAME|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER);
  113.     }
  114.     
  115.     hwndTrayNotify = NULL;
  116.     hwndToolbar = NULL;
  117.     oldWndProcTrayNotify = NULL;
  118.     bFillTray = FALSE;
  119.     bFlatTray = FALSE;
  120. }
  121.  
  122. extern HDC hdcClock;
  123.  
  124. /*------------------------------------------------
  125.    subclass procedure of TrayNotifyWnd
  126. --------------------------------------------------*/
  127. LRESULT CALLBACK WndProcTrayNotify(HWND hwnd, UINT message,
  128.     WPARAM wParam, LPARAM lParam)
  129. {
  130.     switch(message)
  131.     {
  132.         case WM_ERASEBKGND:
  133.         {
  134.             RECT rc;
  135.             if(bNoClock) break;
  136.             GetClientRect(hwnd, &rc);
  137.             FillClock(hwnd, (HDC)wParam, &rc, 0);
  138.             return 1;
  139.         }
  140.         case WM_PAINT:
  141.         {
  142.             PAINTSTRUCT ps;
  143.             HDC hdc;
  144.             RECT rc;
  145.             if(bNoClock) break;
  146.             hdc = BeginPaint(hwnd, &ps);
  147.             GetClientRect(hwnd, &rc);
  148.             FillClock(hwnd, hdc, &rc, 0);
  149.             EndPaint(hwnd, &ps);
  150.             return 0;
  151.         }
  152.         case WM_SIZE:
  153.             if(bNoClock) break;
  154.             SendMessage(s_hwndClock, WM_SIZE, 0, 0);
  155.             break;
  156.         case WM_NOTIFY:
  157.         {
  158.             LPNMHDR pnmh;
  159.             if(bNoClock) break;
  160.             pnmh = (LPNMHDR)lParam;
  161.             if (pnmh->code == NM_CUSTOMDRAW && pnmh->idFrom == 0)
  162.             {
  163.                 LPNMCUSTOMDRAW pnmcd;
  164.                 pnmcd = (LPNMCUSTOMDRAW)lParam;
  165.                 if (pnmcd->dwDrawStage  == CDDS_ITEMPREPAINT
  166.                     && hdcClock != NULL)
  167.                 {
  168.                     POINT ptTray, ptToolbar;
  169.                     int x, y;
  170.                     ptTray.x = ptTray.y = 0;
  171.                     ClientToScreen(hwnd, &ptTray);
  172.                     ptToolbar.x = ptToolbar.y = 0;
  173.                     ClientToScreen(pnmh->hwndFrom, &ptToolbar);
  174.                     x = ptToolbar.x - ptTray.x;
  175.                     y = ptToolbar.y - ptTray.y;
  176.                     BitBlt(pnmcd->hdc, pnmcd->rc.left, pnmcd->rc.top,
  177.                         pnmcd->rc.right - pnmcd->rc.left,
  178.                         pnmcd->rc.bottom - pnmcd->rc.top,
  179.                         hdcClock, x + pnmcd->rc.left, y + pnmcd->rc.top,
  180.                         SRCCOPY);
  181.                 }
  182.             }
  183.             break;
  184.         }
  185.     }
  186.     return CallWindowProc(oldWndProcTrayNotify, hwnd, message, wParam, lParam);
  187. }
  188.