关于API的小问题,模拟词霸效果,最小化到任务栏右边。(加急,谢谢提前)(300分)

  • 主题发起人 主题发起人 gophie
  • 开始时间 开始时间
G

gophie

Unregistered / Unconfirmed
GUEST, unregistred user!
1、启动后图标出现在任务栏右边小图标区<br>2、最小化任务栏不出现最小化窗口,仅出现在任务栏右边小图标,并且与1情况有异<br>3、双击任务栏右边小图标,程序激活<br>效果类似词霸。
 
建议你看看控件的源代码吧:<br>CoolTray,LMD,AHM,RX,JV(BU)等控件包都有这个功能
 
不要说工具,告诉我关键的几个API函数,并给个思想就可以啦!
 
建议你搜索一下帖子吧,也可以到www.playicq.com找找,这样浪费分数实在不明智。
 
不出现最小化窗口,可以使用ShowWindow(Application.Handle,SW_Hide);<br>隐藏程序窗口,可以用ShowWindow(MainForm.Handle,SW_Hide);<br>而任务栏的图标,可以使用Shell_NotifyIcon(NIM_ADD,@fIconData);<br>具体你看Shell_NotifyIcon的帮助,很详细,你可以看懂的
 
Shell_NotifyIcon(NIM_ADD,@fIconData);<br>可以实现!
 
DeLphi开发人员指南上又例子,138元/本
 
uses shellapi;<br>procedure addico;<br>var<br>&nbsp; ICONDATA: TNOTIFYICONDATA;<br>begin<br>&nbsp; ICONDATA.Wnd := HANDLE;<br>&nbsp; ICONDATA.uID := 1;<br>&nbsp; ICONDATA.uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP;<br>&nbsp; ICONDATA.uCallbackMessage := WM_USER + 254;<br>&nbsp; ICONDATA.hIcon := application.Icon.Handle;<br>&nbsp; ICONDATA.szTip := 'hello';<br>&nbsp; shell_notifyicon(nim_add, @icondata);<br>end;<br><br>procedure delico;<br>var<br>&nbsp; ICONDATA: TNOTIFYICONDATA;<br>begin<br>&nbsp; ICONDATA.Wnd := HANDLE;<br>&nbsp; IconData.cbSize := SizeOf(IconData);<br>// &nbsp;ICONDATA.Wnd := application.Icon.Handle;<br>&nbsp; IconData.uID := 1;<br>&nbsp; IconData.uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP;<br>&nbsp; shell_notifyicon(NIM_DELETE, @icondata);<br>end;<br>自己定义一个最小化,最大化过程如appmini,apprestore<br>再form的create事件中写入<br>&nbsp;application.OnMinimize := appmini;<br>&nbsp; application.OnRestore := apprestore;<br>在appmini中<br>&nbsp;addico;<br>&nbsp; showwindow(application.Handle, sw_hide);<br>在apprestore中<br>&nbsp;ShowWindow(application.Handle, SW_SHOW);<br><br><br>搞定.给分吧!<br>
 
给个现成的吧。<br><br><br>unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils,shellapi, Variants, Classes, Graphics, Controls, Forms,<br>&nbsp; Dialogs,Registry;<br><br>const CM_RESTORE = WM_USER &nbsp;+ 100;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; procedure FormCreate(Sender: TObject);<br>&nbsp; &nbsp; procedure FormShow(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; procedure WMSysCommand(var msg: TWMSysCommand); message WM_SysCommand;<br>&nbsp; &nbsp; procedure RestoreRequest(var message:TMessage);message CM_RESTORE;<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br><br>procedure TForm1.RestoreRequest(var message:TMessage);<br>begin<br>&nbsp; &nbsp; if Message.LParam =WM_LBUTTONUP then &nbsp; &nbsp; &nbsp; //按左键show..<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; show;<br>&nbsp; &nbsp; &nbsp; application.BringToFront;<br>&nbsp; &nbsp; end;<br><br>end;<br><br><br>procedure TForm1.FormCreate(Sender: TObject);<br>var<br>&nbsp; nid: TNotifyIconData;<br>&nbsp; myreg:TRegistry;<br>&nbsp; MySysPath:string;<br>begin<br>&nbsp; nid.cbSize := sizeof(nid); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //在任务栏创建图标<br>&nbsp; nid.Wnd := Handle;<br>&nbsp; nid.uID:=4;<br>&nbsp; nid.hIcon := Application.Icon.Handle;<br>&nbsp; nid.szTip := '红太阳Vod数据库程序';<br>&nbsp; nid.uCallbackMessage := CM_RESTORE;<br>&nbsp; nid.uFlags := NIF_ICON or NIF_TIP or NIF_MESSAGE; // 指明哪些字段有效<br>&nbsp; if not Shell_NotifyIcon(NIM_ADD, @nid) then begin<br>&nbsp; &nbsp; &nbsp;ShowMessage('Failed!');<br>&nbsp; &nbsp; &nbsp;Application.Terminate;<br>&nbsp; end;<br>end;<br><br>procedure TForm1.WMSysCommand(var msg: TWMSysCommand);<br>begin <br>&nbsp; if msg.CmdType and $FFF0 = SC_MINIMIZE then <br>&nbsp; &nbsp; hide <br>&nbsp; else <br>&nbsp; &nbsp; inherited; <br>end;<br><br>procedure TForm1.FormShow(Sender: TObject);<br>begin<br>&nbsp; ShowWindow(Application.Handle,SW_HIDE);<br>end;<br><br>end.<br>
 
unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; ShellAPI, Menus, McMenu, StdCtrls;<br><br>const<br>&nbsp; WM_MIDASICON &nbsp; &nbsp;= WM_USER + 1;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; PopupMenu1: TPopupMenu;<br>&nbsp; &nbsp; N1: TMenuItem;<br>&nbsp; &nbsp; N2: TMenuItem;<br>&nbsp; &nbsp; McMenu1: TMcMenu;<br>&nbsp; &nbsp; procedure FormDestroy(Sender: TObject);<br>&nbsp; &nbsp; procedure N1Click(Sender: TObject);<br>&nbsp; &nbsp; procedure N2Click(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; FIconData: TNotifyIconData;<br>&nbsp; &nbsp; procedure InitMenu(var Message: TMessage); &nbsp;message WM_MIDASICON;<br>&nbsp; &nbsp; procedure WndProc(var Message: TMessage); override;<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; procedure AddIcon;<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br><br>procedure TForm1.WndProc(var Message: TMessage);<br>begin<br>&nbsp; inherited WndProc(Message);<br>end;<br><br>procedure TForm1.InitMenu(var Message: TMessage);<br>var<br>&nbsp; pt: TPoint;<br>begin<br>&nbsp; case Message.LParam of<br>&nbsp; &nbsp; WM_RBUTTONUP:<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; if not Visible then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; SetForegroundWindow(Handle);<br>&nbsp; &nbsp; &nbsp; &nbsp; GetCursorPos(pt);<br>&nbsp; &nbsp; &nbsp; &nbsp; PopupMenu1.Popup(pt.x, pt.y);<br>&nbsp; &nbsp; &nbsp; end else<br>&nbsp; &nbsp; &nbsp; &nbsp; SetForegroundWindow(Handle);<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; WM_LBUTTONDBLCLK:<br>&nbsp; &nbsp; &nbsp; if Visible then<br>&nbsp; &nbsp; &nbsp; &nbsp; SetForegroundWindow(Handle) else<br>// &nbsp; &nbsp; &nbsp; &nbsp;miPropertiesClick(nil);<br>&nbsp; end;<br>end;<br><br>procedure TForm1.AddIcon;<br>begin<br>&nbsp; with FIconData do<br>&nbsp; begin<br>&nbsp; &nbsp; cbSize := SizeOf(FIconData);<br>&nbsp; &nbsp; Wnd := Self.Handle;<br>&nbsp; &nbsp; uID := $DEDB;<br>&nbsp; &nbsp; uFlags := NIF_MESSAGE or NIF_ICON or NIF_TIP;<br>&nbsp; &nbsp; hIcon := Forms.Application.Icon.Handle;<br>&nbsp; &nbsp; uCallbackMessage := WM_MIDASICON;<br>&nbsp; &nbsp; StrCopy(szTip, PChar(Caption));<br>&nbsp; end;<br>&nbsp; Shell_NotifyIcon(NIM_Add, @FIconData);<br>end;<br><br>procedure TForm1.FormDestroy(Sender: TObject);<br>begin<br>&nbsp; Shell_NotifyIcon(NIM_delete, @FIconData);<br>end;<br><br>procedure TForm1.N1Click(Sender: TObject);<br>begin<br>&nbsp; close;<br>end;<br><br>procedure TForm1.N2Click(Sender: TObject);<br>begin<br>&nbsp; show;<br>end;<br><br>end.<br><br>~~~~~~~~~~~~~~~~~~~~~~<br>program trayico;<br><br>uses<br>&nbsp; Forms,<br>&nbsp; Unit1 in 'Unit1.pas' {Form1};<br><br>{$R *.RES}<br><br>begin<br>&nbsp; Forms.Application.ShowMainForm := False;<br>&nbsp; Application.Initialize;<br>&nbsp; Application.CreateForm(TForm1, Form1);<br>&nbsp; Form1.AddIcon;<br>&nbsp; Application.Run;<br>end.
 
这样的程序网上有非常多的例子。是个系统托盘问题。
 
unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; Menus,ShellAPI;<br>&nbsp; const<br>&nbsp; mousemsg=wm_user+1;<br>&nbsp; iid=100;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; PopupMenu1: TPopupMenu;<br>&nbsp; &nbsp; Exit: TMenuItem;<br>&nbsp; &nbsp; procedure FormCreate(Sender: TObject);<br>&nbsp; &nbsp; procedure FormClose(Sender: TObject; var Action: TCloseAction);<br>&nbsp; &nbsp; procedure ExitClick(Sender: TObject);<br>&nbsp; private<br>&nbsp; procedure mousemessage(var message:tmessage);message mousemsg;<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br>&nbsp; ntida:TNotifyIcondataA;<br><br>implementation<br><br>{$R *.DFM}<br><br>procedure TForm1.mousemessage (var message:tmessage);<br>var<br>&nbsp; mousept:TPoint;<br>begin<br>&nbsp; inherited;<br>&nbsp; if message.LParam=wm_rbuttonup then begin<br>&nbsp; &nbsp; getcursorpos(mousept);<br>&nbsp; &nbsp; popupmenu1.Popup(mousept.x,mousept.y);<br>&nbsp; end;<br>&nbsp; if message.LParam=wm_lbuttonup then<br>&nbsp; begin<br>&nbsp; &nbsp; ShowWindow(Handle,sw_show);<br>&nbsp; &nbsp; ShowWindow(Application.handle,SW_SHOW);<br>&nbsp; &nbsp; SetWindowLong(Application.Handle,GWL_eXSTYLE,not (GetWindowLong(Application.handle,gwl_exstyle)or ws_ex_toolwindow and not ws_ex_appwindow));<br>&nbsp; end;<br>end;<br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br>&nbsp; ntida.cbSize:=sizeof(tnotifyicondataa);<br>&nbsp; ntida.Wnd:=handle;<br>&nbsp; ntida.uID:=iid;<br>&nbsp; ntida.uFlags:=nif_icon+nif_tip+nif_message;<br>&nbsp; ntida.uCallbackMessage:=mousemsg;<br>&nbsp; ntida.hIcon:=Application.Icon.Handle;<br>&nbsp; ntida.szTip:='Icon';<br>&nbsp; shell_notifyicona(NIM_ADD,@ntida);<br>end;<br><br>procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);<br>begin<br>&nbsp; Action:=caNone;<br>&nbsp; ShowWindow(Handle,SW_HIDE);<br>&nbsp; ShowWindow(Application.Handle,Sw_HIDE);<br>&nbsp; SetWindowLong(Application.Handle,GWL_EXSTYLE,GETWindowLong(Application.handle,GWL_exstyle)or ws_ex_toolwindow and ws_ex_appwindow);<br>end;<br><br>procedure TForm1.ExitClick(Sender: TObject);<br>begin<br>&nbsp; ntida.cbSize:=sizeof(tnotifyicondataa);<br>&nbsp; ntida.Wnd:=handle;<br>&nbsp; ntida.uID:=iid;<br>&nbsp; ntida.uCallbackMessage:=nif_icon+nif_tip+nif_message;<br>&nbsp; ntida.hIcon:=Application.Icon.Handle;<br>&nbsp; ntida.szTip:='Icon' ;<br>&nbsp; Shell_notifyicona(NIM_DELETE,@ntida);<br>&nbsp; Application.Terminate;<br>end;<br><br>end.
 
请看:<br>http://www.delphibbs.com/delphibbs/dispq.asp?lid=200656<br>非常详细
 
多人接受答案了。
 
后退
顶部