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

  程序开发应用环境:
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……


这个受用。。。

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值