How do you set icons of .exe files? - c++

Preferably using C++. Or a tool I can use from the command line. So far I've figured out how to extract icons from .exe files, but I can't set icons... Any suggestions?

If you want an icon to show in Explorer in a directory list, you'll need to add an icon to your app's .rc file. It must be the first icon in the resource file.
Do you want an icon to appear in the task bar and have it associated with your app's window? In this case you must set the hIcon member in your registered WNDCLASS structure.

Here's a code sample that might help:
Change Icon of EXE file through code extracting it from other EXE file

Related

Show mp3 files but select folder with QFileDialog

Currently, I can select a folder using QFileDialog's getExistingDirectory function. Even thought I managed to let the dialog show the files as well, I would like to filter them, i.e. display only folders and *.mp3 files.
QString folder = QFileDialog::getExistingDirectory(this, "test", "", QFileDialog::ReadOnly);
Is this possible without creating a custom dialog?
QFileDialog d(this);
d.setFileMode(QFileDialog::Directory);
d.setNameFilter("*.mp3");
if (d.exec())
qDebug () << d.selectedFiles();
I am on mobile rt now. Giving a kind of hints only....
On Windows and macOS, this static function will use the native file dialog and not a QFileDialog. However, the native Windows file dialog does not support displaying files in the directory chooser. You need to pass DontUseNativeDialog to display files using a QFileDialog. ( from qfiledialog documentation)
So set the 'QFileDialog::DontUseNativeDialog' option using 'setflags'
Then using file dialog's 'setfilter' set the filter for your MP3 files..

Cant open html resource file using ifstream::open - Visual Studio 2013

I am working on a project which requires me to open an HTML file and use its contents. I added it to Resource files but when I try to open it lie this:
std::ifstream templateFile;
templateFile.open("filename.html", std::ifstream::in);
The operation fails. I checked it by using templateFile.fail().
The above operation works when I provide the full path. The file lies in the project folder along with other files. I tried setting build action to content but still it doesnt work. Please Help.
Output directory, where your executable is compiled and put into differs from the source directory, where you create all your .cpp/.hpp files (I assume there is filename.html file). Local path filename.html is supposed to be local for your executable file, not the source file.
Read more about changing the output directory here: https://msdn.microsoft.com/en-us/library/ms165410.aspx
Under Configuration Properties / Debugging, see what your Working Directory is using the macros dialog box. Move your file into this folder.
Click the button shown in the figure. There, click either Edit or Browse. Browse will take you to the working directory. Edit will expose the link to open the macros box

How can I quickly rename an open file in WebStorm?

The documentation for WebStorm says if you want to rename a file, do it in the Project Tool window. The problem is that finding a file in the Project Tool window is a hassle. If you start typing there to find the file, it won't be able to locate it unless it is in an expanded folder.
How can I easily rename a file in WebStorm?
There is no way to rename file right from the editor. Try Navigate/Select In.../Project view to open a file in Project Tool window and then use Refactor/rename in its right-click menu
You can also enable the 'Autoscroll from source' Project tool window option to have the currently opened file auto-selected in the project tree
Also, Refactor/rename is available in file right-click menu in the Navigation Bar if it's enabled (View/Navigation bar)
In addition to that, You can use the shourtcut.
Click on the file in the project window & Press the buttton Shift+F6.
Right click on the file -> Refactor -> Rename or just use Shift+F6 as a shortcut and a dialog window will open up so you can change the name.

Creating shader files

I'm trying to learn some DirectX11 and I found good tutorial I'm following; however, for some reason the program crashes (The window appears but then a "not responding" message box appears), even though the build was successful. There were some thing about creating shader-files the author did specify on how to do, and i wanted to make sure I'm not making any errors there and that why my program crashes. So my questions are :
How do you create a shader files? In the tutorial we are using the extension .fx, but when you add a file in vs you can only choose from .h and .cpp . Do you only have to select .cpp and then add .fx in the end of the file name?
In what directory is the file suppose to be? (My files are currently in Source Files)
Yes that will work. Another way to do it is just to create a .txt then change the extention to .fx
(To show the file extention just open any folder, click on the organize button in the menu then choose "folder and search options". Uncheck the box "Hide extentions for know file types" under the tab view). After you change the extention you can open the document in notepad and write your code there
Go in to your project folder (in windows file system) and create a map called Data. Add you .fx file there. Then go to your solution explorer and rigth click on the project and choose properties. Go to Build Events -> Pre- Build Events. Add the line "xcopy /y /d "$(ProjectDir)Data" "$(OutDir)" in the box "Command Line". Now when building your project the files will be copied to the rigth place and you will be able to use your .fx file.
The .fx is associate it with an effect file. Meaning you have a combination of many shaders in the same file. Can you post some code of your render loop... also, are you calling the Present method?i.e.,
m_pSwapChain->Present(0, 0);

Where can I find the default icons used for folders and applications?

I'm trying to load the default HICON that explorer displays for:
An open folder
An exe that has no embedded default icon of its own. This can also be seen in 'Add/Remove Programs' or 'Programs and Features' as it's called on Vista.
Do you know where these can be found? I think the folder icon might be in the resources of explorer.exe. But have no idea where the default application icon can be retrieved from.
And additionally, do you have any sample code that could load them into HICONs.
I really need this to work on multiple Windows OSs: 2000, XP, Vista, 2008
Thanks for the help so far. I'm on Vista and have looked through Shell32.dll. I don't see an icon in there that looks the same as the default one displayed by an application in explorer. I could be missing it - there are 278 icons to look through - is it definitely in there, or is there some other location I should look?
Use the SHGetFileInfo API.
SHFILEINFO sfi;
SecureZeroMemory(&sfi, sizeof sfi);
SHGetFileInfo(
_T("Doesn't matter"),
FILE_ATTRIBUTE_DIRECTORY,
&sfi, sizeof sfi,
SHGFI_ICON | SHGFI_SMALLICON | SHGFI_USEFILEATTRIBUTES);
will get you the icon handle to the folder icon.
To get the 'open' icon (i.e., the icon where the folder is shown as open), also pass SHGFI_OPENICON in the last parameter to SHGetFileInfo().
[edit]
ignore all answers which tell you to poke around in the registry! Because that won't work reliably, will show the wrong icons if they're customized/skinned and might not work in future windows versions.
Also, if you extract the icons from system dlls/exes you could get into legal troubles because they're copyrighted.
Vista added SHGetStockIconInfo and so on NT6+ its the best way.
Archive of MSDN documentation that shows the available icons
On older platforms, SHGetFileInfo like Stefan says.
If you want to use undocumented stuff, the first 5 or so icons in the system image list includes the default folder and application icon (system image list is NOT shared on NT, but for some reason, all the copies get the first 5 or so icons without asking for them with SHGetFileInfo)
These default icons come from shell32.dll by default, but can be changed in the registry:
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Icons
In Visual Studio:
click on File|Open
select
C:\WINDOWS\System32\Shell32.dll
VS will open the file using the resource explorer. You can now look at all the icon & other resources embedded in shell32.dll.
I think they are in %windir%\system32\SHELL32.dll
Found some code in the internet, try if that works:
HINSTANCE hDll;
hDll = LoadLibrary ( "SHELL32.dll" );
wincl.hIcon = LoadIcon (hDll , MAKEINTRESOURCE ( 1 ));
wincl.hIconSm = LoadIcon (hDll, MAKEINTRESOURCE ( 2 ));
Edit: Windows has a lot more icons in the "moricons.dll", but I think the file and folder icons should all be in the shell32.dll. Remind, that icons in Vista have different resolutions, up to 256x256, so the icon you are looking at a resolution 32x32 might look different then the full resolution version of the same icon.
The user's selected icon can be found in the registry at HKEY_CLASSES_ROOT\Folder\DefaultIcon
By looking up the value here, you'll also pick up if they've changed it for whatever reason.
For folders where a desktop.ini file exists, you'd need to read the IconFile and IconIndex entries.
If you are in MFC, following code for loading icons should work.
HICON hicon;
hicon = LoadIcon(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ICON1));
In the above example, AfxGetResourceHandle() is the only thing where MFC is used, otherwise LoadIcon is an API call as far as I remember.
Icons are available in windows\system32\shell32.dll
If you have visual studio installed, then visual studio is also shipped with a set of icons at a path like this "C:\Program Files\Microsoft Visual Studio 9.0\Common7\VS2008ImageLibrary"
It's probably in explorer.exe.
it's much easier, just open the shell32.dll with resource hacker
and right-click on "ICONS" and save all icons resource in a directory.
and you'll get all the windows default icons in that directory.
[link]http://www.angusj.com/resourcehacker/[/link]