Thread: Changing focus in an MFC Application

  1. #1
    Registered User
    Join Date
    Jun 2005

    Changing focus in an MFC Application

    Hi all,

    In my MFC application, the whole application is a modal dialog box and on the press of enter key I want to change focus from one control to the other short I want to sinulate the tab key with enter key ....

    my application is only this dialog box and in dialog boxes, enter should close them but in my application enter should meen the confirmation of the user input so I am planning to simulate enter through tab.

    on the default button's click event I am
    writing ......

    void CPIVSyncDlg::OnBnClickedDummy() 
    //these two are edit controls from which I want to remove focus 
    //this is a button control on which I want o set the focus 
    this gives me a very strange behaviour, i.e. after the focus has been shifted to the next control, I cannot select text or set the mouse cursor on the edit control which has lost the focus until I press a tab key..

  2. #2
    train spotter
    Join Date
    Aug 2001
    near a computer

    Return 0 as you have handled the message.
    Don't 'kill focus'.
    Use GetFocus() to find which control has focus and so where to set the focus.


    handle the OnKillFocus() msg for the window. Use the param to find which window HAD focus and to determine which to one to give the focus to.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    Registered User
    Join Date
    Jun 2005
    thanks novacain,

    I searched in the msdn and found one function


    which shifts control to the next control and this works fine for me ...there is also a functino


    that takes control to the desired window..


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. MFC support in ATL project
    By Arkanos in forum Windows Programming
    Replies: 2
    Last Post: 01-29-2006, 05:15 PM
  2. Replies: 1
    Last Post: 09-18-2005, 09:06 PM
  3. MFC Perils
    By cboard_member in forum C++ Programming
    Replies: 4
    Last Post: 07-27-2005, 05:11 PM
  4. Save As Dialog MFC Application howto
    By jkw2068 in forum Windows Programming
    Replies: 2
    Last Post: 08-06-2003, 05:10 PM
  5. Problem with changing input focus
    By Clyde in forum Windows Programming
    Replies: 2
    Last Post: 05-25-2002, 05:06 AM