Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have written a program, it can run on Windows SP2 and SP3, but today it can not work correctly on one colleague's computer. I have tried other person's computer, where it always work well. So I use MessageBox to debug the program. When I use EndDialog to close a modal dialog, it failed and GetLastError code is:

1420, ERROR_NOT_WINDOW_DIALOG.

I don't know why. I also use SendMessage to replay EndDialog to close the dialog. But I can't see WM_CLOSE in Spy++. When I use ALT+F4 close the dialog, then SendMessage can work well. I was very confusing!

C++
CWnd* pWnd = FindWindow(NULL, _T("Progress"));

if (pWnd != NULL)
{
  BOOL bResult = ::EndDialog(pWnd->m_hWnd, IDOK);

  if (bResult)
  {
     MessageBox(_T("OK"));
  }
  else
  {
    CString strMsg;
    strMsg.Format(_T("NOT OK %d"), GetLastError());
    MessageBox(strMsg);
  }
}
Posted
Updated 17-Jun-10 10:06am
v3

yeah u must call EndDialog in side the window procedure. Or else you can post a message to window procedure to exit your dialog

Other wise you can use SendMessage to exit the window

C#
public const int WM_COMMAND = 0x0112;
public const int WM_CLOSE = 0xF060;


SendMessage(pWnd, WM_COMMAND, WM_CLOSE, 0);
 
Share this answer
 
Comments
zwhate 20-Jun-10 9:55am    
I know what you said, but what is confusing me is that when I changed the dialog's title name it was OK.

I think it maybe another window's titil name is same to my dialog's, but I have not find it...
You should only call EndDialog() from within your dialog's message handler. See the remarks on this page[^].
 
Share this answer
 
Comments
zwhate 17-Jun-10 21:12pm    
Yeah, it was a dialog which was created by follow code:

CprogressDlg progressDlg;
progressDlg.DoMal();

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