简体   繁体   English

如何更改.exe的图标:任务栏,在左上角,当按下Alt-Tab时的图标

[英]How to change icon of: taskbar, in the top left corner, icon when Alt-Tab is pressed, of my .exe

Platform: Windows 7 平台:Windows 7

IDE: VS2013 IDE:VS2013

Language: C++ 语言:C ++

Windows class: WinAPI Windows类:WinAPI

I have a custom image: Icon.png. 我有一个自定义图片:Icon.png。

I also have a windows class from the msdn sample code to create a basic Win32 window. 我也有一个来自msdn示例代码的Windows类,用于创建基本的Win32窗口。 It has two things hIcon and hIconSm of my windows class structure which I am not sure what they correspond to, but they both are probably related to icons. 我的Windows类结构有两个东西hIcon和hIconSm,我不确定它们分别对应什么,但是它们可能都与图标有关。

I need to: Change the icon of the taskbar to Icon.png, do same thing for the icons in top left corner of the exe, and change the icon which displays when alt+tab is pressed. 我需要:将任务栏的图标更改为Icon.png,对exe左上角的图标执行相同的操作,并更改按alt + tab时显示的图标。

So that means I need to know which variables I change, what functions to use, and what its parameters stand for. 因此,这意味着我需要知道要更改的变量,要使用的功能以及其参数代表什么。 Also if any clicking in VS or additional file creation is needed I also need instructions on how to do that. 另外,如果需要单击VS或创建其他文件,我还需要有关如何执行此操作的说明。

Any help is greatly appreciated. 任何帮助是极大的赞赏。

PS I tried the stuff posted by other people on here but it either didn't work or the instructions were unclear, hence my asking for specifics. 附言:我尝试了其他人在这里发布的内容,但是它要么无效,要么说明不清晰,因此我要求提供详细信息。

So, I found my own answer. 因此,我找到了自己的答案。

A) I could meddle with resource loading (which I did, and came out frustrated and unsuccessful at linking it to the LoadIcon function. A)我可以干预资源加载(我确实这样做了,但是在将其链接到LoadIcon函数时感到沮丧且失败了。

B) Second way: Use LoadImage and cast return value to HICON (hacky apparently, but it worked for all icons I was trying to change!!!!! So, problem solved hah. Below is the pseudocode I used into my project. B)第二种方式:使用LoadImage并将返回值强制转换为HICON(显然是hacky,但是它适用于我尝试更改的所有图标!!!!),因此,问题解决了哈。

   windowclass.hIcon = (HICON) LoadImage( // returns a HANDLE so we have to cast to HICON
   NULL,             // hInstance must be NULL when loading from a file
   "iconfile.ico",   // the icon file name
   IMAGE_ICON,       // specifies that the file is an icon
   0,                // width of the image (we'll specify default later on)
   0,                // height of the image
   LR_LOADFROMFILE|  // we want to load a file (as opposed to a resource)
   LR_DEFAULTSIZE|   // default metrics based on the type (IMAGE_ICON, 32x32)
   LR_SHARED         // let the system release the handle when it's no longer used
   );

So, if you want some other customization to above, I recommend going to MSDN definition of LoadImage and customize your parameters according to it. 因此,如果您要在上面进行其他自定义,建议您转到MSDN的LoadImage定义并根据它自定义参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM