/* Copyright (C) 2003 Matthew Vilcsak This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #define WIN32_LEAN_AND_MEAN #include #include #include #include #define HOTKEY_ID 40022 #define SHELL_ICON_ID 402442 #define SHELL_CALLBACK WM_USER+14 #include "resource.h" using namespace std; LRESULT CALLBACK winProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp); HMENU hmenu; string check = "SoF2 MP\tEnemy Territory"; int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmdLine, int nCmdShow) { HWND hwnd; WNDCLASSEX wc; wc.cbSize = sizeof(WNDCLASSEX); wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hbrBackground = (HBRUSH)WHITE_BRUSH+1; wc.hCursor = NULL; wc.hIcon = NULL; wc.hIconSm = NULL; wc.hInstance = hInst; wc.lpfnWndProc = winProc; wc.lpszClassName = "gminimizer"; wc.style = CS_DBLCLKS; wc.lpszMenuName = NULL; if (!RegisterClassEx(&wc)) { return -1; } hwnd = CreateWindow("gminimizer", "gminimizer", NULL, 0, 0, 50, 50, NULL, NULL, hInst, NULL); if (!hwnd) { MessageBox(0, "crap", NULL, NULL); return -1; } //register hot key if (!RegisterHotKey(NULL, HOTKEY_ID, MOD_ALT, 'Z')) { MessageBox(0, "crapolio", NULL, NULL); return -1; } // ShowWindow(hwnd, SW_SHOW); //create tray icon NOTIFYICONDATA nid; ZeroMemory(&nid, sizeof(NOTIFYICONDATA)); nid.cbSize = sizeof(NOTIFYICONDATA); nid.hWnd = hwnd; nid.uID = SHELL_ICON_ID; nid.uFlags = NIF_ICON | NIF_TIP | NIF_MESSAGE; nid.uCallbackMessage = SHELL_CALLBACK; nid.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_ICON)); strcpy(nid.szTip, "Enemy Territory Minimizer"); // nid.dwState = NULL; // nid.dwStateMask = NULL; // nid.szInfo = NULL; // nid.uVersion = NULL; // nid.szInfoTitle = NULL; // nid.dwInfoFlags = NULL; Shell_NotifyIcon(NIM_ADD, &nid); //get menu hmenu = GetSubMenu(LoadMenu(hInst, MAKEINTRESOURCE(IDR_MENU1)), 0); //open check.txt FILE *fp = fopen("check.txt", "r"); if (fp) { check = ""; while (!feof(fp)) { char buf[1024*32]; fread(buf, 1, 1024*32-1, fp); buf[1024*32-1] = 0; check += buf; } fclose(fp); } //message loop MSG msg; while (GetMessage(&msg, NULL, NULL, NULL) != 0) { if (msg.message == WM_HOTKEY) msg.hwnd = hwnd; TranslateMessage(&msg); DispatchMessage(&msg); } //cleanup Shell_NotifyIcon(NIM_DELETE, &nid); UnregisterHotKey(NULL, HOTKEY_ID); return 0; } void tryMin() { string::size_type f = 0; string::size_type r = 0; string curWin; HWND hwet; while (f != string::npos) { r = check.find('\t', r+1); if (r == string::npos) { curWin = check.substr(f); f = r; } else { curWin = check.substr(f,r); f=r+1; } hwet = FindWindow(curWin.c_str(), NULL); if (hwet) { WINDOWPLACEMENT wp; GetWindowPlacement(hwet, &wp); if (wp.showCmd == SW_SHOWMINIMIZED) ShowWindow(hwet, SW_RESTORE); else ShowWindow(hwet, SW_MINIMIZE); } } } LRESULT CALLBACK winProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) { switch(msg) { case WM_CREATE: //do stuff break; case WM_HOTKEY: if (wp == HOTKEY_ID) tryMin(); break; case SHELL_CALLBACK: switch(lp) { case WM_RBUTTONDOWN: { if (hmenu != 0) { SetForegroundWindow(hwnd); POINT p; GetCursorPos(&p); TrackPopupMenu(hmenu, 0, p.x, p.y, 0, hwnd, 0); PostMessage(hwnd, WM_NULL, 0,0); } } break; case WM_LBUTTONDBLCLK: tryMin(); break; } return TRUE; break; case WM_COMMAND: switch(LOWORD(wp)) { case ID_SHELL_TOGGLESTATE: tryMin(); break; case ID_SHELL_EXIT: DestroyWindow(hwnd); break; case ID_SHELL_MADEBYGON: MessageBox(0, "To allow this program to support other games, create a file in the same directory called \"check.txt\", and fill it with the window classes of the programs you want to minimize.\nEx. For SoF2 and RTCW: ET (The default supported games, because I play them), put\nSoF2 MP\tEnemy Territory\n(The space between the window class names is a tab, if it is a space, or a new line it will not work.)\nET Minimizer, Copyright (C) 2003 Matthew Vilcsak\nET Minimizer comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions.\nSee http://www.gnu.org/licenses/gpl.txt for details.", "helP", MB_OK); break; } break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hwnd, msg, wp, lp); } return TRUE; }