diff options
author | brg@chromium.com <brg@chromium.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-25 00:24:57 +0000 |
---|---|---|
committer | brg@chromium.com <brg@chromium.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-25 00:24:57 +0000 |
commit | 3df2aafb359c4ffae0f16b2ce1d7fc37ed376f88 (patch) | |
tree | bbf119bebf751f312a931bf83f368dc050ef982f /app | |
parent | ade3b63c489ed162de38637be1c551276e3ce5f2 (diff) | |
download | chromium_src-3df2aafb359c4ffae0f16b2ce1d7fc37ed376f88.zip chromium_src-3df2aafb359c4ffae0f16b2ce1d7fc37ed376f88.tar.gz chromium_src-3df2aafb359c4ffae0f16b2ce1d7fc37ed376f88.tar.bz2 |
Partial fix to 7028 - Pinning in Win7.A complete fix will require Gears to set the application id as a property on the shortcut As of this cl, web applications hosted by Chrome will appear in their own groups on the task bar. However, they can not be pinned from the main application window nor can they be pinned from the shortcut. The former results in Chrome being pinned, and the latter results in a quick start button but does not group web applications under that button. Instead in the latter case a web appliation will form a new group.
Bug=7028
Test=None. (When there is a Win7 trybot there may be at test to check if the windows group in the taskbar properly)
Review URL: http://codereview.chromium.org/159336
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21595 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app')
-rw-r--r-- | app/win_util.cc | 54 | ||||
-rw-r--r-- | app/win_util.h | 5 |
2 files changed, 59 insertions, 0 deletions
diff --git a/app/win_util.cc b/app/win_util.cc index 9e54f5c..2d8c3f3 100644 --- a/app/win_util.cc +++ b/app/win_util.cc @@ -8,6 +8,7 @@ #include <atlapp.h> #include <commdlg.h> #include <dwmapi.h> +#include <propvarutil.h> #include <shellapi.h> #include <shlobj.h> @@ -19,6 +20,7 @@ #include "base/gfx/gdi_util.h" #include "base/gfx/png_encoder.h" #include "base/logging.h" +#include "base/native_library.h" #include "base/registry.h" #include "base/scoped_handle.h" #include "base/string_util.h" @@ -35,6 +37,18 @@ const int kAutoHideTaskbarThicknessPx = 2; namespace { +const wchar_t kShell32[] = L"shell32.dll"; +const char kSHGetPropertyStoreForWindow[] = "SHGetPropertyStoreForWindow"; + +// Define the type of SHGetPropertyStoreForWindow is SHGPSFW. +typedef DECLSPEC_IMPORT HRESULT (STDAPICALLTYPE *SHGPSFW)(HWND hwnd, + REFIID riid, + void** ppv); + +EXTERN_C const PROPERTYKEY DECLSPEC_SELECTANY PKEY_AppUserModel_ID = + { { 0x9F4C2855, 0x9F79, 0x4B39, + { 0xA8, 0xD0, 0xE1, 0xD4, 0x2D, 0xE1, 0xD5, 0xF3, } }, 5 }; + // Enforce visible dialog box. UINT_PTR CALLBACK SaveAsDialogHook(HWND dialog, UINT message, WPARAM wparam, LPARAM lparam) { @@ -825,4 +839,44 @@ gfx::Font GetWindowTitleFont() { return gfx::Font::CreateFont(caption_font); } +void SetAppIdForWindow(const std::wstring& app_id, HWND hwnd) { + // This funcationality is only available on Win7+. + if (win_util::GetWinVersion() != win_util::WINVERSION_WIN7) + return; + + // Load Shell32.dll into memory. + // TODO(brg): Remove this mechanism when the Win7 SDK is available in trunk. + std::wstring shell32_filename(kShell32); + FilePath shell32_filepath(shell32_filename); + base::NativeLibrary shell32_library = base::LoadNativeLibrary( + shell32_filepath); + + if (!shell32_library) + return; + + // Get the function pointer for SHGetPropertyStoreForWindow. + void* function = base::GetFunctionPointerFromNativeLibrary( + shell32_library, + kSHGetPropertyStoreForWindow); + + if (!function) { + base::UnloadNativeLibrary(shell32_library); + return; + } + + // Set the application's name. + PROPVARIANT pv; + InitPropVariantFromString(app_id.c_str(), &pv); + + IPropertyStore* pps; + SHGPSFW SHGetPropertyStoreForWindow = static_cast<SHGPSFW>(function); + if (S_OK == SHGetPropertyStoreForWindow(hwnd, IID_PPV_ARGS(&pps)) && + S_OK == pps->SetValue(PKEY_AppUserModel_ID, pv)) { + pps->Commit(); + } + + // Cleanup. + base::UnloadNativeLibrary(shell32_library); +} + } // namespace win_util diff --git a/app/win_util.h b/app/win_util.h index be5f325..c9340d1 100644 --- a/app/win_util.h +++ b/app/win_util.h @@ -288,6 +288,11 @@ gfx::Font GetWindowTitleFont(); // The thickness of an auto-hide taskbar in pixels. extern const int kAutoHideTaskbarThicknessPx; +// Sets the application id given as the Application Model ID for the window +// specified. This method is used to insure that different web applications +// do not group together on the Win7 task bar. +void SetAppIdForWindow(const std::wstring& app_id, HWND hwnd); + } // namespace win_util #endif // APP_WIN_UTIL_H_ |