CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2001
    Posts
    342

    Test whether my MDI app has the focus?

    I did a search but could not find this, though I'm sure it's been answered before.

    I need to be able to test whether my MDI app has the focus or not.

    What's the best way to do this?

  2. #2
    Join Date
    Sep 2002
    Location
    14° 39'19.65"N / 121° 1'44.34"E
    Posts
    9,815
    The following should work:
    Code:
    if(CWnd::GetFocus()->GetSafeHwnd() == AfxGetMainWnd()->GetSafeHwnd())
    {
      // Our App's main window has focus
    }

  3. #3
    Join Date
    Feb 2001
    Posts
    342

    Looks like it should, but

    doesn't.

  4. #4
    Join Date
    Sep 2002
    Location
    14° 39'19.65"N / 121° 1'44.34"E
    Posts
    9,815
    What exactly is not working? Did you look at the values returned by GetFocus()->GetSafeHwnd() and AfxGetMainWnd()->GetSafeHwnd() and looked them up in Spy++? Could it be that a child window (and not the main window) actually has the focus when you are testing?

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