如何隐藏程序,就是任务栏上没有程序,系统右下角的托盘上有显示程序图标
解决方案 »
- 怎样把sqlserver和程序一起打包呢?
- richedit的readonly-->true后,如何改变字体颜色?
- ◆有什么API函数或办法能让一个指定的窗口(其它程序的窗口)总显示在另一个窗口(自己的或其它程序的窗口)的前面?
- dcu文件,大家帮忙
- 在XP SP2的服务器上启用Windows防火墙之后,客户端调用其COM+组件报错:RPC 服务器不可用,关闭防火墙又好了,为什么?
- 招聘软件开发人员(工作地点石家庄)
- 在TreeView控件中。当点击图标时,要改变其图标的图片,如何实现?
- 如何将16进制转换成String类型 急!急!急!急!急!急!急!
- 用TIdTcpClient接收一个服务端发送的数据时发生延迟,请教各位如何解决
- 为感谢大家对我这个菜鸟的帮助。特地把DELPHI5开发人员指南电子版发到公司的服务器上请下载。但是希望别用太多线程。要不就完了。普通的虚拟主机而已。
- 关于系统托盘问题
- 关于message消息
const
WM_NID = WM_USER + 200;type
...
private
{ Private declarations }
NotifyIcon: TNotifyIconData;
procedure IconOnClick(var Msg: TMessage); message WM_NID;
procedure AddIcon;
procedure DelIcon;
procedure WMSYSCOMMAND(var Msg: TMessage); message WM_SYSCOMMAND;
procedure OnMinimize(Sender: TObject);
...
implementationprocedure TfrmIcon.FormCreate(Sender: TObject);
begin
Application.OnMinimize := OnMinimize;
end;procedure TfrmIcon.AddIcon;
begin
with NotifyIcon do
begin
cbSize := SizeOf(TNotifyIconData);
Wnd := self.Handle;
uID := 1;
uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP;
uCallBackMessage := WM_NID;
hIcon := Application.Icon.Handle;
szTip := '我的托盘窗体';
end;
Application.Minimize;
ShowWindow(Application.Handle, SW_HIDE);
self.Hide;
Shell_NotifyIcon(NIM_ADD, @NotifyIcon);
end;procedure TfrmIcon.DelIcon;
begin
ShowWindow(Application.Handle, SW_SHOW);
Application.Restore;
self.Show;
SetForegroundWindow(Self.Handle);
Shell_NotifyIcon(NIM_DELETE, @NotifyIcon);
end;procedure TfrmIcon.OnMinimize(Sender: TObject);
begin
AddIcon;
end;procedure TfrmIcon.IconOnClick(var Msg: TMessage);
var
mp: TPoint;
begin
if Msg.LParam = WM_LBUTTONDBLCLK then
DelIcon
else if Msg.LParam = WM_RBUTTONUP then
begin
GetCursorPos(mp);
pmMain.Popup(mp.X, mp.Y);
end
else
Inherited;
end;procedure TfrmIcon.WMSYSCOMMAND(var Msg: TMessage);
begin
if Msg.WParam = SC_MINIMIZE then
AddIcon
else
Inherited;
end;procedure TfrmIcon.pmOpenClick(Sender: TObject);
begin
DelIcon;
end;procedure TfrmIcon.pmExitClick(Sender: TObject);
begin
Close();
end;procedure TfrmIcon.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Shell_NotifyIcon(NIM_DELETE, @NotifyIcon);
end;
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long Const SW_HIDE = 0
Const GW_OWNER = 4Private Sub Command1_Click()
Dim rc As Long
Dim OwnerhWnd As Long Me.Visible = False '使窗体不可见
'从任务管理器应用程序列表中隐藏
OwnerhWnd = GetWindow(Me.hwnd, GW_OWNER)
rc = ShowWindow(OwnerhWnd, SW_HIDE)End Sub
可以用
SetWindowLong(Form1.handle,GWL_EXSTYLE,WS_EX_TOOLWINDOW);
托盘编程则麻烦一些
有相关帖子
可以搜一下~
这里的 NIF_ICON,NIF_MESSAGE, NIF_TIP是什么?
我在编译的时候 报错
Undeclared identifier:'NIM_ICON'
Undeclared identifier:'NIM_MESSAGE'
怎么回事啊
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, Menus,shellapi; const
WM_TrayMessage=WM_User+100; //这句是你要加的
type
TForm1 = class(TForm)
MainMenu1: TMainMenu;
N11: TMenuItem;
N21: TMenuItem;
N22: TMenuItem;
N23: TMenuItem;
N24: TMenuItem;
N31: TMenuItem;
N32: TMenuItem;
PopupMenu1: TPopupMenu;
er1: TMenuItem;
rer1: TMenuItem;
rer2: TMenuItem;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure N21Click(Sender: TObject);
procedure rer1Click(Sender: TObject);
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
protected
procedure AppMinimized(Sender: TObject);
procedure WMTrayMessage(var msg:TMessage);message WM_TrayMessage;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
NID:TNotifyIconData;
implementation
{$R *.DFM}
{ TForm1 }
procedure TForm1.AppMinimized(Sender: TObject);
begin
NID.cbSize:=SizeOf(TNotifyIconData);
NID.hIcon:=Application.Icon.Handle;
NID.szTip:= '工程一 ';
NID.uCallbackMessage:=WM_TrayMessage;
NID.uFlags:=NIF_ICON or NIF_MESSAGE or NIF_TIP; //这句是你要改的
NID.uID:=0;
NID.Wnd:=Handle;
Shell_NotifyIcon(NIM_ADD,@NID);
ShowWindow(Application.Handle,SW_Hide);
end;
procedure TForm1.WMTrayMessage(var msg: TMessage);
var
p:TPoint;
begin
if msg.LParam=WM_LButtonDown then
begin
ShowWindow(Application.Handle,SW_Show);
Application.Restore;
end
else if msg.LParam=WM_RButtonDown then
begin
GetCursorPos(p);
PopupMenu1.Popup(p.x,p.y);
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
//var Owner : HWnd;
begin
//Owner:=GetWindow(Handle,GW_OWNER);
// ShowWindow(Owner,SW_HIDE);
Application.OnMinimize:=AppMinimized;
AppMinimized(nil);
end;
还是说
Undeclared identifier:'NIM_ICON'
Undeclared identifier:'NIM_MESSAGE'
Undeclared identifier:'NIF_TIP'
是不是调用这三个参数要加什么东西啊
大家帮忙看看吧unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, shellapi;
const WM_NID=WM_USER+1000;type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
procedure WMNID(var msg:TMessage); message WM_NID; //这里message报错
var
Form1: TForm1;
Extendedstyle:integer;
NotifyIcon:TNotifyIconData;
implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
begin
Extendedstyle := GetWindowLong (Application.Handle, GWL_EXstyle);
SetWindowLong(Application.Handle, GWL_EXstyle, Extendedstyle OR WS_EX_TOOLWINDOW
AND NOT WS_EX_APPWINDOW); //用于隐藏任务栏上的程序 With NotifyIcon do
begin
cbSize:=SizeOf(TNotifyIconData);
Wnd:=Handle;
uID:=1;
uFlags:=NIM_ICON or NIM_MESSAGE or NIM_TIP; //这里的三个参数也报错,说是 //Undeclared identifier
uCallBackMessage:=WM_NID;
hIcon:=Application.Icon.Handle;
szTip:='我是老大';
end;
Shell_NotifyIcon(NIM_ADD,@NotifyIcon);
end;procedure WMNID(var msg:TMessage); message WM_NID; //这里的message也有问题
begin
case msg.LParam of
WM_LBUTTONUp: Form1.Visible:=not Form1.Visible;
WM_RBUTTONUP: ShowMessage('right');
End;
End;
procedure TForm1.FormDestroy(Sender: TObject);
begin
Shell_NotifyIcon(NIM_DELETE,@NotifyIcon);
end;end.