如何自动隐藏,显示windows的任务栏,最好有源代码

torrentwang 2001-06-22 03:01:00
...全文
91 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
torrentwang 2001-06-22
  • 打赏
  • 举报
回复
测试一切OK,感谢大家的参与

to Apollo47(阿波罗) 我想向你请教个问题
http://www.csdn.net/expert/topicview1.asp
有时间帮忙看一下好吗


wonderxin 2001-06-22
  • 打赏
  • 举报
回复
如何隐藏和显示Windows的任务条?仅仅调用以下的函数就可以.

procedure hideTaskbar; //隐藏

var

wndHandle : THandle;

wndClass : array[0..50] of Char;

begin

StrPCopy(@wndClass[0], 'Shell_TrayWnd');

wndHandle := FindWindow(@wndClass[0], nil);

ShowWindow(wndHandle, SW_HIDE);

End;

 

procedure showTaskbar;

var

wndHandle : THandle;

wndClass : array[0..50] of Char;

begin

StrPCopy(@wndClass[0], 'Shell_TrayWnd');

wndHandle := FindWindow(@wndClass[0], nil);

ShowWindow(wndHandle, SW_RESTORE);

end;

enlightenment 2001-06-22
  • 打赏
  • 举报
回复

这个问题不知被问了多少次啦!

给你一个托盘组件的源代码。


unit TrayIcon;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, Menus, ShellAPI;

type
TDCPTrayIcon = class(TComponent)
private
{ Private declarations }
FNotificationHandle: HWnd;
FTrayIcon: TIcon;
FShowHint: Boolean;
FHint: string;
FActive: Boolean;
FCurrentlyActive: Boolean;
FOnDblClick: TNotifyEvent;
FPopupMenu: TPopupMenu;
procedure NotificationWndProc(var Message : TMessage);
procedure SetShowHint(const Value: Boolean);
procedure SetHint(const Value: string);
procedure SetTrayIcon(const Value: TIcon);
procedure SetActive(const Value: Boolean);
procedure SetPopupMenu(const Value: TPopupMenu);
protected
{ Protected declarations }
procedure DoDblClick;
procedure Loaded; override;
procedure OnAppMinimize(Sender: TObject);
function SendTrayMessage(AMessage: DWORD): Boolean;
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure RemoveTrayIcon;
procedure RestoreApp;
procedure ShowTrayIcon;
procedure RemoveFromTaskbar;
procedure ShowInTaskbar;
published
{ Published declarations }
property Active: Boolean read FActive write SetActive;
property Hint: string read FHint write SetHint;
property OnDblClick: TNotifyEvent read FOnDblClick write FOnDblClick;
property PopupMenu: TPopupMenu read FPopupMenu write SetPopupMenu;
property ShowHint: Boolean read FShowHint write SetShowHint;
property TrayIcon: TIcon read FTrayIcon write SetTrayIcon;
end;

procedure Register;

implementation

const
ID_TRAYICON = 1;
UWM_TRAYICON = WM_USER + 1;

procedure Register;
begin
RegisterComponents('YourPallateName', [TDCPTrayIcon]);
end;

{ TDCPTrayIcon }

constructor TDCPTrayIcon.Create(AOwner: TComponent);
begin
inherited Create(AOwner);

FNotificationHandle := AllocateHWnd(NotificationWndProc);
FTrayIcon := TIcon.Create;

Application.OnMinimize := OnAppMinimize;
end;

destructor TDCPTrayIcon.Destroy;
begin
if FCurrentlyActive then
RemoveTrayIcon;

FTrayIcon.Free;

if FNotificationHandle <> 0 then
DeallocateHWnd(FNotificationHandle);

inherited Destroy;
end;

procedure TDCPTrayIcon.DoDblClick;
begin
if Assigned(OnDblClick) then
OnDblClick(self);
end;

procedure TDCPTrayIcon.Loaded;
begin
inherited Loaded;

if not (csDesigning in ComponentState) then begin
if FTrayIcon.Handle = 0 then
FTrayIcon.Assign(Application.Icon);
end;

SetTrayIcon(FTrayIcon);

if FActive then
ShowTrayIcon;
end;

procedure TDCPTrayIcon.NotificationWndProc(var Message: TMessage);
var
Pt: TPoint;
begin
if Message.Msg = UWM_TRAYICON then begin
case Message.lParam of
WM_LBUTTONDBLCLK:
DoDblClick;

WM_RBUTTONDOWN:
if Assigned(FPopupMenu) then begin
SetForegroundWindow(FNotificationHandle);
GetCursorPos(Pt);
FPopupMenu.Popup(Pt.X, Pt.Y);
end;
end;
end;
end;

procedure TDCPTrayIcon.OnAppMinimize(Sender: TObject);
begin
if FCurrentlyActive then
RemoveFromTaskbar;
end;

procedure TDCPTrayIcon.RemoveFromTaskbar;
begin
if not (csDesigning in ComponentState) then begin
ShowWindow(Application.Handle, SW_HIDE);
ShowWindow(Application.MainForm.Handle, SW_HIDE);
end;
end;

procedure TDCPTrayIcon.RemoveTrayIcon;
begin
if FCurrentlyActive then
if SendTrayMessage(NIM_DELETE) then begin
FCurrentlyActive := False;

ShowInTaskbar;
end;
end;

procedure TDCPTrayIcon.RestoreApp;
begin
ShowInTaskbar;
SetForegroundWindow(Application.MainForm.Handle);
end;

function TDCPTrayIcon.SendTrayMessage(AMessage: DWORD): Boolean;
var
Flags: Integer;
NotifyIconData: TNotifyIconData;
begin
Result := True;
if csDesigning in ComponentState then
exit;

Flags := NIF_MESSAGE or NIF_ICON;
if FShowHint then
Flags := Flags or NIF_TIP;

FillChar(NotifyIconData, SizeOf(NotifyIconData), 0);
with NotifyIconData do begin
cbSize := SizeOf(TNotifyIconData);
Wnd := FNotificationHandle;
uID := ID_TRAYICON;
uFlags := Flags;
uCallBackMessage := UWM_TRAYICON;
hIcon := FTrayIcon.Handle;
StrLCopy(szTip, PChar(FHint), SizeOf(szTip));
end;

Result := Shell_NotifyIcon(AMessage, @NotifyIconData);
end;

procedure TDCPTrayIcon.SetActive(const Value: Boolean);
begin
FActive := Value;

if FActive then
ShowTrayIcon
else
RemoveTrayIcon;
end;

procedure TDCPTrayIcon.SetHint(const Value: string);
begin
FHint := Value;

SendTrayMessage(NIM_MODIFY);
end;

procedure TDCPTrayIcon.SetPopupMenu(const Value: TPopupMenu);
begin
FPopupMenu := Value;
end;

procedure TDCPTrayIcon.SetShowHint(const Value: Boolean);
begin
FShowHint := Value;

SendTrayMessage(NIM_MODIFY);
end;

procedure TDCPTrayIcon.SetTrayIcon(const Value: TIcon);
begin
FTrayIcon.Assign(Value);

SendTrayMessage(NIM_MODIFY);
end;

procedure TDCPTrayIcon.ShowInTaskbar;
begin
if not (csDesigning in ComponentState) then begin
if Application.MainForm <> nil then
ShowWindow(Application.MainForm.Handle, SW_SHOWNORMAL);
ShowWindow(Application.Handle, SW_SHOWNORMAL);
end;
end;

procedure TDCPTrayIcon.ShowTrayIcon;
begin
if SendTrayMessage(NIM_ADD) then
FCurrentlyActive := True;
end;

end.




由菜单Component->Install Component...导入该新组件。





Apollo47 2001-06-22
  • 打赏
  • 举报
回复
ShowWindow(FindWindow('Shell_TrayWnd',nil),SW_Hide); // 隐藏;
ShowWindow(FindWindow('Shell_TrayWnd',nil),SW_Show); // 显示;

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧