本程序思路是通过定时截取屏幕图形,来作为被控端。源码如下所示 code: option explicitprivate type bitmap bmtype as long bmwidth as long bmheight as long bmwidthbytes as long bmplanes as integer bmbitspixel as integer bmbits as longend typeprivate declare function getobj lib \"gdi32\" alias \"getobjecta\" (byval hobject as long, byval ncount as long, lpobject as any) as longprivate declare function getdesktopwindow lib \"user32\" () as longprivate declare function getdc lib \"user32\" (byval hwnd as long) as longprivate declare function releasedc lib \"user32\" (byval hwnd as long, byval hdc as long) as longprivate declare function bitblt lib \"gdi32\" (byval hdestdc as long, byval x as long, byval y as long, byval nwidth as long, byval nheight as long, byval hsrcdc as long, byvalxsrc as long, byval ysrc as long, byval dwrop as long) as longprivate declare sub copymemory lib \"kernel32\" alias \"rtlmovememory\" (destination as any, source as any, byval length as long)private declare function getbitmapbits lib \"gdi32\" (byval hbitmap as long, byval dwcount as long, lpbits as any) as longprivate declare function setbitmapbits lib \"gdi32\" (byval hbitmap as long, byval dwcount as long, lpbits as any) as longprivate declare function createcompatiblebitmap lib \"gdi32\" (byval hdc as long, byval nwidth as long, byval nheight as long) as longprivate declare function createcompatibledc lib \"gdi32\" (byval hdc as long) as longprivate declare function selectobject lib \"gdi32\" (byval hdc as long, byval hobject as long) as longprivate declare function deletedc lib \"gdi32\" (byval hdc as long) as longprivate declare function deleteobject lib \"gdi32\" (byval hobject as long) as longprivate myhdc1 as long, mybmp1 as long, myoldbmp1 as long, scrw as long, scrh as longprivate startt as singleprivate sub form_load()dim bm as bitmap, bmpsize as longtimer1.enabled = false '间隔时间获取图形me.scalemode = 3scrw = screen.width \ screen.twipsperpixelxscrh = screen.height \ screen.twipsperpixely'这只是方便调试的示例,实用程序中,不用临时dc,可直接取窗体的bmp,会快一些myhdc1 = createcompatibledc(frmclient.hdc)mybmp1 = createcompatiblebitmap(frmclient.hdc, scrw, scrh)myoldbmp1 = selectobject(myhdc1, mybmp1)'ws2为winsock控件,用于发送数据 'ws2.remotehost = inputbox(\"请输入远程服务器ip地址\", \"远程监控测试\", \"127.0.0.1\")'ws2.remoteport = 2345'ws2.connecttimer1.interval = 10000timer1.enabled = trueend subprivate sub form_unload(cancel as integer)'ws2.closeselectobject myhdc1, myoldbmp1deleteobject mybmp1deletedc myhdc1end subprivate sub timer1_timer()dim i as long, d as long, b as long, bm as bitmap, dat() as byte, bmpsize as longstartt = timerd = getdesktopwindowi = getdc(d)bitblt myhdc1, 0, 0, scrw, scrh, i, 0, 0, vbsrccopyreleasedc d, igetobj mybmp1, len(bm), bmbmpsize = bm.bmwidthbytes * bm.bmheightredim dat(bmpsize - 1)getbitmapbits mybmp1, bmpsize, dat(0)redim preserve dat(bmpsize + 1)dat(bmpsize) = 13dat(bmpsize + 1) = 10'startt = timer'ws2.senddata datdebug.print dat 'dat为获取到的屏幕图形数据end subprivate sub ws2_close()statusbar1.simpletext = ws2.remotehost & \" disconnected..\"ws2.closeend subprivate sub ws2_connect()statusbar1.simpletext = ws2.remotehost & \" connected..\"end subprivate sub ws2_error(byval number as integer, description as string, byval scode as long, byval source as string, byval helpfile as string, byval helpcontext as long, canceldisplay as boolean)on error resume nextstatusbar1.simpletext = ws2.remotehost & \" error : \" & descriptionws2.closeend sub'============================================================='项目名称: server (远程屏幕监控端)'窗口名称: frmserver'winsock控件:ws1'statusbar控件:statusbar1 (注意:statusbar1.style = sbrsimple)'=============================================================option explicitprivate type bitmap bmtype as long bmwidth as long bmheight as long bmwidthbytes as long bmplanes as integer bmbitspixel as integer bmbits as longend typeprivate declare function getobj lib \"gdi32\" alias \"getobjecta\" (byval hobject as long, byval ncount as long, lpobject as any) as longprivate declare function getdesktopwindow lib \"user32\" () as longprivate declare function getdc lib \"user32\" (byval hwnd as long) as longprivate declare function releasedc lib \"user32\" (byval hwnd as long, byval hdc as long) as longprivate declare function bitblt lib \"gdi32\" (byval hdestdc as long, byval x as long, byval y as long, byval nwidth as long, byval nheight as long, byval hsrcdc as long, byvalxsrc as long, byval ysrc as long, byval dwrop as long) as longprivate declare sub copymemory lib \"kernel32\" alias \"rtlmovememory\" (destination as any, source as any, byval length as long)private declare function getbitmapbits lib \"gdi32\" (byval hbitmap as long, byval dwcount as long, lpbits as any) as longprivate declare function setbitmapbits lib \"gdi32\" (byval hbitmap as long, byval dwcount as long, lpbits as any) as longprivate declare function createcompatiblebitmap lib \"gdi32\" (byval hdc as long, byval nwidth as long, byval nheight as long) as longprivate declare function createcompatibledc lib \"gdi32\" (byval hdc as long) as longprivate declare function selectobject lib \"gdi32\" (byval hdc as long, byval hobject as long) as longprivate declare function deletedc lib \"gdi32\" (byval hdc as long) as longprivate declare function deleteobject lib \"gdi32\" (byval hobject as long) as longprivate scrw as long, scrh as longprivate myhdc as long, mybmp as long, myoldbmp as long, bmpdat() as byte, revbyte as longprivate startt as singleprivate sub form_load()dim bm as bitmap, bmpsize as longon error goto errloadme.scalemode = 3scrw = screen.width \ screen.twipsperpixelxscrh = screen.height \ screen.twipsperpixely'这只是方便调试的示例,实用程序中,不用临时dc,可直接取窗体的bmp,会快一些myhdc = createcompatibledc(frmserver.hdc)mybmp = createcompatiblebitmap(frmserver.hdc, scrw, scrh)myoldbmp = selectobject(myhdc, mybmp) getobj mybmp, len(bm), bmbmpsize = bm.bmwidthbytes * bm.bmheightredim bmpdat(bmpsize - 1)getbitmapbits mybmp, bmpsize, bmpdat(0)ws1.localport = 2345ws1.listenexit suberrload:msgbox errorend subsub getscreen()end subprivate sub form_unload(cancel as integer)on error resume nextws1.closeselectobject myhdc, myoldbmpdeleteobject mybmpdeletedc myhdcend subprivate sub ws1_close()statusbar1.simpletext = ws1.remotehostip & \" disconnected..\"ws1.closeif ws1.state = scklistening then ws1.closeelse ws1.localport = 2345 ws1.listenend ifend subprivate sub ws1_connectionrequest(byval requestid as long)if ws1.state <> sckclosed then ws1.closestatusbar1.simpletext = ws1.remotehostip & \" connecting..\"ws1.accept requestidif ws1.state = 7 then statusbar1.simpletext = ws1.remotehostip & \" connected..\"end subprivate sub ws1_dataarrival(byval bytestotal as long)dim dat() as byte, i as long, ntime as longon error resume nextws1.getdata dat, vbarray or vbbytei = instrb(1, dat, chrb(13) & chrb(10))if i > 0 then 'startt = timer if i > 1 then copymemory bmpdat(revbyte), dat(0), i - 1 setbitmapbits mybmp, ubound(bmpdat) + 1, bmpdat(0) revbyte = 0 '实用程序中,不用临时dc,下面一步可省 bitblt me.hdc, 0, 0, me.scalewidth, me.scaleheight, myhdc, 0, 0, vbsrccopy ntime = timer - val(me.