在DEV-C ++中更改程序的图标(win32 GUI模式) [英] Changing my program's icon in DEV-C++ (win32 GUI mode)

查看:532
本文介绍了在DEV-C ++中更改程序的图标(win32 GUI模式)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习使用DEV-C ++ 5.11,希望能够制作一个我想到的程序。

在我再继续之前,我想更改生成的程序的图标,但它似乎不起作用。

这就是我所做的:

1 - 我开始一个新项目(文件 - 新建 - 项目 - Windows应用程序)并将其命名为test。这将在其中创建一个通用的main.cpp文件,其中包含WndProc和WinMain函数。

2 - 我编译并运行,它创建了一个程序(test.exe),它只能工作。 3 - 我删除了.exe文件。

3 - 我在项目目录中复制了一个图标文件(test.ico)。

4 - 我将图标设置为项目图标。 (项目 - 项目选项 - 常规 - 图标 - 浏览 - 类型 - Win32 GUI)

5 - 我再次编译并运行,生成的程序可以工作,但仍显示通用图标(在标题栏中,任务栏,在文件资源管理器和Alt + Tab选择器中)。

我缺少什么?任何帮助将不胜感激。

P.S.我在Windows 7上运行,.ico文件是一个有效的图标文件,我从另一个程序中取出并重命名,以便进行测试。



< b>我尝试了什么:



这就是我所做的:

1 - 我开始一个新项目(文件 - 新建 - 项目 - Windows应用程序)并将其命名为test。这将在其中创建一个通用的main.cpp文件,其中包含WndProc和WinMain函数。

2 - 我编译并运行,它创建了一个程序(test.exe),它只能工作。 3 - 我删除了.exe文件。

3 - 我在项目目录中复制了一个图标文件(test.ico)。

4 - 我将图标设置为项目图标。 (项目 - 项目选项 - 常规 - 图标 - 浏览 - 类型 - Win32 GUI)

5 - 我再次编译并运行,生成的程序可以工作,但仍显示通用图标(在标题栏中,任务栏,在文件资源管理器和Alt + Tab选择器中。

解决方案

在您创建的 WinMain 中函数应用程序主窗口通常注册调用 RegisterClassEx

 WNDCLASSEX wc; 
// ...
wc.hIconSm = LoadIcon(NULL,IDI_APPLICATION);
RegisterClassEx(& wc);
HWND hwnd = CreateWindowEx(...);

IDI_APPLICATION 是可删除文件中包含的图标的资源ID。该图标将显示在窗口的标题栏中。您可以将ID更改为可执行文件中存在的任何图标ID。



每个Windows可执行文件都包含嵌入式资源,如图标,字符串,对话框模板,游标,版本信息。用于Windows应用程序的IDE创建一组预定义ID并提供相关资源。



使用Visual Studio,资源在资源源脚本文件中组织( * .rc )和一个或多个带有ID定义的头文件( resource.h 用于项目特定ID)。您可以使用VS资源编辑器修改这些或使用文本编辑器编辑 rc 文件。



我不知道如何开发-C ++处理资源但它应该以类似的方式处理(快速研究表明它似乎也使用 rc 脚本文件)。您必须通过提供ID和图标文件的路径来添加图标资源,或者编辑现有资源脚本文件以更改图标文件的路径。



另请参见关于资源文件(Windows) [ ^ ]。


我终于搞清楚了!

我更换了以下两行

 wc.hIcon = LoadIcon(NULL,IDI_APPLICATION); / *加载标准图标* / 
wc.hIconSm = LoadIcon(NULL,IDI_APPLICATION); / *使用名称A来使用项目图标* /



with

 wc.hIcon = LoadIcon (hInstance,A); 
wc.hIconSm = LoadIcon(hInstance,A);


I'm learning to use DEV-C++ 5.11, hoping to make a program I have in mind.
Before I go any further, I would like to change the icon for the resulting program, but it doesn't seem to work.
Here's what I did:
1 - I start a new project (File - New - Project - Windows Application) and name it "test". This creates a generic main.cpp file in the with the WndProc and WinMain functions in it.
2 - I compile and run, it creates a program (test.exe) which does nothing but works. 3 - I delete the .exe file.
3 - I copy an icon file (test.ico) in the directory of the project.
4 - I set the icon as the project icon. (Project - Project Options - General - Icon - Browse - Type - Win32 GUI)
5 - I compile and run again, the resulting program works but still shows that generic icon (in the title bar, on the task bar, in the file explorer and the Alt+Tab selector).
What am I missing? Any help would be greatly appreciated.
P.S. I'm running on Windows 7 and the .ico file is a valid icon file that I took from another program and renamed, for the sake of the test.

What I have tried:

Here's what I did:
1 - I start a new project (File - New - Project - Windows Application) and name it "test". This creates a generic main.cpp file in the with the WndProc and WinMain functions in it.
2 - I compile and run, it creates a program (test.exe) which does nothing but works. 3 - I delete the .exe file.
3 - I copy an icon file (test.ico) in the directory of the project.
4 - I set the icon as the project icon. (Project - Project Options - General - Icon - Browse - Type - Win32 GUI)
5 - I compile and run again, the resulting program works but still shows that generic icon (in the title bar, on the task bar, in the file explorer and the Alt+Tab selector).

解决方案

Within your created WinMain function the application main window is usually registered calling RegisterClassEx:

WNDCLASSEX wc;
// ...
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
RegisterClassEx(&wc);
HWND hwnd = CreateWindowEx(...);

IDI_APPLICATION is the resource ID of an icon contained in the excutable file. That icon will be shown in the title bar of the window. You may change the ID to any icon ID that is present in the executable.

Each Windows executable contains embedded resources like icons, strings, dialog templates, cursors, version information. An IDE for Windows application creates a set of predefined IDs and provides the related resources.

With Visual Studio the resources are organised in resource source script files (*.rc) and one or more header files with the ID definitions (resource.h for project specific IDs). You can use the VS resource editor to modify these or edit the rc files with a text editor.

I don't know how Dev-C++ handles resources but it should be in a similar manner (a quick research shows that it seems to use rc script files too). You have to add an icon resource by providing an ID and the path to the icon file or edit the existing resource script file to change the path to your icon file.

See also About Resource Files (Windows)[^].


I finally figured it out!
I replaced the following two lines

wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); /* Load a standard icon */
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION); /* use the name "A" to use the project icon */


with

wc.hIcon = LoadIcon(hInstance, "A"); 
wc.hIconSm = LoadIcon(hInstance, "A"); 


这篇关于在DEV-C ++中更改程序的图标(win32 GUI模式)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆