Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Side by Side Diff: app/win_util.cc

Issue 159336: Partial fix to 7028 - Pinning in Win7.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « app/win_util.h ('k') | chrome/browser/browser.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-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 <atlbase.h> 7 #include <atlbase.h>
8 #include <atlapp.h> 8 #include <atlapp.h>
9 #include <commdlg.h> 9 #include <commdlg.h>
10 #include <dwmapi.h> 10 #include <dwmapi.h>
11 #include <propvarutil.h>
11 #include <shellapi.h> 12 #include <shellapi.h>
12 #include <shlobj.h> 13 #include <shlobj.h>
13 14
14 #include "app/l10n_util.h" 15 #include "app/l10n_util.h"
15 #include "app/l10n_util_win.h" 16 #include "app/l10n_util_win.h"
16 #include "base/base_switches.h" 17 #include "base/base_switches.h"
17 #include "base/command_line.h" 18 #include "base/command_line.h"
18 #include "base/file_util.h" 19 #include "base/file_util.h"
19 #include "base/gfx/gdi_util.h" 20 #include "base/gfx/gdi_util.h"
20 #include "base/gfx/png_encoder.h" 21 #include "base/gfx/png_encoder.h"
21 #include "base/logging.h" 22 #include "base/logging.h"
23 #include "base/native_library.h"
22 #include "base/registry.h" 24 #include "base/registry.h"
23 #include "base/scoped_handle.h" 25 #include "base/scoped_handle.h"
24 #include "base/string_util.h" 26 #include "base/string_util.h"
25 #include "base/win_util.h" 27 #include "base/win_util.h"
26 #include "grit/app_strings.h" 28 #include "grit/app_strings.h"
27 #include "net/base/mime_util.h" 29 #include "net/base/mime_util.h"
28 30
29 // Ensure that we pick up this link library. 31 // Ensure that we pick up this link library.
30 #pragma comment(lib, "dwmapi.lib") 32 #pragma comment(lib, "dwmapi.lib")
31 33
32 namespace win_util { 34 namespace win_util {
33 35
34 const int kAutoHideTaskbarThicknessPx = 2; 36 const int kAutoHideTaskbarThicknessPx = 2;
35 37
36 namespace { 38 namespace {
37 39
40 const wchar_t kShell32[] = L"shell32.dll";
41 const char kSHGetPropertyStoreForWindow[] = "SHGetPropertyStoreForWindow";
42
43 // Define the type of SHGetPropertyStoreForWindow is SHGPSFW.
44 typedef DECLSPEC_IMPORT HRESULT (STDAPICALLTYPE *SHGPSFW)(HWND hwnd,
45 REFIID riid,
46 void** ppv);
47
48 EXTERN_C const PROPERTYKEY DECLSPEC_SELECTANY PKEY_AppUserModel_ID =
49 { { 0x9F4C2855, 0x9F79, 0x4B39,
50 { 0xA8, 0xD0, 0xE1, 0xD4, 0x2D, 0xE1, 0xD5, 0xF3, } }, 5 };
51
38 // Enforce visible dialog box. 52 // Enforce visible dialog box.
39 UINT_PTR CALLBACK SaveAsDialogHook(HWND dialog, UINT message, 53 UINT_PTR CALLBACK SaveAsDialogHook(HWND dialog, UINT message,
40 WPARAM wparam, LPARAM lparam) { 54 WPARAM wparam, LPARAM lparam) {
41 static const UINT kPrivateMessage = 0x2F3F; 55 static const UINT kPrivateMessage = 0x2F3F;
42 switch (message) { 56 switch (message) {
43 case WM_INITDIALOG: { 57 case WM_INITDIALOG: {
44 // Do nothing here. Just post a message to defer actual processing. 58 // Do nothing here. Just post a message to defer actual processing.
45 PostMessage(dialog, kPrivateMessage, 0, 0); 59 PostMessage(dialog, kPrivateMessage, 0, 0);
46 return TRUE; 60 return TRUE;
47 } 61 }
(...skipping 770 matching lines...) Expand 10 before | Expand all | Expand 10 after
818 } 832 }
819 833
820 gfx::Font GetWindowTitleFont() { 834 gfx::Font GetWindowTitleFont() {
821 NONCLIENTMETRICS ncm; 835 NONCLIENTMETRICS ncm;
822 win_util::GetNonClientMetrics(&ncm); 836 win_util::GetNonClientMetrics(&ncm);
823 l10n_util::AdjustUIFont(&(ncm.lfCaptionFont)); 837 l10n_util::AdjustUIFont(&(ncm.lfCaptionFont));
824 ScopedHFONT caption_font(CreateFontIndirect(&(ncm.lfCaptionFont))); 838 ScopedHFONT caption_font(CreateFontIndirect(&(ncm.lfCaptionFont)));
825 return gfx::Font::CreateFont(caption_font); 839 return gfx::Font::CreateFont(caption_font);
826 } 840 }
827 841
842 void SetAppIdForWindow(const std::wstring& app_id, HWND hwnd) {
843 // This funcationality is only available on Win7+.
844 if (win_util::GetWinVersion() != win_util::WINVERSION_WIN7)
845 return;
846
847 // Load Shell32.dll into memory.
848 // TODO(brg): Remove this mechanism when the Win7 SDK is available in trunk.
849 std::wstring shell32_filename(kShell32);
850 FilePath shell32_filepath(shell32_filename);
851 base::NativeLibrary shell32_library = base::LoadNativeLibrary(
852 shell32_filepath);
853
854 if (!shell32_library)
855 return;
856
857 // Get the function pointer for SHGetPropertyStoreForWindow.
858 void* function = base::GetFunctionPointerFromNativeLibrary(
859 shell32_library,
860 kSHGetPropertyStoreForWindow);
861
862 if (!function) {
863 base::UnloadNativeLibrary(shell32_library);
864 return;
865 }
866
867 // Set the application's name.
868 PROPVARIANT pv;
869 InitPropVariantFromString(app_id.c_str(), &pv);
870
871 IPropertyStore* pps;
872 SHGPSFW SHGetPropertyStoreForWindow = static_cast<SHGPSFW>(function);
873 if (S_OK == SHGetPropertyStoreForWindow(hwnd, IID_PPV_ARGS(&pps)) &&
874 S_OK == pps->SetValue(PKEY_AppUserModel_ID, pv)) {
875 pps->Commit();
876 }
877
878 // Cleanup.
879 base::UnloadNativeLibrary(shell32_library);
880 }
881
828 } // namespace win_util 882 } // namespace win_util
OLDNEW
« no previous file with comments | « app/win_util.h ('k') | chrome/browser/browser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698