From 331b1958e068eec8b30f7434d65f373ed62559f5 Mon Sep 17 00:00:00 2001 From: Stefan Sundin Date: Tue, 16 Sep 2008 17:09:22 +0000 Subject: [PATCH] Made the detection of Ctrl+Alt+F4 more secure. Made the log much more compact. Now getting SeDebugPrivilege when dll loads. Only one instance can be run, tray icon of first instance is readded. Released 0.8. --- SuperF4.exe.manifest | 3 +- info.txt | 6 +- keyhook.c | 269 ++++++++++++++++--------------------------- resources.rc | 6 +- superf4.c | 152 ++++++++++-------------- 5 files changed, 173 insertions(+), 263 deletions(-) diff --git a/SuperF4.exe.manifest b/SuperF4.exe.manifest index 756d5e8..1080ed7 100644 --- a/SuperF4.exe.manifest +++ b/SuperF4.exe.manifest @@ -3,9 +3,8 @@ -SuperF4 vkCode; @@ -75,185 +84,69 @@ _declspec(dllexport) LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPA if (vkey == VK_MENU || vkey == VK_LMENU || vkey == VK_RMENU) { alt=1; } - if (vkey == VK_F4) { - f4=1; - } - } - else if (wParam == WM_KEYUP || wParam == WM_SYSKEYUP) { - if (vkey == VK_CONTROL || vkey == VK_LCONTROL || vkey == VK_RCONTROL) { - ctrl=0; - } - if (vkey == VK_MENU || vkey == VK_LMENU || vkey == VK_RMENU) { - alt=0; - } - if (vkey == VK_F4) { - f4=0; - } - } - - //Double check that Ctrl and Alt are pressed - //This prevents a faulty kill if keyhook haven't received the KEYUP for these keys - if (ctrl && alt && f4) { - if (!(GetAsyncKeyState(VK_CONTROL)&0x8000)) { - ctrl=0; - } - else if (!(GetAsyncKeyState(VK_MENU)&0x8000)) { - alt=0; - } - /*else if (!(GetAsyncKeyState(VK_F4)&0x8000)) { - f4=0; - }*/ - } - - //This will happen if Ctrl+Alt+F4 is being pressed - if (ctrl && alt && f4) { - //Open log - FILE *output; - if ((output=fopen("log-keyhook.txt","ab")) == NULL) { - sprintf(msg,"Failed to open log file.\nfopen() failed in file %s, line %d.",__FILE__,__LINE__); - MessageBox(NULL, msg, "SuperF4 Warning", MB_ICONWARNING|MB_OK); - } - - if (output != NULL) { - //Print timestamp - time_t rawtime; - struct tm *timeinfo; - time(&rawtime); - timeinfo=localtime(&rawtime); - strftime(msg,sizeof(msg),"[%Y-%m-%d %H:%M:%S]",timeinfo); - fprintf(output,"\n%s\n",msg); - - fprintf(output,"Ctrl+Alt+F4 pressed!\n"); - } - - //Get hwnd of foreground window - HWND hwnd; - if ((hwnd=GetForegroundWindow()) == NULL) { - sprintf(msg,"GetForegroundWindow() failed in file %s, line %d.",__FILE__,__LINE__); - if (output != NULL) { - fprintf(output,"%s\n",msg); - fclose(output); + if (ctrl && alt && vkey == VK_F4) { + //Double check that Ctrl and Alt are pressed + //This prevents a faulty kill if keyhook haven't received the keyup for these keys + if (!(GetAsyncKeyState(VK_CONTROL)&0x8000)) { + ctrl=0; } - MessageBox(NULL, msg, "SuperF4 Error", MB_ICONERROR|MB_OK); - return 0; - } - - //Get hwnd title (for log) - if (output != NULL) { - char title[100]; - GetWindowText(hwnd,title,100); - fprintf(output,"Window title: %s\n",title); - } - - //Get process id of hwnd - DWORD pid; - GetWindowThreadProcessId(hwnd,&pid); - if (output != NULL) { - fprintf(output,"Process id: %d\n",pid); - fprintf(output,"Opening process... "); - } - - HANDLE process; - if ((process=OpenProcess(PROCESS_TERMINATE,FALSE,pid)) == NULL) { - if (output != NULL) { - fprintf(output,"failed! (error: %d)\n",GetLastError()); - fprintf(output,"Attempting to aquire SeDebugPrivilege privilege... "); + else if (!(GetAsyncKeyState(VK_MENU)&0x8000)) { + alt=0; } - - //Get token - HANDLE hToken; - if (OpenThreadToken(GetCurrentThread(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, FALSE, &hToken) == 0) { - if (GetLastError() == ERROR_NO_TOKEN) { - if (ImpersonateSelf(SecurityImpersonation) == 0) { - sprintf(msg,"ImpersonateSelf() failed (error: %d) in file %s, line %d.",GetLastError(),__FILE__,__LINE__); - if (output != NULL) { - fprintf(output,"failed!\n%s\n",msg); - fclose(output); - } - MessageBox(NULL, msg, "SuperF4 Error", MB_ICONERROR|MB_OK); - return 0; - } - - if (OpenThreadToken(GetCurrentThread(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, FALSE, &hToken) == 0) { - sprintf(msg,"OpenThreadToken() failed (error: %d) in file %s, line %d.",GetLastError(),__FILE__,__LINE__); - if (output != NULL) { - fprintf(output,"failed!\n%s\n",msg); - fclose(output); - } - MessageBox(NULL, msg, "SuperF4 Error", MB_ICONERROR|MB_OK); - return 0; - } + else { + //Kill program + fprintf(output,"%s ",GetTimestamp(msg,sizeof(msg),"[%Y-%m-%d %H:%M:%S]")); + + //Get hwnd of foreground window + HWND hwnd; + if ((hwnd=GetForegroundWindow()) == NULL) { + fprintf(output,"Error: GetForegroundWindow() failed in file %s, line %d.",__FILE__,__LINE__); + fflush(output); + return 0; } - else { - sprintf(msg,"OpenThreadToken() failed (error: %d) in file %s, line %d.",GetLastError(),__FILE__,__LINE__); - if (output != NULL) { - fprintf(output,"failed!\n%s\n",msg); - fclose(output); - } - MessageBox(NULL, msg, "SuperF4 Error", MB_ICONERROR|MB_OK); + + //Get hwnd title (for log) + char title[100]; + GetWindowText(hwnd,title,100); + + //Get process id of hwnd + DWORD pid; + GetWindowThreadProcessId(hwnd,&pid); + + fprintf(output,"Killing \"%s\" (pid %d)... ",title,pid); + + //Open the process + HANDLE process; + if ((process=OpenProcess(PROCESS_TERMINATE,FALSE,pid)) == NULL) { + fprintf(output,"failed!\n"); + fprintf(output,"Error: OpenProcess() failed (error: %d) in file %s, line %d.\n",GetLastError(),__FILE__,__LINE__); + fflush(output); return 0; } - } - - //Enable SeDebugPrivilege - if (SetPrivilege(hToken, SE_DEBUG_NAME, TRUE) == FALSE) { - sprintf(msg,"SetPrivilege() failed (error: %d) in file %s, line %d.",GetLastError(),__FILE__,__LINE__); - if (output != NULL) { - fprintf(output,"failed!\n%s\n",msg); - fclose(output); + + //Terminate process + if (TerminateProcess(process,1) == 0) { + fprintf(output,"failed!\n"); + fprintf(output,"Error: TerminateProcess() failed (error: %d) in file %s, line %d.\n",GetLastError(),__FILE__,__LINE__); + fflush(output); + return 0; } - MessageBox(NULL, msg, "SuperF4 Error", MB_ICONERROR|MB_OK); - CloseHandle(hToken); - return 0; - } - CloseHandle(hToken); - - //Try to open process again - if (output != NULL) { + fprintf(output,"success!\n"); - fprintf(output,"Opening process... "); - } - if ((process=OpenProcess(PROCESS_TERMINATE,FALSE,pid)) == NULL) { - sprintf(msg,"OpenProcess() failed (error: %d) in file %s, line %d.",GetLastError(),__FILE__,__LINE__); - if (output != NULL) { - fprintf(output,"failed!\n%s\n",msg); - fclose(output); - } - MessageBox(NULL, msg, "SuperF4 Error", MB_ICONERROR|MB_OK); - return 0; + fflush(output); + + //Prevent this keypress from being propagated to the window selected after the kill + return 1; } } - - //Terminate process - if (output != NULL) { - fprintf(output,"success!\n"); - fprintf(output,"Killing process... "); - } - if (TerminateProcess(process,1) == 0) { - sprintf(msg,"TerminateProcess() failed (error: %d) in file %s, line %d.",GetLastError(),__FILE__,__LINE__); - if (output != NULL) { - fprintf(output,"failed!\n%s\n",msg); - fclose(output); - } - MessageBox(NULL, msg, "SuperF4 Error", MB_ICONERROR|MB_OK); - return 0; + } + else if (wParam == WM_KEYUP || wParam == WM_SYSKEYUP) { + if (vkey == VK_CONTROL || vkey == VK_LCONTROL || vkey == VK_RCONTROL) { + ctrl=0; } - - if (output != NULL) { - fprintf(output,"success!\n"); - - //Close log - if (fclose(output) == EOF) { - sprintf(msg,"fclose() failed in file %s, line %d.",__FILE__,__LINE__); - fprintf(output,"%s\n",msg); - fclose(output); - MessageBox(NULL, msg, "SuperF4 Error", MB_ICONERROR|MB_OK); - return 0; - } + if (vkey == VK_MENU || vkey == VK_LMENU || vkey == VK_RMENU) { + alt=0; } - - //Prevent this keypress from being propagated to the window selected after the kill - return 1; } } @@ -261,5 +154,43 @@ _declspec(dllexport) LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPA } BOOL APIENTRY DllMain(HINSTANCE hInstance, DWORD reason, LPVOID reserved) { + if (reason == DLL_PROCESS_ATTACH) { + //Open log + output=fopen("log-keyhook.txt","ab"); + fprintf(output,"\n%s ",GetTimestamp(msg,sizeof(msg),"[%Y-%m-%d %H:%M:%S]")); + fprintf(output,"New session. Getting SeDebugPrivilege privilege... "); + + //Create security context + if (ImpersonateSelf(SecurityImpersonation) == 0) { + fprintf(output,"failed!\n"); + fprintf(output,"Error: ImpersonateSelf() failed (error: %d) in file %s, line %d.\n",GetLastError(),__FILE__,__LINE__); + fflush(output); + return TRUE; + } + //Get access token + HANDLE hToken; + if (OpenThreadToken(GetCurrentThread(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, FALSE, &hToken) == 0) { + fprintf(output,"failed!\n"); + fprintf(output,"Error: OpenThreadToken() failed (error: %d) in file %s, line %d.\n",GetLastError(),__FILE__,__LINE__); + fflush(output); + return TRUE; + } + //Enable SeDebugPrivilege + if (SetPrivilege(hToken, SE_DEBUG_NAME, TRUE) == FALSE) { + fprintf(output,"failed!\n"); + fprintf(output,"Error: SetPrivilege() failed (error: %d) in file %s, line %d.\n",GetLastError(),__FILE__,__LINE__); + fflush(output); + CloseHandle(hToken); + return TRUE; + } + CloseHandle(hToken); + fprintf(output,"success!\n"); + fflush(output); + } + else if (reason == DLL_PROCESS_ATTACH) { + //Close log + fclose(output); + } + return TRUE; } diff --git a/resources.rc b/resources.rc index 635b217..4c99425 100644 --- a/resources.rc +++ b/resources.rc @@ -8,8 +8,8 @@ CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "SuperF4.exe.manifest" #define VS_VERSION_INFO 1 VS_VERSION_INFO VERSIONINFO - FILEVERSION 0,7,0,0 - PRODUCTVERSION 0,7,0,0 + FILEVERSION 0,8,0,0 + PRODUCTVERSION 0,8,0,0 FILEFLAGSMASK 0x3fL FILEFLAGS 0x0L FILEOS 0x40004L @@ -21,7 +21,7 @@ BEGIN BLOCK "040904b0" BEGIN VALUE "FileDescription", "SuperF4" - VALUE "FileVersion", "0.7" + VALUE "FileVersion", "0.8" VALUE "InternalName", "superf4" VALUE "LegalCopyright", "© Stefan Sundin 2008" VALUE "OriginalFilename", "SuperF4.exe" diff --git a/superf4.c b/superf4.c index c2bf0e8..720a1b5 100644 --- a/superf4.c +++ b/superf4.c @@ -21,8 +21,9 @@ #include #include -//Tray messages +//Messages #define WM_ICONTRAY WM_USER+1 +#define WM_ADDTRAY WM_USER+2 #define SWM_TOGGLE WM_APP+1 #define SWM_HIDE WM_APP+2 #define SWM_AUTOSTART_ON WM_APP+3 @@ -33,26 +34,29 @@ #define SWM_EXIT WM_APP+8 //Stuff -LPSTR szClassName="SuperF4"; LRESULT CALLBACK MyWndProc(HWND, UINT, WPARAM, LPARAM); -//Hook data -static HINSTANCE hinstDLL; -static HOOKPROC hkprcSysMsg; -static HHOOK hhookSysMsg; - -//Global info static HICON icon[2]; static NOTIFYICONDATA traydata; static UINT WM_TASKBARCREATED; static int tray_added=0; -static int hook_installed=0; static int hide=0; +static HINSTANCE hinstDLL; +static HHOOK keyhook; +static int hook_installed=0; + static char msg[100]; int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR szCmdLine, int iCmdShow) { - //Change current directory + //Look for previous instance + HWND previnst; + if ((previnst=FindWindow("SuperF4",NULL)) != NULL) { + SendMessage(previnst,WM_ADDTRAY,0,0); + return 0; + } + + //Change working directory char path[MAX_PATH]; if (GetModuleFileName(NULL, path, sizeof(path)) == 0) { sprintf(msg,"GetModuleFileName() failed (error code: %d) in file %s, line %d.",GetLastError(),__FILE__,__LINE__); @@ -80,7 +84,7 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR szCmdLine, in wnd.hCursor=LoadImage(NULL, IDC_ARROW, IMAGE_CURSOR, 0, 0, LR_DEFAULTCOLOR); wnd.hbrBackground=(HBRUSH)(COLOR_BACKGROUND+1); wnd.lpszMenuName=NULL; - wnd.lpszClassName=szClassName; + wnd.lpszClassName="SuperF4"; //Register class if (RegisterClass(&wnd) == 0) { @@ -90,41 +94,36 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR szCmdLine, in } //Create window - HWND hWnd; - hWnd=CreateWindow(szClassName, "SuperF4", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInst, NULL); - //ShowWindow(hWnd, iCmdShow); //Show - //UpdateWindow(hWnd); //Update + HWND hwnd=CreateWindow(wnd.lpszClassName, wnd.lpszClassName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInst, NULL); + + //Register TaskbarCreated so we can readd the tray icon if explorer.exe crashes + if ((WM_TASKBARCREATED=RegisterWindowMessage("TaskbarCreated")) == 0) { + sprintf(msg,"RegisterWindowMessage() failed (error code: %d) in file %s, line %d.",GetLastError(),__FILE__,__LINE__); + MessageBox(NULL, msg, "SuperF4 Warning", MB_ICONWARNING|MB_OK); + } + + //Load tray icons + if ((icon[0] = LoadImage(hInst, "tray-disabled", IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR)) == NULL) { + sprintf(msg,"LoadImage() failed (error code: %d) in file %s, line %d.",GetLastError(),__FILE__,__LINE__); + MessageBox(NULL, msg, "SuperF4 Error", MB_ICONERROR|MB_OK); + PostQuitMessage(1); + } + if ((icon[1] = LoadImage(hInst, "tray-enabled", IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR)) == NULL) { + sprintf(msg,"LoadImage() failed (error code: %d) in file %s, line %d.",GetLastError(),__FILE__,__LINE__); + MessageBox(NULL, msg, "SuperF4 Error", MB_ICONERROR|MB_OK); + PostQuitMessage(1); + } + + //Create icondata + traydata.cbSize=sizeof(NOTIFYICONDATA); + traydata.uID=0; + traydata.uFlags=NIF_MESSAGE|NIF_ICON|NIF_TIP; + traydata.hWnd=hwnd; + traydata.uCallbackMessage=WM_ICONTRAY; + //Add tray icon if (!hide) { - //Register TaskbarCreated so we can readd the tray icon if explorer.exe crashes - if ((WM_TASKBARCREATED=RegisterWindowMessage("TaskbarCreated")) == 0) { - sprintf(msg,"RegisterWindowMessage() failed (error code: %d) in file %s, line %d.",GetLastError(),__FILE__,__LINE__); - MessageBox(NULL, msg, "SuperF4 Warning", MB_ICONWARNING|MB_OK); - } - - //Load tray icons - if ((icon[0] = LoadImage(hInst, "tray-disabled", IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR)) == NULL) { - sprintf(msg,"LoadImage() failed (error code: %d) in file %s, line %d.",GetLastError(),__FILE__,__LINE__); - MessageBox(NULL, msg, "SuperF4 Error", MB_ICONERROR|MB_OK); - PostQuitMessage(1); - } - if ((icon[1] = LoadImage(hInst, "tray-enabled", IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR)) == NULL) { - sprintf(msg,"LoadImage() failed (error code: %d) in file %s, line %d.",GetLastError(),__FILE__,__LINE__); - MessageBox(NULL, msg, "SuperF4 Error", MB_ICONERROR|MB_OK); - PostQuitMessage(1); - } - - //Create icondata - traydata.cbSize=sizeof(NOTIFYICONDATA); - traydata.uID=0; - traydata.uFlags=NIF_MESSAGE|NIF_ICON|NIF_TIP; - traydata.hWnd=hWnd; - traydata.uCallbackMessage=WM_ICONTRAY; - strncpy(traydata.szTip,"SuperF4 (disabled)",sizeof(traydata.szTip)); - traydata.hIcon=icon[0]; - - //Add tray icon - AddTray(); + UpdateTray(); } //Install hook @@ -221,13 +220,11 @@ void ShowContextMenu(HWND hWnd) { DestroyMenu(hMenu); } -int AddTray() { - if (tray_added) { - //Tray already added - return 1; - } +int UpdateTray() { + strncpy(traydata.szTip,(hook_installed?"AltDrag (enabled)":"AltDrag (disabled)"),sizeof(traydata.szTip)); + traydata.hIcon=icon[hook_installed]; - if (Shell_NotifyIcon(NIM_ADD,&traydata) == FALSE) { + if (Shell_NotifyIcon((tray_added?NIM_MODIFY:NIM_ADD),&traydata) == FALSE) { sprintf(msg,"Shell_NotifyIcon() failed (error code: %d) in file %s, line %d.",GetLastError(),__FILE__,__LINE__); MessageBox(NULL, msg, "SuperF4 Warning", MB_ICONWARNING|MB_OK); return 1; @@ -267,14 +264,15 @@ int InstallHook() { } //Get address to keyboard hook (beware name mangling) - if ((hkprcSysMsg=(HOOKPROC)GetProcAddress(hinstDLL,"KeyboardProc@12")) == NULL) { + HOOKPROC procaddr; + if ((procaddr=(HOOKPROC)GetProcAddress(hinstDLL,"KeyboardProc@12")) == NULL) { sprintf(msg,"GetProcAddress() failed (error code: %d) in file %s, line %d.",GetLastError(),__FILE__,__LINE__); MessageBox(NULL, msg, "SuperF4 Warning", MB_ICONWARNING|MB_OK); return 1; } //Set up the hook - if ((hhookSysMsg=SetWindowsHookEx(WH_KEYBOARD_LL,hkprcSysMsg,hinstDLL,0)) == NULL) { + if ((keyhook=SetWindowsHookEx(WH_KEYBOARD_LL,procaddr,hinstDLL,0)) == NULL) { sprintf(msg,"SetWindowsHookEx() failed (error code: %d) in file %s, line %d.",GetLastError(),__FILE__,__LINE__); MessageBox(NULL, msg, "SuperF4 Warning", MB_ICONWARNING|MB_OK); return 1; @@ -282,15 +280,7 @@ int InstallHook() { //Success hook_installed=1; - traydata.hIcon=icon[1]; - strncpy(traydata.szTip,"SuperF4 (enabled)",sizeof(traydata.szTip)); - if (tray_added) { - if (Shell_NotifyIcon(NIM_MODIFY,&traydata) == FALSE) { - sprintf(msg,"Shell_NotifyIcon() failed (error code: %d) in file %s, line %d.",GetLastError(),__FILE__,__LINE__); - MessageBox(NULL, msg, "SuperF4 Warning", MB_ICONWARNING|MB_OK); - return 1; - } - } + UpdateTray(); return 0; } @@ -301,7 +291,7 @@ int RemoveHook() { } //Remove hook - if (UnhookWindowsHookEx(hhookSysMsg) == 0) { + if (UnhookWindowsHookEx(keyhook) == 0) { sprintf(msg,"UnhookWindowsHookEx() failed (error code: %d) in file %s, line %d.",GetLastError(),__FILE__,__LINE__); MessageBox(NULL, msg, "SuperF4 Warning", MB_ICONWARNING|MB_OK); return 1; @@ -316,15 +306,7 @@ int RemoveHook() { //Success hook_installed=0; - traydata.hIcon=icon[0]; - strncpy(traydata.szTip,"SuperF4 (disabled)",sizeof(traydata.szTip)); - if (tray_added) { - if (Shell_NotifyIcon(NIM_MODIFY,&traydata) == FALSE) { - sprintf(msg,"Shell_NotifyIcon() failed (error code: %d) in file %s, line %d.",GetLastError(),__FILE__,__LINE__); - MessageBox(NULL, msg, "SuperF4 Warning", MB_ICONWARNING|MB_OK); - return 1; - } - } + UpdateTray(); return 0; } @@ -355,21 +337,11 @@ void SetAutostart(int on, int hide) { } //Add char value[MAX_PATH+10]; - if (hide) { - sprintf(value,"\"%s\" -hide",path); - if (RegSetValueEx(key,"SuperF4",0,REG_SZ,value,strlen(value)+1) != ERROR_SUCCESS) { - sprintf(msg,"RegSetValueEx() failed (error code: %d) in file %s, line %d.",GetLastError(),__FILE__,__LINE__); - MessageBox(NULL, msg, "SuperF4 Warning", MB_ICONWARNING|MB_OK); - return; - } - } - else { - sprintf(value,"\"%s\"",path); - if (RegSetValueEx(key,"SuperF4",0,REG_SZ,value,strlen(value)+1) != ERROR_SUCCESS) { - sprintf(msg,"RegSetValueEx() failed (error code: %d) in file %s, line %d.",GetLastError(),__FILE__,__LINE__); - MessageBox(NULL, msg, "SuperF4 Warning", MB_ICONWARNING|MB_OK); - return; - } + sprintf(value,(hide?"\"%s\" -hide":"\"%s\""),path); + if (RegSetValueEx(key,"SuperF4",0,REG_SZ,value,strlen(value)+1) != ERROR_SUCCESS) { + sprintf(msg,"RegSetValueEx() failed (error code: %d) in file %s, line %d.",GetLastError(),__FILE__,__LINE__); + MessageBox(NULL, msg, "SuperF4 Warning", MB_ICONWARNING|MB_OK); + return; } } else { @@ -411,7 +383,7 @@ LRESULT CALLBACK MyWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { SetAutostart(1,0); } else if (wmId == SWM_ABOUT) { - MessageBox(NULL, "SuperF4 - 0.7\nhttp://superf4.googlecode.com/\nrecover89@gmail.com\n\nWhen enabled, press Ctrl+Alt+F4 to kill the process of the currently selected window.\nThe effect is the same as when you kill the process from the task manager.\n\nYou can use -hide as a parameter to hide the tray icon.\n\nSend feedback to recover89@gmail.com", "About SuperF4", MB_ICONINFORMATION|MB_OK); + MessageBox(NULL, "SuperF4 - 0.8\nhttp://superf4.googlecode.com/\nrecover89@gmail.com\n\nWhen enabled, press Ctrl+Alt+F4 to kill the process of the currently selected window.\nThe effect is the same as when you kill the process from the task manager.\n\nYou can use -hide as a parameter to hide the tray icon.\n\nSend feedback to recover89@gmail.com", "About SuperF4", MB_ICONINFORMATION|MB_OK); } else if (wmId == SWM_EXIT) { DestroyWindow(hWnd); @@ -428,7 +400,7 @@ LRESULT CALLBACK MyWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { else if (msg == WM_TASKBARCREATED) { tray_added=0; if (!hide) { - AddTray(); + UpdateTray(); } } else if (msg == WM_DESTROY) { @@ -441,5 +413,9 @@ LRESULT CALLBACK MyWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { PostQuitMessage(0); return 0; } + else if (msg == WM_ADDTRAY) { + hide=0; + UpdateTray(); + } return DefWindowProc(hWnd, msg, wParam, lParam); }