CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 1999
    Posts
    2

    Which control has the focus?



    I want to know which control has the focus on my dialog box.


    I'm searching something like the Form.ActiveControl property in VB (return a reference to the active control).


    Thanks!

  2. #2
    Join Date
    Apr 1999
    Posts
    20

    Re: Which control has the focus?



    CWnd has a static member GetFocus() which will return a CWnd* of the window that has current focus, or NULL if there isn't one. Give that a try.

  3. #3
    Join Date
    Mar 1999
    Posts
    22

    Re: How do you want to konw it by button?



    Hi.


    I'm just curious about how you want to know it by pushing button?

    If so, this approach is easy because GetFocus triggar by message handler.


    However, if you want to know it always withouh pushing button showing

    "Show which the control is focusing now", this approach seems to be a little

    diffcult.


    Regards.

    -Masaaki Onishi-

  4. #4
    Join Date
    Apr 1999
    Posts
    2

    Re: Let me add some details...



    My dialog has 30 textbox and 1 push button.


    What I wanna do is copy the content of the active textbox into all the other textbox when the button is clicked.


    By using CWnd::GetFocus() I get near the expected result but when called in the click event the CWnd * returned is the button itself.


    I'll continue to work on it, thanks for your answers.

  5. #5
    Join Date
    Apr 1999
    Location
    Frankfurt, Germany
    Posts
    113

    Re: Let me add some details...



    Hi Patrick,

    Your textboxes have a SETFOCUS message .You could try something like this:

    dialog class member YourTextBox * m_pTextboxWithInputFocus


    YourTextBox::OnSetFocus(...)

    {

    m_pYourDialog->m_pTextBoxWithInputFocus = this;

    }


    So You always know which of Your textboxes was the last one with input focus...


    Hope this helps,

    Rudolf

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

Featured