Click here to Skip to main content
15,886,017 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I have two dialog box.
FirstDlg.h
C++
public:
	afx_msg void CapturePhoto();
	LRESULT ButtonPressed(WPARAM w, LPARAM l);

FirstDlg.cpp
C++
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
C++
private:
	LRESULT LeftMouseDown(WPARAM w, LPARAM l);

SecondDlg.cpp
C++
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;
}



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!
Posted

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:
C++
// in FirstDlg.h
afx_msg void OnBnClickedButton1();


And the handler for the button should be mapped using this macro:
C++
  // 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
 
Share this answer
 
Comments
Member 7909353 15-Nov-12 0:57am    
Actually I am creating controls(button,text ....) on a tab control at run time for FirstDlg box. Then how to write like
BEGIN_MESSAGE_MAP(CFirstDlg, CDialog)
...
ON_BN_CLICKED(IDC_BUTTON1, &CFirstDlg::OnBnClickedButton1)
...
END_MESSAGE_MAP()
I have added a ActiveX control on picture control.
And mouse down ,up, move event on it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900