Changing IE Show Picture Setting
The following sample program demonstrates how to change the Internet Explorer Show Picture setting. This program toggles the state of this setting. Note the usage of the SendMessageTimeoutW function with the WM_SETTINGCHANGE message that causes all the open instances of IE to update themselves. If you use SendMessageW instead, and a window procedure for some window on the system falls into an infinite loop for some reason, then, your process would also stop responding. Here's the sample program. Note that this is a Unicode program, so it doesn't run on Win95/98/Me. However, making this an ANSI application is a trivial task, as I've done it below the Unicode source code:
<font face="Courier New" color="#000000"><font color="#6464ff"><b>int</b></font> <font color="#6464ff"><b>__stdcall</b></font> wWinMain(<font color="#6464c8">HINSTANCE</font>, <font color="#6464c8">HINSTANCE</font>, <font color="#6464c8">LPSTR</font>, <font color="#6464ff"><b>int</b></font>)<br />{<br /> <font color="#6464c8">HKEY</font> hkey;<br /> <font color="#6464c8">DWORD</font> dwType = REG_SZ;<br /> <font color="#6464c8">BYTE</font> pData[100];<br /> <font color="#6464c8">DWORD</font> cbSize = 100;<br /> <font color="#6464c8">BYTE</font> pDataToWrite[100];<br /> <font color="#6464c8">DWORD</font> cbSizeToWrite = 100;<br /> ::ZeroMemory( pData, <font color="#6464ff"><b>sizeof</b></font>(<font color="#6464c8">BYTE</font>) * cbSize );<br /> ::ZeroMemory( pDataToWrite, <font color="#6464ff"><b>sizeof</b></font>(<font color="#6464c8">BYTE</font>) * cbSizeToWrite );<br /> <font color="#6464c8">DWORD</font> dwResult;<br /><br /> <font color="#6464c8">WCHAR</font> szRegKey[] = L<font color="#669999">"Software\\Microsoft\\Internet Explorer\\Main\\"</font>;<br /><br /> <font color="#6464c8">LONG</font> lRet;<br /><br /> <font color="#6464ff"><b>try</b></font><br /> {<br /> lRet = ::RegOpenKeyExW( HKEY_CURRENT_USER,<br /> szRegKey,<br /> 0, KEY_READ | KEY_WRITE, &hkey );<br /> <font color="#6464ff"><b>if</b></font> (ERROR_SUCCESS != lRet)<br /> <font color="#6464ff"><b>throw</b></font> L<font color="#669999">"Failed to open the Internet Explorer registry key."</font>;<br /> lRet = ::RegQueryValueExW( hkey, L<font color="#669999">"Display Inline Images"</font>, <font color="#6464c8">NULL</font>,<br /> &dwType, pData, &cbSize );<br /> <font color="#6464ff"><b>if</b></font> (ERROR_SUCCESS != lRet)<br /> <font color="#6464ff"><b>throw</b></font> L<font color="#669999">"Failed to read the registry value."</font>;<br /><br /> <font color="#6464ff"><b>if</b></font> (::lstrcmpiW( (<font color="#6464c8">LPCWSTR</font>) pData, L<font color="#669999">"yes"</font> ) == 0)<br /> ::lstrcpyW( (<font color="#6464c8">LPWSTR</font>) pDataToWrite, L<font color="#669999">"no"</font> );<br /> <font color="#6464ff"><b>else</b></font><br /> ::lstrcpyW( (<font color="#6464c8">LPWSTR</font>) pDataToWrite, L<font color="#669999">"yes"</font> );<br /><br /> cbSizeToWrite = (::lstrlenW( (<font color="#6464c8">LPCWSTR</font>) pDataToWrite ) + 1) * <font color="#6464ff"><b>sizeof</b></font>(<font color="#6464c8">WCHAR</font>);<br /><br /> lRet = ::RegSetValueExW( hkey, L<font color="#669999">"Display Inline Images"</font>, 0, REG_SZ,<br /> pDataToWrite, cbSizeToWrite );<br /> <font color="#6464ff"><b>if</b></font> (ERROR_SUCCESS != lRet)<br /> <font color="#6464ff"><b>throw</b></font> L<font color="#669999">"Failed to set the registry key value."</font>;<br /><br /> ::RegCloseKey( hkey );<br /><br /> ::SendMessageTimeoutW( HWND_BROADCAST, WM_SETTINGCHANGE, 0, (<font color="#6464c8">LPARAM</font>) szRegKey,<br /> SMTO_ABORTIFHUNG | SMTO_BLOCK, 3 * 1000, &dwResult ); <font color="#64b464">// wait 3 seconds on each window</font><br /> }<br /> <font color="#6464ff"><b>catch</b></font> (<font color="#6464c8">WCHAR</font> * pwsz)<br /> {<br /> ::MessageBoxW( ::GetDesktopWindow(), pwsz, L<font color="#669999">"Error"</font>, MB_OK | MB_ICONSTOP );<br /> }<br /> <font color="#6464ff"><b>return</b></font> 0;<br />}</font>
Here's a version of the same program that can be compiled using both Unicode and ANSI modes.
<font face="Courier New" color="#000000"><font color="#6464ff"><b>int</b></font> <font color="#6464ff"><b>__stdcall</b></font> <font color="#6464c8">WinMain</font>(<font color="#6464c8">HINSTANCE</font>, <font color="#6464c8">HINSTANCE</font>, <font color="#6464c8">LPSTR</font>, <font color="#6464ff"><b>int</b></font>)<br />{<br /> <font color="#6464c8">HKEY</font> hkey;<br /> <font color="#6464c8">DWORD</font> dwType = REG_SZ;<br /> <font color="#6464c8">BYTE</font> pData[100];<br /> <font color="#6464c8">DWORD</font> cbSize = 100;<br /> <font color="#6464c8">BYTE</font> pDataToWrite[100];<br /> <font color="#6464c8">DWORD</font> cbSizeToWrite = 100;<br /> ::ZeroMemory( pData, <font color="#6464ff"><b>sizeof</b></font>(<font color="#6464c8">BYTE</font>) * cbSize );<br /> ::ZeroMemory( pDataToWrite, <font color="#6464ff"><b>sizeof</b></font>(<font color="#6464c8">BYTE</font>) * cbSizeToWrite );<br /> <font color="#6464c8">DWORD</font> dwResult;<br /><br /> <font color="#6464c8">TCHAR</font> szRegKey[] = <font color="#6464c8">_T</font>(<font color="#669999">"Software\\Microsoft\\Internet Explorer\\Main\\"</font>);<br /><br /> <font color="#6464c8">LONG</font> lRet;<br /><br /> <font color="#6464ff"><b>try</b></font><br /> {<br /> lRet = ::RegOpenKeyEx( HKEY_CURRENT_USER,<br /> szRegKey,<br /> 0, KEY_READ | KEY_WRITE, &hkey );<br /> <font color="#6464ff"><b>if</b></font> (ERROR_SUCCESS != lRet)<br /> <font color="#6464ff"><b>throw</b></font> <font color="#6464c8">_T</font>(<font color="#669999">"Failed to open the Internet Explorer registry key."</font>);<br /> lRet = ::RegQueryValueEx( hkey, <font color="#6464c8">_T</font>(<font color="#669999">"Display Inline Images"</font>), <font color="#6464c8">NULL</font>,<br /> &dwType, pData, &cbSize );<br /> <font color="#6464ff"><b>if</b></font> (ERROR_SUCCESS != lRet)<br /> <font color="#6464ff"><b>throw</b></font> <font color="#6464c8">_T</font>(<font color="#669999">"Failed to read the registry value."</font>);<br /><br /> <font color="#6464ff"><b>if</b></font> (::lstrcmpi( (<font color="#6464c8">LPCTSTR</font>) pData, <font color="#6464c8">_T</font>(<font color="#669999">"yes"</font>) ) == 0)<br /> ::lstrcpy( (<font color="#6464c8">LPTSTR</font>) pDataToWrite, <font color="#6464c8">_T</font>(<font color="#669999">"no"</font>) );<br /> <font color="#6464ff"><b>else</b></font><br /> ::lstrcpy( (<font color="#6464c8">LPTSTR</font>) pDataToWrite, <font color="#6464c8">_T</font>(<font color="#669999">"yes"</font>) );<br /><br /> cbSizeToWrite = (::lstrlen( (<font color="#6464c8">LPCTSTR</font>) pDataToWrite ) + 1) * <font color="#6464ff"><b>sizeof</b></font>(<font color="#6464c8">TCHAR</font>);<br /><br /> lRet = ::RegSetValueEx( hkey, <font color="#6464c8">_T</font>(<font color="#669999">"Display Inline Images"</font>), 0, REG_SZ,<br /> pDataToWrite, cbSizeToWrite );<br /> <font color="#6464ff"><b>if</b></font> (ERROR_SUCCESS != lRet)<br /> <font color="#6464ff"><b>throw</b></font> <font color="#6464c8">_T</font>(<font color="#669999">"Failed to set the registry key value."</font>);<br /><br /> ::RegCloseKey( hkey );<br /><br /> ::SendMessageTimeout( HWND_BROADCAST, WM_SETTINGCHANGE, 0, (<font color="#6464c8">LPARAM</font>) szRegKey,<br /> SMTO_ABORTIFHUNG | SMTO_BLOCK, 3 * 1000, &dwResult ); <font color="#64b464">// wait 3 seconds on each window</font><br /> }<br /> <font color="#6464ff"><b>catch</b></font> (<font color="#6464c8">TCHAR</font> * psz)<br /> {<br /> ::MessageBox( ::GetDesktopWindow(), psz, <font color="#6464c8">_T</font>(<font color="#669999">"Error"</font>), MB_OK | MB_ICONSTOP );<br /> }<br /> <font color="#6464ff"><b>return</b></font> 0;<br />}</font>
This article originally appeared on BeginThread.com. It's been republished here, and may contain modifications from the original article.

