您的位置:首页 > 其它

有其它方法在对话框背景图片 指定区域添加鼠标单击响应事件

2011-11-06 00:39 751 查看
程序开发应用环境:

VS2005(vc++),wince 6.0 ,MFC;

实现功能:

在图片背景的指定区域如(0,0,100,30)显示当前的系统时间(用时钟控制的,ExtTextOut直接输出时间),并且该区域要能响应鼠标的单击事件.另外对话框的背景图片是外部资源(选择路径);

思路:

捕获所有的的鼠标单击消息(PreTranslateMessage),判断当前单击时所在的点是否被指定区域所包含.

出现问题:

使用ExtTextOut后单击事件就不能正常的捕获了.

C/C++ code
(一)安装时钟
OninitDialog()
{
...
SetTimer(1,1000,NULL);
...
}
(二)时钟响应
void CWince_TimeTextDlg::OnTimer(UINT_PTR nIDEvent)
{
// TODO: Add your message handler code here and/or call default
if(nIDEvent==1)
{
//CDC *pDC=CClientDC(this);
CDC *pDC=GetDC();
pDC->SetBkMode(TRANSPARENT);
CRect rect(0,0,100,30);
Invalidate();
UpdateWindow();
CTime time;
time=CTime::GetCurrentTime();
CString strShow;
strShow=time.Format(L"%Y-%m-%d %H:%M:%S");
pDC->SetTextColor(RGB(0,0,255));
[color=#FF6600]pDC->ExtTextOut(0, 0, ETO_OPAQUE,NULL,strShow,wcslen(strShow),0);//注释这行捕获鼠标单击正常[/color]
ReleaseDC(pDC);
}
CDialog::OnTimer(nIDEvent);
}
(3)捕获鼠标点击消息,并响应,现在是任何时候断点跟踪时都会进入if.鼠标没有单击也会进去.
BOOL CWince_TimeTextDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if(pMsg->wParam == VK_LBUTTON)
{
CPoint MousePoint;
GetCursorPos(&MousePoint);
CRect Nowrect(0,0,100,40);
ClientToScreen(Nowrect);
if(Nowrect.PtInRect(MousePoint))
{
AfxMessageBox(_T("鼠标点击"));
}
}
return CDialog::PreTranslateMessage(pMsg);
}


只要鼠标一移动到那个区域就会有响应,而我想要的是单击响应.

引用 2 楼 fishion 的回复:

if(pMsg->message== WM_LBUTTONDOWN)

{

CPoint MousePoint;

GetCursorPos(&MousePoint);

CRect Nowrect(0,0,100,40);

ClientToScreen(Nowrect);

if(Nowrect.PtInRect(MousePoint))

{

Af……

这个受用。。。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: