1.资源的概念
资源是数据,他们被保存于一个程序的. EXE 程序中,但他们不再可执行程序的数据区。不能再程序代码中用变量直接寻址,Window提供了函数来将其加载到内存中,如:
HICON LoadIcon(
HINSTANCE hInstance,// handle to application instance
LPCTSTR lpIconName // name string or resource identifier
);
HCURSOR LoadCursor(
HINSTANCE hInstance, // handle to application instance
LPCTSTR lpCursorName // name or resource identifier
);
HMENU LoadMenu(
HINSTANCE hInstance, // handle to module
LPCTSTR lpMenuName // menu name or resource identifier
);
HGLOBAL LoadResource(
HMODULE hModule,// module handle
HRSRC hResInfo // resource handle 自定义资源
);
int LoadString(
HINSTANCE hInstance, // handle to resource module
UINT uID, // resource identifier
LPTSTR lpBuffer, // resource buffer
int nBufferMax // size of buffer
);
2.资源包括: Icon
Cursor
String
自定义资源
Menu
Dialog
Bitmap
3.创建这些资源会生成一个 资源脚本文件和一个头文件,后缀名分别为:*.RC *.h 。
ICONDEMO.RC
#include "resource.h"
IDI_ICON ICON DISCARDABLE "icon1.ico"
Resource.h
#define IDI_ICON 101
#define IDM_APP_EXIT 40001
#define IDM_BKGRD_WHITE 40002
4.获得图标句柄( 在 上上课中专门说明)
获得图标句柄有三种方式:分别为通过MAKEINTRESOURCE宏,字符串和数字三种方式定义。
LoadIcon (hInstance, MAKEINTRESOURCE(IDI_ICON)) ;
LoadIcon (hInstance, szAppName) ;
LoadIcon (hInstance, MAKEINTRESOURCE (125)) ;