Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

problem with modeless!...

Posted on 2000-04-17
10
Medium Priority
?
391 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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 400 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

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
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.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

705 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