2

I'm working on a taskbar for secondary monitors. I have it working fairly well. I've also got the aero blur look working as well. But my question is probably not related to the aero stuff.

What i want to do is to have my taskbar window to always appear focused/activated. It does not need to actually be focused or activated, I just want it to look that way. You can see the effect I'm after by just putting a setforgroundwindow call in the app idle. But I can't use that as I don't really want it grabbing the focus like that. I just want it to always look the way it does when it does have focus.

I've tried all sorts of WM_XXX message calls, both trapping and sending, I've tried setwindowpos calls, and on and on. The only thing that has worked is calling Mouse_Event(MOUSEEVENTF_LEFTDOWN and then Mouse_Event(MOUSEEVENTF_LEFTUP. I don't like this solution though as it's a really cheesy hack/workaround to what I want to do. But whatever gets called with the Mouse_Event is essentially what I need to make happen only without actually clicking on my app or sending it Mouse_Event calls.

tshepang
  • 12,111
  • 21
  • 91
  • 136
  • Does your application *look* like a taskbar? i ask because the "real" taskbar doesn't have any focused/unfocus look - there is no non-client frame to change colors. i guess i don't understand what the "focused" verses "unfocused" look for a taskbar would be. – Ian Boyd Dec 21 '09 at 19:53
  • Yes, it looks just like the win7 taskbar when it's set to "aero" mode. Due to the way I had to implement the blurbehind code, when you clicked on my taskbar it looked active. Click off of it and it looked deactivated. The answer below actually helped me solve it. –  Dec 21 '09 at 22:13
  • I think you might be able to see the screenshot here: http://www.facebook.com/photo.php?pid=106932&l=8cf7240918&id=100000261298303 –  Dec 21 '09 at 22:30

1 Answers1

3

You don't say what language you are working in or whether this is managed or unmanaged code.

For C++ unmanaged code, you just handle the WM_NCACTIVATE message and force it to always seem active, like this:

case WM_NCACTIVATE:
   {
   // wParam tells us whether we are active or inactive, but we are going to ignore
   // that and always pass active down to DefWindowProc so it will draw us active.
   DefWindowProc(hwnd, uMsg, TRUE, lParam);
   //return FALSE; // returning false here prevents actual deactivation
   return TRUE; // return true allows deactivation (even though we draw as active)
   }
   break;

edit: the solution in delphi code (moved from comment to make it more readable)

procedure TForm1.WndProc(var Message: TMessage); 
begin inherited; 
  if (Message.Msg = WM_NCACTIVATE) then 
  begin 
    DefWindowProc(handle, Message.Msg, 1, Message.LParam ); 
    Message.Result := 1; 
  end; 
end;
John Knoeller
  • 33,512
  • 4
  • 61
  • 92
  • THANK YOU. I've spent hours trying to solve this. I knew it would probably be something simple like a msg intercept, but I was going in circles. It's delphi code. The key was the DefWindowProc part. Here's the fixed code: procedure TForm1.WndProc(var Message: TMessage); begin inherited; if (Message.Msg = WM_NCACTIVATE) then begin DefWindowProc(handle, Message.Msg, 1, Message.LParam ); Message.Result := 1; end; end; –  Dec 21 '09 at 22:16
  • Yeah, you really REALLY don't want to get in the buisiness of drawing your own non-client area. – John Knoeller Dec 21 '09 at 22:20