delphi写QQ消息群发(模拟按键精灵)

本文只供学习研究,不能用于非法用途,转载请保留本文链接。

本文地址:http://blog.csdn.net/sushengmiyan/article/details/8774780

使用函数:EnumWindows,EnumWindowsProc

源代码奉上:

unit QMsgMainFrm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Clipbrd;

type
  TForm1 = class(TForm)
    edtMsg: TEdit;
    lblTip: TLabel;
    btnTry: TButton;
    lblMsgWindow: TLabel;
    lblMsgContextWindow: TLabel;
    procedure btnTryClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

  function EnumWindowsProc(hwnd: HWND; lParam: LPARAM): Boolean ;stdcall;
implementation

{$R *.dfm}

procedure TForm1.btnTryClick(Sender: TObject);
begin
  if Trim(edtMsg.Text) = '' then
  begin
    ShowMessage('请输入要发送的消息,消息不能为空');
  end else
  begin
    EnumWindows(@EnumWindowsProc ,0);
  end;
end;

function EnumWindowsProc(hwnd: HWND; lParam: LPARAM): Boolean ;stdcall;
var
  WindowText    : string  ;
  WindowClass   : string  ;
  SendHwnd      : DWORD   ;     
  tdiahandle    : THandle ;
  tedithandle   : THandle ;
  tduihuakhandle: THandle ;
  c: Cardinal;
  ProcessHandle:LongWord;
 begin
  if ( IsWindowVisible(hwnd) or IsIconic(hwnd) ) and
       (
        (GetWindowLong(hwnd, GWL_HWNDPARENT) = 0) or
        (GetWindowLong(hwnd, GWL_HWNDPARENT) = Longint(GetDesktopWindow))
       ) and
     ( GetWindowLong(hwnd, GWL_EXSTYLE) and WS_EX_TOOLWINDOW = 0)  then
  begin
    SetLength(WindowText, GetWindowTextLength(hwnd)+2);
    Getwindowtext(hwnd, Pchar(WindowText), GetWindowTextLength(hwnd)+2);
    WindowText := string(Pchar(WindowText));
    SetLength(WindowClass, 512);
    GetClassName(hwnd, Pchar(WindowClass), 512);
    WindowClass := string(Pchar(WindowClass) );
    if SameStr(WindowClass , 'TXGuiFoundation') then
    begin
      BringWindowToTop(hwnd);
      Form1.lblMsgContextWindow.Caption := WindowText;
      if Clipboard.HasFormat(CF_TEXT) then
        Clipboard.Clear;
      Form1.edtMsg.SelectAll;
      Form1.edtMsg.CopyToClipboard;
      keybd_event(VK_CONTROL, MapVirtualKey(VK_CONTROL, 0), 0, 0);
      keybd_event(Ord('V'), MapVirtualKey(Ord('V'), 0), 0, 0);
      keybd_event(Ord('V'), MapVirtualKey(Ord('V'), 0), KEYEVENTF_KEYUP, 0);
      keybd_event(VK_CONTROL, MapVirtualKey(VK_CONTROL, 0), KEYEVENTF_KEYUP, 0);
      keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0),0 ,0);
    end;
  end;
  Result := True;
 end;
end.
我们在网络中经常会有这样的需求,有一篇推销内容要发送到QQ群或者QQ好友,手动一个一个发实在是麻烦的很,那么就需要有一套好的工具来辅助我们,所以就写了这么一个东东。大家多多支持。

你可能感兴趣的:(Delphi,QQ消息群发,苏生苏米沿)