Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

problem with modeless!...

Posted on 2000-04-17
10
Medium Priority
?
393 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
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
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 …
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 how to clear a vector as well as how to detect empty vectors in C++.

927 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