/*------------------------------------------------ initialize the clock --------------------------------------------------*/ void InitClock(HWND hwnd) { RECT rc; if(g_bInitClock) return; g_bInitClock = TRUE; g_hInst = GetModuleHandle(DLLFILENAME); g_winver = CheckWinVersion(); // common/utl.c g_bVisualStyle = IsXPVisualStyle(); // common/utl.c #if 0 if(!(g_winver&WIN10RS1)) { // check subclassification if(IsSubclassed(hwnd)) { SendMessage(g_hwndTClockMain, TCM_CLOCKERROR, 0, 6); return; } } #endif GetModuleFileName(g_hInst, g_mydir, MAX_PATH); del_title(g_mydir); strcpy(g_inifile, g_mydir); add_title(g_inifile, "tclock.ini"); g_bIniSetting = TRUE; /* g_bIniSetting = FALSE; if(IsFile(g_inifile)) g_bIniSetting = TRUE; */ // Save the original window size GetWindowRect(hwnd, &rc); g_OrigClockWidth = rc.right - rc.left; g_OrigClockHeight = rc.bottom - rc.top; // Save taskbar direction g_bVertTaskbar = IsVertTaskbar(GetParent(GetParent(hwnd))); g_bTaskbarPosChanging = FALSE; // tell tclock.exe clock's HWND PostMessage(g_hwndTClockMain, TCM_HWNDCLOCK, 0, (LPARAM)hwnd); // read settings LoadSetting(hwnd); InitTooltip(hwnd); // tooltip.c InitUserStr(); // userstr.c // subclassfy the clock window !! if(g_winver&WIN10RS1) { SetWindowSubclass(GetParent(hwnd), SubclassTrayProc, SUBCLASSTRAY_ID, (DWORD_PTR)hwnd); } SetWindowSubclass(hwnd, SubclassProc, SUBCLASS_ID, 0); // don't accept double clicks SetClassLong(hwnd, GCL_STYLE, GetClassLong(hwnd, GCL_STYLE) & ~CS_DBLCLKS); #if TC_ENABLE_STARTBUTTON InitStartButton(hwnd); // startbtn.c #endif #if TC_ENABLE_STARTMENU InitStartMenu(hwnd); // startmenu.c #endif #if TC_ENABLE_TASKBAR InitTaskbar(hwnd); // taskbar.c #endif #if TC_ENABLE_TASKSWITCH InitTaskSwitch(hwnd); // taskswitch.c #endif #if TC_ENABLE_TRAYNOTIFY InitTrayNotify(hwnd); // traynotify.c #endif #if TC_ENABLE_VOLUME InitMixer(); // mixer.c #endif #if TC_ENABLE_SYSINFO InitSysInfo(hwnd); // sysinfo.c #endif #if TC_ENABLE_TASKBAR RefreshTaskbar(hwnd); // taskbar.c #else PostMessage(GetParent(GetParent(hwnd)), WM_SIZE, SIZE_RESTORED, 0); InvalidateRect(GetParent(GetParent(hwnd)), NULL, TRUE); #endif SetTimer(hwnd, IDTIMER_MAIN, 1000, NULL); #if TC_ENABLE_DESKTOPICON SetDesktopIcons(); // desktop.c #endif }
/*------------------------------------------------ subclass procedure of the clock --------------------------------------------------*/ LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { switch(message) // for tooltip { case WM_MOUSEMOVE: case WM_LBUTTONDOWN: case WM_RBUTTONDOWN: case WM_MBUTTONDOWN: case WM_LBUTTONUP: case WM_RBUTTONUP: case WM_MBUTTONUP: #if TC_ENABLE_WHEEL case WM_MOUSEWHEEL: #endif OnTooltipMouseMsg(hwnd, message, wParam, lParam); break; } switch(message) { /* -------- drawing & sizing ------------- */ case WM_PAINT: { PAINTSTRUCT ps; HDC hdc; if(g_bNoClock) break; hdc = BeginPaint(hwnd, &ps); OnPaint(hwnd, hdc, NULL); EndPaint(hwnd, &ps); return 0; } case WM_ERASEBKGND: break; case (WM_USER+100): // a message requesting for clock size if(g_bNoClock) break; // sent from parent window return OnCalcRect(hwnd); case WM_WINDOWPOSCHANGING: // size arrangement if(g_bNoClock) break; OnWindowPosChanging(hwnd, (LPWINDOWPOS)lParam); break; case WM_SIZE: if(g_bNoClock) break; CreateClockDC(hwnd); // create offscreen DC return 0; case WM_SYSCOLORCHANGE: case WM_THEMECHANGED: if(g_bNoClock) break; CreateClockDC(hwnd); // create offscreen DC InvalidateRect(hwnd, NULL, FALSE); #if TC_ENABLE_DESKTOPICON SetDesktopIcons(); // desktop.c #endif return 0; case WM_WININICHANGE: case WM_TIMECHANGE: case (WM_USER+101): case WM_SETFOCUS: case WM_KILLFOCUS: if(g_bNoClock) break; InvalidateRect(hwnd, NULL, FALSE); return 0; /* -------- Timers ------------- */ case WM_TIMER: switch (wParam) { case IDTIMER_MAIN: OnTimerMain(hwnd); return 0; #if TC_ENABLE_SYSINFO case IDTIMER_SYSINFO: OnTimerSysInfo(); // sysinfo.c #if TC_ENABLE_DESKTOPICON SetDesktopIcons(); // desktop.c #endif return 0; #endif } if(g_bNoClock) break; return 0; /* -------- Mouse messages ------------- */ case WM_LBUTTONDOWN: // mouse button is down case WM_RBUTTONDOWN: case WM_MBUTTONDOWN: case WM_XBUTTONDOWN: return OnMouseDown(hwnd, message, wParam, lParam); case WM_LBUTTONUP: // mouse button is up case WM_RBUTTONUP: case WM_MBUTTONUP: case WM_XBUTTONUP: return OnMouseUp(hwnd, message, wParam, lParam); case WM_MOUSEMOVE: return 0; case WM_NCRBUTTONUP: return 0; case WM_CONTEXTMENU: PostMessage(g_hwndTClockMain, WM_CONTEXTMENU, wParam, lParam); return 0; case WM_NCHITTEST: // not to pass to g_oldWndProc return DefWindowProc(hwnd, message, wParam, lParam); case WM_MOUSEACTIVATE: return MA_ACTIVATE; #if TC_ENABLE_MOUSEDROP case WM_DROPFILES: // files are dropped PostMessage(g_hwndTClockMain, WM_DROPFILES, wParam, lParam); return 0; #endif #if TC_ENABLE_WHEEL case WM_MOUSEWHEEL: // the mouse wheel is rotated PostMessage(g_hwndTClockMain, WM_MOUSEWHEEL, wParam, lParam); return 0; #endif case WM_NOTIFY: // tooltip { LRESULT res; if(OnTooltipNotify(hwnd, &res, (LPNMHDR)lParam)) return res; break; } /* messages sent from other program */ case CLOCKM_EXIT: // clean up all EndClock(hwnd); return 0; case CLOCKM_REFRESHCLOCK: // refresh the clock OnRefreshClock(hwnd); return 0; case CLOCKM_DELUSRSTR: // clear user strings InitUserStr(); return 0; #if TC_ENABLE_TASKBAR case CLOCKM_REFRESHTASKBAR: // refresh other elements than clock OnRefreshTaskbar(hwnd); return 0; #endif #if TC_ENABLE_STARTMENU case CLOCKM_REFRESHSTARTMENU: // refresh Start menu OnRefreshStartMenu(hwnd); return 0; #endif case CLOCKM_REFRESHTOOLTIP: // refresh tooltip OnRefreshTooltip(hwnd); return 0; case CLOCKM_BLINK: // blink the clock g_nBlink = 2; m_nBlinkSec = lParam; if(lParam) m_nBlinkTick = GetTickCount(); return 0; case CLOCKM_COPY: // copy format to clipboard OnCopy(hwnd, NULL); return 0; #if TC_ENABLE_VOLUME case CLOCKM_VOLCHANGE: OnVolumeChange(hwnd); return 0; #endif case WM_COPYDATA: OnCopyData(hwnd, (HWND)wParam, (COPYDATASTRUCT*)lParam); return 0; /* WM_DESTROY is sent only when Win95+IE4/98/Me is shut down */ case WM_DESTROY: OnDestroy(hwnd); // main2.c break; } return CallWindowProc(g_oldWndProc, hwnd, message, wParam, lParam); }