I don't want [Enter] to close my dialog

This is a discussion on I don't want [Enter] to close my dialog within the Windows Programming forums, part of the Platform Specific Boards category; Hi, I'm writing a dialog based app (multithreaded, db accessing). And I realised that when you press enter, the windows ...

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    106

    I don't want [Enter] to close my dialog

    Hi,

    I'm writing a dialog based app (multithreaded, db accessing). And I realised that when you press enter, the windows message pump sends an IDOK response causing windows to end the modal loop. This would be ok if I wanted to shut down the app this way, but I don't have code in place to cleanup here and I don't want the program to exit on pressing [Enter].
    So far, I wrote:

    void CMyDlg::OnOK()
    {
    return;
    }

    to override the OnOK message and do nothing. It works but I'm not sure if it's the best way to do this. Would it be better, or is there a way to intercept the IDOK message/disable the message or something? Thanks for any/all help.
    Don't talk to strangers, unless they offer candy.

  2. #2
    Registered User ski6ski's Avatar
    Join Date
    Aug 2001
    Posts
    133
    You could set focus to a different control.
    Or you could remove the OnOK(); from the button.

    Usualy I comment the OnOK(); out like this: //OnOK();
    That usualy works.
    C++ Is Powerful
    I use C++
    There fore I am Powerful

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    106
    Thanks ski6ski,

    I did try removing the button, but MFC (I think) still processes the message, even when I took OnOK() out of the message map. Kind of a pain, thats why I wanted to intercept the message rather that override it.
    Just after I posted, I found this on codeguru.com:

    >>
    Unfortunately, when the user press
    Enter, the sheet still closes. To avoid this, do
    not just hide the control but also disable it.

    So the complete code will be:

    CWnd * pButton = GetDlgItem(IDOK);
    pButton->ShowWindow(FALSE);
    pButton->EnableWindow(FALSE);
    >>

    But I still have to put the button somewhere on the dialog (its hidden at runtime).
    Anyways, thanks for your help.

    Corrollary:
    Is there onything else (besides pressing [Enter] or the OK button) that will pass an IDOK response?
    Don't talk to strangers, unless they offer candy.

  4. #4
    Caffienated jinx's Avatar
    Join Date
    Oct 2001
    Posts
    235

    Lightbulb If u r in MSVC++ then,,,

    Right click on your edit control. Goto to the Styles tab, I think... Then check the Want Return option. If its not there, then goto another tab until u find it.
    Weeel, itss aboot tieme wee goo back too Canada, eeehy boyss.

  5. #5
    Registered User ski6ski's Avatar
    Join Date
    Aug 2001
    Posts
    133
    Oh yeah i forgot about that. Good idea jinx.
    C++ Is Powerful
    I use C++
    There fore I am Powerful

  6. #6
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,138
    If you don't want [Return] to end your dialog, you probably don't
    want [ESC] to cancel it either....
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  7. #7
    Registered User
    Join Date
    Aug 2001
    Posts
    106
    Thanks guys,

    >If you don't want [Return] to end your dialog, you probably don't want [ESC] to cancel it either....>

    You're right nv, but I actully handle that one becaue I have a cancel button that the user can press to abort a process. This is important because the dialog starts a long process that if the user changes his mind and doesn't want to do it any more, I have to clean up what was done. Pressing [ESC] actually passes an IDCANCEL message the same as the cancel button.

    I ended up disabling the button and making it invisible in the code. The app has been running for 5 days now with no ill effects.

    Thanks again

  8. #8
    Registered User
    Join Date
    Aug 2001
    Posts
    223

    removing focus from IDOK

    try to remove focus as you may to remove the focus from the IDOK.... it is a weird button... what I normally do is hide it, disable it... and create a different button... say submit or something then
    I call the CDialog::OnOK(); from there...


    something like this...

    void CMyDlg::OnSubmit()
    {

    if( AllDataIsValid() )
    CDialog::OnOK();
    else
    WarnUser();
    }

    the new button will not have the default focus like the OK button...
    zMan

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 02-13-2008, 01:59 PM
  2. Dialog box determined to close!!!
    By mhandlon in forum Windows Programming
    Replies: 1
    Last Post: 01-18-2006, 08:33 AM
  3. Dialog will not close
    By curlious in forum Windows Programming
    Replies: 6
    Last Post: 10-21-2003, 01:25 AM
  4. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM
  5. Ghost in the CD Drive
    By Natase in forum A Brief History of Cprogramming.com
    Replies: 17
    Last Post: 10-12-2001, 05:38 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21