How to manage the application icon on the taskbar? - winapi

Intro:
OS: Windows 10
DPI: 96
I got metrics of recommended sizes small (16x16) and large (32x32) icons of my application, called SetClassLong function to set him. Everything is working!
BUT!! After launching the application, the icon displayed in the taskbar has a size of 24x24.
Why such a size? I setted only the recommended 16x16 and 32x32? How can I control the real icon in the taskbar (except for calling SetOverlayIcon)

How can I give the system a 24x24 icon (which one should it be for
other dpi?) If the metric request recommends me 16x16 and 32x32?
Forget about the GetSystemMetrics() since it hasn't been updated in ages. To provide a 24x24 icon that Windows 10 uses for display on the task bar just set the hIcon member of your WNDCLASS to such icon.

Related

Make Windows Common Dialogs "Per Monitor DPI-Aware"

I have a program which was created in VS2008 with MFC.
Now I've modified it to make it "Per Monitor DPI-Aware", and it's almost done. I've modified the manifest and handled the WM_DPICHANGE message. But there's still one problem:
I used CFileDialog class to show Open/Save dialogs, and used SHBrowseForFolder function to show folder selection dialog. But all these dialogs are NOT "Per Monitor DPI-Aware", they won't adjust their UI when you move them between monitors with different DPI settings.
I use spy++ to monitor messages of these dialogs, I find they can receive WM_DPICHANGED message but they just don't handle it.
And I've tested the open file dialog in notepad.exe on Windows 10, it worked perfectly.
Does anyone know how can I make these dialogs "Per Monitor DPI-Aware"?
--------EDIT--------
There're two more problems:
When I move a window to a monitor with different DPI, the window resize itself, but the height of it's title bar and title font-size are not changed.
The checkbox controls' box size is not changed either.
I feel these problems may have some kind of connections, but I can't figure it out.
--------SAD NEWS--------
I compiled microsoft's "DPI Tutorial Sample" with VS2013, and it has the same problem.
https://code.msdn.microsoft.com/DPI-Tutorial-sample-64134744
The titlebar (caption bar) can be scaled by calling EnableNonClientDpiScaling which is available on versions of Windows >= the Windows 10 Anniversary Update (1607).
If you want to DPI scale an older dialog that doesn't support per-monitor DPI scaling you can use SetThreadDpiAwarenessContext (with DPI_AWARENESS_CONTEXT_SYSTEM_AWARE or DPI_AWARENESS_CONTEXT_UNAWARE) to have the top-level windows of the dialog scaled by Windows. The dialog might be blurry but it will at least be sized correctly (also only available on >= 1607 builds of Windows 10). The usage pattern is to call this API before opening the dialog and then restore the previous DPI context immediately after calling the API.
According to MSDN the window that processes WM_DPICHANGED message should return 0. However, any MFC window or control you send WM_DPICHANGED will return 0, since thay call the default window procedure for the unknown messages.
Therefore, judging if some window does process WM_DPICHANGED message by testing its LRESULT return value against zero is not accurate.
The window's title bar of a per-monitor DPI aware application doesn't scale when moving across different DPI monitors as documented on MSDN. Unfortunately, non-client area of the window never adjust the DPI.
Calculator and other per-monitor DPI aware Windows native apps have custom title bar drawing, as described here.

Setting small and large icon in Visual C++

I am porting an old (Visual Studio 6.0) application to Visual Studio 2012 in order to add some enhancements. The application's icon in the resources view clearly has 2 versions of the icon, a 32x32 4bit bitmap and a 16x16 4bit bitmap.
In the main AppDlg.cpp there are 2 calls to SetIcon() as follows (created by default by MFC app wizard):
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
However, the icon displayed in the top left corner of the application's dialog window is the larger one, scaled down to 16x16 instead of the small one. Its also happening for the icon shown in the system tray.
It seems it uses the correct small one for the executable file when viewing it in Windows Explorer (detailed view / list view). So it is picking the small one in some circumstances.
How do I make it choose the smaller 16x16 icon for the top left corner of the dialog box and System tray?
Known Microsoft bug. See this discussion. (if you do not want to read, just comment out SetIcon(m_hIcon, FALSE) line and you'll be fine). Please note, that SetIcon only sets the icon on the dialog title bar (small icon) and when you use Alt-tab (big icon)
The icons you see in the Windows Explorer are the main Application Icons (the icon with the lowest ID in you rc file). It has nothing to do with the main dialog's SetIcon() method
The icon in the System Tray is something completely different. Normally, you would use Shell_NotifyIcon API to set the icon, but I bet your project would have a helper class that sets the icon CSystemTray by Chris Maunder is a popular one used by many programmers. Just search for Shell_NotifyIcon in your program to find out exactly what resource is used for the system tray icon

How can I tell if the taskbar is using small icons

I'm looking for a way to detect if the user is using small icons :
I couldn't find anything in GetSystemMetrics \ SystemParametersInfo.
I tried to use the "Running applications" window's size :
it works fine when the taskbar's orientation is bottom\top, but when it's left\right this window takes the entire taskbar width.
Any ideas?
Deskbands are not quite dead on Windows, but they are on life-support. First make sure if you don't want to take advantage of thumbnail toolbars, ITaskbarList3::ThumbBarXxx() functions.
I'm not aware of an api to read back the button size setting. There's a backdoor you can use, these configuration settings are always saved to the registry. Run SysInternals' ProcMon utility and change the setting. On my machine (Windows 8), out popped this registry key:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\TaskbarSmallIcons
That almost surely works, I can't guarantee anything beyond Windows 8 of course.

Windows Mobile 6.5 Running Program List Icon

I've got an windows mobile 6.5 application I'm developing and am having trouble with one icon. At the top right hand of the screen there is an icon that, when clicked, will display a list of programs running the background with the option to close them.
When my program is in this list, it's icon does not show up as the others do.
I'm my exe I've got an .ico for 16x16, 22x22, 32x32, 36x36, 44x44, 45x45, 60x60, and 64x64, with the optional 90x90 png and registry setting in my cab.
What am I missing?
I'm just guessing here, but is this an HTC phone? Stock Windows Mobile does not have a "task list" icon in the system tray, so this task list is provided by the OEM. You would need to find out how they are obtaining the icon.
Chances are they are not obtaining it from the cab, but are actually getting it from your top level app window. You should check you're specifying the right icon in your WNDCLASS structure when calling RegisterClass. It is pretty common in WM to forget this because normally this icon is not visible.
Windows Embedded Handheld (Windows Mobile) 6.5/6.5.3 Appications use the exe embedded ico files only if there is no icon via registry available. In those cases the icon also look very ugly in the start menu. So you will have to add a registry entry to an icon file.
[HKEY_LOCAL_MACHINE\Security\Shell\StartInfo\Start\MyApp.lnk]
"Icon"="\Windows\myapp.png"
See also: https://blogs.windows.com/windowsexperience/2009/08/11/using-custom-icons-in-windows-mobile-6-5/

Control Panel Item Icons (Windows XP)

Control Panel items are normally registered under HKLM\Software\Microsoft\Windows\CurrentVersion\Explorer\ControlPanel\NameSpace, however a lot of the built-in panels aren't listed there, such as the Automatic Updates item.
I'm trying to find out where the icon used for the Automatic Updates item is. If you open the Control Panel in Tiles mode (48x48 icons) you'll see the icon is being scaled up, yet all of the icon resources in all of the Windows Update files have 48x48 subimages, so I can't figure this one out.
It's a similar story with the NVidia control panel item: the icon is black and seemingly downscaled from a subimage larger than 48x48, yet the actual nvidia control panel files don't contain this black icon (instead they have the silver version). When I create a Shortcut to the control panel item and inspect its binary bits there is no path to the icon specified, just to the cpl file itself (with the totally different icon). I've checked the registry and there aren't any clues in there either.
Any ideas?
Control Panel applets can be registered in several different ways, or not at all (if they reside in the %system% folder):
Registering Control Panel Items
If an applet does not register its icon information in the Registry, then the applet has to provide the icon information when requested by the Control Panel via the CPL_INQUIRE and/or CPL_NEWINQUIRE messages to its CPLApplet() entry point, in which case the applet has no idea what size icon to return. It sounds like maybe you are running into that scenario.

Resources