1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
|
#include "Windows.h"
#include "Shellapi.h"
#include "commctrl.h"
#ifdef _DEBUG
extern "C" __declspec(naked) void _chkesp()
{
__asm je return0
__asm int 3
return0:
__asm ret
}
#endif
#define SHOW_TRAY_ICON
void _declspec(dllimport) KillTT_Hook();
void _declspec(dllimport) KillTT_SetBlock(BOOL bBlock);
void _declspec(dllimport) KillTT_Unhook();
HWND wndNotify;
NOTIFYICONDATA nidIconData;
HICON icoEnabledIcon;
HICON icoDisabledIcon;
HMENU mnuPopup;
bool blnEnabled=TRUE;
const UINT WM_TASKBARCREATED = ::RegisterWindowMessage("TaskbarCreated");
BOOL CALLBACK KillTT_EnableTooltips(HWND hwnd,LPARAM lParam)
{
CHAR buf[256];
GetClassName(hwnd,buf,256);
if(lstrcmp(buf,TEXT("tooltips_class32"))==0)
{
PostMessage(hwnd,TTM_ACTIVATE,lParam,0);
}
EnumChildWindows(hwnd,&KillTT_EnableTooltips,lParam);
return TRUE;
}
void KillTT_SetState(bool kill)
{
#ifdef SHOW_TRAY_ICON
MENUITEMINFO mii;
mii.cbSize=sizeof(mii);
mii.fMask=MIIM_STATE;
#endif
KillTT_SetBlock(kill);
if(kill)
{
EnumWindows(&KillTT_EnableTooltips,0);
#ifdef SHOW_TRAY_ICON
nidIconData.hIcon=icoEnabledIcon;
mii.fState=MFS_CHECKED|MFS_ENABLED;
#endif
}
else
{
EnumWindows(&KillTT_EnableTooltips,1);
#ifdef SHOW_TRAY_ICON
nidIconData.hIcon=icoDisabledIcon;
mii.fState=MFS_UNCHECKED|MFS_ENABLED;
#endif
}
#ifdef SHOW_TRAY_ICON
SetMenuItemInfo(mnuPopup,100,FALSE,&mii);
Shell_NotifyIcon(NIM_MODIFY,&nidIconData);
#endif
}
#ifdef SHOW_TRAY_ICON
void CreateTrayIcon()
{
nidIconData.cbSize=sizeof(nidIconData);
nidIconData.hWnd=wndNotify;
nidIconData.uID=0;
nidIconData.uFlags=NIF_ICON|NIF_MESSAGE|NIF_TIP;
nidIconData.uCallbackMessage=WM_USER+11;
nidIconData.hIcon=icoEnabledIcon;
nidIconData.szTip[0]=NULL;
Shell_NotifyIcon(NIM_ADD,&nidIconData);
}
LRESULT CALLBACK KillTT_WndProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
if(uMsg==WM_USER+11)
{
if(lParam==WM_LBUTTONUP)
{
blnEnabled=!blnEnabled;
KillTT_SetState(blnEnabled);
}
if(lParam==WM_RBUTTONUP || lParam == WM_CONTEXTMENU)
{
POINT popupPt;
GetCursorPos(&popupPt);
SetForegroundWindow(wndNotify);
UINT item=TrackPopupMenu(mnuPopup,
TPM_NONOTIFY|TPM_RETURNCMD|TPM_LEFTALIGN|
TPM_BOTTOMALIGN,popupPt.x,popupPt.y,0,
wndNotify,NULL);
PostMessage(wndNotify,WM_NULL,0,0);
switch(item)
{
case 100:
blnEnabled=!blnEnabled;
KillTT_SetState(blnEnabled);
break;
case 101:
PostQuitMessage(0);
break;
default:
break;
}
}
if(uMsg == WM_TASKBARCREATED)
{
CreateTrayIcon();
}
}
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
#endif
extern "C" BOOL WINAPI WinMainCRTStartup()
{
KillTT_Hook();
#ifdef SHOW_TRAY_ICON
HINSTANCE hInst=GetModuleHandle(NULL);
icoDisabledIcon=(HICON)LoadImage(hInst,MAKEINTRESOURCE(1001),
IMAGE_ICON,0,0,LR_DEFAULTSIZE|LR_SHARED);
icoEnabledIcon=(HICON)LoadImage(hInst,MAKEINTRESOURCE(1000),
IMAGE_ICON,0,0,LR_DEFAULTSIZE|LR_SHARED);
mnuPopup=LoadMenu(hInst,MAKEINTRESOURCE(1002));
MENUITEMINFO mii;
mii.cbSize=sizeof(mii);
mii.fMask=MIIM_SUBMENU;
GetMenuItemInfo(mnuPopup,0,TRUE,&mii);
mnuPopup=mii.hSubMenu;
wndNotify=CreateWindow("EDIT","ttkiller_notification_window",
0,0,0,1,1,NULL,NULL,hInst,0);
SetWindowLong(wndNotify,GWL_WNDPROC,(LONG)&KillTT_WndProc);
CreateTrayIcon();
#endif
KillTT_SetState(blnEnabled);
MSG msg;
BOOL bRet;
while((bRet=GetMessage(&msg,NULL,0,0))!=0)
{
if(bRet==-1)
{
break;
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
KillTT_SetState(FALSE);
KillTT_Unhook();
#ifdef SHOW_TRAY_ICON
Shell_NotifyIcon(NIM_DELETE,&nidIconData);
#endif
return 0;
}
|