鼠标事件的问题 [英] problem with mouse event

查看:61
本文介绍了鼠标事件的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个对话框.
FirstDlg.h

I have two dialog box.
FirstDlg.h

public:
	afx_msg void CapturePhoto();
	LRESULT ButtonPressed(WPARAM w, LPARAM l);


FirstDlg.cpp


FirstDlg.cpp

BEGIN_MESSAGE_MAP(FirstDlg, CDialog)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_MESSAGE(WM_BUTTONPRESSED,ButtonPressed) 
	ON_WM_CTLCOLOR()
	ON_WM_TIMER()
END_MESSAGE_MAP()
LRESULT CFirstDlg::ButtonPressed(WPARAM w, LPARAM l)
{
   try
   {
      CFirstDlg::CapturePhoto();		
   }
   catch(const std::exception& rSEX)
   {
     ShowException(rSEX);
   }
	return 0;
}

void CFirstDlg::CapturePhoto()
{
	CSecondDlg dlgWin2; 
	if(IDOK==dlgWin2.DoModal())
	{
		((CStatic*)m_cTab.GetDlgItem(6))->SetBitmap(dlgWin2.m_hBmp);
		DeleteObject(dlgWin2.m_hBmp);
	}
}


SecondDlg.h


SecondDlg.h

private:
	LRESULT LeftMouseDown(WPARAM w, LPARAM l);


SecondDlg.cpp


SecondDlg.cpp

BEGIN_MESSAGE_MAP(CWin2Dlg, CDialog)
	ON_WM_TIMER()
	ON_MESSAGE(MK_LBUTTON,LeftMouseDown)
END_MESSAGE_MAP()

LRESULT CSecondDlg::LeftMouseDown(WPARAM w, LPARAM l)
{
	CRgn clipregion;
	 clipregion.CreateRectRgn( 245, 26, 204, 184 ); // Prepare clip region.
	 m_nHeight.SetWindowRgn(clipregion, TRUE);
	return 0;
}




问题是当我单击Button1(在FirstDlg框上表示)时,它调用LeftMouseDown()方法,该方法已定义并为SecondDlg框声明.
我想将其称为onclick Button2(在SecondDlg框上).




Problem is when I click on Button1(means on FirstDlg box) it calls the LeftMouseDown() method which is defined and declare for SecondDlg box.
I want to call it onclick Button2(on SecondDlg box).
Help me!

推荐答案

而不是为Button Clicked事件声明ON_MESSAGE宏,您需要学习如何使用
Instead of declaring ON_MESSAGE macros for the Button Clicked events, you need to learn how to use Class Wizard[^] for creating message handling for the controls.

To handle Button Clicked events in your dialogs the following methods should be defined:
// in FirstDlg.h
afx_msg void OnBnClickedButton1();



并且按钮的处理程序应使用以下宏进行映射:
FirstDlg.cpp中的



And the handler for the button should be mapped using this macro:

  // in FirstDlg.cpp
BEGIN_MESSAGE_MAP(CFirstDlg, CDialog)
  ...
  ON_BN_CLICKED(IDC_BUTTON1, &CFirstDlg::OnBnClickedButton1)
  ...
END_MESSAGE_MAP()

...

void CFirstDlg::OnBnClickedButton1()
{
   try
   {
      CFirstDlg::CapturePhoto();		
   }
   catch(const std::exception& rSEX)
   {
     ShowException(rSEX);
   }
   return 0;
}



同样,在第二个对话框上定义按钮的消息处理程序



Similarly, define the message handlers for the button on the second dialog


我在图片控件上添加了ActiveX控件.
然后将鼠标向下,向上移动事件.
I have added a ActiveX control on picture control.
And mouse down ,up, move event on it.


这篇关于鼠标事件的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆