I'm developing application with QT and my window is created with QDialog. When app state is changed I need to change the app's task bar icon:
parentWidget()->setWindowIcon(QIcon(":/new.ico"));
However, in a run-time, if you changed the icon with code above and then make right click to your app's icon (or pin it to taskbar), it will be changed to default one (I suspect to the executable icon).
I found if my icon is reset to default one, I can pin it to taskbar and then unpin back and the icon will be set to the 'new' one.
Is there a way to prevent this somehow and keep the icon always like I want?
Related
I am having some issues with invalidating the Windows icon cache. I'm running a Win32 app that used to show the taskbar icon properly, however, after replacing the app's icon, the taskbar icon appears blank. It's interesting because when I use ALT-TAB, the correct icon does show up.
The window is created with WS_EX_APPWINDOW. I know it registers the correct icon because after pinning/unpinning it from the taskbar, the icon shows up as expected. I’ve gone through several attempts to solve this and have narrowed it down to refreshing the icon cache.
A few of the ways I tried to reset the icon cache:
Delete all icon cache files in folder:
%LOCALAPPDATA%/Microsoft/Windows/Explorer/, and restart explorer.exe
In Command Prompt: $ie4uinit.exe -show
Using Shell APIs to force the taskbar to refresh (SHChangeNotify)
Having gone through several different attempts and configuration techniques, the taskbar icon remains blank as shown above. I was wondering if there is another foolproof technique for resetting the Windows icon cache.
Using MFC in Visual Studio 2012
I want to use a CMFCColorButton in a dialog in my application.
I added the CMFCColorButton button to my dialog in the resource editor (test it, works OK); click on the button and the underlying CMFCColorPopupMenu is display and stay displayed until manually dismissed (choosing a color or clicking somewhere else).
When I build my application and try the button in the dialog, it works differently, when I click the button, the underlying CMFCColorPopupMenu is displayed and immediately dismissed. If I want to select a color, I need to keep the mouse button down.
I tried in a different application (default MFC application) and I get the desired behavior (click and the CMFCColorPopupMenu stay visible).
I am not certain what could trigger the behavior difference.
I try toggling the CMFCColorButton::m_bAutoSetFocus value of the button and there is no change of behavior. ( I am not certain what is the purpose of this variable, but that is another subject)
Any ideas? hints/tips?
Thanks,
Max.
I implemented the possibility to load a custom taskbar icon during runtime dynamically (according to How to set the Windows taskbar icon during runtime? ).
Now I noticed a strange behaviour: the new taskbar icon is set correctly, but Windows 7 still shows the old (original) icon when the "Taskbar buttons" in properties of taskbar are configured to "Always combine, hide labels". When choosing one of the other options the custom icon is shown.
So: any idea what causes this or how to overcome tihs problem? I want to show the custom icon in all configurations of taskbar.
Thanks!
I am trying to change the icon of the application, and I have changed it and the project builds completely fine.
But when the application starts, I still see the default icon on the taskbar. On the otherhand, when I click on About, I can see the new Icon.
What am I missing?
You need to make sure that the resource ID of your icon is the lowest of all the icons in your resources. Windows will display the icon with the lowest ID.
In C++, is there anyway to let the user chose the icon of the app? For example, Winamp lets you select which icon you wish to use from a list of icons in it's preferences. How is it done?
There is the icon that you see in explorer. This is a resource in your executable. You could change that, but I wouldn't advise you too. Virus scanners can get nervous if executables are modified, and in Windows Vista you will not even be allowed to write in the Program Files folder.
But the icon that is displayed on the task bar or in the system tray can be changed. This is actually the icon of your application window and it can be set by sending a WM_SETICON message.
And there are shortcuts. They can be changed too, and in a shortcut you can specify which icon should be used.
I found a discussion on changing icons that has information about the first two options.
For Visual Studio 2010 in an MFC dialog based app
A. In the resource view, rightclick Icon folder and add icon. Give it an ID like IDI_MYICON. Leave it as is or draw something nice.
B. Go to OnInitDialog. Add the following two lines of code:
HICON hMyIcon = LoadIcon( AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_MYICON) );
SetIcon( hMyIcon, FALSE ); // FALSE == use as small icon
You can read about these functions in the help to understand what is happening.
This sets the icon as icon for the sysmenu (topleft) and in the taskbar. This is however not automatically reflected in all situations. E.g. for a systray icon you need to explicitly specify the icon again in the call to Shell_NotifyIcon().