鱼C论坛

 找回密码
 立即注册

WinAPI学习 基础篇 学习笔记_11

热度 2已有 267 次阅读2012-3-17 15:20

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);
}

 
 
 

 

路过

鸡蛋
2

鲜花

握手

雷人

刚表态过的朋友 (2 人)

评论 (0 个评论)

facelist

您需要登录后才可以评论 登录 | 立即注册

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-17 11:32

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

返回顶部