Click here to Skip to main content
11,703,632 members (70,221 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VS2008 MFC VC++
I have two dialog box.
FirstDlg.h
public:
	afx_msg void CapturePhoto();
	LRESULT ButtonPressed(WPARAM w, LPARAM l);
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
private:
	LRESULT LeftMouseDown(WPARAM w, LPARAM l);
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;
}


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 7-Nov-12 22:47pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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();

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
  Permalink  
Comments
Member 7909353 at 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()
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

I have added a ActiveX control on picture control.
And mouse down ,up, move event on it.
  Permalink  

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

  Print Answers RSS
0 Maciej Los 570
1 OriginalGriff 515
2 Sergey Alexandrovich Kryukov 460
3 Andy Lanng 209
4 CPallini 195
0 OriginalGriff 8,519
1 Sergey Alexandrovich Kryukov 7,667
2 CPallini 4,987
3 Maciej Los 4,686
4 Mika Wendelius 3,566


Advertise | Privacy | Mobile
Web04 | 2.8.150819.1 | Last Updated 16 Nov 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100