1.在资源编辑器中添加一个按钮.把它的Bitmap属性设为true
2.在按钮上点右键,添加一个变量m_Btn(CButton类型的)
3.将图片导入到资源管理器中.ID为IDB_BITMAP1
4.然后在初始化中加入如下代码:
HBITMAP hBmp=::LoadBitmap(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_BITMAP1))
m_Btn.SetBitmap(hBmp)
2.依然用vs2005的rc.exe/dll.譬如加LayerManage.ico(1).import icon,导入LayerManage.ico,此时vs会报告32bit无法载入,没事,点确定, 此时发现LayerManage.ico已经被vs改成一个默认的icon.(2)关闭vs,把LayerManage.ico替代成你自己的,重新打开vs就行了lz 你好
具体步骤如下:
(1)右键"资源文件" ->“添加”->"新建项"
(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)运行效果如下:
希望能帮助你哈
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)