Solved

problem with modeless!...

Posted on 2000-04-17
10
384 Views
Last Modified: 2010-04-02
hi!
my main application is a dialog based app.i created a modeless dialog box as below
BOOL CMDApp::InitInstance()
{
AfxEnableControlContainer();
#ifdef _AFXDLL
  Enable3Controls();
#else
 Enable3ControlsStatic();
#endif
 CMDDlg *dlg= new CMDDlg;
 dlg->Create();
 m_pMainWnd = dlg;
 return TRUE;
}
i destroyed it using..
void CMDDlg::OnCancel()
{
  CMDDlg::DestroyWindow();
}

now my problem is that when the user presses the ESC key the dialog box vanishes.i want the dialog box to stay.
how can modify this?..what is the reason for the dialog box to vanish even after overriding the OnCancel() function?
0
Comment
Question by:ijkl
  • 5
  • 4
10 Comments
 

Author Comment

by:ijkl
ID: 2723900
Adjusted points from 50 to 100
0
 
LVL 1

Expert Comment

by:MT_MU
ID: 2723928
As you mentioned ESC invokes OnCancel.

Remove the DestroyWindow from OnCancel - leaving the handler blank.



0
 
LVL 1

Expert Comment

by:Toad224
ID: 2724801
If you remove the "CMDDlg::DestroyWindow();" from the code, then your dialog should not close when Esc is pressed.

You should use:

void CMDDlg::OnCancel()
{
}

to destroy it instead.
0
 
LVL 1

Expert Comment

by:MT_MU
ID: 2724852
Toad

I hate to ask this...but your answer differs from mine how?
0
 
LVL 1

Expert Comment

by:MT_MU
ID: 2725053
As an alternative - if you wish **just** to disable the Escape key...

BOOL CTestDlg::PreTranslateMessage(MSG* pMsg)
{
      if (pMsg->message == WM_KEYDOWN)
      {
            if (pMsg->wParam == VK_ESCAPE)
            {
                  return TRUE;
            }
      }
      return CDialog::PreTranslateMessage(pMsg);
}
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:ijkl
ID: 2727759
I tried to do that but it is givig the error as
'PreTranslateMessage' : overloaded member function 'int (struct tagMSG *)' not found in 'CTestDlg'

!

0
 
LVL 1

Accepted Solution

by:
MT_MU earned 100 total points
ID: 2727810
Did you include the following in your header file?

virtual BOOL PreTranslateMessage(MSG* pMsg);

If you used ClassWizard to add the function this would be done automagically for you.
0
 

Author Comment

by:ijkl
ID: 2727851
the method given by Toad224 is not working for my purpose.
i want the dialog box to close when clicked cancel but stay when ESC is pressed!
thanx anyway..
0
 

Author Comment

by:ijkl
ID: 2727855
Mt Mu thanx it is working now...i appreciate it..
ijkl..:-)
0
 

Author Comment

by:ijkl
ID: 2727902

i already added a comment MT MU ...:-)
thanx..
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
returning a dereferenced pts in C++ 10 141
Losing latter half of command line in Visual Studio C++ online program 10 79
Compile GLUT with Visual Studio 2015 1 108
C++ question 3 62
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now