FreeObjectInstance(FNewWndProc);
FNewWndProc := nil;
……
inherited Destroy;
end; //end of destructor
procedure TEoCSysTray.SetActive(Value: boolean);
begin
if Value <> FActive then
begin
FActive := Value;
if not (csDesigning in ComponentState) then //控件未处于设计状态
case Value of
True:
begin
……
HookParentForm; //替换父窗口的窗口过程
……
end;
False:
begin
……
UnHookParentForm; //还原父窗口的窗口过程
……
end;
end;
end;
end; //end of procedure SetActive
procedure TEoCSysTray.HookParentForm; //替换父窗口的窗口过程
var
P : Pointer;
begin
if Assigned(FParentWindow) and
not ((csDesigning in FParentWindow.ComponentState) or
(csDestroying in FParentWindow.ComponentState) or FDestroying) then
begin
FParentWindow.HandleNeeded;
P := Pointer(GetWindowLong(FParentWindow.Handle, GWL_WNDPROC));
if (P <> FNewWndProc) then
begin
FPrevWndProc := P;
SetWindowLong(FParentWindow.Handle,
GWL_WNDPROC, LongInt(FNewWndProc)); //替换父窗口的窗口过程
end;
end;
end; //end of procedure HookParentForm
procedure TEoCSysTray.UnHookParentForm; //还原父窗口的窗口过程
begin
if Assigned(FParentWindow) then
begin
if Assigned(FPrevWndProc) and FParentWindow.HandleAllocated and
(Pointer(GetWindowLong(FParentWindow.Handle, GWL_WNDPROC)) = FNewWndProc) then
SetWindowLong(FParentWindow.Handle,
GWL_WNDPROC, LongInt(FPrevWndProc)); //还原父窗口的窗口过程
end;
FPrevWndProc := nil;
end; //end of procedure UnHookParentForm
procedure TEoCSysTray.HookWndProc(var AMsg: TMessage);
begin
if Assigned(FParentWindow) then
begin
with AMsg do
begin
if Msg = MsgTaskbarCreated then //接收到任务栏重建消息
DoTaskBarCreated; //触发任务栏重建事件
if Assigned(FPrevWndProc) then //调用原窗口的窗口过程
Result := CallWindowProc(FPrevWndProc, FParentWindow.Handle,
Msg, WParam, LParam)
else
Result := CallWindowProc(THack(FParentWindow).DefWndProc,
FParentWindow.Handle, Msg, WParam, LParam);
if Msg = WM_DESTROY then //窗口正被销毁
UnHookParentForm; //还原父窗口的窗口过程
end;
end;
end; //end of procedure HookWndProc
procedure TEoCSysTray.DoTaskBarCreated;
begin
…… //在这里重新添加通知栏图标
if Assigned(FTaskBarCreated) then
FTaskBarCreated(Self);
end; //end of procedure DoTaskBarCreated
initialization
//注册询问任务栏重建的消息
MsgTaskbarCreated := RegisterWindowMessage(''''TaskbarCreated'''');
end.
文章整理:西部数码--专业提供域名注册、虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!




