类似金山词霸的启动(100分)

  • 主题发起人 sinohunter
  • 开始时间
S

sinohunter

Unregistered / Unconfirmed
GUEST, unregistred user!
请问如何制作运行后不显示界面,只是想金山词霸一样,显示在windows的状态条中
 
看看开始菜单的菜单属性就知道“开始”里面的“金山词霸”是加了运行参数的。
那么程序在启动时有没有带参数。如果有,而且是特定的,那么就不显示主FORM。
在FORM create的时候:
application.ShowMainForm:=false;
 
你把主Form的Windowstate设为wsminimized
 
http://delphi.mychangshu.com/folder.asp?id=39&Folder_name=系统相关
上面的地址里有如何加图标到tray栏的范例。
 
随便去哪下个控件不就得了吗
TRAYICON搜一把
 
看看这个控件。
unit TrayIcon;
interface
uses
SysUtils, Windows, Messages, Classes, Graphics, Controls, ShellAPI, Forms, menus;
const WM_TOOLTRAYICON = WM_USER+1;
WM_RESETTOOLTIP = WM_USER+2;
type
TTrayIcon = class(TComponent)
private
{ Field Variables }
IconData: TNOTIFYICONDATA;
fIcon : TIcon;
fToolTip : String;
fWindowHandle : HWND;
fActive : boolean;
fShowDesigning : Boolean;
{ Events }
fOnClick : TNotifyEvent;
fOnDblClick : TNotifyEvent;
fOnRightClick : TMouseEvent;
fPopupMenu : TPopupMenu;
function AddIcon : boolean;
function ModifyIcon : boolean;
function DeleteIcon : boolean;
procedure SetActive(Value : boolean);
procedure SetShowDesigning(Value : boolean);
procedure SetIcon(Value : TIcon);
procedure SetToolTip(Value : String);
procedure WndProc(var msg : TMessage);
procedure FillDataStructure;
proceduredo
RightClick( Sender : TObject );

protected
public
constructor create(aOwner : TComponent);
override;
destructor destroy;
override;
published
property Active : boolean read fActive write SetActive;
property ShowDesigning : boolean read fShowDesigning write SetShowDesigning;
property Icon : TIcon read fIcon write SetIcon;
property ToolTip : string read fTooltip write SetToolTip;
property OnClick : TNotifyEvent read FOnClick write FOnClick;
property OnDblClick : TNotifyEvent read FOnDblClick write FOnDblClick;
property OnRightClick : TMouseEvent read FOnRightClick write FonRightClick;
property PopupMenu : TPopupMenu read fPopupMenu write fPopupMenu;
end;

procedure Register;
implementation
procedure TTrayIcon.SetActive(Value : boolean);
begin
if value <> fActive then
begin
fActive := Value;
if not (csdesigning in ComponentState) then
begin
if Value then
begin
AddIcon;
end else
begin
DeleteIcon;
end;
end;
end;
end;

procedure TTrayIcon.SetShowDesigning(Value : boolean);
begin
if csdesigning in ComponentState then
begin
if value <> fShowDesigning then
begin
fShowDesigning := Value;
if Value then
begin
AddIcon;
end else
begin
DeleteIcon;
end;
end;
end;
end;

procedure TTrayIcon.SetIcon(Value : Ticon);
begin
if Value <> fIcon then
begin
fIcon.Assign(value);
ModifyIcon;
end;
end;

procedure TTrayIcon.SetToolTip(Value : string);
begin

// This routine ALWAYS re-sets the field value and re-loads the
// icon. This is so the ToolTip can be set blank when the component
// is first loaded. If this is changed, the icon will be blank on
// the tray when no ToolTip is specified.
if length( Value ) > 62 then
Value := copy(Value,1,62);
fToolTip := value;
ModifyIcon;
end;

constructor TTrayIcon.create(aOwner : Tcomponent);
begin
inherited create(aOwner);
FWindowHandle := AllocateHWnd( WndProc );
FIcon := TIcon.Create;
end;

destructor TTrayIcon.destroy;
begin

if (not (csDesigning in ComponentState) and fActive)
or ((csDesigning in ComponentState) and fShowDesigning) then
DeleteIcon;
FIcon.Free;
DeAllocateHWnd( FWindowHandle );
inherited destroy;
end;

procedure TTrayIcon.FillDataStructure;
begin

with IconDatado
begin

cbSize := sizeof(TNOTIFYICONDATA);
wnd := FWindowHandle;
uID := 0;
// is not passed in with message so make it 0
uFlags := NIF_MESSAGE + NIF_ICON + NIF_TIP;
hIcon := fIcon.Handle;
StrPCopy(szTip,fToolTip);
uCallbackMessage := WM_TOOLTRAYICON;
end;

end;

function TTrayIcon.AddIcon : boolean;
begin
FillDataStructure;
result := Shell_NotifyIcon(NIM_ADD,@IconData);
// For some reason, if there is no tool tip set up, then
the icon
//do
esn't display. This fixes that.
if fToolTip = '' then
PostMessage( fWindowHandle, WM_RESETTOOLTIP,0,0 );
end;

function TTrayIcon.ModifyIcon : boolean;
begin

FillDataStructure;
if fActive then
result := Shell_NotifyIcon(NIM_MODIFY,@IconData)
else
result := True;
end;

procedure TTrayIcon.DoRightClick( Sender : TObject );
var MouseCo: Tpoint;
begin

GetCursorPos(MouseCo);
if assigned( fPopupMenu ) then
begin
SetForegroundWindow( Application.Handle );
Application.ProcessMessages;
fPopupmenu.Popup( Mouseco.X, Mouseco.Y );
end;

if assigned( FOnRightClick ) then
begin
FOnRightClick(self,mbRight,[],MouseCo.x,MouseCo.y);
end;
end;

function TTrayIcon.DeleteIcon : boolean;
begin
result := Shell_NotifyIcon(NIM_DELETE,@IconData);
end;

procedure TTrayIcon.WndProc(var msg : TMessage);
begin
with msgdo
if (msg = WM_RESETTOOLTIP) then
SetToolTip( fToolTip )
else
if (msg = WM_TOOLTRAYICON) then
begin
case lParam of
WM_LBUTTONDBLCLK : if assigned (FOnDblClick) then
FOnDblClick(self);
WM_LBUTTONUP : if assigned(FOnClick)then
FOnClick(self);
WM_RBUTTONUP :do
RightClick(self);
end;
end
else
// Handle all messages with the default handler
Result := DefWindowProc(FWindowHandle, Msg, wParam, lParam);
end;
procedure Register;
begin
RegisterComponents('WL', [TTrayIcon]);
end;
end.
如果写程序来实现也可,那就不如写成控件有价值了。
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
955
SUNSTONE的Delphi笔记
S
顶部