| 发表于:2007-05-19 18:21:32 楼主 |
由于以前qq消息尾巴病毒的流行,腾讯使用了一些技术,使得现在的qq聊天窗口屏蔽了wm_settext消息 这样的话,要利用程序自动向qq聊天窗口发送文本就比较难了。不过经过测试发现,wm_char消息没有被qq屏蔽。因此,可以使用这个消息把字符发送到聊天窗口。不过要注意的是,发送中文的话,要发送2次,也就是高低2个字节,不然会乱码的。 declare function sendmessage lib "user32 " alias "sendmessagea " (byval hwnd as long, byval wmsg as long, byval wparam as long, lparam as any) as long declare function findwindowex lib "user32 " alias "findwindowexa " (byval hwnd1 as long, byval hwnd2 as long, byval lpsz1 as string, byval lpsz2 as string) as long declare function getwindowtext lib "user32 " alias "getwindowtexta " (byval hwnd as long, byval lpstring as string, byval cch as long) as long declare function postmessage lib "user32 " alias "postmessagea " (byval hwnd as long, byval wmsg as long, byval wparam as long, lparam as any) as long declare function setwindowtext lib "user32 " alias "setwindowtexta " (byval hwnd as long, byval lpstring as string) as long public const wm_char = &h102 public const wm_settext = &hc public const wm_lbuttondown = &h201 public const wm_lbuttonup = &h202 public const bm_click = &hf5 public const wm_gettext = &hd sub setqqtext(byval fhwnd as long, byval mystr as string) ' 向聊天窗口的文本框写入消息。fhwnd 是那个文本框的句柄,mystr 是你要写入的消息 dim mydata() as byte, i as long, tmp_k as long i = 0 mydata = strconv(mystr, vbfromunicode) tmp_k = ubound(mydata) while i <= tmp_k if mydata(i) < 128 then postmessage fhwnd, wm_char, mydata(i), 0& i = i + 1 else postmessage fhwnd, wm_char, mydata(i), 0& postmessage fhwnd, wm_char, mydata(i + 1), 0& i = i + 2 end if wend end sub 顺便再附上几段代码,是关于如何找到qq那个文本框的句柄的。 function myfindwindowex(wname as string, fhwnd as long, temphnd as long) as long dim mystr as string * 255 do temphnd = findwindowex(fhwnd, temphnd, vbnullstring, vbnullstring) getwindowtext temphnd, mystr, len(mystr) - 1 if instr(1, mystr, wname) > 0 then myfindwindowex = temphnd exit function else myfindwindowex = 0 end if loop until temphnd = 0 end function 先用上面的函数找到qq消息窗口的句柄,像这样 qqhwnd=myfindwindowex( "聊天中 ",0,0) 再用下面的函数找到qq文本输入框的句柄,像这样,传入qq消息窗口的句柄 qqtexthwnd=myfindqqchattext(qqhwnd) function myfindqqchattext(byval fhwnd as long) as long '获得qq聊天窗口的文本输入框句柄 dim tmp_hwnd as long tmp_hwnd = mycheckwindow(fhwnd, 4) tmp_hwnd = mycheckwindow(tmp_hwnd, 23) tmp_hwnd = mycheckwindow(tmp_hwnd, 1) myfindqqchattext = tmp_hwnd end function function mycheckwindow(fhwnd as long, myno as long) as long dim mycheck as long mycheckwindow = 0 for mycheck = 1 to myno mycheckwindow = findwindowex(fhwnd, mycheckwindow, vbnullstring, vbnullstring) next end function 然后就可以写入消息了。写入消息后,还可以自动按下发送按钮来发送消息 找到发送按钮的句柄 qqsendhwnd=myfindqqchatsend(qqhwnd) function myfindqqchatsend(byval fhwnd as long) as long '获得qq聊天窗口的发送按钮句柄 dim tmp_hwnd as long tmp_hwnd = mycheckwindow(fhwnd, 4) tmp_hwnd = mycheckwindow(tmp_hwnd, 17) myfindqqchatsend = tmp_hwnd end function 再模拟按下发送键 myclickbotton qqsendhwnd sub myclickbotton(byval fhwnd as long) '按下某个按钮 postmessage fhwnd, bm_click, 0&, 0& end sub 差不多就是这样了。有什么问题可以联系我,qq:511795070 |
|
|
|
|