Solved

problem with modeless!...

Posted on 2000-04-17
10
385 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
ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 
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
 

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
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 user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

803 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