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