1*32b1fd08SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*32b1fd08SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*32b1fd08SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*32b1fd08SAndrew Rist  * distributed with this work for additional information
6*32b1fd08SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*32b1fd08SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*32b1fd08SAndrew Rist  * "License"); you may not use this file except in compliance
9*32b1fd08SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*32b1fd08SAndrew Rist  *
11*32b1fd08SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*32b1fd08SAndrew Rist  *
13*32b1fd08SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*32b1fd08SAndrew Rist  * software distributed under the License is distributed on an
15*32b1fd08SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*32b1fd08SAndrew Rist  * KIND, either express or implied.  See the License for the
17*32b1fd08SAndrew Rist  * specific language governing permissions and limitations
18*32b1fd08SAndrew Rist  * under the License.
19*32b1fd08SAndrew Rist  *
20*32b1fd08SAndrew Rist  *************************************************************/
21*32b1fd08SAndrew Rist 
22*32b1fd08SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifdef _MSC_VER
25cdf0e10cSrcweir #pragma warning(push, 1) /* disable warnings within system headers */
26cdf0e10cSrcweir #endif
27cdf0e10cSrcweir #define WIN32_LEAN_AND_MEAN
28cdf0e10cSrcweir #include <windows.h>
29cdf0e10cSrcweir #include <msiquery.h>
30cdf0e10cSrcweir #ifdef _MSC_VER
31cdf0e10cSrcweir #pragma warning(pop)
32cdf0e10cSrcweir #endif
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include <stdlib.h>
35cdf0e10cSrcweir 
RebuildShellIconCache(MSIHANDLE)36cdf0e10cSrcweir extern "C" UINT __stdcall RebuildShellIconCache(MSIHANDLE)
37cdf0e10cSrcweir {
38cdf0e10cSrcweir 	// Rebuild icon cache on windows OS prior XP
39cdf0e10cSrcweir 
40cdf0e10cSrcweir 	OSVERSIONINFO	osverinfo;
41cdf0e10cSrcweir 
42cdf0e10cSrcweir 	osverinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
43cdf0e10cSrcweir 
44cdf0e10cSrcweir 	if (
45cdf0e10cSrcweir 		GetVersionEx( &osverinfo ) &&
46cdf0e10cSrcweir 		VER_PLATFORM_WIN32_NT == osverinfo.dwPlatformId &&
47cdf0e10cSrcweir 		(
48cdf0e10cSrcweir 		5 < osverinfo.dwMajorVersion ||
49cdf0e10cSrcweir 		5 == osverinfo.dwMajorVersion && 0 < osverinfo.dwMinorVersion
50cdf0e10cSrcweir 		)
51cdf0e10cSrcweir 		)
52cdf0e10cSrcweir 	{
53cdf0e10cSrcweir 		return ERROR_SUCCESS;
54cdf0e10cSrcweir 	}
55cdf0e10cSrcweir 
56cdf0e10cSrcweir 	HKEY	hKey;
57cdf0e10cSrcweir 	DWORD	dwDispostion;
58cdf0e10cSrcweir 	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 );
59cdf0e10cSrcweir 
60cdf0e10cSrcweir 	if ( ERROR_SUCCESS == lError )
61cdf0e10cSrcweir 	{
62cdf0e10cSrcweir 		TCHAR	szValue[256];
63cdf0e10cSrcweir 		TCHAR	szTempValue[256];
64cdf0e10cSrcweir 		DWORD	cbValue = sizeof(szValue);
65cdf0e10cSrcweir 		DWORD	dwType;
66cdf0e10cSrcweir 		int		iSize = 0;
67cdf0e10cSrcweir 
68cdf0e10cSrcweir 		lError = RegQueryValueEx( hKey, TEXT("Shell Icon Size"), 0, &dwType, (LPBYTE)szValue, &cbValue );
69cdf0e10cSrcweir 
70cdf0e10cSrcweir 		if ( ERROR_SUCCESS == lError )
71cdf0e10cSrcweir 			iSize = atoi( szValue );
72cdf0e10cSrcweir 
73cdf0e10cSrcweir 		if ( !iSize )
74cdf0e10cSrcweir 		{
75cdf0e10cSrcweir 			iSize = GetSystemMetrics( SM_CXICON );
76cdf0e10cSrcweir 			itoa( iSize, szValue, 10 );
77cdf0e10cSrcweir 			cbValue = strlen( szValue ) + 1;
78cdf0e10cSrcweir 			dwType = REG_SZ;
79cdf0e10cSrcweir 		}
80cdf0e10cSrcweir 
81cdf0e10cSrcweir 		itoa( iSize + 1, szTempValue, 10 );
82cdf0e10cSrcweir 		lError = RegSetValueEx( hKey, TEXT("Shell Icon Size"), 0, dwType, (LPBYTE)szTempValue, strlen( szTempValue ) + 1 );
83cdf0e10cSrcweir 
84cdf0e10cSrcweir 		LRESULT	lResult = SendMessageTimeout(
85cdf0e10cSrcweir 			 HWND_BROADCAST,
86cdf0e10cSrcweir 			 WM_SETTINGCHANGE,
87cdf0e10cSrcweir 			 SPI_SETNONCLIENTMETRICS,
88cdf0e10cSrcweir 			 (LPARAM)TEXT("WindowMetrics"),
89cdf0e10cSrcweir 			 SMTO_NORMAL|SMTO_ABORTIFHUNG,
90cdf0e10cSrcweir 			 0, NULL);
91cdf0e10cSrcweir 
92cdf0e10cSrcweir 		lError = RegSetValueEx( hKey, TEXT("Shell Icon Size"), 0, dwType, (LPBYTE)szValue, cbValue );
93cdf0e10cSrcweir 
94cdf0e10cSrcweir 		lResult = SendMessageTimeout(
95cdf0e10cSrcweir 			 HWND_BROADCAST,
96cdf0e10cSrcweir 			 WM_SETTINGCHANGE,
97cdf0e10cSrcweir 			 SPI_SETNONCLIENTMETRICS,
98cdf0e10cSrcweir 			 (LPARAM)TEXT("WindowMetrics"),
99cdf0e10cSrcweir 			 SMTO_NORMAL|SMTO_ABORTIFHUNG,
100cdf0e10cSrcweir 			 0, NULL);
101cdf0e10cSrcweir 
102cdf0e10cSrcweir 		lError = RegCloseKey( hKey );
103cdf0e10cSrcweir 	}
104cdf0e10cSrcweir 
105cdf0e10cSrcweir     return ERROR_SUCCESS;
106cdf0e10cSrcweir }
107