主题:[讨论]关于鼠标响应问题,帮我看一下哪里出错了
我用MFC设计了一个对话框,
我想在对话框的客户区添加一个恩钮图标,当鼠标在该图标上移动时,显示另一个图标
编译通过,但总是不出现相应的结果,请帮忙看一下
代码如下:
int m_BorderWidth; //边框宽度
int m_BorderHeight; //边框高度
int m_CaptionHeight; //标题栏的高度
CString m_Caption; //窗口标题
COLORREF m_CapitonColor; //标题字体颜色
CFont m_CaptionFont; //标题字体
int m_ButtonWidth; //按钮位图宽度
int m_ButtonHeight; //按钮位图高度
BOOL m_FirstShow; //窗口首次被显示
CRect m_OrigonRect;//原始窗口区域
CRect m_IniRect,m_MinRect,m_MaxRect,m_CloseRect;//标题栏按钮的显示区域
CButtonState m_ButtonState; //按钮状态
enum CButtonState{bsNone,bsIni,bsMin,bsMax,bsRes,bsClose};//按钮状态
//初始化对话框
BOOL CDrawFormDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
m_BorderHeight = GetSystemMetrics(SM_CYBORDER);
m_BorderWidth = GetSystemMetrics(SM_CXBORDER);
m_CaptionHeight = GetSystemMetrics(SM_CYCAPTION);
//获取按钮位图大小
CBitmap bitmap;
bitmap.LoadBitmap(IDB_BITMAP6);//加载位图
BITMAPINFO bInfo;
bitmap.GetObject(sizeof(bInfo),&bInfo);
m_ButtonWidth = bInfo.bmiHeader.biWidth;
m_ButtonHeight = bInfo.bmiHeader.biHeight;
bitmap.DeleteObject();
CRect rect;
GetClientRect(rect);
//按钮所在的区域
m_IniRect.CopyRect(CRect(8,(m_CaptionHeight+3*m_BorderHeight -m_ButtonHeight)/2,m_ButtonWidth,m_ButtonHeight));
。
。
。
。
。
//鼠标响应
void CMy0712Dlg::OnMouseMove(UINT nFlags, CPoint point) //鼠标响应
{
// TODO: Add your message handler code here and/or call default
CDialog::OnMouseMove(nFlags, point);
CRect tempIni,tempMin,tempMax,tempClose,ClientRect;
CDC* pWindowDC = GetWindowDC();
CDC memDC;
memDC.CreateCompatibleDC(pWindowDC);
BITMAPINFO bInfo;
CBitmap LeftLine;
int x,y;
GetWindowRect(ClientRect);
//GetClientRect();
tempIni.CopyRect(CRect(8,(m_CaptionHeight+3*m_BorderHeight -m_ButtonHeight)/2,m_ButtonWidth,m_ButtonHeight));//按钮位图区域
if (tempIni.PtInRect(point)) //鼠标在初始化按钮上移动时,更改按钮显示的位图
{
LeftLine.LoadBitmap(IDB_BITMAP7);
LeftLine.GetObject(sizeof(bInfo),&bInfo);
x = bInfo.bmiHeader.biWidth;
y = bInfo.bmiHeader.biHeight;
memDC.SelectObject(&LeftLine);
pWindowDC->StretchBlt(m_IniRect.left,m_IniRect.top,m_IniRect.right,m_IniRect.bottom,&memDC,0,0,x,y,SRCCOPY);
m_IsDrawForm = FALSE;
m_ButtonState = bsIni;
LeftLine.DeleteObject();
}
}
我想在对话框的客户区添加一个恩钮图标,当鼠标在该图标上移动时,显示另一个图标
编译通过,但总是不出现相应的结果,请帮忙看一下
代码如下:
int m_BorderWidth; //边框宽度
int m_BorderHeight; //边框高度
int m_CaptionHeight; //标题栏的高度
CString m_Caption; //窗口标题
COLORREF m_CapitonColor; //标题字体颜色
CFont m_CaptionFont; //标题字体
int m_ButtonWidth; //按钮位图宽度
int m_ButtonHeight; //按钮位图高度
BOOL m_FirstShow; //窗口首次被显示
CRect m_OrigonRect;//原始窗口区域
CRect m_IniRect,m_MinRect,m_MaxRect,m_CloseRect;//标题栏按钮的显示区域
CButtonState m_ButtonState; //按钮状态
enum CButtonState{bsNone,bsIni,bsMin,bsMax,bsRes,bsClose};//按钮状态
//初始化对话框
BOOL CDrawFormDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
m_BorderHeight = GetSystemMetrics(SM_CYBORDER);
m_BorderWidth = GetSystemMetrics(SM_CXBORDER);
m_CaptionHeight = GetSystemMetrics(SM_CYCAPTION);
//获取按钮位图大小
CBitmap bitmap;
bitmap.LoadBitmap(IDB_BITMAP6);//加载位图
BITMAPINFO bInfo;
bitmap.GetObject(sizeof(bInfo),&bInfo);
m_ButtonWidth = bInfo.bmiHeader.biWidth;
m_ButtonHeight = bInfo.bmiHeader.biHeight;
bitmap.DeleteObject();
CRect rect;
GetClientRect(rect);
//按钮所在的区域
m_IniRect.CopyRect(CRect(8,(m_CaptionHeight+3*m_BorderHeight -m_ButtonHeight)/2,m_ButtonWidth,m_ButtonHeight));
。
。
。
。
。
//鼠标响应
void CMy0712Dlg::OnMouseMove(UINT nFlags, CPoint point) //鼠标响应
{
// TODO: Add your message handler code here and/or call default
CDialog::OnMouseMove(nFlags, point);
CRect tempIni,tempMin,tempMax,tempClose,ClientRect;
CDC* pWindowDC = GetWindowDC();
CDC memDC;
memDC.CreateCompatibleDC(pWindowDC);
BITMAPINFO bInfo;
CBitmap LeftLine;
int x,y;
GetWindowRect(ClientRect);
//GetClientRect();
tempIni.CopyRect(CRect(8,(m_CaptionHeight+3*m_BorderHeight -m_ButtonHeight)/2,m_ButtonWidth,m_ButtonHeight));//按钮位图区域
if (tempIni.PtInRect(point)) //鼠标在初始化按钮上移动时,更改按钮显示的位图
{
LeftLine.LoadBitmap(IDB_BITMAP7);
LeftLine.GetObject(sizeof(bInfo),&bInfo);
x = bInfo.bmiHeader.biWidth;
y = bInfo.bmiHeader.biHeight;
memDC.SelectObject(&LeftLine);
pWindowDC->StretchBlt(m_IniRect.left,m_IniRect.top,m_IniRect.right,m_IniRect.bottom,&memDC,0,0,x,y,SRCCOPY);
m_IsDrawForm = FALSE;
m_ButtonState = bsIni;
LeftLine.DeleteObject();
}
}