OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "app/win_util.h" | 5 #include "app/win_util.h" |
6 | 6 |
7 #include <commdlg.h> | 7 #include <commdlg.h> |
8 #include <dwmapi.h> | 8 #include <dwmapi.h> |
9 #include <propvarutil.h> | |
10 #include <shellapi.h> | 9 #include <shellapi.h> |
11 #include <shlobj.h> | 10 #include <shlobj.h> |
12 | 11 |
13 #include <algorithm> | 12 #include <algorithm> |
14 | 13 |
15 #include "app/gfx/codec/png_codec.h" | 14 #include "app/gfx/codec/png_codec.h" |
16 #include "app/gfx/gdi_util.h" | 15 #include "app/gfx/gdi_util.h" |
17 #include "app/l10n_util.h" | 16 #include "app/l10n_util.h" |
18 #include "app/l10n_util_win.h" | 17 #include "app/l10n_util_win.h" |
19 #include "base/base_switches.h" | 18 #include "base/base_switches.h" |
(...skipping 20 matching lines...) Expand all Loading... |
40 namespace { | 39 namespace { |
41 | 40 |
42 const wchar_t kShell32[] = L"shell32.dll"; | 41 const wchar_t kShell32[] = L"shell32.dll"; |
43 const char kSHGetPropertyStoreForWindow[] = "SHGetPropertyStoreForWindow"; | 42 const char kSHGetPropertyStoreForWindow[] = "SHGetPropertyStoreForWindow"; |
44 | 43 |
45 // Define the type of SHGetPropertyStoreForWindow is SHGPSFW. | 44 // Define the type of SHGetPropertyStoreForWindow is SHGPSFW. |
46 typedef DECLSPEC_IMPORT HRESULT (STDAPICALLTYPE *SHGPSFW)(HWND hwnd, | 45 typedef DECLSPEC_IMPORT HRESULT (STDAPICALLTYPE *SHGPSFW)(HWND hwnd, |
47 REFIID riid, | 46 REFIID riid, |
48 void** ppv); | 47 void** ppv); |
49 | 48 |
50 EXTERN_C const PROPERTYKEY DECLSPEC_SELECTANY PKEY_AppUserModel_ID = | |
51 { { 0x9F4C2855, 0x9F79, 0x4B39, | |
52 { 0xA8, 0xD0, 0xE1, 0xD4, 0x2D, 0xE1, 0xD5, 0xF3, } }, 5 }; | |
53 | |
54 // Enforce visible dialog box. | 49 // Enforce visible dialog box. |
55 UINT_PTR CALLBACK SaveAsDialogHook(HWND dialog, UINT message, | 50 UINT_PTR CALLBACK SaveAsDialogHook(HWND dialog, UINT message, |
56 WPARAM wparam, LPARAM lparam) { | 51 WPARAM wparam, LPARAM lparam) { |
57 static const UINT kPrivateMessage = 0x2F3F; | 52 static const UINT kPrivateMessage = 0x2F3F; |
58 switch (message) { | 53 switch (message) { |
59 case WM_INITDIALOG: { | 54 case WM_INITDIALOG: { |
60 // Do nothing here. Just post a message to defer actual processing. | 55 // Do nothing here. Just post a message to defer actual processing. |
61 PostMessage(dialog, kPrivateMessage, 0, 0); | 56 PostMessage(dialog, kPrivateMessage, 0, 0); |
62 return TRUE; | 57 return TRUE; |
63 } | 58 } |
(...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
847 | 842 |
848 gfx::Font GetWindowTitleFont() { | 843 gfx::Font GetWindowTitleFont() { |
849 NONCLIENTMETRICS ncm; | 844 NONCLIENTMETRICS ncm; |
850 win_util::GetNonClientMetrics(&ncm); | 845 win_util::GetNonClientMetrics(&ncm); |
851 l10n_util::AdjustUIFont(&(ncm.lfCaptionFont)); | 846 l10n_util::AdjustUIFont(&(ncm.lfCaptionFont)); |
852 ScopedHFONT caption_font(CreateFontIndirect(&(ncm.lfCaptionFont))); | 847 ScopedHFONT caption_font(CreateFontIndirect(&(ncm.lfCaptionFont))); |
853 return gfx::Font::CreateFont(caption_font); | 848 return gfx::Font::CreateFont(caption_font); |
854 } | 849 } |
855 | 850 |
856 void SetAppIdForWindow(const std::wstring& app_id, HWND hwnd) { | 851 void SetAppIdForWindow(const std::wstring& app_id, HWND hwnd) { |
857 // This funcationality is only available on Win7+. | 852 // This functionality is only available on Win7+. |
858 if (win_util::GetWinVersion() != win_util::WINVERSION_WIN7) | 853 if (win_util::GetWinVersion() != win_util::WINVERSION_WIN7) |
859 return; | 854 return; |
860 | 855 |
861 // Load Shell32.dll into memory. | 856 // Load Shell32.dll into memory. |
862 // TODO(brg): Remove this mechanism when the Win7 SDK is available in trunk. | 857 // TODO(brg): Remove this mechanism when the Win7 SDK is available in trunk. |
863 std::wstring shell32_filename(kShell32); | 858 std::wstring shell32_filename(kShell32); |
864 FilePath shell32_filepath(shell32_filename); | 859 FilePath shell32_filepath(shell32_filename); |
865 base::NativeLibrary shell32_library = base::LoadNativeLibrary( | 860 base::NativeLibrary shell32_library = base::LoadNativeLibrary( |
866 shell32_filepath); | 861 shell32_filepath); |
867 | 862 |
868 if (!shell32_library) | 863 if (!shell32_library) |
869 return; | 864 return; |
870 | 865 |
871 // Get the function pointer for SHGetPropertyStoreForWindow. | 866 // Get the function pointer for SHGetPropertyStoreForWindow. |
872 void* function = base::GetFunctionPointerFromNativeLibrary( | 867 void* function = base::GetFunctionPointerFromNativeLibrary( |
873 shell32_library, | 868 shell32_library, |
874 kSHGetPropertyStoreForWindow); | 869 kSHGetPropertyStoreForWindow); |
875 | 870 |
876 if (!function) { | 871 if (!function) { |
877 base::UnloadNativeLibrary(shell32_library); | 872 base::UnloadNativeLibrary(shell32_library); |
878 return; | 873 return; |
879 } | 874 } |
880 | 875 |
881 // Set the application's name. | 876 // Set the application's name. |
882 PROPVARIANT pv; | |
883 InitPropVariantFromString(app_id.c_str(), &pv); | |
884 | |
885 ScopedComPtr<IPropertyStore> pps; | 877 ScopedComPtr<IPropertyStore> pps; |
886 SHGPSFW SHGetPropertyStoreForWindow = static_cast<SHGPSFW>(function); | 878 SHGPSFW SHGetPropertyStoreForWindow = static_cast<SHGPSFW>(function); |
887 HRESULT result = SHGetPropertyStoreForWindow( | 879 HRESULT result = SHGetPropertyStoreForWindow( |
888 hwnd, __uuidof(*pps), reinterpret_cast<void**>(pps.Receive())); | 880 hwnd, __uuidof(*pps), reinterpret_cast<void**>(pps.Receive())); |
889 if (S_OK == result) { | 881 if (S_OK == result) { |
890 if (S_OK == pps->SetValue(PKEY_AppUserModel_ID, pv)) | 882 SetAppIdForPropertyStore(pps, app_id.c_str()); |
891 pps->Commit(); | |
892 } | 883 } |
893 | 884 |
894 // Cleanup. | 885 // Cleanup. |
895 PropVariantClear(&pv); | |
896 base::UnloadNativeLibrary(shell32_library); | 886 base::UnloadNativeLibrary(shell32_library); |
897 } | 887 } |
898 | 888 |
899 } // namespace win_util | 889 } // namespace win_util |
OLD | NEW |