Application Size Increases When Setting Application Icon from Resources - visual-studio-2010

I have an application whose size is 16kb.
After adding an icon resource through the Project Properties menu, the application, as expected, increased to a size of 299kb.
Now, under Properties/Application when I set the Icon File to "Resource\IconName.ico" the file size again increases to 581kb.
Is this normal behavior? I understand that it increases when I add the icon as a resource, but not when I set the icon from the resources to the Application Icon.
Can anyone explain why this is happening?
EDIT:
Maybe a better question would be how can I set the Application Icon using an icon from the Properties/Resources section?

Yes, this is normal behaviour. Your icon isn't being stored as a resource twice (as suggested in some comments), it's simply being linked into the exe during compilation while also being stored as a resource. Since the icon is public-facing (i.e. explorer.exe accesses it directly when rendering the icon), you essentially end up with 2 copies of the icon in different formats:
One copy of the icon compiled directly into the exe in a Windows-standard format
One copy as a .NET resource
If you really want to save this extra space, remove the embedded resource, change your application icon reference to point straight to the icon on disk, then, when you need a copy of the icon to assign to your forms, extract it directly from the assembly:
var executablePath = Assembly.GetExecutingAssembly().Location;
var icon = Icon.ExtractAssociatedIcon(executablePath);

Related

Preview handler dll permissions issue

I'm creating a preview handler dll for a custom graphics file type associated with an application I've developed. For various reasons the preview handler dll is not able to render the graphic for the preview itself. Instead I'm attempting to do it in the following way.
My graphics application associated with the file has been modified to accept specific command line parameters (file path, width, height). With these parameters the application loads the file, renders an image and saves it as a .png file in the user's AppData/Roaming folder and then terminates. This works fine if I call the application from the command line with valid parameters. The .png is created as expected.
When the preview handler is run it calls the application with command line parameters for the file being previewed and dimensions of the preview pane. It does this using the windows function CreateProcess and waits for the application to terminate before continuing.
The preview handler then loads the .png file and draws it to the preview pane.
The problem I'm experiencing is in the second step. The preview handler calls the application but the application gives an error that it is unable to save the .png file ("Cannot create file. Access is denied"). It seems that the application is being run with less permissions when executed by the preview handler than when I run it myself from the command line.
I have tried changing the save location of the file such as user's AppData/Local the shared ProgramData folder and the application's location, but all give the same result. I've also tried setting various CreationFlags in the call to CreateProcess, but none of them help.
Does anyone know why the application doesn't have permissions to save a file when called from a preview handler and is there anything I can do to get it to work? I realise that this is an unusual way of implementing a preview handler, but it's the easiest way without porting a lot of code. Another advantage is that I'm not replicating the rendering code in the main application and the preview handler, which means that the preview handler can be much smaller.
Note that I'm running on Windows 10.
Does anyone know why the application doesn't have permissions to save a file when called from a preview handler and is there anything I can do to get it to work?
Per the documentation:
Preview Handlers and Shell Preview Host
Preview handlers are called when an item is selected to show a lightweight, rich, read-only preview of the file's contents in the view's reading pane. This is done without launching the file's associated application.
...
By default, preview handlers run in a low integrity level (IL) process for security reasons. You can optionally disable running as a low IL process by setting the following value in the registry. However, it is not recommended to do so. Systems could eventually be configured to reject any process that is not low IL.
HKEY_CLASSES_ROOT
   CLSID
      {YOUR HANDLER'S CLSID}
         DisableLowILProcessIsolation
Another advantage is that I'm not replicating the rendering code in the main application and the preview handler, which means that the preview handler can be much smaller.
I would suggest moving the rendering code into a DLL. Export a function that takes a file name/pidl/stream and a target HDC as parameters. The function can read from the file and draw to the HDC as needed. The main app and the preview handler can then share the DLL, calling the function when needed to render the file directly to their respective UIs. You won't need to create a temp .PNG file at all.

When changing the icon of the Hard Drive in MacOS - where are the icns-file actually stored?

Long story short - I bought a new computer and decided not to do a migration from my old Mac to the new one. Still - there are some things I would like to keep and the icon I found years ago to replace the "Macintosh HD" icon is something I very much would like to find.
So my question is - where are these icons actually stored? I've searched "everywhere". It's not in /System/Library/CoreServices/C­oreTypes.bundle/Contents/Resou­rces where the system icons is stored.
Anyone out there with the same level of OCD as me who can help me out?
I'm running Catalina 10.15.1 if relevant.
First of all:
Custom icons that you use to override System default ones will never be stored inside /System/Library/.. as this is a System reserved folder.
On macOS when you paste a custom icon to a folder or file using the Finder Info panel these are stored in the resource fork of the extended attributes of a file/folder.
Now regarding your use case:
In order to see these you need to show the hidden files and you will see
.VolumeIcon.icns on your / local drive (Macintosh HD):
As this is a write protected path (SIP) you cannot store custom data there and instead this .VolumeIcon.icns alias is there and will point to the actual icon file.
If you are still not able to locate the icon file you can always use this next trick. Open the Finder "Info Panel" for your MacintoshHD that has the custom icon and click on the icon representation and copy it to the clipboard (cmd + C) and then open Preview and select "File > New from Clipboard" and then save the icon as icns. Done!

Write data to file and set custom icon

I'm currently developing a macOS cocoa application. Within one of the windows I'm gathering values from multiple arrays and building an xml file as a key/value backup. After saving the file I'm wanting to set a custom icon for the particular xml file. I've searched throughout stackoverflow and the rest of the web and haven't been able to find any solutions. Throughout the different functions within my application I'm able to pull a previously set icon from a file but haven't been able to set one for a newly created file. Any assistance would be greatly appreciated.
In order to change the XML file icon you should use that:
[[NSWorkspace sharedWorkspace] setIcon:iconImage forFile:path options:0];
Where iconImage is a NSImage of the icon and path is the path of the xml file. Note that the change may not be visible until you rename the file or restart the computer. A workaround is renaming the xml file and then renaming it with the old name back again.
Also, note that macOS icons are different of Windows and Linux icons, so that icon may only be visible in macOS systems (in some cases, only in your machine).

How to get the windows applications original size when it is first opened from window handle?

Say I open paint.exe from a c++ code using windows apis or just by clicking it.
After app opened up. I resized it(by hand or programmaticly) . And closed the app.
Next time I open it, it gives me the size from where I left off.
Is there a place where I can query the default size of apps(sizes when you see the apps when you first open it (for the very fist time) before you re size any windows)
And If i can, maybe I can call SetWindowPos to set the original position for that app.
Maybe this is not exactly a programming question.
This is always going to be different between applications.
Most application will remember their window size/position by using the registry. In the case of "paint", it stores this information in the registry at:
HKCU\Software\Microsoft\Windows\CurrentVersion\Applets\Paint\View
Notepad stores similar information in HKCU\Software\Microsoft\Notepad - in an entirely different schema of registry key values.

save the action performed by context menu in vb.net forms app on pc reboot

I have made a vb.net app which hides the utorrent and other less usable icons from tray. I used to fetch these icons in a listview in vb.net and on right clicking the program name, there appears a context menu which hides the icon. But after rebooting the system the icon appears again. Is there any way to save the event in mysettings.settings so that rebooting doesn't affect the action taken... here's my code
Public Shared Sub hideTaskbarIcons(hide As Boolean, indexcnt As Integer)
buttonsOverflow = GetButtons(hwndOverflow)
SendMessage(FindTrayToolbarWindowOverflow, TB_HIDEBUTTON, indexcnt, hide)
end sub
The My.Settings object is for settings that are defined at build-time (such as the state of the application's own notification icon, for instance). Since you want to store the state of a variable number of application icons, you're better off with manually reading and writing an XML document with the System.Xml namespace. You could also store the states in the registry with the Microsoft.Win32.Registry class.
Either of those options will free you from the constraints of the application settings system.

Resources