1.
光标资源
HCURSOR LoadCursor(
HINSTANCE hInstance, //实例句柄
LPCTSTR lpCursorName //光标定义
);
#define MAKEINTERSOURCE(i) (LPTSTR)((DWORD)((WORD)(i)))
//系统默认
IDC_APPSTARTING Standard arrow and small hourglass.
IDC_ARROW Standard arrow.
IDC_CROSS Crosshair.
IDC_HAND Hand.
IDC_HELP Arrow and question mark.
IDC_ICON Obsolete.
IDC_NO Slashed circle.
IDC_SIZE Obsolete; use IDC_SIZEALL.
IDC_SIZEALL Four-pointed arrow pointing north, south, east, and west.
IDC_SIZENESW Double-pointed arrow pointing northeast and southwest.
IDC_SIZENS Double-pointed arrow pointing north and south.
IDC_SIZENWSE Double-pointed arrow pointing northwest and southeast.
IDC_SIZEWE Double-pointed arrow pointing west and east.
IDC_UPARROW Vertical arrow.
IDC_WAIT Hourglass.
//设置光标 要注意设置 热点
//设置光标
HCURSOR SetCursor(
HCURSOR hCursor
);
加载字符串资源 做多语言 不同语言进行资源切换
int LoadString(
HINSTANCE hInstance, //实例句柄
UINT uID, //字符串资源ID
LPTSTR lpBuffer, //缓冲器首地址 输出
int cchBufferMax //最大字节数
);
//查找自定义资源
Insert -> Custom //自定义
//查找资源
HRSRC FindResource(
HMODULE hModule, //全局对象
LPCWSTR lpName, //资源名称
LPCWSTR lpType //是个字符串 不是宏
);
//加载资源
HGLOBAL LoadResource(
HMODULE hModule,
HRSRC hResInfo //资源句柄
);
//锁定资源 得到资源在内存中的首地址
LPVOID LockResource(
HGLOBAL hResData
);
/////////////////////////////////////////////
#include <windows.h>
#include "resource.h"
static TCHAR CURSORNAME[] = "MYCURSOR";
LRESULT CALLBACK MyWinProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
);
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nShowCmd)
{
WNDCLASS wndClass;
TCHAR* strClassName = TEXT("lovt");
HWND hWndMsg;
MSG msg;
ZeroMemory(&wndClass, sizeof(WNDCLASS));
wndClass.cbClsExtra = 0;
wndClass.cbWndExtra = 0;
wndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wndClass.hCursor = LoadCursor(hInstance, CURSORNAME);
// wndClass.hCursor = LoadCursor(hInstance, MAKEINTRESOURCE(IDC_CURSOR1));
wndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndClass.hInstance = hInstance;
wndClass.lpfnWndProc = MyWinProc;
wndClass.lpszClassName = strClassName;
wndClass.lpszMenuName = NULL;
wndClass.style = CS_HREDRAW | CS_VREDRAW;
if(!RegisterClass(&wndClass))
{
MessageBox(NULL, TEXT("注册失败!"), TEXT("ERROR"), MB_OK);
}
hWndMsg = CreateWindow(strClassName,
TEXT("光标"),
WS_OVERLAPPEDWINDOW | WS_HSCROLL | WS_VSCROLL,
100, 100, 400, 300,
NULL,
NULL,
hInstance,
NULL
);
ShowWindow(hWndMsg, nShowCmd);
while(GetMessage(&msg, hWndMsg, 0, 0)) //从消息队列中获取消息 如果HWND 为NULL 获取系统消息队列
{
TranslateMessage(&msg); //键盘消息转换
DispatchMessage(&msg); //消息传回windows windows调用消息处理函数
}
}
#define WM_MYUSER WM_USER+1 //非系统标识符
LRESULT CALLBACK MyWinProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam )
{
static HINSTANCE hInstance;
static HCURSOR hCuror;
HDC hdc;
switch(uMsg)
{
case WM_CREATE:
hInstance = ((LPCREATESTRUCT)lParam)->hInstance;
return 0;
case WM_LBUTTONDOWN:
return 0;
case WM_MOUSEMOVE:
hCuror = LoadCursor(hInstance, MAKEINTRESOURCE(IDC_CURSOR1));
SetCursor(hCuror);
return 0;
case WM_DESTROY:
PostQuitMessage(0); //非队列消息
return 0;
default:
break;
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}