我做的一个控件没有用。onmouseup,onmousemove,onmousedown;分太少,谢谢各位(30分)

  • 主题发起人 devexpress
  • 开始时间
D

devexpress

Unregistered / Unconfirmed
GUEST, unregistred user!
我装上delphi自带的active条码控件,这个控件没有onmouseup,onmousemove,onmousedown;事件
打开源代码。加了三个事件。
published
property ParentColor;
property ParentFont;
property TabStop;
property Align;
property DragCursor;
property DragMode;
property OnMouseDown;//改动
property OnMouseMove;//改动
property OnMouseUp;//改动
重新编译后,控件有了这三个事件,但根本不执行里面的代码。 怎样才能响应呢?
 
我怎么没有这个控件,“active条码控件”是个ActiveX吗?
 
通过improt->microsoft access barcode 9.0
可以装上,这个条码控件的
 
是个ActiveX,可能改不了了,你没有它的源码,改的只是个声明而已。而且即使有源码,你这样简单
的加一个也是不行的,要么从父类继承,要么截获消息。
参考:
{
demonstrate a mouse hook in a form.
}
unit Unit1;

interface

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

type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
FMHook: HHOOK;
function FMHookProc(Code: Integer; WParam: Longint; var Msg: TMsg): Longint; stdcall;

implementation

{$R *.DFM}

function FMHookProc(Code: Integer; WParam: Longint; var Msg: TMsg): Longint; stdcall;
begin
if Msg.Message = WM_MOUSEMOVE then
with form1 do
begin
//Edit1.text := inttostr(msg.wParam);//做你要做的事
caption := format('Mouse Pos in the form:%d,%d',[msg.pt.x,msg.pt.y]);
end ;
Result := CallNextHookEx(FMHook, Code, WParam, Longint(@Msg)); //放出消息给下一个.
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
FMHook := SetWindowsHookEx(WH_GETMESSAGE, @FMHookProc, 0, GetCurrentThreadID);
end;

end.


 
可以触发移动事件.
。如果要按下和onmoveup那怎样
if Msg.Message = WM_MOUSEdown then//这样写不起做用的。
 
WM_LBUTTONDOWN
WM_LBUTTONUP
WM_RBUTTONDOWN
WM_RBUTTONUP
 
上面的消息是对整个form区域都起作用,但我想就针对条码控件起作用,怎么办,
 
先判断位置(利用WM_MOUSEMOVE ):if a.left < msg.pt.x < a.left+a.width then ...
y类似。
 
if (Form1.BarCodeCtrl1.left < msg.pt.x) and ( msg.pt.x< Form1.BarCodeCtrl1.left+Form1.BarCodeCtrl1.width) Then//不对
Begin
if Msg.Message = WM_MOUSEMOVE then
with form1 do
begin
//Edit1.text := inttostr(msg.wParam);//做你要做的事
caption := format('Mouse Pos in the form:%d,%d',[msg.pt.x,msg.pt.y]);
end ;
 
多人接受答案了。
 
顶部