diff --git a/brightray/browser/win/win32_desktop_notifications/common.h b/brightray/browser/win/win32_desktop_notifications/common.h index 5c7d5ae37640..2785f187fc70 100644 --- a/brightray/browser/win/win32_desktop_notifications/common.h +++ b/brightray/browser/win/win32_desktop_notifications/common.h @@ -31,9 +31,11 @@ struct ScreenMetrics { ScreenMetrics() { typedef HRESULT WINAPI GetDpiForMonitor_t(HMONITOR, int, UINT*, UINT*); - auto GetDpiForMonitor = - (GetDpiForMonitor_t*)GetProcAddress(GetModuleHandle(TEXT("shcore")), - "GetDpiForMonitor"); + + auto GetDpiForMonitor = reinterpret_cast( + GetProcAddress(GetModuleHandle(TEXT("shcore")), + "GetDpiForMonitor")); + if (GetDpiForMonitor) { auto monitor = MonitorFromPoint({}, MONITOR_DEFAULTTOPRIMARY); if (GetDpiForMonitor(monitor, 0, &dpi_x, &dpi_y) == S_OK) diff --git a/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.cc b/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.cc index b371df608a25..f0d65469b9d9 100644 --- a/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.cc +++ b/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.cc @@ -174,7 +174,9 @@ void DesktopNotificationController::AnimateAll() { POINT origin = { workArea.right, workArea.bottom - metrics.Y(toast_margin_) }; - auto hdwp = BeginDeferWindowPos((int)instances_.size()); + auto hdwp = + BeginDeferWindowPos(static_cast(instances_.size())); + for (auto&& inst : instances_) { if (!inst.hwnd) continue; @@ -183,6 +185,7 @@ void DesktopNotificationController::AnimateAll() { if (!hdwp) break; keepAnimating |= notification->IsAnimationActive(); } + if (hdwp) EndDeferWindowPos(hdwp); } } diff --git a/brightray/browser/win/win32_desktop_notifications/toast.cc b/brightray/browser/win/win32_desktop_notifications/toast.cc index 798dd76fba44..2727bc9ed12f 100644 --- a/brightray/browser/win/win32_desktop_notifications/toast.cc +++ b/brightray/browser/win/win32_desktop_notifications/toast.cc @@ -24,7 +24,7 @@ static COLORREF GetAccentColor() { DWORD type, size; if (RegQueryValueEx(hkey, TEXT("AccentColor"), nullptr, &type, - (BYTE*)&color, + reinterpret_cast(&color), &(size = sizeof(color))) == ERROR_SUCCESS && type == REG_DWORD) { // convert from RGBA @@ -36,7 +36,7 @@ static COLORREF GetAccentColor() { else if ( RegQueryValueEx(hkey, TEXT("ColorizationColor"), nullptr, &type, - (BYTE*)&color, + reinterpret_cast(&color), &(size = sizeof(color))) == ERROR_SUCCESS && type == REG_DWORD) { // convert from BGRA @@ -82,26 +82,32 @@ static HBITMAP StretchBitmap(HBITMAP bitmap, unsigned width, unsigned height) { bmi.biCompression = BI_RGB; void* alphaSrcBits; - alphaSrcBitmap = CreateDIBSection(NULL, (BITMAPINFO*)&bmi, + alphaSrcBitmap = CreateDIBSection(NULL, + reinterpret_cast(&bmi), DIB_RGB_COLORS, &alphaSrcBits, NULL, 0); if (alphaSrcBitmap) { if (GetDIBits(hdcScreen, bitmap, 0, 0, 0, - (BITMAPINFO*)&bmi, DIB_RGB_COLORS) && + reinterpret_cast(&bmi), + DIB_RGB_COLORS) && bmi.biSizeImage > 0 && (bmi.biSizeImage % 4) == 0) { - auto buf = (BYTE*)_aligned_malloc(bmi.biSizeImage, - sizeof(DWORD)); + auto buf = reinterpret_cast( + _aligned_malloc(bmi.biSizeImage, sizeof(DWORD))); + if (buf) { GetDIBits(hdcScreen, bitmap, 0, bm.bmHeight, buf, - (BITMAPINFO*)&bmi, DIB_RGB_COLORS); + reinterpret_cast(&bmi), + DIB_RGB_COLORS); - BYTE* dest = (BYTE*)alphaSrcBits; - for (const DWORD *src = (DWORD*)buf, - *end = (DWORD*)(buf + bmi.biSizeImage); - src != end; - ++src, ++dest) { + const DWORD *src = reinterpret_cast(buf); + const DWORD *end = + reinterpret_cast(buf + bmi.biSizeImage); + + BYTE* dest = reinterpret_cast(alphaSrcBits); + + for (; src != end; ++src, ++dest) { BYTE a = *src >> 24; *dest++ = a; *dest++ = a; @@ -123,12 +129,14 @@ static HBITMAP StretchBitmap(HBITMAP bitmap, unsigned width, unsigned height) { bmi.biCompression = BI_RGB; void* colorBits; - auto colorBitmap = CreateDIBSection(NULL, (BITMAPINFO*)&bmi, + auto colorBitmap = CreateDIBSection(NULL, + reinterpret_cast(&bmi), DIB_RGB_COLORS, &colorBits, NULL, 0); void* alphaBits; - auto alphaBitmap = CreateDIBSection(NULL, (BITMAPINFO*)&bmi, + auto alphaBitmap = CreateDIBSection(NULL, + reinterpret_cast(&bmi), DIB_RGB_COLORS, &alphaBits, NULL, 0); @@ -156,8 +164,8 @@ static HBITMAP StretchBitmap(HBITMAP bitmap, unsigned width, unsigned height) { GdiFlush(); // apply the alpha channel - auto dest = (BYTE*)colorBits; - auto src = (const BYTE*)alphaBits; + auto dest = reinterpret_cast(colorBits); + auto src = reinterpret_cast(alphaBits); auto end = src + (width * height * 4); while (src != end) { dest[3] = src[0]; @@ -167,7 +175,8 @@ static HBITMAP StretchBitmap(HBITMAP bitmap, unsigned width, unsigned height) { // create the resulting bitmap resultBitmap = CreateDIBitmap(hdcScreen, &bmi, CBM_INIT, - colorBits, (BITMAPINFO*)&bmi, + colorBits, + reinterpret_cast(&bmi), DIB_RGB_COLORS); } @@ -657,8 +666,8 @@ void DesktopNotificationController::Toast::SetVerticalPosition(int y) { return; // Make sure the new animation's origin is at the current position - vertical_pos_ += - (int)((vertical_pos_target_ - vertical_pos_) * stack_collapse_pos_); + vertical_pos_ += static_cast( + (vertical_pos_target_ - vertical_pos_) * stack_collapse_pos_); // Set new target position and start the animation vertical_pos_target_ = y; @@ -699,11 +708,11 @@ HDWP DesktopNotificationController::Toast::Animate( auto yOffset = (vertical_pos_target_ - vertical_pos_) * stackCollapsePos; - size.cx = (int)(toast_size_.cx * easeInPos); + size.cx = static_cast(toast_size_.cx * easeInPos); size.cy = toast_size_.cy; pt.x = origin.x - size.cx; - pt.y = (int)(origin.y - vertical_pos_ - yOffset - size.cy); + pt.y = static_cast(origin.y - vertical_pos_ - yOffset - size.cy); ulw.pptDst = &pt; ulw.psize = &size; diff --git a/brightray/browser/win/win32_notification.cc b/brightray/browser/win/win32_notification.cc index 36242c06a409..f1ac9598a7f5 100644 --- a/brightray/browser/win/win32_notification.cc +++ b/brightray/browser/win/win32_notification.cc @@ -27,7 +27,8 @@ void Win32Notification::Show( HDC hdcScreen = GetDC(NULL); image = CreateDIBitmap(hdcScreen, &bmi, CBM_INIT, icon.getPixels(), - (BITMAPINFO*)&bmi, DIB_RGB_COLORS); + reinterpret_cast(&bmi), + DIB_RGB_COLORS); ReleaseDC(NULL, hdcScreen); icon.unlockPixels();