吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1598|回复: 22
收起左侧

[求助] Delphi编程求助

[复制链接]
冥界3大法王 发表于 2019-12-11 14:44
本帖最后由 冥界3大法王 于 2019-12-11 15:27 编辑

直接是Button1单击时,测试正常!想变成函数或过程调用,好节约或重复代码!
当定义成函数或过程 ,再Button2调用时就没有反映了,为什么?
procedure TForm1.Button2Click(Sender: TObject);
begin
  Test1(Edit1.Text);
end;




function Test1(s: string): string;
加上面的代码
[Delphi] 纯文本查看 复制代码
var
  hCurrentWindow: hWnd;
  szText: array[0..254] of char;
  h: Integer;
  lpCaption: array[Byte] of Char;
begin
  hCurrentWindow := GetWindow(Handle, GW_HWNDFIRST);    //获取第一个窗口的句柄
  while hCurrentWindow <> 0 do
  begin                      //获取窗口的名称
    if GetWindowText(hCurrentWindow, szText, 255) > 0 then
    begin
//ListBox1.Items.Add(StrPas(szText));        //获取下一窗口的句柄
      if (POS('- x32dbg', StrPas(szText)) > 0) or (POS('- x64dbg', StrPas(szText)) > 0) then
      begin
//ShowMessage(StrPas(szText));
        h := FindWindow(nil, PWideChar(StrPas(szText)));
//ShowMessage(IntToStr(h));
        IntToStr(GetWindowText(h, lpCaption, 255));
//ShowMessage(lpCaption);
        SetForegroundWindow(FindWindow(nil, PWideChar(StrPas(szText))));
        Sleep(500);
        SetCursorPos(850, 350);
        mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
        mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);

        Sleep(1000);
        keybd_event(VK_Control, MapVirtualKey(VK_Control, 0), 0, 0);                   //按下Ctrl键
        keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), 0, 0);                     //按下回车键
        keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), KEYEVENTF_KEYUP, 0);       //弹起回车键
        keybd_event(VK_Control, MapVirtualKey(VK_Control, 0), KEYEVENTF_KEYUP, 0);    //放开Ctrl键

        Sleep(1000);
        keybd_event(VK_Control, MapVirtualKey(VK_Control, 0), 0, 0);                 //按下Ctrl键
        keybd_event(ord('V'), MapVirtualKey(ord('V'), 0), 0, 0);                     //按下v键
        keybd_event(VK_Control, MapVirtualKey(VK_Control, 0), KEYEVENTF_KEYUP, 0);    //放开Ctrl键
        keybd_event(ord('V'), MapVirtualKey(ord('V'), 0), KEYEVENTF_KEYUP, 0);       //放开v键
      end;
    end;
    hCurrentWindow := GetWindow(hCurrentWindow, GW_HWNDNEXT);
  end;
end;

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

dazhuangzhuang 发表于 2019-12-11 15:02
楼主:“以下”,“上面”表达不清,没看明白你的问题。

免费评分

参与人数 1吾爱币 +1 收起 理由
冥界3大法王 + 1 已升级 @dazhuangzhuang

查看全部评分

 楼主| 冥界3大法王 发表于 2019-12-11 15:04
本帖最后由 冥界3大法王 于 2019-12-11 15:06 编辑

晕,还行不行,最后请来一个ActrionList!
procedure TForm1.Button2Click(Sender: TObject);
begin
  SendPressExecute(SendPress);  这样调用!
end;

SendPress是动作的名字 ,这样竟然正常了。

什么原因呢,还得请上仙解答吧。
pzx521521 发表于 2019-12-11 15:04
GetWindow(Handle, GW_HWNDFIRST);
这句代码引起的原因
function Test1(s: string): string;
改成
function TForm1.Test1(s: string): string;
才是完全的相等

TForm1.Test1时
Handle指的是TForm1.Handle
Test1时
Handle会编译前报错的,就是编译不过去的
不知道你为什么没有报错

免费评分

参与人数 1吾爱币 +1 热心值 +1 收起 理由
冥界3大法王 + 1 + 1 感谢指点,还是没动静。修改后 @pzx521521

查看全部评分

 楼主| 冥界3大法王 发表于 2019-12-11 15:08
pzx521521 发表于 2019-12-11 15:04
GetWindow(Handle, GW_HWNDFIRST);
这句代码引起的原因
function Test1(s: string): string;

因为我把Handle 改成0了。
虽然编译通过,但是点击没效果。
 楼主| 冥界3大法王 发表于 2019-12-11 15:24
改成function TForm1.Test1(s: string): string;
结果报错:  E2003 Undeclared identifier: 'Test1'
coolcalf 发表于 2019-12-11 15:26
说句泄气的话:delphi其实不是一个好选择。
 楼主| 冥界3大法王 发表于 2019-12-11 15:28
dazhuangzhuang 发表于 2019-12-11 15:02
楼主:“以下”,“上面”表达不清,没看明白你的问题。

还是上完整的代码吧。
[Delphi] 纯文本查看 复制代码
unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
  System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
  Vcl.StdCtrls, System.Actions, Vcl.ActnList;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Edit1: TEdit;
    ActionList1: TActionList;
    SendPress: TAction;
    Button3: TButton;
    procedure Button1Click(Sender: TObject);
    procedure SendPressExecute(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
uses
  Tlhelp32;

function TForm1.Test2(s: string): string;
var
  hCurrentWindow: hWnd;
  szText: array[0..254] of char;
  h: Integer;
  lpCaption: array[Byte] of Char;
begin
  hCurrentWindow := GetWindow(0, GW_HWNDFIRST);    //获取第一个窗口的句柄
  while hCurrentWindow <> 0 do
  begin                                           //获取窗口的名称
    if GetWindowText(hCurrentWindow, szText, 255) > 0 then
    begin
//ListBox1.Items.Add(StrPas(szText));            //获取下一窗口的句柄
      if (POS('- x32dbg', StrPas(szText)) > 0) or (POS('- x64dbg', StrPas(szText)) > 0) then
      begin
//ShowMessage(StrPas(szText));
        h := FindWindow(nil, PWideChar(StrPas(szText)));
//ShowMessage(IntToStr(h));
        IntToStr(GetWindowText(h, lpCaption, 255));
//ShowMessage(lpCaption);
        SetForegroundWindow(FindWindow(nil, PWideChar(StrPas(szText))));
        Sleep(500);
        SetCursorPos(850, 350);
        mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
        mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);

        Sleep(1000);
        keybd_event(VK_Control, MapVirtualKey(VK_Control, 0), 0, 0);                   //按下Ctrl键
        keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), 0, 0);                     //按下回车键
        keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), KEYEVENTF_KEYUP, 0);       //弹起回车键
        keybd_event(VK_Control, MapVirtualKey(VK_Control, 0), KEYEVENTF_KEYUP, 0);    //放开Ctrl键

        Sleep(1000);
        keybd_event(VK_Control, MapVirtualKey(VK_Control, 0), 0, 0);                 //按下Ctrl键
        keybd_event(ord('V'), MapVirtualKey(ord('V'), 0), 0, 0);                     //按下v键
        keybd_event(VK_Control, MapVirtualKey(VK_Control, 0), KEYEVENTF_KEYUP, 0);    //放开Ctrl键
        keybd_event(ord('V'), MapVirtualKey(ord('V'), 0), KEYEVENTF_KEYUP, 0);       //放开v键
      end;
    end;
    hCurrentWindow := GetWindow(hCurrentWindow, GW_HWNDNEXT);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  hCurrentWindow: hWnd;
  szText: array[0..254] of char;
  h: Integer;
  lpCaption: array[Byte] of Char;
begin
  hCurrentWindow := GetWindow(0, GW_HWNDFIRST);    //获取第一个窗口的句柄
  while hCurrentWindow <> 0 do
  begin                      //获取窗口的名称
    if GetWindowText(hCurrentWindow, szText, 255) > 0 then
    begin
//ListBox1.Items.Add(StrPas(szText));        //获取下一窗口的句柄
      if (POS('- x32dbg', StrPas(szText)) > 0) or (POS('- x64dbg', StrPas(szText)) > 0) then
      begin
//ShowMessage(StrPas(szText));
        h := FindWindow(nil, PWideChar(StrPas(szText)));
//ShowMessage(IntToStr(h));
        IntToStr(GetWindowText(h, lpCaption, 255));
//ShowMessage(lpCaption);
        SetForegroundWindow(FindWindow(nil, PWideChar(StrPas(szText))));
        Sleep(500);
        SetCursorPos(850, 350);
        mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
        mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);

        Sleep(1000);
        keybd_event(VK_Control, MapVirtualKey(VK_Control, 0), 0, 0);                   //按下Ctrl键
        keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), 0, 0);                     //按下回车键
        keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), KEYEVENTF_KEYUP, 0);       //弹起回车键
        keybd_event(VK_Control, MapVirtualKey(VK_Control, 0), KEYEVENTF_KEYUP, 0);    //放开Ctrl键

        Sleep(1000);
        keybd_event(VK_Control, MapVirtualKey(VK_Control, 0), 0, 0);                 //按下Ctrl键
        keybd_event(ord('V'), MapVirtualKey(ord('V'), 0), 0, 0);                     //按下v键
        keybd_event(VK_Control, MapVirtualKey(VK_Control, 0), KEYEVENTF_KEYUP, 0);    //放开Ctrl键
        keybd_event(ord('V'), MapVirtualKey(ord('V'), 0), KEYEVENTF_KEYUP, 0);       //放开v键
      end;
    end;
    hCurrentWindow := GetWindow(hCurrentWindow, GW_HWNDNEXT);
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  SendPressExecute(SendPress);
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  Test2(Edit1.Text);
end;

procedure TForm1.SendPressExecute(Sender: TObject);
var
  hCurrentWindow: hWnd;
  szText: array[0..254] of char;
  h: Integer;
  lpCaption: array[Byte] of Char;
begin
  hCurrentWindow := GetWindow(Handle, GW_HWNDFIRST);    //获取第一个窗口的句柄
  while hCurrentWindow <> 0 do
  begin                      //获取窗口的名称
    if GetWindowText(hCurrentWindow, szText, 255) > 0 then
    begin
//ListBox1.Items.Add(StrPas(szText));        //获取下一窗口的句柄
      if (POS('- x32dbg', StrPas(szText)) > 0) or (POS('- x64dbg', StrPas(szText)) > 0) then
      begin
//ShowMessage(StrPas(szText));
        h := FindWindow(nil, PWideChar(StrPas(szText)));
//ShowMessage(IntToStr(h));
        IntToStr(GetWindowText(h, lpCaption, 255));
//ShowMessage(lpCaption);
        SetForegroundWindow(FindWindow(nil, PWideChar(StrPas(szText))));
        Sleep(500);
        SetCursorPos(850, 350);
        mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
        mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);

        Sleep(1000);
        keybd_event(VK_Control, MapVirtualKey(VK_Control, 0), 0, 0);                   //按下Ctrl键
        keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), 0, 0);                     //按下回车键
        keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), KEYEVENTF_KEYUP, 0);       //弹起回车键
        keybd_event(VK_Control, MapVirtualKey(VK_Control, 0), KEYEVENTF_KEYUP, 0);    //放开Ctrl键

        Sleep(1000);
        keybd_event(VK_Control, MapVirtualKey(VK_Control, 0), 0, 0);                 //按下Ctrl键
        keybd_event(ord('V'), MapVirtualKey(ord('V'), 0), 0, 0);                     //按下v键
        keybd_event(VK_Control, MapVirtualKey(VK_Control, 0), KEYEVENTF_KEYUP, 0);    //放开Ctrl键
        keybd_event(ord('V'), MapVirtualKey(ord('V'), 0), KEYEVENTF_KEYUP, 0);       //放开v键
      end;
    end;
    hCurrentWindow := GetWindow(hCurrentWindow, GW_HWNDNEXT);
  end;
end;

end.
 楼主| 冥界3大法王 发表于 2019-12-11 15:29

@coolcalf 那你说选择啥?

本帖最后由 冥界3大法王 于 2019-12-11 15:37 编辑
coolcalf 发表于 2019-12-11 15:26
说句泄气的话:delphi其实不是一个好选择。
易语言更狗屎
难道还有哪个学习难度低
马上就能搞出来的工具?
https://doc.ivx.cn 这个说得很牛逼,不知真的假的。骗大伙的钱我看是真!  
忧伤中找坚强 发表于 2019-12-11 15:31
看不懂,不理解
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-26 22:16

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表