1. Prepare windows APIs, which are developed in C #. Therefore, prepare windows APIs encapsulated in C. You can download it at the following address:
C # Windows API encapsulated by Version C, simplified version + added version, source code
Http://bmpj.net/forum-viewthread-tid-461-fromuid-13.html
2. Define the object class for saving the QQ chat form
Internal class qqchatwindows {private intptr _ ?whwnd = intptr. zero; Public intptr when whwnd {get {return _ windowhwnd;} set {_ Then whwnd = value ;}} private string _ caption = string. empty; Public String caption {get {return _ Caption;} set {_ caption = value ;}} public qqchatwindows (intptr when whwnd, string Caption) {_ When whwnd = windowhwnd; _ caption = caption ;}}
3. traverse the QQ chat form
Private void enumqqchatwindows () {This. listqqwindows. items. clear (); this. _ qqlistwindows. clear (); nativemethods. enumdesktopwindows (intptr. zero, new nativemethods. enumdesktopwindowsdelegate (enumwindowsproc), intptr. zero);} private bool enumwindowsproc (intptr hwnd, uint lparam) {string qqproname = This. getprocessname (hwnd); stringbuilder classname = new stringbuilder (255 + 1); // classname longest native Methods. getclassname (hwnd, classname, classname. capacity); If (! Qqproname. equals (string. empty) & qqproname. equals ("QQ") & classname. tostring (). equals ("txguifoundation") {stringbuilder caption = new stringbuilder (nativemethods. getwindowtextlength (hwnd) + 1); nativemethods. getwindowtext (hwnd, caption, caption. capacity); If (! Caption. tostring (). Equals (string. Empty )&&! Caption. tostring (). Equals ("txfloatingwnd ")&&! Caption. tostring (). Equals ("txmenuwindow ")&&! Caption. tostring (). equals ("qq2011") {qqchatwindows qqchat = new qqchatwindows (hwnd, caption. tostring (); this. _ qqlistwindows. add (qqchat); this. listqqwindows. items. add (Caption) ;}} return true;} Public String getprocessname (intptr hwnd) {try {string processname = string. empty; int proid = 0; uint threadid = nativemethods. getwindowthreadprocessid (hwnd, out proid); If (threadid> 0 & proid> 0) {process pro = process. getprocpolicyid (proid); processname = pro. processname;} return processname;} catch {return string. empty ;}}
4. automatically send QQ messages cyclically
Private bool sendqqmsg (intptr hwnd, string qqcaption, string sendtext) {try {nativemethods. showwindow (hwnd, nativemethods. showwindowcommands. normal); nativemethods. bringwindowtotop (hwnd); sendkeys. sendwait (sendtext); sendkeys. sendwait ("^ {enter }");//CTRL + enterReturn true;} catch {return false ;}}
Download source code:
Automatic sender of baimu QQ InformationSource codeYou can complete it !!
Http://bmpj.net/forum-viewthread-tid-498-fromuid-13.html