Thread: WM_ACTIVATE woes...

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547

    WM_ACTIVATE woes...

    (Note: Also posted on Pelles C forums)

    The problems with WM_ACTIVATE for setting keyboard focus are well known. This is one solution but it's still not right.

    Can someone please suggest a better way...

    I've just spent a whole day struggling with WM_ACTIVATE... I have a window with a treeview and a listview in the more or less standard explorer configuration... The goal is to have it place the keyboard focus back where it came from after the main window loses then regains forgeround status... It's insane! Half the time GetFocus() returns NULL. When the window is minimized it returns different values than if you just click on the desktop... worse still, if you don't handle the message at all, it comes back to foreground with *nothing* selected and you have to click it to get it going again...

    Here's the handler code I came up with. It mostly works but there remains a problem that if you launch the program and immediately minimize it... or if you minimize it before it loses focus some other way, it resets back to the treeview control... (As you can see from my notes, I'm convinced there has to be a better way)

    Code:
    // set keyboard focus
    BOOL DoWMActivate(WPARAM Action)                // note this is a horrible Kludge
      { static HWND Focus;                          // it seriously needs fixing
        switch (Action)                             // Microsoft seriously needs fixing
         { case WA_INACTIVE : 
            Focus = GetFocus();
            break;
          case WA_ACTIVE :
          case WA_CLICKACTIVE :
            SetFocus( Focus ? Focus : gTreeView );
            break;
          default : 
            SetFocus(gTreeView); }
        return FALSE; }
    Last edited by CommonTater; 09-29-2011 at 01:16 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Wm_activate
    By Hawkin in forum Windows Programming
    Replies: 3
    Last Post: 04-01-2007, 06:28 PM
  2. .NET woes
    By VirtualAce in forum A Brief History of Cprogramming.com
    Replies: 49
    Last Post: 07-18-2006, 02:41 PM
  3. MD2 woes
    By psychopath in forum Game Programming
    Replies: 9
    Last Post: 07-02-2005, 07:46 PM
  4. ASP.NET woes
    By nickname_changed in forum C# Programming
    Replies: 0
    Last Post: 03-20-2004, 04:34 PM
  5. Dll woes
    By Abiotic in forum Windows Programming
    Replies: 3
    Last Post: 11-09-2003, 11:32 AM