Changing focus in an MFC Application

This is a discussion on Changing focus in an MFC Application within the Windows Programming forums, part of the Platform Specific Boards category; Hi all, In my MFC application, the whole application is a modal dialog box and on the press of enter ...

  1. #1
    Registered User
    Join Date
    Jun 2005
    Posts
    3

    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 ..in 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 ......

    Code:
    void CPIVSyncDlg::OnBnClickedDummy() 
    { 
    
    //these two are edit controls from which I want to remove focus 
    SendDlgItemMessage(IDC_PDINPUT,WM_KILLFOCUS,IDC_STARTSTOP,0); 
    SendDlgItemMessage(IDC_QSWITCHREP,WM_KILLFOCUS,IDC_STARTSTOP,0); 
    //this is a button control on which I want o set the focus 
    SendDlgItemMessage(IDC_STARTSTOP,WM_SETFOCUS,(WPARAM)GetFocus(),0); 
    
    }
    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
    Location
    near a computer
    Posts
    3,859
    Try....

    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.


    OR

    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
    Posts
    3
    thanks novacain,

    I searched in the msdn and found one function

    NextDlgCtrl()

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

    GotoDlgCtrl(HWND)

    that takes control to the desired window..

    Hardik

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, 10:06 PM
  3. MFC Perils
    By cboard_member in forum C++ Programming
    Replies: 4
    Last Post: 07-27-2005, 06:11 PM
  4. Save As Dialog MFC Application howto
    By jkw2068 in forum Windows Programming
    Replies: 2
    Last Post: 08-06-2003, 06:10 PM
  5. Problem with changing input focus
    By Clyde in forum Windows Programming
    Replies: 2
    Last Post: 05-25-2002, 06:06 AM

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