Keep Window Looking Active
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 Mous开发者_开发问答e_Event calls.
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;
精彩评论