Click here to Skip to main content
15,923,678 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionRe: why i cannot close a dialog? the close operation by a button which sendmessage the WM_CLOSE message. Pin
Rajesh R Subramanian8-May-08 19:19
professionalRajesh R Subramanian8-May-08 19:19 
AnswerRe: why i cannot close a dialog? the close operation by a button which sendmessage the WM_CLOSE message. Pin
Nitheesh George8-May-08 19:53
Nitheesh George8-May-08 19:53 
AnswerRe: why i cannot close a dialog? the close operation by a button which sendmessage the WM_CLOSE message. Pin
Hamid_RT8-May-08 19:56
Hamid_RT8-May-08 19:56 
AnswerRe: why i cannot close a dialog? the close operation by a button which sendmessage the WM_CLOSE message. Pin
Dan8-May-08 20:19
Dan8-May-08 20:19 
GeneralRe: why i cannot close a dialog? the close operation by a button which sendmessage the WM_CLOSE message. Pin
xqhrs2328-May-08 21:12
xqhrs2328-May-08 21:12 
GeneralRe: why i cannot close a dialog? the close operation by a button which sendmessage the WM_CLOSE message. Pin
Mark Salsbery9-May-08 6:51
Mark Salsbery9-May-08 6:51 
GeneralRe: why i cannot close a dialog? the close operation by a button which sendmessage the WM_CLOSE message. Pin
xqhrs23210-May-08 16:12
xqhrs23210-May-08 16:12 
GeneralRe: why i cannot close a dialog? the close operation by a button which sendmessage the WM_CLOSE message. [modified] Pin
Mark Salsbery10-May-08 17:07
Mark Salsbery10-May-08 17:07 
xqhrs232 wrote:
Because the button which is used to close the Diaolg is created by myself.


There's rarely a need to override WindowProc(). If you're using MFC,
why not just use MFC's message handling instead of doing it the Win32 way?


Regardless, your code snip is incomplete so it's not much help.

The WM_CLOSE message should be posted, not sent from your window proc.
BEGIN_MESSAGE_MAP(CSettingDlg, CDialog)
	ON_BN_CLICKED(IDC_Btn_SetEsc, &CSettingDlg::OnBnClickedBtn_SetEsc)
	ON_WM_CLOSE()
END_MESSAGE_MAP()


LRESULT CSettingDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
//	switch(message)
//	{
//		case WM_COMMAND:
//
//			//I use the button to exit the dialog,which is static create by me!
//			if(wID==IDC_Btn_SetEsc) //static create the button
//			{
//				this->SendMessage(WM_CLOSE,NULL,NULL);
//				return TRUE;
//		
//				//break;
//			}
//
//		case WM_CLOSE:
//			// case WM_DESTROY://2008--4--24 xqh_xg
//			DeleteObjects(); //free the used object
//			break;
//
//	}//switch(message)

	return CDialog::WindowProc(message, wParam, lParam);
} 


void CSettingDlg::OnBnClickedBtn_SetEsc()
{
	PostMessage(WM_CLOSE);
}

void CSettingDlg::OnClose()
{
	DeleteObjects(); //free the used object

	CDialog::OnClose();
}



Mark

Mark Salsbery
Microsoft MVP - Visual C++

Java | [Coffee]

modified on Saturday, May 10, 2008 11:18 PM

GeneralRe: why i cannot close a dialog? the close operation by a button which sendmessage the WM_CLOSE message. Pin
xqhrs23213-May-08 3:28
xqhrs23213-May-08 3:28 
GeneralRe: why i cannot close a dialog? the close operation by a button which sendmessage the WM_CLOSE message. Pin
Mark Salsbery13-May-08 4:45
Mark Salsbery13-May-08 4:45 
GeneralRe: why i cannot close a dialog? the close operation by a button which sendmessage the WM_CLOSE message. Pin
xqhrs23213-May-08 20:38
xqhrs23213-May-08 20:38 
GeneralRe: why i cannot close a dialog? the close operation by a button which sendmessage the WM_CLOSE message. Pin
Mark Salsbery14-May-08 5:53
Mark Salsbery14-May-08 5:53 
GeneralRe: why i cannot close a dialog? the close operation by a button which sendmessage the WM_CLOSE message. Pin
xqhrs23214-May-08 17:13
xqhrs23214-May-08 17:13 
GeneralRe: why i cannot close a dialog? the close operation by a button which sendmessage the WM_CLOSE message. Pin
Mark Salsbery14-May-08 18:00
Mark Salsbery14-May-08 18:00 
GeneralRe: why i cannot close a dialog? the close operation by a button which sendmessage the WM_CLOSE message. Pin
xqhrs23215-May-08 0:16
xqhrs23215-May-08 0:16 
QuestionTaking advantage of multi-core procesors?? Pin
97C5ENVY8-May-08 11:13
97C5ENVY8-May-08 11:13 
AnswerRe: Taking advantage of multi-core procesors?? Pin
CPallini8-May-08 12:33
mveCPallini8-May-08 12:33 
AnswerRe: Taking advantage of multi-core procesors?? Pin
toxcct8-May-08 21:48
toxcct8-May-08 21:48 
AnswerRe: Taking advantage of multi-core procesors?? Pin
Michael Schubert8-May-08 21:51
Michael Schubert8-May-08 21:51 
GeneralRe: Taking advantage of multi-core procesors?? Pin
Mark Salsbery9-May-08 6:54
Mark Salsbery9-May-08 6:54 
GeneralRe: Taking advantage of multi-core procesors?? Pin
Michael Schubert9-May-08 11:02
Michael Schubert9-May-08 11:02 
GeneralRe: Taking advantage of multi-core procesors?? Pin
Mark Salsbery9-May-08 12:18
Mark Salsbery9-May-08 12:18 
GeneralRe: Taking advantage of multi-core procesors?? Pin
Michael Schubert9-May-08 13:48
Michael Schubert9-May-08 13:48 
GeneralRe: Taking advantage of multi-core procesors?? Pin
Mark Salsbery9-May-08 14:40
Mark Salsbery9-May-08 14:40 
GeneralRe: Taking advantage of multi-core procesors?? Pin
97C5ENVY16-May-08 8:35
97C5ENVY16-May-08 8:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.