1.
procedure TForm1.Timer1Timer(Sender: TObject);
var
Handle:THandle;
Caption:PAnsiChar;
ClassName:PAnsiChar;
begin
Handle := WindowFromPoint(Mouse.CursorPos);
GetMem(Caption,255);
GetMem(ClassName,255);
GetWindowText(Handle,Caption,255);
GetClassName(Handle,ClassName,255);
if GetKeyState(VK_MBUTTON)<0 then
begin
Edit1.Text := Caption;
Edit2.Text := ClassName;
Hand := Handle;
end;end;
Timer1的时间间隔是100
我是在任意一个窗体货组件上按下鼠标键时候,就获取该窗体的标题文本。EDIT1存放类名,EDIT2存放标题名。
实现不了,请大家帮忙。2.我要关闭一个应用程序用
sendmessage(hwnd,wm_close,0,0);
如果这个应用程序会提示“是否保存”,我想跳过这步,不保存关闭它,怎么写代码?谢谢!
procedure TForm1.Timer1Timer(Sender: TObject);
var
Handle:THandle;
Caption:PAnsiChar;
ClassName:PAnsiChar;
begin
Handle := WindowFromPoint(Mouse.CursorPos);
GetMem(Caption,255);
GetMem(ClassName,255);
GetWindowText(Handle,Caption,255);
GetClassName(Handle,ClassName,255);
if GetKeyState(VK_MBUTTON)<0 then
begin
Edit1.Text := Caption;
Edit2.Text := ClassName;
Hand := Handle;
end;end;
Timer1的时间间隔是100
我是在任意一个窗体货组件上按下鼠标键时候,就获取该窗体的标题文本。EDIT1存放类名,EDIT2存放标题名。
实现不了,请大家帮忙。2.我要关闭一个应用程序用
sendmessage(hwnd,wm_close,0,0);
如果这个应用程序会提示“是否保存”,我想跳过这步,不保存关闭它,怎么写代码?谢谢!
第一个不是很清楚……
begin
Edit1.Text := Caption;
Edit2.Text := ClassName;
//Handle := Handle;
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Timer1: TTimer;
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
procedure Timer1Timer(Sender: TObject);
procedure Button1Click(Sender: TObject); private
{ Private declarations } public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Timer1Timer(Sender: TObject);
var
Handle:THandle;
Caption:PAnsiChar;
ClassName:PAnsiChar;
begin
Handle := WindowFromPoint(Mouse.CursorPos);
GetMem(Caption,255);
GetMem(ClassName,255);
GetWindowText(Handle,Caption,255);
GetClassName(Handle,ClassName,255);
if GetKeyState(VK_LBUTTON) >0 then
begin
Edit1.Text := Caption;
Edit2.Text := ClassName;
//Handle := Handle;
//timer1.Enabled:=false;
end;end;
procedure TForm1.Button1Click(Sender: TObject);
{var
Handle:THandle;
Caption:array[0..MAX_PATH] of Char;
ClassName:array[0..MAX_PATH] of Char; }
begin
{Handle := WindowFromPoint(Mouse.CursorPos);
GetMem(Caption,SizeOf(Caption));
GetMem(ClassName,255);
GetWindowText(Handle,Caption,255);
GetClassName(Handle,ClassName,255);
if GetKeyState(VK_LBUTTON) <0 then
begin
Edit1.Text := Caption;
Edit2.Text := ClassName;
//Handle := Handle;
end; }end;
end.
已测试通过
有GetKeyState(VK_MBUTTON)这个条件,是要按下鼠标中键的时候才在edit中显示呢
根据窗口句柄找到进程ID,然后用TerminateProcess终止进程