This article is for study purposes only and cannot be used for illegal purposes. repost this article.
Address: http://blog.csdn.net/sushengmiyan/article/details/8774780
Function used: enumwindows and enumwindowsproc
Source code:
Unit execution; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls, clipbrd; Type tform1 = Class (tform) edtmsg: tedit; lbltip: tlabel; btntry: tbutton; lblmsgwindow: tlabel; labels: 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 ('Enter the message to be sent, the message cannot be blank '); End else begin enumwindows (@ enumwindowsproc, 0); end; function enumwindowsproc (hwnd: hwnd; lparam: lparam): Boolean; stdcall; var windowtext: string; windowclass: string; sendhwnd: DWORD; tdiahandle: thandle; tedithandle: thandle; role: thandle; C: Cardinal; processhandle: longword; begin if (iswindowvisible (hwnd) or isiconic (hwnd) and (getwindowlong (hwnd, gwl_hwndparent) = 0) or (getwindowlong (hwnd, rows) = 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, 'txguifounder') 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; Result: = true; end.
We often have this kind of requirement in the network. It is very troublesome to send a sales promotion content to the QQ group or QQ friends and send it one by one manually, so we need a set of good tools to help us, so I wrote this stuff. We have a lot of support.