怎么隐藏我这段代码的程序窗体(就是一运行的时候自动隐藏起来,然后通过热键激活程序界面)(10分)

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

suyude

Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;

type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
procedure WMHotKey(var Message: TWMHOTKEY); message WM_HOTKEY;

{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
//注册ctrl+alt+z热键
RegisterHotKey(Handle, GlobalAddAtom('hotkey'), MOD_CONTROL+MOD_ALT, ord('Z'));
end;

procedure TForm1.WMHotKey(var Message: TWMHOTKEY);
begin
//按下热键所执行的事件{问,如果成功隐藏程序窗体以后,这里用什么代码激活程序界面呢?}
application.MessageBox('内容','标题',mb_ok);
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
//在关闭时注销热键
UnregisterHotKey(Handle, GlobalAddAtom('hotkey'));
end;

end.
 
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,shellapi,
Menus;
const MI_ICONEVENT=WM_User+1;
ICON_ID = 10001;
type
TForm1 = class(TForm)
PopupMenu1: TPopupMenu;
pop_show: TMenuItem;
N1: TMenuItem;
procedure FormCreate(Sender: TObject);
procedure pop_showClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormPaint(Sender: TObject);
procedure N1Click(Sender: TObject);
private
procedure InstallIcon;
procedure UnInstallIcon;
procedure WMHotkeyHandle(var Msg:TMessage);message WM_HOTKEY; //响应敏感键按键消息
procedure IconOnClick(var Msg:TMessage);message MI_ICONEVENT;
procedure WMSysCommand(var Msg:TMessage);message WM_SysCommand;
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
HotkeyId:integer;
implementation

uses Unit2;
procedure TForm1.InstallIcon;
var
IconData: TNotifyIconData;
begin
IconData.cbSize := SizeOf(IconData);
IconData.Wnd := Handle;
IconData.uID := 0;
IconData.uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP;
IconData.uCallbackMessage := MI_ICONEVENT;
IconData.hIcon := Application.Icon.Handle;
IconData.szTip := '程序运行';
Shell_NotifyIcon(NIM_ADD,@IconData);
end;
procedure TForm1.UnInstallIcon;
var
IconData: TNotifyIconData;
begin
IconData.cbSize := SizeOf(IconData);
IconData.Wnd := Handle;
IconData.uID := ICON_ID;
Shell_NotifyIcon(NIM_DELETE,@IconData);
end;
{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
InstallIcon;
showwindow(Application.handle,SW_HIDE);
SetwindowLong(Application.handle,GWL_EXSTYLE,WS_EX_TOOLWINDOW);
HotkeyId:=GlobalAddAtom(pchar('0'))-$C000; //减去$C000是为了保证取值范围的限制
RegisterHotkey(Handle,HotkeyId,MOD_CONTROL or MOD_Alt, $41);//敏感键为ctrl+Alt+A
end;
procedure TForm1.WMHotkeyHandle(var Msg:TMessage); //响应敏感键按键消息
begin
if (Msg.LParamHi=$41) and (msg.lparamLo=MOD_CONTROL or mod_Alt) then
begin
Msg.Result:=1; //该消息已经处理
form2.show;
end;
end;
procedure TForm1.IconOnClick(var Msg:TMessage);
var
p: TPoint;
begin
if (Msg.LParam = WM_RBUTTONDOWN) then
begin
GetCursorPos(p);
PopupMenu1.Popup(p.x,p.y);
end;
end;
procedure TForm1.pop_showClick(Sender: TObject);
var
handle:Thandle;
begin
Form2.show;
{handle:=Findwindow(nil,'project1');
showwindow(handle,SW_SHOW);}
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
UnInstallIcon;
end;
procedure TForm1.WMSysCommand(var Msg:TMessage);
begin
if Msg.WParam=SC_MINIMIZE then
begin
Application.Minimize;
Form1.Hide;
end;
inherited;
end;
procedure TForm1.FormPaint(Sender: TObject);
begin
hide;
end;

procedure TForm1.N1Click(Sender: TObject);
begin
close;
end;

end.
 
接受答案了.
 
后退
顶部