Update ooo320-m1
[ooovba.git] / setup_native / source / win32 / customactions / shellextensions / iconcache.cxx
blob319de101defd67940c1538d265380d782588ac0d
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: iconcache.cxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifdef _MSC_VER
32 #pragma warning(push, 1) /* disable warnings within system headers */
33 #endif
34 #define WIN32_LEAN_AND_MEAN
35 #include <windows.h>
36 #include <msiquery.h>
37 #ifdef _MSC_VER
38 #pragma warning(pop)
39 #endif
41 #include <stdlib.h>
43 extern "C" UINT __stdcall RebuildShellIconCache(MSIHANDLE)
45 // Rebuild icon cache on windows OS prior XP
47 OSVERSIONINFO osverinfo;
49 osverinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
51 if (
52 GetVersionEx( &osverinfo ) &&
53 VER_PLATFORM_WIN32_NT == osverinfo.dwPlatformId &&
55 5 < osverinfo.dwMajorVersion ||
56 5 == osverinfo.dwMajorVersion && 0 < osverinfo.dwMinorVersion
60 return ERROR_SUCCESS;
63 HKEY hKey;
64 DWORD dwDispostion;
65 LONG lError = RegCreateKeyEx( HKEY_CURRENT_USER, TEXT("Control Panel\\Desktop\\WindowMetrics"), 0, NULL, REG_OPTION_VOLATILE, KEY_SET_VALUE | KEY_QUERY_VALUE, NULL, &hKey, &dwDispostion );
67 if ( ERROR_SUCCESS == lError )
69 TCHAR szValue[256];
70 TCHAR szTempValue[256];
71 DWORD cbValue = sizeof(szValue);
72 DWORD dwType;
73 int iSize = 0;
75 lError = RegQueryValueEx( hKey, TEXT("Shell Icon Size"), 0, &dwType, (LPBYTE)szValue, &cbValue );
77 if ( ERROR_SUCCESS == lError )
78 iSize = atoi( szValue );
80 if ( !iSize )
82 iSize = GetSystemMetrics( SM_CXICON );
83 itoa( iSize, szValue, 10 );
84 cbValue = strlen( szValue ) + 1;
85 dwType = REG_SZ;
88 itoa( iSize + 1, szTempValue, 10 );
89 lError = RegSetValueEx( hKey, TEXT("Shell Icon Size"), 0, dwType, (LPBYTE)szTempValue, strlen( szTempValue ) + 1 );
91 LRESULT lResult = SendMessageTimeout(
92 HWND_BROADCAST,
93 WM_SETTINGCHANGE,
94 SPI_SETNONCLIENTMETRICS,
95 (LPARAM)TEXT("WindowMetrics"),
96 SMTO_NORMAL|SMTO_ABORTIFHUNG,
97 0, NULL);
99 lError = RegSetValueEx( hKey, TEXT("Shell Icon Size"), 0, dwType, (LPBYTE)szValue, cbValue );
101 lResult = SendMessageTimeout(
102 HWND_BROADCAST,
103 WM_SETTINGCHANGE,
104 SPI_SETNONCLIENTMETRICS,
105 (LPARAM)TEXT("WindowMetrics"),
106 SMTO_NORMAL|SMTO_ABORTIFHUNG,
107 0, NULL);
109 lError = RegCloseKey( hKey );
112 return ERROR_SUCCESS;