From b6fbc56252f016ff23df78df574553c2593d4d38 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 23 Jan 2022 21:35:33 +0300 Subject: =?UTF-8?q?fixes=20#3006=20(Ping:=20=D0=BE=D1=82=D1=80=D0=B8=D1=81?= =?UTF-8?q?=D0=BE=D0=B2=D0=BA=D0=B0=20=D1=84=D1=80=D0=B5=D0=B9=D0=BC=D0=B0?= =?UTF-8?q?=20=D0=B3=D0=BB=D1=8E=D1=87=D0=B8=D1=82)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/Ping/src/pinggraph.cpp | 302 ++++++++++++++++++---------------------- plugins/Ping/src/pinglist.cpp | 15 +- plugins/Ping/src/pingthread.cpp | 81 ++++------- 3 files changed, 173 insertions(+), 225 deletions(-) diff --git a/plugins/Ping/src/pinggraph.cpp b/plugins/Ping/src/pinggraph.cpp index 3a4e509e94..68850b73bd 100644 --- a/plugins/Ping/src/pinggraph.cpp +++ b/plugins/Ping/src/pinggraph.cpp @@ -4,7 +4,8 @@ HistoryMap history_map; #define ID_REPAINT_TIMER 10101 -struct WindowData { +struct WindowData +{ uint32_t item_id; HistoryList list; HWND hwnd_chk_grid; @@ -17,33 +18,33 @@ struct WindowData { LRESULT CALLBACK GraphWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { + RECT r; + WindowData *wd = (WindowData *)GetWindowLongPtr(hwnd, GWLP_USERDATA); + switch (msg) { case WM_REBUILDLIST: - { - WindowData *wd = (WindowData *)GetWindowLongPtr(hwnd, GWLP_USERDATA); - - bool found = false; - mir_cslock lck(data_list_cs); - for (pinglist_it i = data_list.begin(); i != data_list.end(); ++i) { - if (i->item_id == wd->item_id) { - wd->list = history_map[wd->item_id]; - found = true; - break; + { + bool found = false; + mir_cslock lck(data_list_cs); + for (pinglist_it i = data_list.begin(); i != data_list.end(); ++i) { + if (i->item_id == wd->item_id) { + wd->list = history_map[wd->item_id]; + found = true; + break; + } + } + + if (!found) { + PostMessage(hwnd, WM_CLOSE, 0, 0); + return TRUE; } - } - if (!found) { - PostMessage(hwnd, WM_CLOSE, 0, 0); - return TRUE; + InvalidateRect(hwnd, nullptr, FALSE); } + return TRUE; - InvalidateRect(hwnd, nullptr, FALSE); - } - return TRUE; case WM_SHOWWINDOW: if (wParam == TRUE && lParam == 0) { - WindowData *wd = (WindowData *)GetWindowLongPtr(hwnd, GWLP_USERDATA); - if (wd->hwnd_chk_grid == nullptr) { wd->hwnd_chk_grid = CreateWindow(L"BUTTON", TranslateT("Show grid lines"), WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX, 0, 0, 0, 0, hwnd, nullptr, g_plugin.getInst(), nullptr); SendMessage(wd->hwnd_chk_grid, BM_SETCHECK, wd->show_grid ? BST_CHECKED : BST_UNCHECKED, 0); @@ -53,18 +54,14 @@ LRESULT CALLBACK GraphWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPar SendMessage(wd->hwnd_chk_stat, BM_SETCHECK, wd->show_stat ? BST_CHECKED : BST_UNCHECKED, 0); } KillTimer(hwnd, ID_REPAINT_TIMER); -#ifdef min - SetTimer(hwnd, ID_REPAINT_TIMER, min(options.ping_period * 1000, 5000), nullptr); -#else - SetTimer(hwnd, ID_REPAINT_TIMER, std::min(options.ping_period * 1000, 5000), 0); -#endif + SetTimer(hwnd, ID_REPAINT_TIMER, min(options.ping_period * 1000, 5000), nullptr); SendMessage(hwnd, WM_REBUILDLIST, 0, 0); } break; + case WM_COMMAND: if (HIWORD(wParam) == BN_CLICKED) { - WindowData *wd = (WindowData *)GetWindowLongPtr(hwnd, GWLP_USERDATA); if ((HWND)lParam == wd->hwnd_chk_grid) { wd->show_grid = (SendMessage(wd->hwnd_chk_grid, BM_GETCHECK, 0, 0) == BST_CHECKED); } @@ -74,185 +71,162 @@ LRESULT CALLBACK GraphWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPar InvalidateRect(hwnd, nullptr, TRUE); } return TRUE; + case WM_TIMER: - { SendMessage(hwnd, WM_REBUILDLIST, 0, 0); - } - return TRUE; + return TRUE; + case WM_PAINT: - { - PAINTSTRUCT ps; - HDC hdc; - RECT r; - WindowData *wd = (WindowData *)GetWindowLongPtr(hwnd, GWLP_USERDATA); - if (wd && (hdc = BeginPaint(hwnd, &ps)) != nullptr) { - GetClientRect(hwnd, &r); - FillRect(hdc, &r, GetSysColorBrush(COLOR_WINDOW)); - - short max_value = -1, min_value = (short)0x7FFF, - graph_height = 0; // this is minimum graph height, in ms - - double avg = 0; - for (HistoryList::Iterator hli = wd->list.begin(); hli.has_val(); hli.next()) - { - if (hli.val().first > max_value) - max_value = hli.val().first; - if (hli.val().first >= 0 && hli.val().first < min_value) - min_value = hli.val().first; - avg += hli.val().first; - } - - if (wd->list.size()) - avg /= wd->list.size(); - - graph_height = (int)(max_value * 1.2f); - - if (graph_height < MIN_GRAPH_HEIGHT) - graph_height = MIN_GRAPH_HEIGHT; - -#ifdef max - float unit_width = (r.right - r.left) / (float)max((int)wd->list.size(), MIN_BARS), // space for at least MIN_BARS bars -#else - float unit_width = (r.right - r.left) / (float)std::max((int)wd->list.size(), MIN_BARS), // space for at least MIN_BARS bars -#endif - unit_height = (r.bottom - r.top) / (float)graph_height; - - time_t last_time = 0, time, start_time = 0; - if (wd->list.size()) - start_time = wd->list.begin().val().second; - - RECT bar; - bar.bottom = r.bottom; - float x = r.right - (unit_width * wd->list.size() + 0.5f); - bar.left = (int)(x + 0.5f); - bar.right = (int)(x + unit_width + 0.5f); - - // set up pen for horiz (ping time) and vert (time covered by graph) lines - HPEN hPenOld, hPen = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_3DDKSHADOW)); - hPenOld = (HPEN)SelectObject(hdc, hPen); - - for (HistoryList::Iterator hi = wd->list.begin(); hi.has_val(); hi.next()) - { - if (hi.val().first != -1) - { - bar.top = bar.bottom - (int)(hi.val().first * unit_height + 0.5f); - FillRect(hdc, &bar, GetSysColorBrush(COLOR_HOTLIGHT)); + PAINTSTRUCT ps; + HDC hdc; + if (wd && (hdc = BeginPaint(hwnd, &ps)) != nullptr) { + GetClientRect(hwnd, &r); + FillRect(hdc, &r, GetSysColorBrush(COLOR_WINDOW)); + + short max_value = -1, min_value = (short)0x7FFF, + graph_height = 0; // this is minimum graph height, in ms + + double avg = 0; + for (HistoryList::Iterator hli = wd->list.begin(); hli.has_val(); hli.next()) { + if (hli.val().first > max_value) + max_value = hli.val().first; + if (hli.val().first >= 0 && hli.val().first < min_value) + min_value = hli.val().first; + avg += hli.val().first; } - time = hi.val().second - start_time; + if (wd->list.size()) + avg /= wd->list.size(); - if (time / MARK_PERIOD != last_time / MARK_PERIOD) - { // new minute - MoveToEx(hdc, bar.left, r.bottom, nullptr); - LineTo(hdc, bar.left, r.top); - } + graph_height = (int)(max_value * 1.2f); + + if (graph_height < MIN_GRAPH_HEIGHT) + graph_height = MIN_GRAPH_HEIGHT; - last_time = time; + float unit_width = (r.right - r.left) / (float)max((int)wd->list.size(), MIN_BARS), // space for at least MIN_BARS bars + unit_height = (r.bottom - r.top) / (float)graph_height; - x += unit_width; - bar.left = bar.right; + time_t last_time = 0, time, start_time = 0; + if (wd->list.size()) + start_time = wd->list.begin().val().second; + + RECT bar; + bar.bottom = r.bottom; + float x = r.right - (unit_width * wd->list.size() + 0.5f); + bar.left = (int)(x + 0.5f); bar.right = (int)(x + unit_width + 0.5f); - } - if (wd->show_grid) - { - // draw horizontal lines to mark every 100ms - for (int li = 0; li < graph_height; li += MARK_TIME) - { - MoveToEx(hdc, r.left, r.bottom - (int)(li * unit_height + 0.5f), nullptr); - LineTo(hdc, r.right, r.bottom - (int)(li * unit_height + 0.5f)); + // set up pen for horiz (ping time) and vert (time covered by graph) lines + HPEN hPenOld, hPen = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_3DDKSHADOW)); + hPenOld = (HPEN)SelectObject(hdc, hPen); + + for (HistoryList::Iterator hi = wd->list.begin(); hi.has_val(); hi.next()) { + if (hi.val().first != -1) { + bar.top = bar.bottom - (int)(hi.val().first * unit_height + 0.5f); + FillRect(hdc, &bar, GetSysColorBrush(COLOR_HOTLIGHT)); + } + + time = hi.val().second - start_time; + + if (time / MARK_PERIOD != last_time / MARK_PERIOD) { // new minute + MoveToEx(hdc, bar.left, r.bottom, nullptr); + LineTo(hdc, bar.left, r.top); + } + + last_time = time; + + x += unit_width; + bar.left = bar.right; + bar.right = (int)(x + unit_width + 0.5f); } - } - HPEN hPen2 = CreatePen(PS_SOLID, 1, RGB(255, 0, 0)); - if (wd->show_stat) - { - SelectObject(hdc, hPen2); - MoveToEx(hdc, r.left, r.bottom - (int)(avg * unit_height + 0.5f), nullptr); - LineTo(hdc, r.right, r.bottom - (int)(avg * unit_height + 0.5f)); - if (max_value != avg) - { - MoveToEx(hdc, r.left, r.bottom - (int)(max_value * unit_height + 0.5f), nullptr); - LineTo(hdc, r.right, r.bottom - (int)(max_value * unit_height + 0.5f)); - MoveToEx(hdc, r.left, r.bottom - (int)(min_value * unit_height + 0.5f), nullptr); - LineTo(hdc, r.right, r.bottom - (int)(min_value * unit_height + 0.5f)); + if (wd->show_grid) { + // draw horizontal lines to mark every 100ms + for (int li = 0; li < graph_height; li += MARK_TIME) { + MoveToEx(hdc, r.left, r.bottom - (int)(li * unit_height + 0.5f), nullptr); + LineTo(hdc, r.right, r.bottom - (int)(li * unit_height + 0.5f)); + } } - } - // restore pen - SelectObject(hdc, hPenOld); - DeleteObject(hPen); - DeleteObject(hPen2); - - SetBkMode(hdc, TRANSPARENT); - SetTextColor(hdc, GetSysColor(COLOR_3DDKSHADOW)); - wchar_t buff[64]; - if (wd->show_grid) - { - mir_snwprintf(buff, TranslateT("%d ms"), MARK_TIME); - TextOut(hdc, r.right - 100, r.bottom - (int)(unit_height * MARK_TIME + 0.5f), buff, (int)mir_wstrlen(buff)); - } + HPEN hPen2 = CreatePen(PS_SOLID, 1, RGB(255, 0, 0)); + if (wd->show_stat) { + SelectObject(hdc, hPen2); + MoveToEx(hdc, r.left, r.bottom - (int)(avg * unit_height + 0.5f), nullptr); + LineTo(hdc, r.right, r.bottom - (int)(avg * unit_height + 0.5f)); + if (max_value != avg) { + MoveToEx(hdc, r.left, r.bottom - (int)(max_value * unit_height + 0.5f), nullptr); + LineTo(hdc, r.right, r.bottom - (int)(max_value * unit_height + 0.5f)); + MoveToEx(hdc, r.left, r.bottom - (int)(min_value * unit_height + 0.5f), nullptr); + LineTo(hdc, r.right, r.bottom - (int)(min_value * unit_height + 0.5f)); + } + } - if (wd->show_stat) - { - SetTextColor(hdc, RGB(255, 0, 0)); - mir_snwprintf(buff, TranslateT("AVG %.1lf ms"), avg); - TextOut(hdc, r.left + 10, r.bottom - (int)(avg * unit_height + 0.5f), buff, (int)mir_wstrlen(buff)); - if (max_value != avg) { - mir_snwprintf(buff, TranslateT("MAX %hd ms"), max_value); - TextOut(hdc, r.left + 10, r.bottom - (int)(max_value * unit_height + 0.5f), buff, (int)mir_wstrlen(buff)); - mir_snwprintf(buff, TranslateT("MIN %hd ms"), min_value); - TextOut(hdc, r.left + 10, r.bottom - (int)(min_value * unit_height + 0.5f), buff, (int)mir_wstrlen(buff)); + // restore pen + SelectObject(hdc, hPenOld); + DeleteObject(hPen); + DeleteObject(hPen2); + + SetBkMode(hdc, TRANSPARENT); + SetTextColor(hdc, GetSysColor(COLOR_3DDKSHADOW)); + wchar_t buff[64]; + if (wd->show_grid) { + mir_snwprintf(buff, TranslateT("%d ms"), MARK_TIME); + TextOut(hdc, r.right - 100, r.bottom - (int)(unit_height * MARK_TIME + 0.5f), buff, (int)mir_wstrlen(buff)); } - } - EndPaint(hwnd, &ps); + if (wd->show_stat) { + SetTextColor(hdc, RGB(255, 0, 0)); + mir_snwprintf(buff, TranslateT("AVG %.1lf ms"), avg); + TextOut(hdc, r.left + 10, r.bottom - (int)(avg * unit_height + 0.5f), buff, (int)mir_wstrlen(buff)); + if (max_value != avg) { + mir_snwprintf(buff, TranslateT("MAX %hd ms"), max_value); + TextOut(hdc, r.left + 10, r.bottom - (int)(max_value * unit_height + 0.5f), buff, (int)mir_wstrlen(buff)); + mir_snwprintf(buff, TranslateT("MIN %hd ms"), min_value); + TextOut(hdc, r.left + 10, r.bottom - (int)(min_value * unit_height + 0.5f), buff, (int)mir_wstrlen(buff)); + } + } + + EndPaint(hwnd, &ps); + } } - } - return TRUE; + return TRUE; case WM_ERASEBKGND: return TRUE; case WM_SIZE: - { - WindowData *wd = (WindowData *)GetWindowLongPtr(hwnd, GWLP_USERDATA); - RECT r; GetClientRect(hwnd, &r); - if (wd->hwnd_chk_grid != nullptr) SetWindowPos(wd->hwnd_chk_grid, nullptr, r.right - 150, r.top + 10, 120, 20, SWP_NOZORDER | SWP_NOACTIVATE); - if (wd->hwnd_chk_stat != nullptr) SetWindowPos(wd->hwnd_chk_stat, nullptr, r.right - 150, r.top + 30, 120, 20, SWP_NOZORDER | SWP_NOACTIVATE); - } - InvalidateRect(hwnd, nullptr, FALSE); - break; + if (wd->hwnd_chk_grid != nullptr) + SetWindowPos(wd->hwnd_chk_grid, nullptr, r.right - 150, r.top + 10, 120, 20, SWP_NOZORDER | SWP_NOACTIVATE); + if (wd->hwnd_chk_stat != nullptr) + SetWindowPos(wd->hwnd_chk_stat, nullptr, r.right - 150, r.top + 30, 120, 20, SWP_NOZORDER | SWP_NOACTIVATE); + InvalidateRect(hwnd, nullptr, FALSE); + break; + case WM_CLOSE: - { KillTimer(hwnd, ID_REPAINT_TIMER); - WindowData *wd = (WindowData *)GetWindowLongPtr(hwnd, GWLP_USERDATA); { char buff[30]; mir_snprintf(buff, "pinggraphwnd%d", wd->item_id); Utils_SaveWindowPosition(hwnd, 0, MODULENAME, buff); } - } - break; + break; + case WM_DESTROY: - { - WindowData *wd = (WindowData *)GetWindowLongPtr(hwnd, GWLP_USERDATA); { char buff[30]; mir_snprintf(buff, "WindowHandle%d", wd->item_id); g_plugin.setDword(buff, 0); } delete wd; - } - // drop through }; return DefWindowProc(hwnd, msg, wParam, lParam); } -INT_PTR ShowGraph(WPARAM wParam, LPARAM lParam) { +INT_PTR ShowGraph(WPARAM wParam, LPARAM lParam) +{ char buff[30]; mir_snprintf(buff, "WindowHandle%d", (uint32_t)wParam); HWND hGraphWnd = (HWND)g_plugin.getDword(buff, 0); @@ -308,7 +282,8 @@ INT_PTR ShowGraph(WPARAM wParam, LPARAM lParam) { } // save window positions, close windows -void graphs_cleanup() { +void graphs_cleanup() +{ int list_size = GetListSize(0, 0); char buff[64]; HWND hwnd; @@ -325,7 +300,8 @@ void graphs_cleanup() { } // remove old data, possibly left from a crash -void graphs_init() { +void graphs_init() +{ PINGLIST pl; char buff[64]; CallService(MODULENAME "/GetPingList", 0, (LPARAM)&pl); diff --git a/plugins/Ping/src/pinglist.cpp b/plugins/Ping/src/pinglist.cpp index bf6c9c59df..d10a51174a 100644 --- a/plugins/Ping/src/pinglist.cpp +++ b/plugins/Ping/src/pinglist.cpp @@ -13,19 +13,16 @@ BOOL changing_clist_handle() return clist_handle_changing; } - void set_changing_clist_handle(BOOL flag) { clist_handle_changing = flag; } - const bool PINGADDRESS::operator==(const PINGADDRESS &b) const { return index == b.index; } - const bool PINGADDRESS::operator<(const PINGADDRESS &b) const { return index < b.index; @@ -51,7 +48,6 @@ INT_PTR GetListSize(WPARAM, LPARAM) return ret; } - void write_ping_address(PINGADDRESS &i) { char buff[16]; @@ -85,8 +81,7 @@ void write_ping_address(PINGADDRESS &i) void write_ping_addresses() { int index = 0; - for (pinglist_it i = list_items.begin(); i != list_items.end(); ++i, index++) - { + for (pinglist_it i = list_items.begin(); i != list_items.end(); ++i, index++) { i->index = index; write_ping_address(*i); } @@ -105,7 +100,8 @@ void write_ping_addresses() } while (found); } -bool read_ping_address(PINGADDRESS &pa) { +bool read_ping_address(PINGADDRESS &pa) +{ int index = pa.index; char buff[16]; @@ -175,14 +171,12 @@ void read_ping_addresses() pa.index = 0; list_items.clear(); - while (read_ping_address(pa)) - { + while (read_ping_address(pa)) { list_items.push_back(pa); ++pa.index; } } - INT_PTR LoadPingList(WPARAM, LPARAM) { mir_cslock lck(list_cs); @@ -239,4 +233,3 @@ INT_PTR ClearPingList(WPARAM, LPARAM) NotifyEventHooks(reload_event_handle, 0, 0); return 0; } - diff --git a/plugins/Ping/src/pingthread.cpp b/plugins/Ping/src/pingthread.cpp index e4957fff04..c4f8ebb6e4 100644 --- a/plugins/Ping/src/pingthread.cpp +++ b/plugins/Ping/src/pingthread.cpp @@ -71,7 +71,7 @@ void SetProtoStatus(wchar_t *pszLabel, char *pszProto, int if_status, int new_st } } -void __cdecl sttCheckStatusThreadProc(void*) +void __cdecl sttCheckStatusThreadProc(void *) { MThreadLock threadLock(status_update_thread); @@ -140,8 +140,9 @@ void __cdecl sttCheckStatusThreadProc(void*) if (get_thread_finished()) break; if (get_list_changed()) break; - { mir_cslock lck(data_list_cs); - + { + mir_cslock lck(data_list_cs); + for (pinglist_it i = data_list.begin(); i != data_list.end(); ++i) { if (i->item_id == pa.item_id) { i->responding = pa.responding; @@ -246,7 +247,7 @@ int FillList(WPARAM, LPARAM) int index = 0; for (pinglist_it j = data_list.begin(); j != data_list.end(); ++j, index++) { - SendMessage(list_hwnd, LB_INSERTSTRING, (WPARAM)-1, (LPARAM)&(*j)); + SendMessage(list_hwnd, LB_INSERTSTRING, (WPARAM)-1, (LPARAM) & (*j)); } set_list_changed(true); @@ -341,16 +342,14 @@ LRESULT CALLBACK FrameWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPar SetBkColor(dis->hDC, tcol); FillRect(dis->hDC, &dis->rcItem, (ttbrush = CreateSolidBrush(tcol))); - tcol = db_get_dw(0, "CLC", "SelTextColour", GetSysColor(COLOR_HIGHLIGHTTEXT)); - SetTextColor(dis->hDC, tcol); + SetTextColor(dis->hDC, db_get_dw(0, "CLC", "SelTextColour", GetSysColor(COLOR_HIGHLIGHTTEXT))); } else { tcol = bk_col; SetBkColor(dis->hDC, tcol); FillRect(dis->hDC, &dis->rcItem, (ttbrush = CreateSolidBrush(tcol))); - tcol = g_plugin.getDword("FontCol", GetSysColor(COLOR_WINDOWTEXT)); - SetTextColor(dis->hDC, tcol); + SetTextColor(dis->hDC, font_id.deffontsettings.colour); } SetBkMode(dis->hDC, TRANSPARENT); @@ -461,12 +460,8 @@ LRESULT CALLBACK FrameWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPar } else { - #ifdef WS_EX_LAYERED SetWindowLongPtr(hwnd, GWL_EXSTYLE, GetWindowLongPtr(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED); - #endif - #ifdef LWA_ALPHA SetLayeredWindowAttributes(hwnd, RGB(0, 0, 0), (uint8_t)db_get_b(0, "CList", "Alpha", SETTING_ALPHA_DEFAULT), LWA_ALPHA); - #endif } } @@ -487,9 +482,7 @@ LRESULT CALLBACK FrameWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPar else { if (db_get_b(0, "CList", "Transparent", SETTING_TRANSPARENT_DEFAULT)) { KillTimer(hwnd, TM_AUTOALPHA); - #ifdef LWA_ALPHA SetLayeredWindowAttributes(hwnd, RGB(0, 0, 0), (uint8_t)db_get_b(0, "CList", "Alpha", SETTING_ALPHA_DEFAULT), LWA_ALPHA); - #endif transparentFocus = 1; } } @@ -498,9 +491,7 @@ LRESULT CALLBACK FrameWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPar case WM_SETCURSOR: if (db_get_b(0, "CList", "Transparent", SETTING_TRANSPARENT_DEFAULT)) { if (!transparentFocus && GetForegroundWindow() != hwnd) { - #ifdef LWA_ALPHA SetLayeredWindowAttributes(hwnd, RGB(0, 0, 0), (uint8_t)db_get_b(0, "CList", "Alpha", SETTING_ALPHA_DEFAULT), LWA_ALPHA); - #endif transparentFocus = 1; SetTimer(hwnd, TM_AUTOALPHA, 250, nullptr); } @@ -525,10 +516,10 @@ LRESULT CALLBACK FrameWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPar } if (inwnd != transparentFocus) { //change transparentFocus = inwnd; - #ifdef LWA_ALPHA - if (transparentFocus) SetLayeredWindowAttributes(hwnd, RGB(0, 0, 0), (uint8_t)db_get_b(0, "CList", "Alpha", SETTING_ALPHA_DEFAULT), LWA_ALPHA); - else SetLayeredWindowAttributes(hwnd, RGB(0, 0, 0), (uint8_t)db_get_b(0, "CList", "AutoAlpha", SETTING_AUTOALPHA_DEFAULT), LWA_ALPHA); - #endif + if (transparentFocus) + SetLayeredWindowAttributes(hwnd, RGB(0, 0, 0), (uint8_t)db_get_b(0, "CList", "Alpha", SETTING_ALPHA_DEFAULT), LWA_ALPHA); + else + SetLayeredWindowAttributes(hwnd, RGB(0, 0, 0), (uint8_t)db_get_b(0, "CList", "AutoAlpha", SETTING_AUTOALPHA_DEFAULT), LWA_ALPHA); } if (!transparentFocus) KillTimer(hwnd, TM_AUTOALPHA); return TRUE; @@ -542,16 +533,14 @@ LRESULT CALLBACK FrameWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPar if (noRecurse) break; if (!db_get_b(0, "CLUI", "FadeInOut", 0)) break; - #ifdef WS_EX_LAYERED - if (GetWindowLongPtr(hwnd, GWL_EXSTYLE)&WS_EX_LAYERED) { + + if (GetWindowLongPtr(hwnd, GWL_EXSTYLE) & WS_EX_LAYERED) { uint32_t thisTick, startTick; int sourceAlpha, destAlpha; if (wParam) { sourceAlpha = 0; destAlpha = (uint8_t)db_get_b(0, "CList", "Alpha", SETTING_AUTOALPHA_DEFAULT); - #ifdef LWA_ALPHA SetLayeredWindowAttributes(hwnd, RGB(0, 0, 0), 0, LWA_ALPHA); - #endif noRecurse = 1; ShowWindow(hwnd, SW_SHOW); noRecurse = 0; @@ -562,17 +551,14 @@ LRESULT CALLBACK FrameWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPar } for (startTick = GetTickCount();;) { thisTick = GetTickCount(); - if (thisTick >= startTick + 200) break; - #ifdef LWA_ALPHA - SetLayeredWindowAttributes(hwnd, RGB(0, 0, 0), (uint8_t)(sourceAlpha + (destAlpha - sourceAlpha)*(int)(thisTick - startTick) / 200), LWA_ALPHA); - #endif + if (thisTick >= startTick + 200) + break; + + SetLayeredWindowAttributes(hwnd, RGB(0, 0, 0), (uint8_t)(sourceAlpha + (destAlpha - sourceAlpha) * (int)(thisTick - startTick) / 200), LWA_ALPHA); } - #ifdef LWA_ALPHA SetLayeredWindowAttributes(hwnd, RGB(0, 0, 0), (uint8_t)destAlpha, LWA_ALPHA); - #endif } else AnimateWindow(hwnd, 200, AW_BLEND | (wParam ? 0 : AW_HIDE)); - #endif } return DefWindowProc(hwnd, msg, wParam, lParam); @@ -694,14 +680,11 @@ LRESULT CALLBACK FrameWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPar case WM_SIZE: GetClientRect(hwnd, &rect); { - int winheight = rect.bottom - rect.top, - itemheight = SendMessage(list_hwnd, LB_GETITEMHEIGHT, 0, 0), - count = SendMessage(list_hwnd, LB_GETCOUNT, 0, 0), - #ifdef min - height = min(winheight - winheight % itemheight, itemheight * count); - #else - height = std::min(winheight - winheight % itemheight, itemheight * count); - #endif + int winheight = rect.bottom - rect.top; + int itemheight = SendMessage(list_hwnd, LB_GETITEMHEIGHT, 0, 0); + int count = SendMessage(list_hwnd, LB_GETCOUNT, 0, 0); + int height = min(winheight - winheight % itemheight, itemheight * count); + SetWindowPos(list_hwnd, nullptr, rect.left, rect.top, rect.right - rect.left, height, SWP_NOZORDER); InvalidateRect(list_hwnd, nullptr, FALSE); } @@ -738,7 +721,8 @@ LRESULT CALLBACK FrameWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPar int ReloadFont(WPARAM, LPARAM) { - if (hFont) DeleteObject(hFont); + if (hFont) + DeleteObject(hFont); LOGFONT log_font; Font_GetW(font_id, &log_font); @@ -747,7 +731,6 @@ int ReloadFont(WPARAM, LPARAM) bk_col = Colour_GetW(bk_col_id); RefreshWindow(0, 0); - return 0; } @@ -824,24 +807,19 @@ void InitList() { hwnd_clist = g_clistApi.hwndContactList; - WNDCLASS wndclass; - - wndclass.style = 0; + WNDCLASS wndclass = {}; wndclass.lpfnWndProc = FrameWindowProc; - wndclass.cbClsExtra = 0; - wndclass.cbWndExtra = 0; wndclass.hInstance = g_plugin.getInst(); wndclass.hIcon = hIconResponding; wndclass.hCursor = LoadCursor(nullptr, IDC_ARROW); wndclass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1); - wndclass.lpszMenuName = nullptr; wndclass.lpszClassName = _A2W(MODULENAME) L"WindowClass"; RegisterClass(&wndclass); if (ServiceExists(MS_CLIST_FRAMES_ADDFRAME)) { hpwnd = CreateWindow(_A2W(MODULENAME) L"WindowClass", L"Ping", (WS_BORDER | WS_CHILD | WS_CLIPCHILDREN), 0, 0, 0, 0, hwnd_clist, nullptr, g_plugin.getInst(), nullptr); - CLISTFrame frame = { 0 }; + CLISTFrame frame = {}; frame.cbSize = sizeof(CLISTFrame); frame.szName.a = MODULENAME; frame.szTBname.a = LPGEN("Ping"); @@ -871,8 +849,10 @@ void InitList() mi.pszService = MODULENAME "/ShowWindow"; Menu_AddMainMenuItem(&mi); - if (options.attach_to_clist) AttachToClist(true); - else ShowWindow(hpwnd, SW_SHOW); + if (options.attach_to_clist) + AttachToClist(true); + else + ShowWindow(hpwnd, SW_SHOW); } mir_wstrncpy(font_id.group, LPGENW("Ping"), _countof(font_id.group)); @@ -888,7 +868,6 @@ void InitList() font_id.deffontsettings.style = 0; font_id.deffontsettings.colour = RGB(255, 255, 255); mir_wstrncpy(font_id.deffontsettings.szFace, L"Tahoma", _countof(font_id.deffontsettings.szFace)); - g_plugin.addFont(&font_id); mir_wstrncpy(bk_col_id.group, L"Ping", _countof(bk_col_id.group)); -- cgit v1.2.3