Results 1 to 12 of 12

Thread: [Resolved] MFC: Show Dialog?

  1. #1

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    [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.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  2. #2

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    I'm guessing I have to use the Create() method, but I can't get it working.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  3. #3

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    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?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  4. #4
    Hyperactive Member
    Join Date
    Sep 2001
    Posts
    396

    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.

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  6. #6

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by CornedBee
    But you want to go back to the modal dialog anyway (DoModal())
    I do?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  7. #7
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  8. #8

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    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.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  9. #9
    Hyperactive Member
    Join Date
    Sep 2001
    Posts
    396
    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.

  10. #10

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    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.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  11. #11

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    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.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  12. #12

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Nevermind. Mistake on my part. It also wanted virtual in the header file, too.

    Thanks for your help.
    My evil laugh has a squeak in it.

    kristopherwilson.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width