delphi寫QQ訊息群發(類比按鍵精靈)

來源:互聯網
上載者:User

本文只供學習研究,不能用於非法用途,轉載請保留本文連結。

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

使用函數:EnumWindows,EnumWindowsProc

原始碼奉上:

unit QMsgMainFrm;interfaceuses  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好友,手動一個一個發實在是麻煩的很,那麼就需要有一套好的工具來輔助我們,所以就寫了這麼一個東東。大家多多支援。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.