求如何让PICTURE控件显示MOUSEUP事件啊! 我想让鼠标点击PICTURE控件UP时,能弹出颜色对话框。多谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 为picture空间创建控件变量m_rect,然后添加OnLButtonUp响应函数:void CPage1::OnLButtonUp(UINT nFlags, CPoint point) { if(m_rect.PtInRect(point)) //如果在picture控件中 { CColorDialog colordlg; colordlg.m_cc.Flags |= CC_FULLOPEN; //颜色对话框显示全部 colordlg.DoModal(); //显示对话框 }} Picture是静态类型,所以先将ID改名成别的,然后添加成员变量m_Picture然后重载PreTranslateMessage()BOOL CTestdlg1Dlg::PreTranslateMessage(MSG* pMsg) { // TODO: Add your specialized code here and/or call the base class if(pMsg->message == WM_LBUTTONUP) { CRect rect; POINTS pt = MAKEPOINTS(pMsg->lParam); //将WM_Message的lParam参数转成Point类型 m_Picture.GetWindowRect(&rect); //获取Picture控件的屏幕坐标位置 ScreenToClient(&rect); //将Picture控件的屏幕坐标转成窗口坐标 if(PtInRect(rect,CPoint(pt.x,pt.y))) //判断鼠标的事件是否落在这个控件中 { CColorDialog colordlg; colordlg.m_cc.Flags |= CC_FULLOPEN; //颜色对话框显示全部 colordlg.DoModal(); //显示对话框 } } return CDialog::PreTranslateMessage(pMsg);} 再问一下:PICTURE控件有一个BN_CLICKED消息,我原来是在这里加的调用颜色对话框,但是鼠标点,或是按键都没有反应,这是为什么呢? 你可以在PICTURE控件的:属性->Stytles 中 选中Notify 即可响应BN_CLICKED 消息。 CStatic m_rect;改成什么呢?不然编译时报错:: error C2039: 'PtInRect' : is not a member of 'CStatic'多谢! 不好意思。是把picture类型设置为frame然后CRect m_rect;GetDlgItem(IDC_RECT22)->GetWindowRect(m_rect); //IDC_RECT22为picture控件的ID m_rect.left+=3; m_rect.top +=3; m_rect.right -=3; m_rect.bottom -=3; ScreenToClient(&m_rect);然后再用下面的代码:为picture空间创建控件变量m_rect,然后添加OnLButtonUp响应函数:void CPage1::OnLButtonUp(UINT nFlags, CPoint point) { if(m_rect.PtInRect(point)) //如果在picture控件中 { CColorDialog colordlg; colordlg.m_cc.Flags |= CC_FULLOPEN; //颜色对话框显示全部 colordlg.DoModal(); //显示对话框 }} m_rect是一个CRect对象,不是控件变量,笔误。呵呵。 真是怪了,就是不行啊!在PICTURE上点鼠没有反应啊!我真是太笨啦!PICTURE控件的ID是IDC_PICTURE_COLOR,类型是frameCRect m_rect;BEGIN_MESSAGE_MAP(Ctest, CDialog) //{{AFX_MSG_MAP(CWaterDist) ON_WM_PAINT() ON_BN_CLICKED(IDC_OK, OnOk) ON_WM_LBUTTONUP() <<<<<<<<<<<<<<<<<<<<<加的消息 //}}AFX_MSG_MAPEND_MESSAGE_MAP()在对话框初始时加BOOL Ctest::OnInitDialog() { CDialog::OnInitDialog(); // TODO: Add extra initialization here GetDlgItem(IDC_PICTURE_COLOR)->GetWindowRect(m_rect); //IDC_RECT22为picture控件的ID m_rect.left+=3; m_rect.top +=3; m_rect.right -=3; m_rect.bottom -=3; ScreenToClient(&m_rect); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE}响应函数void Ctest::OnLButtonUp(UINT nFlags, CPoint point) { if(m_rect.PtInRect(point)) //如果在picture控件中 { CColorDialog colordlg; colordlg.m_cc.Flags |= CC_FULLOPEN; //颜色对话框显示全部 colordlg.DoModal(); //显示对话框 } CDialog::OnLButtonUp(nFlags, point);} 方法1:你可以在PICTURE控件的:属性->Stytles 中 选中Notify 即可响应BN_CLICKED 消息。你的方法2:GetDlgItem(IDC_PICTURE_COLOR)->GetWindowRect(m_rect); 改为:GetDlgItem(IDC_PICTURE_COLOR)->GetWindowRect(&m_rect); ScreenToClient(&m_rect); //这里传的是地址,要不然怎么能保存你的变量信息? 经测试,方法2不可行,个人认为,原因如下:由于WM_LBUTTONUP是在XXDlg中映射,当在PICTURE控件上点击时,焦点在控件上,而并没有在XXDlg上,故XXDlg不会接收到LBUTTONUP消息,而是控件接收了。还有一个方法就是:由CStatic派生一个类,即子类化,再处理该消息。个人愚见.... ScreenToClient(&m_rect); 要传地址过去。 菜鸟关于界面的简单问题 Unicode程序中,怎么设置LOGFONT的lfCharSet? TEXT 和_TEXT的区别 程序出现无响应 :( 能监测UI消息吗?? Oracle支持这个函数吗?substring 请教语法: “ |= ” 是什么意思? vc下使用DOM,怎样在每一次load xml之后只保留根节点,讲那些子节点删除 求本科软件工程专业的课程 ”生成报表,打印报表!“谁能帮忙? ???用HtmlView打开html后,如何捕捉滚动条消息??? 排序问题 Help Me,50 score
{
if(m_rect.PtInRect(point)) //如果在picture控件中
{
CColorDialog colordlg;
colordlg.m_cc.Flags |= CC_FULLOPEN; //颜色对话框显示全部 colordlg.DoModal(); //显示对话框
}
}
然后重载PreTranslateMessage()BOOL CTestdlg1Dlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if(pMsg->message == WM_LBUTTONUP)
{
CRect rect;
POINTS pt = MAKEPOINTS(pMsg->lParam); //将WM_Message的lParam参数转成Point类型
m_Picture.GetWindowRect(&rect); //获取Picture控件的屏幕坐标位置
ScreenToClient(&rect); //将Picture控件的屏幕坐标转成窗口坐标
if(PtInRect(rect,CPoint(pt.x,pt.y))) //判断鼠标的事件是否落在这个控件中
{
CColorDialog colordlg;
colordlg.m_cc.Flags |= CC_FULLOPEN; //颜色对话框显示全部
colordlg.DoModal(); //显示对话框
}
}
return CDialog::PreTranslateMessage(pMsg);
}
PICTURE控件有一个BN_CLICKED消息,我原来是在这里加的调用颜色对话框,
但是鼠标点,或是按键都没有反应,这是为什么呢?
改成什么呢?
不然编译时报错:
: error C2039: 'PtInRect' : is not a member of 'CStatic'
多谢!
然后
CRect m_rect;
GetDlgItem(IDC_RECT22)->GetWindowRect(m_rect); //IDC_RECT22为picture控件的ID
m_rect.left+=3;
m_rect.top +=3;
m_rect.right -=3;
m_rect.bottom -=3;
ScreenToClient(&m_rect);然后再用下面的代码:为picture空间创建控件变量m_rect,然后添加OnLButtonUp响应函数:void CPage1::OnLButtonUp(UINT nFlags, CPoint point)
{
if(m_rect.PtInRect(point)) //如果在picture控件中
{
CColorDialog colordlg;
colordlg.m_cc.Flags |= CC_FULLOPEN; //颜色对话框显示全部 colordlg.DoModal(); //显示对话框
}
}
CRect m_rect;
BEGIN_MESSAGE_MAP(Ctest, CDialog)
//{{AFX_MSG_MAP(CWaterDist)
ON_WM_PAINT()
ON_BN_CLICKED(IDC_OK, OnOk)
ON_WM_LBUTTONUP() <<<<<<<<<<<<<<<<<<<<<加的消息
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
在对话框初始时加
BOOL Ctest::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
GetDlgItem(IDC_PICTURE_COLOR)->GetWindowRect(m_rect); //IDC_RECT22为picture控件的ID
m_rect.left+=3;
m_rect.top +=3;
m_rect.right -=3;
m_rect.bottom -=3;
ScreenToClient(&m_rect);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
响应函数
void Ctest::OnLButtonUp(UINT nFlags, CPoint point)
{
if(m_rect.PtInRect(point)) //如果在picture控件中
{
CColorDialog colordlg;
colordlg.m_cc.Flags |= CC_FULLOPEN; //颜色对话框显示全部 colordlg.DoModal(); //显示对话框
}
CDialog::OnLButtonUp(nFlags, point);
}
你可以在PICTURE控件的:属性->Stytles 中 选中Notify 即可响应BN_CLICKED 消息。你的方法2:
GetDlgItem(IDC_PICTURE_COLOR)->GetWindowRect(m_rect);
改为:
GetDlgItem(IDC_PICTURE_COLOR)->GetWindowRect(&m_rect);
要传地址过去。