From b566416e9c7c69492c3955bb9153cb0caba4cd11 Mon Sep 17 00:00:00 2001 From: "hbono@chromium.org" Date: Thu, 15 Jul 2010 05:24:32 +0000 Subject: Supports High DPI mode. When launching an application on the text size larger than 120 DPI, Windows runs the application on the DPI-virtualization mode to hide the text size from it. Unfortunately, this virtualization mode causes some problems when using a custom frame, such as we cannot click system buttons. To fix this issue, this change disables the DPI-virtualization mode on Vista or later. BUG=1715,36939 TEST=Run chrome.exe on the screen resolution higher than 120 DPI. Review URL: http://codereview.chromium.org/2867031 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52446 0039d316-1c4b-4281-b951-d872f2087c98 --- app/win_util.cc | 15 +++++++++++++++ app/win_util.h | 7 +++++++ chrome/browser/browser_init.cc | 7 +++++++ 3 files changed, 29 insertions(+) diff --git a/app/win_util.cc b/app/win_util.cc index b043db3..46a4f92 100644 --- a/app/win_util.cc +++ b/app/win_util.cc @@ -23,6 +23,7 @@ #include "base/scoped_comptr_win.h" #include "base/scoped_handle.h" #include "base/scoped_handle_win.h" +#include "base/scoped_native_library.h" #include "base/string_util.h" #include "base/win_util.h" #include "gfx/codec/png_codec.h" @@ -582,4 +583,18 @@ void SetAppIdForWindow(const std::wstring& app_id, HWND hwnd) { base::UnloadNativeLibrary(shell32_library); } +void CallSetProcessDPIAware() { + // This functionality is only available on Vista or later. + if (win_util::GetWinVersion() < win_util::WINVERSION_VISTA) + return; + + base::ScopedNativeLibrary user32( + FilePath(base::GetNativeLibraryName(L"user32"))); + typedef BOOL (*SetProcessDPIAwareFunc)(); + SetProcessDPIAwareFunc set_process_dpi_aware = + (SetProcessDPIAwareFunc)user32.GetFunctionPointer("SetProcessDPIAware"); + if (set_process_dpi_aware) + set_process_dpi_aware(); +} + } // namespace win_util diff --git a/app/win_util.h b/app/win_util.h index 6e2812e..9d745eb 100644 --- a/app/win_util.h +++ b/app/win_util.h @@ -215,6 +215,13 @@ extern const int kAutoHideTaskbarThicknessPx; // do not group together on the Win7 task bar. void SetAppIdForWindow(const std::wstring& app_id, HWND hwnd); +// Calls SetProcessDPIAware() to declare this application is DPI-aware and to +// disable the DPI virtualization of Windows. Unfortunately, calling this +// function after creating a window confuses some APIs, i.e. some APIs still +// have the DPI virtualization enabled after calling SetProcessDPIAware(). +// Therefore, we need to call this function before creating the first window. +void CallSetProcessDPIAware(); + } // namespace win_util #endif // APP_WIN_UTIL_H_ diff --git a/chrome/browser/browser_init.cc b/chrome/browser/browser_init.cc index 495ce1c..9c72ceb 100644 --- a/chrome/browser/browser_init.cc +++ b/chrome/browser/browser_init.cc @@ -387,6 +387,13 @@ bool BrowserInit::LaunchBrowser( chromeos::InitialTabNotificationObserver::Get(); #endif +#if defined(OS_WIN) + // Disable the DPI-virtualization mode of Windows Vista or later because it + // causes some problems when using system messages (such as WM_NCHITTEST and + // WM_GETTITLEBARINFOEX) on a custom frame. + win_util::CallSetProcessDPIAware(); +#endif + // Continue with the off-the-record profile from here on if --incognito if (command_line.HasSwitch(switches::kIncognito)) profile = profile->GetOffTheRecordProfile(); -- cgit v1.1