为什么不能传递窗体的handle给另一个类的hwnd数据类型的变量?????如何才能在另一个类中得到窗体的句柄??
解决方案 »
- ServerSocket和ClientSocket在局域网通讯问题
- 同志们,问题严重了,关于读取网络连接名称的问题!!!
- 问个有难度的问题,关于StringGrid的,高手进来
- 求敲击键盘代码!
- 我看道大家的程序都把ADOQuery 、ADODataSource 等放在一个DM里面,不解?
- SQl问题
- 怎么可以让toolbar按钮的位图可以很大,imagelist的只能是很小的
- ★★如何实现按一下按钮可以终止一个正在运行中的循环?请举个例子,谢谢!
- access数据库问题
- 高高手们:如何播放存入大字段中的wav文件?
- DELPHI中SQL程序的发布方法
- 谁知道哪有关于ExpressQuantumGrid控件集用法的介绍?
Windows,shellapi,QMenus, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, Menus, StdCtrls; //自定义消息}
const MY_MESSAGE = WM_USER + 102;
const fmsg = WM_USER + 103;
type
TNotify=class(tcomponent)
//const fmsg = WM_USER + 102; //
private
fnd:TNotifyIconData;
fhicon:hicon;
//fmsg:tmessage; //'ucallbackmessage fwnd:hwnd; //'窗体句柄
fRbutoonPop:Tpopupmenu; //'右击托盘出现的菜单
procedure OnIconNotify(var Message: TMessage); message fmsg;
public
constructor create(aowner:tcomponent);override;//'''fwnd1是窗体句柄
procedure hideform(); //'''隐藏窗体
procedure seticon(ficon:hicon); //'''设置图标
procedure setmessage(msg:Tmessage); //'''设置回调函数
procedure setwnd(fwnd1:hwnd);
procedure showme; //'''显示
procedure setRbutoonPop(popmenu:Tpopupmenu); //'''设置右击鼠标时候弹出的菜单
end;type
TForm1 = class(TForm)
imgicon: TImage;
popmenu: TPopupMenu;
open1: TMenuItem;
close1: TMenuItem;
exit1: TMenuItem;
Button1: TButton;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Button1Click(Sender: TObject); private
{ Private declarations }
fnotify:tnotify; public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
//var fnd:TNotifyIconData;
begin
//fnd.cbsize:=sizeof(fnd);
//fnd.wnd:=form1.Handle;
//fnd.uid:=1;
//shell_notifyicon(nim_delete,@fnd);
//shell_notifyicon(nim_delete,@fnd);
end;{ TNotify }constructor TNotify.create(aowner:tcomponent);
begin
inherited create(nil);
//
//showmessage(inttostr(fwnd1));//fwnd:=fwnd1;
//FWindowHandle := AllocateHWnd(WndProc);
//inherited Create(AOwner);
//fwnd := TForm(AOwner).Handle
//fwnd:= AllocateHWnd(OnIconNotify);
end;procedure TNotify.hideform;
begin
showwindow(fwnd, SW_HIDE);
Application.ShowMainForm := False;
end;procedure TNotify.OnIconNotify(var Message: TMessage);
var Busy:Boolean;
begin
busy:=false;
if not Busy then
begin
Busy:=true;
if Message.LParam=WM_LBUTTONDOWN then
begin
SetForegroundWindow(fwnd);
showmessage('fddd');
end;
//if Application.MessageBox('Are you sure','Exit', MB_YESNO)=IDYES then Close;
Busy := false;
end;
end;procedure TNotify.seticon(ficon: hicon);
begin
fhicon:=ficon;
end;procedure TNotify.setmessage(msg: Tmessage);
begin
//fmsg:=msg;
end;procedure TNotify.setRbutoonPop(popmenu: Tpopupmenu);
begin
fRbutoonPop:=popmenu;
end;procedure TNotify.setwnd(fwnd1: hwnd);
begin
fwnd:=fwnd1;
//fwnd:=findwindow('tform1',nil);
end;procedure TNotify.showme;
begin
//
fnd.cbsize:=sizeof(fnd);
fnd.wnd:=fwnd;
fnd.uid:=1;
fnd.uflags:=nif_message or nif_icon or nif_tip;
fnd.ucallbackmessage:=fmsg;
fnd.hIcon:=fhicon;
shell_notifyicon(nim_add,@fnd);
end;procedure TForm1.Button1Click(Sender: TObject);
begin
//fnotify.create(nil);
fnotify.setwnd(self.Handle) ;
fnotify.seticon(imgicon.Picture.Icon.Handle);
//fnotify.setmessage(MY_MESSAGE);
fnotify.setRbutoonPop(popmenu);
fnotify.showme;
end;end.
begin
fwnd:=fwnd1;////////////出错出错???????????
//fwnd:=findwindow('tform1',nil);
end;