BOOL CALLBACK MinimizeToTrayProc(HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam) { static bool bHideIcon=false; static UINT s_uTaskbarRestart; switch(uiMsg) { case WM_CREATE: s_uTaskbarRestart = RegisterWindowMessage(TEXT("TaskbarCreated")); break; case WM_SYSCOMMAND: if(wParam==SC_MINIMIZE) { MinimizeWndToTray(hWnd); ShowNotifyIcon(hWnd, TRUE); // Return TRUE to tell DefDlgProc that we handled the message, and set // DWL_MSGRESULT to 0 to say that we handled WM_SYSCOMMAND SetWindowLong(hWnd,DWL_MSGRESULT,0); return TRUE; } break; case WM_TRAYMESSAGE: switch(lParam) { case WM_LBUTTONDBLCLK: RestoreWndFromTray(hWnd); // If we remove the icon here, the following WM_LBUTTONUP (the user // releasing the mouse button after a double click) can be sent to // the icon that occupies the position we were just using, which can // then activate, when the user doesn't want it to. So, set a flag // so that we remove the icon on the next WM_LBUTTONUP bHideIcon=true; return TRUE; case WM_LBUTTONUP: // The user has previously double-clicked the icon, remove it in // response to this second WM_LBUTTONUP if(bHideIcon) { ShowNotifyIcon(hWnd,FALSE); bHideIcon=false; } return TRUE; } break; case WM_DESTROY: ShowNotifyIcon(hWnd, FALSE); break; default: if(uiMsg == s_uTaskbarRestart) ShowNotifyIcon(hWnd, TRUE); break; } return FALSE; }
BOOL CreateMainWindow(HINSTANCE hInstance, int nCmdShow) { WNDCLASS wc; icon = LoadIcon (hInstance, MAKEINTRESOURCE (IDI_ICON2)); /* Register the frame class */ wc.style = 0; wc.lpfnWndProc = DefDlgProc; wc.cbClsExtra = 0; wc.cbWndExtra = DLGWINDOWEXTRA; wc.hInstance = hInstance; wc.hIcon = icon; wc.hCursor = LoadCursor (NULL,IDC_ARROW); wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wc.lpszMenuName = 0; wc.lpszClassName = SERVER_NAME; if (!RegisterClass (&wc) ) Sys_Error ("Couldn't register window class"); global_hInstance = hInstance; DlgHwnd = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_DIALOG2), NULL, (DLGPROC)DialogFunc); if (!DlgHwnd) { MessageBox(NULL, TEXT("Could not create dialog window"), TEXT("Error"), MB_ICONEXCLAMATION|MB_OK); return 0; } EditBoxBgColor = RGB(0, 64, 64); EditBoxColor = RGB(255, 255, 255); g_hbrBackground = CreateSolidBrush(EditBoxBgColor); // is started with -minimize option, start in tray if (COM_CheckParm("-minimize") || (nCmdShow == SW_SHOWMINNOACTIVE)) { ShowNotifyIcon(); ShowWindow(DlgHwnd,SW_HIDE); UpdateWindow(DlgHwnd); } else { ShowWindow(DlgHwnd,SW_SHOWNORMAL); UpdateWindow(DlgHwnd); } // popup menu of tray icon Menu = CreatePopupMenu(); AppendMenu(Menu, MF_STRING, IDC_RESTORE, "Restore"); //AppendMenu(Menu, MF_STRING, 0, "about"); AppendMenu(Menu, MF_SEPARATOR, 0, NULL); AppendMenu(Menu, MF_STRING, IDC_QUIT, "Quit"); return 1; }
BOOL CALLBACK DialogFunc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_INITDIALOG: HEdit1 = GetDlgItem(hwndDlg, IDC_EDIT1); HEdit2 = GetDlgItem(hwndDlg, IDC_EDIT2); SetFocus(HEdit2); // SendMessage(HEdit1, EM_LIMITTEXT, 1000, 0); HEdit1_size = SendMessage(HEdit1, EM_GETLIMITTEXT, 0, 0) + 1; HEdit1_buf = (char *) Q_malloc (HEdit1_size); //Sys_Printf("%d\n", HEdit1_size); break; case WM_CTLCOLORSTATIC: if ((HWND)lParam != HEdit1) break; SetTextColor((HDC)wParam, EditBoxColor); SetBkColor((HDC)wParam, EditBoxBgColor); return (LONG)g_hbrBackground; case WM_TRAY: switch (lParam) { case 515: ShowWindow(hwndDlg,SW_RESTORE); SetForegroundWindow(hwndDlg); RemoveNotifyIcon(); break; case 516: { static DWORD id; CreateThread(NULL, 0, TrackPopup, NULL, 0, &id); break; } } break; case WM_SIZE: // we don't care until window is fully created if (DlgHwnd == NULL) break; if ((int)wParam == SIZE_MINIMIZED) { ShowWindow(hwndDlg,SW_HIDE); ShowNotifyIcon(); } break; case WM_COMMAND: switch(LOWORD(wParam)) { case IDC_OK: { char str[1024]; SendMessage(HEdit2, WM_GETTEXT, (WPARAM)sizeof(str),(LPARAM)str); if (!str[0]) break; SendMessage(HEdit2, WM_SETTEXT, 0, (LPARAM)0); // normalize text before add to console. ConsoleAddText(Q_normalizetext(va("] %s\n", str))); Cbuf_AddText (str); Cbuf_AddText ("\n"); return TRUE; } case IDC_QUIT: Cbuf_AddText("quit\n"); return TRUE; case IDC_RESTORE: ShowWindow(hwndDlg,SW_RESTORE); RemoveNotifyIcon(); return TRUE; case IDC_CLEAR: SendMessage(HEdit1, WM_SETTEXT, 0, (LPARAM)0); SetFocus(HEdit2); break; } break; case WM_ACTIVATE: break; case WM_CLOSE: SV_Quit_f(); break; } return FALSE; }