Results 1 to 6 of 6

Thread: MFC Question

  1. #1

    Thread Starter
    Fanatic Member nabeels786's Avatar
    Join Date
    Jul 2001
    Location
    New York
    Posts
    919

    MFC Question

    When you make a Dialog project, how do I override the "press enter then it exits" thingy? I can't seem to figure it out

    Thanks

    Ok I think I've figured it out

    I need to add it in the BEGIN_MESSAGE_MAP() thing, like ON_WM_PAINT()
    etc

    ON_WM_KEYPRESS()?

    Edit:
    I got it, but it's not detecting when Enter is pressed. I used "OnKeyPress" and "OnSysKeyDown". OnKeyPress works, but I can't seem to catch the enter key

    Code:
    BEGIN_MESSAGE_MAP(CServerDlg, CDialog)
    	ON_WM_SYSCOMMAND()
    	ON_WM_PAINT()
    	ON_WM_QUERYDRAGICON()
    	ON_WM_KEYDOWN()
    	ON_WM_CLOSE()
    	//}}AFX_MSG_MAP
    END_MESSAGE_MAP()
    
    
    void CServerDlg::OnKeyDown(UINT one, UINT two, UINT three){
    	MessageBox("pressed key","key",MB_OK);
    }
    When I press enter, the message box doesn't show up, for all other keys, it does
    Last edited by nabeels786; Sep 18th, 2002 at 08:36 PM.
    Visit www.fragblast.com
    Gaming, forums, and a online RPG/Battle system




    (__Flagg) DOT NET? is this a Hindi Dating service?

  2. #2
    Member
    Join Date
    Sep 2002
    Location
    in e middle of nowhere..
    Posts
    40

    Red face

    This probably isn't a great fix for your problem when
    the dialog exits with a carriage return, but here is a
    way around the problem...

    1) create an extra button in your dialog.
    2) open the properties box, and on the "General" tab,
    clear the check marks for "Visible" and "Tab Stop".
    (The button will be visible in the resource editor,
    but will not be displayed when the program runs.)
    On the properties box "Styles" tab, put a check mark
    next to "Default button". This button should now
    intercept the carriage return key.


    i've also had the same problem before.

    =o)

  3. #3
    Hyperactive Member
    Join Date
    Sep 2001
    Posts
    396
    nabeels786: What about putting 2 messageboxes to troubleshoot?

    Maybe the messagebox got the enter key as u may be pressing more than once, from MSDN

    "Because of auto-repeat, more than one OnKeyDown call may occur before an OnKeyUp member function call is made. The bit that indicates the previous key state can be used to determine whether the OnKeyDown call is the first down transition or a repeated down transition."

    Try using OnKeyUp insteads.


  4. #4
    Addicted Member HairyDave's Avatar
    Join Date
    Aug 2002
    Location
    Er...I can't remember.
    Posts
    196
    Are you just using the OK button - or is it buttons in general. If it's the OK button, you can override the OnOK() function such that when you press return, the OK button runs a different routine.

    Am I understanding correctly - or am I shooting well wide?

    HD

  5. #5

    Thread Starter
    Fanatic Member nabeels786's Avatar
    Join Date
    Jul 2001
    Location
    New York
    Posts
    919
    Originally posted by hazel
    This probably isn't a great fix for your problem when
    the dialog exits with a carriage return, but here is a
    way around the problem...

    1) create an extra button in your dialog.
    2) open the properties box, and on the "General" tab,
    clear the check marks for "Visible" and "Tab Stop".
    (The button will be visible in the resource editor,
    but will not be displayed when the program runs.)
    On the properties box "Styles" tab, put a check mark
    next to "Default button". This button should now
    intercept the carriage return key.


    i've also had the same problem before.

    =o)
    This worked, I just set the button to default

    Thanks

    No I just deleted the stuff on the form, and the code that I didn't need
    Visit www.fragblast.com
    Gaming, forums, and a online RPG/Battle system




    (__Flagg) DOT NET? is this a Hindi Dating service?

  6. #6
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    You could also have tried overriding PreTranslateMessage and intercepting the message there.
    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.

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