Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Yes, I can reproduce the problem you describe when I use the same code as shown in the question. As we've since determined, the issue only manifests itself at high DPI settings. At 100% scaling (~96 dpi), even on Windows Vista and later, you only need to use the "large" version of the icon (<code>SM_CXICON</code> and <code>SM_CYICON</code>; typically 32x32 pixels) for a window, not the 256x256 pixel version. That's what the apps bundled with Windows do, including the Volume Mixer applet that you're testing with.</p> <p>The issue comes when you're using high DPI settings, which makes the "large" size go up:</p> <pre class="lang-none prettyprint-override"><code>╔════════════╦═════════════════╦═════════════════╗ ║ DPI ║ Large Icon Size ║ Small Icon Size ║ ║ ║ (SM_C?ICON) ║ (SM_C?SMICON) ║ ╠════════════╬═════════════════╬═════════════════╣ ║ 96 (100%) ║ 32x32 ║ 16x16 ║ ║ 120 (125%) ║ 40x40 ║ 20x20 ║ ║ 144 (150%) ║ 48x48 ║ 24x24 ║ ║ 192 (200%) ║ 64x64 ║ 32x32 ║ ╚════════════╩═════════════════╩═════════════════╝ </code></pre> <p>Things work fine regardless of DPI when you load the 256x256 pixel icon, because Windows is automatically scaling it down to the required size. That generates a much better quality icon (without all the jaggies and other artifacts) than attempting to scale <em>up</em> a 32x32 pixel icon. So your guess is correct, the problem is indeed related to scaling.</p> <p>I'm going to assume that what you're seeing in the Volume Mixer applet when you use a 256x256 pixel icon is a bug—it should be scaling that large icon down to the size it expects, which is a "large" icon (<code>SM_C?ICON</code>). Presumably, it's calling the <code>DrawIconEx</code> function with the <code>cxWidth</code> and <code>cxHeight</code> parameters both set to 0 and <em>not</em> passing the <code>DI_DEFAULTSIZE</code> flag. That's causing the icon to be drawing using its actual size—huge.</p> <p>You'll have to work around the problem manually, by scaling the icons yourself. Fortunately, Windows Vista introduces a number of functions that are designed explicitly for this purpose. The easiest one to use in this case is <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb775703.aspx" rel="nofollow"><code>LoadIconWithScaleDown</code></a>. Like the name suggests, it works similarly to the older <code>LoadIcon</code>/<code>LoadImage</code> functions, but rather than scaling up an icon that is too small, it scales down a larger icon—perfect for when you have a giant, high-quality 256x256 pixel icon in your ICO file.</p> <p>Unfortunately, these functions are not available on older versions of Windows, which will likely have the same problem when used at higher DPI settings. You'll need to find alternatives there, or just settle for jagged, scaled icons on these older OSes.</p> <p>Sample code:</p> <pre><code>#include &lt;CommCtrl.h&gt; // include Common Controls header #pragma comment(lib, "comctl32.lib") // link to Common Controls library // Embed a standard manifest to use Common Controls v6 #pragma comment(linker, "/manifestdependency:\"type='win32' " \ "name='Microsoft.Windows.Common-Controls' version='6.0.0.0' " \ "processorArchitecture='*' " \ "publicKeyToken='6595b64144ccf1df' " \ "language='*'\"") </code></pre> <pre><code>// Load and set "large" icon (typically 32x32 pixels, but not necessarily) HICON hIconLg; if (SUCCEEDED(LoadIconWithScaleDown(g_hInstance, MAKEINTRESOURCE(IDI_ICON), GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), &amp;hIconLg))) { SendMessage(hWnd, WM_SETICON, ICON_BIG, reinterpret_cast&lt;LPARAM&gt;(hIconLg)); } // Load and set "small" icon (typically 16x16 pixels, but not necessarily) HICON hIconSm; if (SUCCEEDED(LoadIconWithScaleDown(g_hInstance, MAKEINTRESOURCE(IDI_ICON), GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), &amp;hIconSm))) { SendMessage(hWnd, WM_SETICON, ICON_SMALL, reinterpret_cast&lt;LPARAM&gt;(hIconSm)); } </code></pre> <p>Note that to use these new functions, you will need to link to version 6 of the common controls library. That requires that you instruct the compiler to link in <code>comctl32.lib</code> and embed a manifest in your application. Either can be done using the MSVC-specific <code>#pragma</code>s shown in the sample code above, or configured in your project's properties. If you fail to do either of these things, you'll get a link-time error or an "ordinal not found" error when you first launch the app.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload