变量的声明与定义
全局变量theApp
的定义
CXXXXApp theApp; // 定义
在其他类中想要访问全局变量theApp
时,需在stdafx.h
中进行声明
#include "XXXX.h"
extern CXXXXApp theApp; // 声明
三个被系统接管的消息(缺省,虚函数回调)
WM_INITDIALOG
WM_COMMAND:IDOK、IDCANCEL
永远点不到的按钮
给WM_SETCURSOR消息添加处理函数
方法一
BOOL CTestRectDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{if (pWnd->GetDlgCtrlID() == IDC_TEST){RECT rect,rt;pWnd->GetWindowRect(&rect);// 获取的坐标为屏幕坐标系中的坐标this->ScreenToClient(&rect);// 转换为客户区坐标int nWidth = rect.right - rect.left;rect.left += nWidth;rect.right += nWidth;GetClientRect(&rt);if (rect.right > rt.right){rect.right -= rect.left;rect.left -= rect.left;}pWnd->MoveWindow(&rect);}//TRACE("切换%d\n",pWnd->GetDlgCtrlID());return CDialogEx::OnSetCursor(pWnd, nHitTest, message);
}
方法二
BOOL CTestRectDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{if (pWnd->GetDlgCtrlID() == IDC_TEST){CRect rect,rt;pWnd->GetWindowRect(rect);this->ScreenToClient(rect);rect.OffsetRect(rect.Width(), 0); // 平移GetClientRect(&rt);if (rect.right > rt.right){rect.OffsetRect(-rect.left, 0);}pWnd->MoveWindow(rect);}//TRACE("切换%d\n",pWnd->GetDlgCtrlID());return CDialogEx::OnSetCursor(pWnd, nHitTest, message);
}