逃跑按钮的实现函数

①、CWnd::GetWindowRect 与 CWnd::GetClientRect 的区别:(获取当前窗口)
GetWindowRect 函数:屏幕坐标系,同时包括窗口的标题栏与边框的大小;
GetClientRect 函数:本身窗口坐标系,左上角坐标始终为(0, 0),不包括窗口标题与边框的大小;

全局的 SDK API 函数:(获取指定窗口)
BOOL GetWindowRect(HWND hWnd, LPRECT lpRect); 与 CWnd::GetWindowRect 同
BOOL GetClientRect(HWND hWnd, LPRECT lpRect); 与 CWnd::GetClientRect 同

备注:在对话框的初始化函数 OnInitDialog() 中调用 GetWindowRect 函数时,得到的窗口左上角坐标也是(0, 0),
是因为系统在创建窗口的时候,先在屏幕的左上角的位置进行创建,之后再移动到屏幕的指定位置。

②、屏幕坐标与窗口坐标的转换:
CWnd::ClientToScreen

void ClientToScreen(
   LPPOINT lpPoint
) const;
void ClientToScreen(
   LPRECT lpRect
) const;

CWnd::ScreenToClient

void ScreenToClient(
   LPPOINT lpPoint
) const;
void ScreenToClient(
   LPRECT lpRect
) const;
lpPoint
Points to a CPoint object or POINT structure that contains the screen coordinates to be converted.

lpRect
Points to a CRect object or RECT structure that contains the screen coordinates to be converted.

 

全局的 SDK API 函数:
BOOL ScreenToClient(
  HWND hWnd,        // handle to window
  LPPOINT lpPoint   // screen coordinates
);

BOOL ClientToScreen(
  HWND hWnd,       // handle to window
  LPPOINT lpPoint  // screen coordinates
);

MoveWindow 改变窗口的大小和位置;
SetWindowPos 函数也同样有 MoveWindow 函数的功能,但更灵活,多用于只修改窗口的位置而大小不变或只修改窗口的大小而位置不变的情况

③、“逃跑”按钮的实现

④、要取得 [a, b) 之间的随机整数,使用 (rand()%(b-a))+a (结果值将含a不含b)
在 a=0 的情况下,简写为 rand()%b

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值