[C #] QQ message automatic sending code

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.