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

  1. /*-----------------------------------------------------
  2.   main.c
  3.    API, hook procedure
  4.    KAZUBON 1997-2001
  5. -------------------------------------------------------*/
  6.  
  7. #include "tcdll.h"
  8.  
  9. LRESULT CALLBACK CallWndProc(int nCode, WPARAM wParam, LPARAM lParam);
  10. void InitClock(HWND hwnd);
  11.  
  12. /*------------------------------------------------
  13.   shared data among processes
  14. --------------------------------------------------*/
  15. extern HHOOK hhook;
  16. extern HWND hwndTClockMain;
  17. extern HWND hwndClock;
  18.  
  19. /*------------------------------------------------
  20.   globals
  21. --------------------------------------------------*/
  22. extern HANDLE hmod;
  23. extern WNDPROC oldWndProc;
  24.  
  25. /*------------------------------------------------
  26.   entry point of this DLL
  27. --------------------------------------------------*/
  28. BOOL WINAPI _DllMainCRTStartup(HANDLE hModule, DWORD dwFunction, LPVOID lpNot)
  29. {
  30.     hmod = hModule;
  31.     switch (dwFunction)
  32.     {
  33.         case DLL_PROCESS_ATTACH:
  34.             break;
  35.         case DLL_PROCESS_DETACH:
  36.             break;
  37.         default:
  38.             break;
  39.     }
  40.     return TRUE;
  41. }
  42.  
  43. /*------------------------------------------------
  44.    API: install my hook
  45. --------------------------------------------------*/
  46. void WINAPI HookStart(HWND hwnd)
  47. {
  48.     HWND hwndTray;
  49.     HANDLE hThread;
  50.     
  51.     hwndTClockMain = hwnd;
  52.     
  53.     // find the taskbar
  54.     hwndTray = FindWindow("Shell_TrayWnd", NULL);
  55.     if(!hwndTray)
  56.     {
  57.         SendMessage(hwnd, WM_USER+1, 0, 1);
  58.         return;
  59.     }
  60.     
  61.     // get thread ID of taskbar (explorer)
  62.     // Specal thanks to T.Iwata.
  63.     hThread = (HANDLE)GetWindowThreadProcessId(hwndTray, NULL);
  64.     if(!hThread)
  65.     {
  66.         SendMessage(hwnd, WM_USER+1, 0, 2);
  67.         return;
  68.     }
  69.     
  70.     // install an hook to thread of taskbar
  71.     hhook = SetWindowsHookEx(WH_CALLWNDPROC, (HOOKPROC)CallWndProc, hmod,
  72.         (DWORD)hThread);
  73.     if(!hhook)
  74.     {
  75.         SendMessage(hwnd, WM_USER+1, 0, 3);
  76.         return;
  77.     }
  78.     
  79.     // refresh the taskbar
  80.     PostMessage(FindWindow("Shell_TrayWnd", NULL), WM_SIZE,
  81.         SIZE_RESTORED, 0);
  82. }
  83.  
  84. /*------------------------------------------------
  85.   API: uninstall my hook
  86. --------------------------------------------------*/
  87. void WINAPI HookEnd(void)
  88. {
  89.     HWND hwnd;
  90.     
  91.     // force the clock to end cunstomizing
  92.     if(hwndClock && IsWindow(hwndClock))
  93.         SendMessage(hwndClock, WM_COMMAND, 102, 0);
  94.     // uninstall my hook
  95.     if(hhook != NULL)
  96.         UnhookWindowsHookEx(hhook); hhook = NULL;
  97.     
  98.     // refresh the clock
  99.     if(hwndClock && IsWindow(hwndClock))
  100.         PostMessage(hwndClock, WM_TIMER, 0, 0);
  101.     hwndClock = NULL;
  102.     
  103.     // refresh the taskbar
  104.     hwnd = FindWindow("Shell_TrayWnd", NULL);
  105.     if(hwnd)
  106.     {
  107.         PostMessage(hwnd, WM_SIZE, SIZE_RESTORED, 0);
  108.         InvalidateRect(hwnd, NULL, TRUE);
  109.     }
  110. }
  111.  
  112. /*------------------------------------------------
  113.   hook procedure
  114. --------------------------------------------------*/
  115. LRESULT CALLBACK CallWndProc(int nCode, WPARAM wParam, LPARAM lParam)
  116. {
  117.     LPCWPSTRUCT pcwps;
  118.     char classname[80];
  119.  
  120.     pcwps = (LPCWPSTRUCT)lParam;
  121.  
  122.     if(nCode >= 0 && pcwps && pcwps->hwnd)
  123.     {
  124.         if(hwndClock == NULL &&   // if this message is sent to the clock
  125.             oldWndProc == NULL &&
  126.             GetClassName(pcwps->hwnd, classname, 80) > 0 &&
  127.             lstrcmpi(classname, "TrayClockWClass") == 0)
  128.         {
  129.             // initialize  cf. wndproc.c
  130.             InitClock(pcwps->hwnd);
  131.         }
  132.     }
  133.     
  134.     return CallNextHookEx(hhook, nCode, wParam, lParam);
  135. }
  136.  
  137.