Results 1 to 2 of 2

Thread: A Couple MFC Questions

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Posts
    241

    A Couple MFC Questions

    1. I created a dialog App and ran it. Then when the window had focus I pressed the enter key, it didn't matter whether it was the window or a edit control or a list that had focus the window would always close and the application would quit when I did this. How come and why?

    2. When I try to add an event to my Edit Control it only gives me about 6 or so events to choose from and none of them are the event u get when the user presses a key. What I want to do is have the app do something when the user presses the enter key in the text box. How can I do this with MFC, I mean how can I know when the user presses the enter key in the edit box?

    Thank for any and all help in advanced.

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    1) You need to specify the ES_WANTRETURN style for the edit box. This is some option in the properties of the edit box in the dialog editor. If you don't do that the edit box will forward the enter to the dialog box which interprets it as click on the default button, usually closing the window.

    2) If you look at the API documentation of the edit control you'll notice that there is no notification that informs you of a key being pressed. You have to subclass the edit control and intercept the WM_CHAR message. In MFC you do that by deriving a class from CEditCtrl and adding a control variable (through the wizard) to the dialog that is of the type of your derived class. In your classes message map you can then intercept WM_CHAR. Don't forget to forward the message, else the edit box will lose its functionality.

    Btw, neither of those were MFC questions...
    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