LRESULT CALLBACK WindowProc(HWND hWnd, UINT msg, WPARAM wparam, LPARAM lparam) { switch(msg) { case WM_CLOSE: { if((g_dwPrefs & (1<<PREF_MIOC)) && (g_bCanQuit == false)) { /*******************************************/ /**** to autoaway or not to autoaway... ***/ /*******************************************/ if(g_dwPrefs & (1<<PREF_AOM)) { hexchat_globally_away(g_szAway); } /**************************************************/ /**** Win32 API call to hide the window and **/ /**** save the fact that its minimized for later **/ /**************************************************/ g_iIsActive = 0; ShowWindow(hWnd, SW_HIDE); return 0; } else { if(g_hPrefDlg != NULL) { DestroyWindow(g_hPrefDlg); } StopBlink(hWnd, 1, g_hIcons[0]); if(sdAlertNum()) { sdCloseAlerts(); HoldClose(); return 0; } } } break; case WM_SIZE: { /******************************************/ /***** User wants to minimize HexChat, ****/ /***** are we allowed to go to tray? ******/ /******************************************/ if((g_dwPrefs & (1<<PREF_TOT)) && (wparam == SIZE_MINIMIZED)) { /*******************************************/ /**** to autoaway or not to autoaway... ***/ /*******************************************/ if(g_dwPrefs & (1<<PREF_AOM)) { hexchat_globally_away(g_szAway); } /**************************************************/ /**** Win32 API call to hide the window and **/ /**** save the fact that its minimized for later **/ /**************************************************/ g_iIsActive = 0; ShowWindow(hWnd, SW_HIDE); } } break; /**********************************/ /*** user clicked the tray icon ***/ /**********************************/ case WM_TRAYMSG: { switch(lparam) { case WM_LBUTTONDOWN: { if(!g_iIsActive) { /*********************************************************/ /*** 0: its hiden, restore it and show it, if autoaway ***/ /*** is on, set us as back ***/ /*********************************************************/ SendMessage(hWnd, WM_SYSCOMMAND, SC_RESTORE, 0); SetForegroundWindow(hWnd); g_iIsActive = 1; if(g_dwPrefs & (1<<PREF_AOM)) { hexchat_globally_back(); } } else { SendMessage(hWnd, WM_SYSCOMMAND, SC_MINIMIZE, 0); } } break; case WM_RBUTTONDOWN: { /******************************************/ /*** user wants to see the menu find out **/ /*** where the mouse is and show it **/ /******************************************/ POINT pt; int iRet; GetCursorPos(&pt); SetForegroundWindow(hWnd); ModifyMenu(g_hTrayMenu, 2, (MF_POPUP | MF_BYPOSITION), (UINT)setServerMenu(), _T("Away")); Sleep(175); iRet = TrackPopupMenuEx(g_hTrayMenu, (TPM_RETURNCMD | TPM_LEFTALIGN), pt.x, pt.y, hWnd, NULL); /***********************************/ /*** nRet is the users selection, **/ /*** process it **/ /***********************************/ sdTrayProc(hWnd, iRet); } break; } } break; default: { /*****************************************************/ /*** the taskbar has been restarted, re-add our icon */ /*****************************************************/ if(msg == RegisterWindowMessage(_T("TaskbarCreated"))) { char szVersion[64]; _snprintf(szVersion, 64, "HexChat [%s]", hexchat_get_info(ph, "version")); AddIcon(g_hXchatWnd, 1, g_hIcons[0], szVersion, (NIF_ICON | NIF_MESSAGE | NIF_TIP), WM_TRAYMSG); } } break; } return CallWindowProc(g_hOldProc, hWnd, msg, wparam, lparam); }
int hexchat_plugin_deinit(hexchat_plugin *plugin_handle) { /******************************************/ /****** Remove the Icon from the tray *****/ /******************************************/ StopBlink(g_hXchatWnd, 1, g_hIcons[0]); RemoveIcon(g_hXchatWnd, 1); /*******************************************/ /*******************************************/ /*******************************************/ if(g_dwPrefs & (1<<PREF_DNSIT)) { DWORD dwStyle; dwStyle = GetWindowLong(g_hXchatWnd, GWL_STYLE); dwStyle &= ~(1<<WS_CHILD); SetWindowLongPtr(g_hXchatWnd, GWL_STYLE, (LONG_PTR)dwStyle); SetWindowLongPtr(g_hXchatWnd, GWL_HWNDPARENT, NULL); } /******************************************/ /****** Unload our resources **************/ /******************************************/ DestroyMenu(g_hTrayMenu); for(int i = 0; i <= 11; i++) { DestroyIcon(g_hIcons[i]); } /******************************************/ /****** Remove our window hook ************/ /******************************************/ SetWindowLongPtr(g_hXchatWnd, GWLP_WNDPROC, (LONG_PTR)g_hOldProc); /******************************************/ /****** Remove our hotkey, and destroy ****/ /****** the window that receives its ****/ /****** messages ****/ /******************************************/ UnregisterHotKey(g_hHotkeyWnd, 1); DestroyWindow(g_hHotkeyWnd); DestroyWindow(g_hPrefDlg); /******************************************/ /************* Clean up Isle 7 ************/ /******************************************/ if(sdAlertNum()) { sdCloseAlerts(); } /******************************************/ /****** remove our hexchat_hook_*s **********/ /******************************************/ while(!g_vHooks.empty()) { if(g_vHooks.back() != NULL) { hexchat_unhook(ph, g_vHooks.back()); } g_vHooks.pop_back(); } return 1; }