diff --git a/src/win/win_stbar.c b/src/win/win_stbar.c index 67add30f1..f29ff2523 100644 --- a/src/win/win_stbar.c +++ b/src/win/win_stbar.c @@ -70,6 +70,8 @@ static uint8_t *sb_part_icons; static int sb_parts = 0; static int sb_ready = 0; static uint8_t sb_map[256]; +static int dpi = 96; +static int icon_width = 24; /* Also used by win_settings.c */ intptr_t @@ -537,7 +539,7 @@ ui_sb_update_panes(void) sb_parts = 0; for (i=0; i= (sb_parts - 1)) return; - pt.x = id * SB_ICON_WIDTH; /* Justify to the left. */ + pt.x = id * icon_width; /* Justify to the left. */ pt.y = 0; /* Justify to the top. */ ClientToScreen(hwnd, (LPPOINT) &pt); @@ -744,6 +745,48 @@ StatusBarPopupMenu(HWND hwnd, POINT pt, int id) pt.x, pt.y, 0, hwndSBAR, NULL); } +/* API: Load status bar icons */ +void +StatusBarLoadIcon(HINSTANCE hInst) { + int i; + int x = win_get_system_metrics(SM_CXSMICON, dpi); + + for (i=0; i<256; i++) { + if (hIcon[i] != 0) + DestroyIcon(hIcon[i]); + } + + for (i = 16; i < 18; i++) + hIcon[i] = LoadImage(hInst, MAKEINTRESOURCE(i), IMAGE_ICON, x, x, LR_DEFAULTCOLOR); + for (i = 24; i < 26; i++) + hIcon[i] = LoadImage(hInst, MAKEINTRESOURCE(i), IMAGE_ICON, x, x, LR_DEFAULTCOLOR); + for (i = 32; i < 34; i++) + hIcon[i] = LoadImage(hInst, MAKEINTRESOURCE(i), IMAGE_ICON, x, x, LR_DEFAULTCOLOR); + for (i = 48; i < 50; i++) + hIcon[i] = LoadImage(hInst, MAKEINTRESOURCE(i), IMAGE_ICON, x, x, LR_DEFAULTCOLOR); + for (i = 56; i < 58; i++) + hIcon[i] = LoadImage(hInst, MAKEINTRESOURCE(i), IMAGE_ICON, x, x, LR_DEFAULTCOLOR); + for (i = 64; i < 66; i++) + hIcon[i] = LoadImage(hInst, MAKEINTRESOURCE(i), IMAGE_ICON, x, x, LR_DEFAULTCOLOR); + for (i = 80; i < 82; i++) + hIcon[i] = LoadImage(hInst, MAKEINTRESOURCE(i), IMAGE_ICON, x, x, LR_DEFAULTCOLOR); + for (i = 96; i < 98; i++) + hIcon[i] = LoadImage(hInst, MAKEINTRESOURCE(i), IMAGE_ICON, x, x, LR_DEFAULTCOLOR); + for (i = 144; i < 146; i++) + hIcon[i] = LoadImage(hInst, MAKEINTRESOURCE(i), IMAGE_ICON, x, x, LR_DEFAULTCOLOR); + for (i = 152; i < 154; i++) + hIcon[i] = LoadImage(hInst, MAKEINTRESOURCE(i), IMAGE_ICON, x, x, LR_DEFAULTCOLOR); + for (i = 160; i < 162; i++) + hIcon[i] = LoadImage(hInst, MAKEINTRESOURCE(i), IMAGE_ICON, x, x, LR_DEFAULTCOLOR); + for (i = 176; i < 178; i++) + hIcon[i] = LoadImage(hInst, MAKEINTRESOURCE(i), IMAGE_ICON, x, x, LR_DEFAULTCOLOR); + for (i = 184; i < 186; i++) + hIcon[i] = LoadImage(hInst, MAKEINTRESOURCE(i), IMAGE_ICON, x, x, LR_DEFAULTCOLOR); + for (i = 192; i < 194; i++) + hIcon[i] = LoadImage(hInst, MAKEINTRESOURCE(i), IMAGE_ICON, x, x, LR_DEFAULTCOLOR); + for (i = 243; i < 244; i++) + hIcon[i] = LoadImage(hInst, MAKEINTRESOURCE(i), IMAGE_ICON, x, x, LR_DEFAULTCOLOR); +} /* Handle messages for the Status Bar window. */ #if defined(__amd64__) || defined(__aarch64__) @@ -756,6 +799,8 @@ StatusBarProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) RECT rc; POINT pt; int item_id = 0; + int i; + HINSTANCE hInst; switch (message) { case WM_COMMAND: @@ -768,20 +813,38 @@ StatusBarProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) pt.x = GET_X_LPARAM(lParam); pt.y = GET_Y_LPARAM(lParam); if (PtInRect((LPRECT) &rc, pt)) - StatusBarPopupMenu(hwnd, pt, (pt.x / SB_ICON_WIDTH)); + StatusBarPopupMenu(hwnd, pt, (pt.x / icon_width)); break; case WM_LBUTTONDBLCLK: GetClientRect(hwnd, (LPRECT)& rc); pt.x = GET_X_LPARAM(lParam); pt.y = GET_Y_LPARAM(lParam); - item_id = (pt.x / SB_ICON_WIDTH); + item_id = (pt.x / icon_width); if (PtInRect((LPRECT) &rc, pt) && (item_id < sb_parts)) { if (sb_part_meanings[item_id] == SB_SOUND) SoundGainDialogCreate(hwndMain); } break; + case WM_DPICHANGED_AFTERPARENT: + /* DPI changed, reload icons */ + hInst = (HINSTANCE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE); + dpi = win_get_dpi(hwnd); + icon_width = MulDiv(SB_ICON_WIDTH, dpi, 96); + StatusBarLoadIcon(hInst); + + for (i=0; i