|
-
Mar 28th, 2003, 11:23 AM
#1
Thread Starter
Stuck in the 80s
[Resolved] MFC: Show Dialog?
I'm showing a dialog via this code:
Code:
BOOL CListworkApp::InitInstance() {
CListworkDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK) {
} else if (nResponse == IDCANCEL) {
}
return FALSE;
}
Which is the default code provided by the wizard. However, when I remove the buttons and the code, the app disappears when enter is pressed.
I'm assuming there's another method to show the dialog so that this doesn't happen?
Last edited by The Hobo; Mar 31st, 2003 at 07:19 PM.
-
Mar 28th, 2003, 01:09 PM
#2
Thread Starter
Stuck in the 80s
I'm guessing I have to use the Create() method, but I can't get it working.
-
Mar 28th, 2003, 01:19 PM
#3
Thread Starter
Stuck in the 80s
Okay, now this works:
Code:
BOOL CWorkApp::InitInstance() {
#ifdef _AFXDLL
Enable3dControls();
#else
Enable3dControlsStatic();
#endif
CWorkDlg dlg;
BOOL ret = dlg.Create(IDD_WORK_DIALOG,NULL);
dlg.ShowWindow(SW_SHOW);
return FALSE;
}
But the dialog box disappears right away. How do I fix that?
-
Mar 28th, 2003, 06:42 PM
#4
Hyperactive Member
Re: MFC: Show Dialog?
Originally posted by The Hobo
I'm showing a dialog via this code:
Code:
BOOL CListworkApp::InitInstance() {
CListworkDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK) {
} else if (nResponse == IDCANCEL) {
}
return FALSE;
}
Which is the default code provided by the wizard. However, when I remove the buttons and the code, the app disappears when enter is pressed.
I'm assuming there's another method to show the dialog so that this doesn't happen?
Even if you had removed the ok button and its code, the default code called, when enter key is pressed, is still OnOk().
1 solution is to change the default button, using SetDefID(); in the Initdialog() handler.
example,
SetDefID(ID_MY_OTHER_BUTTON);
SetDefID() is a member function of CDialog. Look it up in the MSDN for more details.
P.S. I don't know how well it works in a modeless dialog, I had only used it in modal dialog.
-
Mar 29th, 2003, 05:12 AM
#5
But you want to go back to the modal dialog anyway (DoModal())
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Mar 29th, 2003, 11:07 AM
#6
Thread Starter
Stuck in the 80s
Originally posted by CornedBee
But you want to go back to the modal dialog anyway (DoModal())
I do?
-
Mar 29th, 2003, 11:54 AM
#7
Yes, so that the dialog doesn't close again immediatly.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Mar 30th, 2003, 07:21 PM
#8
Thread Starter
Stuck in the 80s
Re: Re: MFC: Show Dialog?
Originally posted by transcendental
Even if you had removed the ok button and its code, the default code called, when enter key is pressed, is still OnOk().
1 solution is to change the default button, using SetDefID(); in the Initdialog() handler.
example,
SetDefID(ID_MY_OTHER_BUTTON);
SetDefID() is a member function of CDialog. Look it up in the MSDN for more details.
P.S. I don't know how well it works in a modeless dialog, I had only used it in modal dialog.
But there isn't a button on my dialog. I only want it to close when the X is clicked.
I'm not sure how to fix this...any help would be appreciated.
-
Mar 31st, 2003, 05:19 AM
#9
Hyperactive Member
Either this
Code:
BOOL CYourDialog::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if((pMsg->message == WM_KEYDOWN) && (pMsg->wParam == VK_RETURN))
return TRUE;
return CDialog::PreTranslateMessage(pMsg);
}
or this
Code:
void CYourDialog::OnOK()
{
// CDialog::OnOK(); <-- Disable this line
}
Last edited by transcendental; Mar 31st, 2003 at 10:05 AM.
-
Mar 31st, 2003, 06:25 PM
#10
Thread Starter
Stuck in the 80s
Originally posted by transcendental
Either this
Code:
BOOL CYourDialog::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if((pMsg->message == WM_KEYDOWN) && (pMsg->wParam == VK_RETURN))
return TRUE;
return CDialog::PreTranslateMessage(pMsg);
}
or this
Code:
void CYourDialog::OnOK()
{
// CDialog::OnOK(); <-- Disable this line
}
I don't have an OnOK() but the first one worked perfectly. Thanks, man.
-
Mar 31st, 2003, 07:03 PM
#11
Thread Starter
Stuck in the 80s
Okay, maybe it doesn't work so well. When I use that code, then try to go to the ClassWizard for an object, I get this error:
Parsing error: Expected "afx_msg"
Input Line: BOOL CVGRTaxDlg::PreTranslateMessage(MSG* pMsg);
And then the ClassWizard doesn't work.
-
Mar 31st, 2003, 07:17 PM
#12
Thread Starter
Stuck in the 80s
Nevermind. Mistake on my part. It also wanted virtual in the header file, too.
Thanks for your help.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|