为什么左键右键都没反应(50分)

  • 主题发起人 主题发起人 cemer815
  • 开始时间 开始时间
C

cemer815

Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;

interface

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

const wm_command=wm_user+1000;
type
TForm1 = class(TForm)
PopupMenu1: TPopupMenu;
guan1: TMenuItem;
haoren1: TMenuItem;
kai1: TMenuItem;
procedure FormCreate(Sender: TObject);
// procedure FormDestroy(Sender: TObject);
private
{ Private declarations }

NID:TNotifyIconData;

public
{ Public declarations }
procedure IconTray(var Msg:TMessage); Message wm_command; //托盘


end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
self.Caption :='冰自动';
nid.cbSize :=sizeof(nid);
nid.Wnd :=self.Handle;
nid.uID :=1;
nid.uCallbackMessage := wm_command;
nid.hIcon :=Application.Icon.Handle;
nid.szTip :='冰自动';
nid.uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP;
shell_NotifyIcon(NiM_Add,@nid);
end;

procedure TForm1.IconTray(var msg: TMessage);

var
pt: TPoint;
begin
if Msg.LParam=wm_rbuttondown then //鼠标右键
begin
SetForeGroundWindow(Form1.Handle);
GetCursorPos(pt);
// PopupEx(Self, PopupMenu1, PT.x, PT.y);

PopupMenu1.Popup(pt.x,pt.y);
end;
if Msg.LParam=WM_LBUTTONDBLCLK then //鼠标左键双击
begin
Form1.Show;
SetForeGroundWindow(form1.Handle);
end;
//inherited; //将消息传给祖先对象的处理过程;

end;
end.

大家帮看看
 
const wm_command=wm_user+1000;

把你的wm_command 名称修改一下! 应该是这个跟D定义的冲突了.

改为:wm_Traycommand
 
还是没有用的啊
 
你跟踪一下你的消息触发没有??
记得也修改这里:nid.uCallbackMessage := wm_Traycommand ;
 
都改了,还是没用的!
好象在procedure TForm1.IconTray(var msg: TMessage);中设断点 都是叉
 
procedure IconTray(var Msg:TMessage); Message wm_Traycommand; //托盘
这里也修改了吗??
 
unit Unit1;

interface

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

const wm_Traycommand =wm_user+1000;
type
TForm1 = class(TForm)
PopupMenu1: TPopupMenu;
guan1: TMenuItem;
haoren1: TMenuItem;
kai1: TMenuItem;
procedure FormCreate(Sender: TObject);
// procedure FormDestroy(Sender: TObject);
private
{ Private declarations }

NID:TNotifyIconData;

public
{ Public declarations }
procedure IconTray(var Msg:TMessage); Message wm_Traycommand ; //托盘


end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
self.Caption :='冰自动';
nid.cbSize :=sizeof(nid);
nid.Wnd :=self.Handle;
nid.uID :=1;
nid.uCallbackMessage :=wm_Traycommand ;
nid.hIcon :=Application.Icon.Handle;
nid.szTip :='冰自动';
nid.uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP;
shell_NotifyIcon(NiM_Add,@nid);
end;

procedure TForm1.IconTray(var msg: TMessage);

var
pt: TPoint;
begin
if Msg.LParam=wm_rbuttondown then //鼠标右键
begin
SetForeGroundWindow(Form1.Handle);
GetCursorPos(pt);
// PopupEx(Self, PopupMenu1, PT.x, PT.y);

PopupMenu1.Popup(pt.x,pt.y);
end;
if Msg.LParam=WM_LBUTTONDBLCLK then //鼠标左键双击
begin
Form1.Show;
SetForeGroundWindow(form1.Handle);
end;
//inherited; //将消息传给祖先对象的处理过程;

end;
end.
 
我机器没有D不然我帮你测一下! 有这种现象??
 
不知道为什么?
看了别人的都是这样的啊
是不是错误,没运行到那个地方
 
WM_COMMAND是系统消息,改一下子名字可以吗?
 
wm_user+1000; 难道是消息值超出范围了! 你查一下看看.
别的看不出问题啊!!
 
没有装Delphi,回去给你测一下.
 
const wm_Traycommand =100; 还是没用的啊
 
我的qq: 57798768
 
这样才对啊!
const wm_Traycommand = wm_user + 100
 
都没有用不知道为什么,我都改过了
 
有谁知道吗
帮助一下
卡住了
 
unit Unit1;

interface

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

const wm_Traycommand = wm_user + 1000;
type
TForm1 = class(TForm)
PopupMenu1: TPopupMenu;
guan1: TMenuItem;
haoren1: TMenuItem;
kai1: TMenuItem;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
NID:TNotifyIconData;
public
procedure IconTray(var Msg:TMessage); Message wm_Traycommand; //托盘
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
self.Caption :='冰自动';
nid.cbSize :=sizeof(nid);
nid.Wnd :=self.Handle;
nid.uID :=1;
nid.uCallbackMessage := wm_Traycommand;
nid.hIcon :=Application.Icon.Handle;
nid.szTip :='冰自动';
nid.uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP;
shell_NotifyIcon(NiM_Add,@nid);
end;

procedure TForm1.IconTray(var msg: TMessage);
var
pt: TPoint;
begin
if Msg.LParam = WM_RBUTTONDOWN then //鼠标右键
begin
SetForeGroundWindow(Form1.Handle);
GetCursorPos(pt);
PopupMenu1.Popup(pt.x,pt.y);
end;
if Msg.LParam = WM_LBUTTONDBLCLK then //鼠标左键双击
begin
SetForeGroundWindow(form1.Handle);
SetWindowPos(Form1.Handle, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or SWP_SHOWWINDOW);
PostMessage(Application.Handle, WM_SYSCOMMAND, SC_RESTORE, 0);
end;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Shell_NotifyIcon(NIM_DELETE, @nid);
end;

end.
//昨晚写的运行正常
 
来自:ff_ff, 时间:2006-8-10 9:57:53, ID:3530604
WM_COMMAND是系统消息,改一下子名字可以吗?

不要用这个名字,随便起一个都行,除了系统和VCL使用的
 
实现拖盘不难。。给你以前写的一个代码。自已参考一下。
const
MY_MESSAGE =WM_USER+100;
procedure OnIconNotify(var message:Tmessage); Message MY_MESSAGE;

procedure Tfrmmain.OnIconNotify(var message:Tmessage);
const
Busy :boolean=False;
var
hand :hwnd;
appname :string;
pt :Tpoint;

begin
appname:=Application.Title;
hand:=FindWindow(nil,pchar(appname));
if not Busy then
begin
if message.LParam=WM_LBUTTONDOWN then
begin
if hand<>0 then
begin
if IsZoomed(Handle) then
begin
ShowWindow(hand,SW_SHOW);
SetForegroundWindow(hand);
end
else

begin
ShowWindow(hand,SW_RESTORE);
SetForegroundWindow(hand);
end;
end;
end;

if message.LParam=WM_RBUTTONDOWN then
begin
GetCursorPos(pt);
if IsZoomed(Handle) then
begin
ShowWindow(hand,SW_SHOW);
SetForegroundWindow(hand);
end
else
begin
ShowWindow(hand,SW_RESTORE);
SetForegroundWindow(hand);
end;
PopIcon.Popup(pt.x,pt.Y);//POPICON为一个右键菜单。
end;
end;
end;
在ONSHOW中。
var
nid :TNotifyIconData;

begin
nid.cbSize:=SizeOf(nid); // nid变量的字节数
nid.Wnd:=Handle; // 主窗口句柄
nid.uID:=0; // 内部标识,可设为任意数
nid.hIcon:=Application.Icon.Handle; // 要加入的图标句柄,可任意指
nid.szTip:='服装进销存管理系统'; // 提示字符串
nid.uCallbackMessage:=MY_MESSAGE; // 回调函数消息
nid.uFlags:=NIF_ICON or NIF_TIP or NIF_MESSAGE;// NIF_ICON代表hIcon图标有效 NIF_TIP提示 NIF_MESSAGE回调函数

if not Shell_NotifyIcon(NIM_ADD,@nid) then
begin
Application.MessageBox(pchar('创建图标失败!'),pchar('提示'),MB_OK+mb_iconinformation)
end;
SetWindowLong(Application.Handle,GWL_EXSTYLE,WS_EX_TOOLWINDOW);{将程序的窗口样式设为TOOL窗口,可避免在任务条上出现}
end;
 
后退
顶部