Deleted ico and recreated with different data, icon cache wont update - winapi

I have a ico on my desktop named rawr.ico.
I opened the desktop folder in file explorer:
I atomically overwrite this file with new ico data. I use this algorithm:
https://github.com/Noitidart/Icon-Container-Generator/blob/master/modules/workers/ICGenWorker.js#L1024-L1150
I linked it rather then pasting here, as I don't think this is the problem.
After I do this, the icon on the desktop doesn't update. Double clicking the icon to open it in file viewer, shows the icon contents updated.
As seen in this image:
I tried to get the desktop to update by running this:
SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL);
This refreshes the whle icon cache. I notice icons in my taskbar flash. However on desktop stays the same visually.
I tried to update the item locally:
SHChangeNotify(SHCNE_UPDATEITEM, SHCNF_PATHW, &wcsPath, NULL);
However the icon does not visually update.
Anyone have any ideas whats up?

Related

Application icon becomes blank when folder is changed

I have created an MFC application which has the icon for it as part of its resources. Now, when I place the shortcut to the application on Desktop the icon for the application appears as expected. But now when I create a folder and move this shortcut inside that folder; it becomes blank.
I am facing another situation as well; where the exe kept inside the output folder doesn't show the icon and is blank. But as soon as I change the name of the exe both the icon in the output folder aswell the desktop icon for it appears.
I am using Windows 10 and application is built using VS2008. Could you please help?

How can I add a custom document icon to my documents in a document-based Mac app?

To get custom document icons, do I need to add a new “Icon” set in Xcode’s Assets.xcassets folder by selecting Editor > Add Assets > App Icons & Launch Images > New macOS Generic Icon? Or do I just add a .icns file with appropriate sizes to the Assets.xcassets folder?
Also, I can’t find in the macOS Human Interface Guidelines what a custom document icon should look like. Most of them resemble Apple’s generic document icon with the custom file extension added at the bottom in all caps (TXT, DOCX, etc.). Do we copy Apple’s generic document icon and modify it by adding our own graphic (centered) and extension name across the bottom of it? (If so, where can that template be found?) Do we create another version of that same icon with a preview of the first page of our document (instead of the graphic)—or is that handled by the system automatically? I’ve seen both types of document icons in Finder windows.
If there is any documentation that gives a workflow for creating custom document icons for a Mac or iOS app, I would truly appreciate a reference. I’ve done an enormous amount of reading, but this is my first app. So a step-by-step answer would be most helpful.
Using Assets.xcassets does not really work that well (still with Xcode 10). I'd suggest the following steps:
Generate a ICNS file out of a PNG or TIFF file you designed for your documents, using one of the icon generator tools available in the App Store (see below on how to design a document icon).
Drag the ICNS file into your project (select copy if needed).
Switch to the target settings of your project, select the Info tab. There should be an entry in Document Types.
Select the name of the ICNS file in the drop down menu next to Icon in the document entry.
This should do it. You should see the icon in the document entry. Sometimes the Finder does not display this right away when you save a document, but maybe after a reboot.
On getting a generic document icon: If you save a document from your app without applying an icon to it first, it will show the generic icon. Do a "Get Info" from Finder, select the small icon next to the name on top of the info window and paste the TIFF into some graphic app for editing. GraphicConverter for example features New from clipboard which makes that easy.
You can also get this icon from
/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/GenericDocumentIcon.icns, but then it is in ICNS format already.

How to rebuild Windows Icon Cache without closing explorer.exe or restarting Windows? [duplicate]

This question already has an answer here:
Refresh IconCache.db programmatically
(1 answer)
Closed 6 months ago.
Task
I am trying to customise a folder icon from within my Application but due to the way Windows caches icons and thumbnails I am struggling to get the changed folder to update it's new icon.
In Windows there are two ways that I know of to customise a folders icon, the simplest way is to right click the folder from Windows Explorer, Properties and then select the Customize tab and change its icon, this method is no good though as it requires manually changing the folder properties.
The second way which I am doing from my program is to create a desktop.ini file and place it inside the folder that requires the icon changing, documentation on desktop.ini can be found here: http://hwiegman.home.xs4all.nl/desktopini.html and an article here: http://helpdeskgeek.com/how-to/customize-folder-icons-desktop-ini/
As shown below though, the folder icon in Windows is not updated although you can see from the folder properties that the icon has changed, just Windows is not showing the updated folder icon:
I am fully aware of Windows caching icons and thumbnails, I have searched and read several pages on ways to supposedly rebuild the icon cache and thus get Windows to display the newly changed icon and not the cached one, however I am unable to get this to work from my Application without restarting Windows or the Explorer.exe process, this needs to be done without interrupting Windows though so closing Explorer.exe or requiring a restart is absolutely not an option.
Interestingly though, when changing a folder icon from the first way I described earlier, Windows somehow manages to flush and rebuild the icon cache as the changed folder is promptly updated to show the new icon, however I cannot see what tricks Windows does to achieve this.
Attempts
A few things I tried unsucessfully, (in no particular order):
Executing the following: ie4uinit.exe -ClearIconCache
Running this code in Lazarus: SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nil, nil);
Deleting the IconCache.db file from AppData\Local
Toggling the "Always show icons, never thumbnails" Explorer option from the registry, located here: HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced which is stored in the IconsOnly value
Changing the icon size from the registry and back, located here: HKEY_CURRENT_USER\Control Panel\Desktop\WindowMetrics which is stored in the Shell Icon Size value
This link provides an apparent solution in Delphi which I was unable to convert in Lazarus: http://www.aha-soft.com/faq/q18.htm
I am aware of cached db files here: AppData\Local\Microsoft\Windows\Explorer although I am not sure if they are of any help, attempting to delete some of them does not seem possible as they may be locked etc.
Renaming the folder and then rename back to original name.
Right click an empty space in Windows Explorer and selecting Refresh does not seem to update the folder icon either.
Have also tried performing some of the above in combination with no luck.
Question
When changing a folder icon directly from Windows Explorer, using the properties context menu and customize tab, when applying and closing this dialog the folder icon is changed almost immediately, there is no closing explorer.exe or restarting Windows, the change happens very much right away.
How can I achieve this from my Application programmatically the same way Windows Explorer does? Is there a way to find out how Windows Explorer does this?
My Operating System is Windows 10 which could explain why some of the older methods don't work for me.
I don't think this is anything to do with icon caching; you just need to inform Explorer that the folder's icon has changed. You can do this using the SHChangeNotify function.
LPCWSTR pszFolder = L"c:\\path\\to\\folder";
SHChangeNotify(SHCNE_UPDATEITEM, SHCNF_PATH, pszFolder, NULL);

Visual Studio icon looks bad

I'm having trouble with my application icon looking bad after adding it into my project, building it, and creating a shortcut to it.
Here's what I've done:
1) I started with a 256x256 PNG file that looks great.
2) I used IcoFX to generate a .ICO file with all the recommended sizes.
3) I add the icon to my project as follows:
A) Open project properties -> Resources -> Add Resource -> Add Existing File
B) Choose the .ICO file that I created in step 2.
4) Go to "Application" section of project properties.
5) In "Icon and Manifest", drop down "Icon" and choose the icon that I added in step 3.
6) Save my project and build it.
7) Go to Windows Explorer and find the newly built EXE.
8) Create a shortcut to the EXE on the desktop.
The icon looks like this:
As you can see, it doesn't look very good. The edges are jagged, etc.
At first, I thought it was an issue with my .ICO file, but here's the kicker... I then did the following:
9) Right-click on the desktop icon, and go to Properties.
10) Go to the Shortcut tab and click "Change Icon".
11) Click "Browse", and select the EXACT SAME ICON FILE that I added to my project in step 3.
Now, my desktop icon looks like this:
Now, the icon looks pretty and smooth!
Again, both icons used the exact same source .ICO file. The only difference is that the first one was imported into Visual Studio and embedded in my .EXE, and the other one was directly used via the OS.
What is Visual Studio doing to my icon to make it look so crummy, and how can I prevent it?
This could be a problem with the windows icon cache. I had the same problem that I fixed by clearing the cache.
The first version of your code that you copied to the desktop - did this have a low res icon ?
Windows will cache the icon when it first sees the EXE, and then does not refresh even when you rebuild your executable if it has the same filename. You will also see the same behavior in windows explorer.
I think by changing the icon through the OS, you've just manually refreshed the icon cache.
You can quickly test this by renaming the EXE before copying it to the desktop. This will bypass the cache and show the actual icon in your EXE.
To get rid of any old icons in the icon cache, you can clear it as described in this link
http://www.winability.com/how-to-erase-icon-thumbnail-cache-windows-8/

How to create drag-and-drop installer for MacOS X?

What tools are used to create installers like this:
EDIT:
Here's a full tutorial: http://chromasoft.blogspot.com/2010/02/building-dmg-installer-for-mac-simple.html
It's just a folder with a custom background image (right click on the folder background and select "Show View Options"; Firefox also sets a larger icon size and adjusts the grid to match, also in the same place). The link to /Applications is created by Control-dragging. Once you have the original folder set up, you can use hdiutil to create a DMG disk image from the folder.
goin to Disk Utility
File>New Image>Blank Image
Select the Settings (Size must be lager than files you want to store)
Open DMG to mount the image
Drag into the folder of image your App, and an Applications Folder Alias.
Right-Click on image folder>Show View Options .
And then you can customize your background, etc.

Resources