lz 你好
具体步骤如下:
(2)选择"资源"->族改"资源文件.rc"->命名为"resource"
(3)菜单栏选择"视图"->"资源视图", 右键"resource.rc"->"添加资源"
(4)选择"Icon"->"导入" 选择你要加入的图标
(5)右键添加好的图标,选择"属性",修改ID
(6)修改源代码,如下:
//IconDemo.c#include<windows.h>
#include"resource.h"//添知指加资源头文件
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM)
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
PSTR szCmdLine,
int iCmdShow)
{
static TCHAR szAppName[] = TEXT("IconDemo")
HWND hwnd
MSG msg
WNDCLASS wndclass
int cxScreen, cyScreen
wndclass.style = CS_HREDRAW | CS_VREDRAW
wndclass.lpfnWndProc = WndProc
wndclass.cbClsExtra = 0
wndclass.cbWndExtra = 0
wndclass.hInstance = hInstance
wndclass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON))//加载图标
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW)
wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH)
wndclass.lpszMenuName = NULL
wndclass.lpszClassName = szAppName
if(!RegisterClass(&wndclass))
{
MessageBox(NULL, TEXT("This 兆猛判program requires Windows NT!"),
szAppName, MB_ICONERROR)
return 0
}
cxScreen = GetSystemMetrics(SM_CXSCREEN)
cyScreen = GetSystemMetrics(SM_CYSCREEN)
hwnd = CreateWindow(szAppName,
TEXT("IconDemo"),
WS_OVERLAPPEDWINDOW,
cxScreen * 7 / 20,
cyScreen / 4,
cxScreen * 3 / 10,
cyScreen / 2,
NULL,
NULL,
hInstance,
NULL)
ShowWindow(hwnd, iCmdShow)
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg)
DispatchMessage(&msg)
}
return msg.wParam
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_DESTROY:
PostQuitMessage(0)
return 0
}
return DefWindowProc(hwnd, message, wParam, lParam)
}
(7)运行效果如下:
希望能帮助你哈
在工程里面添加一个资源文件(.rc文件),然后在资源文件里面添加一个图标(.ico文件)闹笑慎液敬,然后构建工程即可。注:学习版(express版)的VC++2010没有附带图形化的资源编辑器(不过升指可以允许你手工改代码),但是可以编译已经写好的资源文件
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)