TSPlugInterFace.cpp 82 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014
  1. // TSPlugInterFace.cpp : CTSPlugInterFace 的实现
  2. /*
  3. 本源码由TC简单软件科技有限公司开源,功能可以自由修改、发布、
  4. 长沙简单软件科技有限公司对于源码不做后期维护,,请大家在使用过程中遵循开源协议
  5. */
  6. #include "stdafx.h"
  7. #include "TSPlugInterFace.h"
  8. #include "TSRuntime.h"
  9. #include "DXBind.h"
  10. #include "TsMessage.h"
  11. #include "D3dx9tex.h"
  12. #include <comutil.h>
  13. #pragma comment(lib, "comsuppw.lib")
  14. #include "dllmain.h"
  15. #include "TSMyKernel32DllFuntion.h"
  16. #include "Wininet.h"
  17. #pragma comment(lib,"Wininet.lib")
  18. //绑定互斥
  19. TsMutex gDXbindMutex(TS_BINDEVEN);
  20. //解绑定互斥
  21. TsMutex gDXUnbindMutex(TS_UNBINDEVEN);
  22. //按键按下互斥
  23. TsMutex gDXKeyDownMutex(TS_KEYDOWNEVEN);
  24. //按键弹起互斥
  25. TsMutex gDXKeyUpMutex(TS_KEYUPEVEN);
  26. //按键互斥
  27. TsMutex gDXKeyPressMutex(TS_KEYPRESSEVEN);
  28. //KeyPressStr互斥
  29. TsMutex gDXKeyPressStrMutex(TS_KEYPRESSSTREVEN);
  30. //KeyPressChar互斥
  31. TsMutex gDXKeyPressCharMutex(TS_KEYPRESSCHAREVEN);
  32. //SendString互斥
  33. TsMutex gDXSendStringMutex(TS_SENDSTRINGEVEN);
  34. //SendString互斥
  35. TsMutex gDXSendString2Mutex(TS_SENDSTRING2EVEN);
  36. //SendStringIme互斥
  37. TsMutex gDXSendStringImeMutex(TS_SENDSTRINGIMEEVEN);
  38. //LeftDown互斥
  39. TsMutex gDXLeftDownMutex(TS_LEFTDOWNEVEN);
  40. //LeftUp互斥
  41. TsMutex gDXLeftUpMutex(TS_LEFTUPEVEN);
  42. //LeftClick互斥
  43. TsMutex gDXLeftClickMutex(TS_MOVETOEVEN);
  44. //MoveTo互斥
  45. TsMutex gDXMoveToMutex(TS_LEFTCLICKEVEN);
  46. //FindPic互斥
  47. TsMutex gDXFindPicMutex(TS_FINDPICEVEN);
  48. ////RightClick互斥
  49. TsMutex gDXRightClickMutex(TS_RIGHTCLICKEVEN);
  50. //RightDown互斥
  51. TsMutex gDXRightDownMutex(TS_RIGHTDOWNEVEN);
  52. //RightUp互斥
  53. TsMutex gDXRightUpMutex(TS_RIGHTUPEVEN);
  54. //FindColor互斥
  55. TsMutex gDXFindColorMutex(TS_FINDCOLOREVEN);
  56. //GetColor互斥
  57. TsMutex gDXGetColorMutex(TS_GETCOLOREVEN);
  58. //GetCursorShape互斥
  59. TsMutex gDXGetCursorShapeMutex(TS_GETCURSORSHAPEEVEN);
  60. //SetPath互斥
  61. TsMutex gDXSetPathMutex(TS_SETPATHEVEN);
  62. //GetCursorPos互斥
  63. TsMutex gDXGetCursorPosMutex(TS_GETCURSORPOSEVEN);
  64. //MoveR互斥
  65. TsMutex gDXMoveRMutex(TS_MOVEREVEN);
  66. //MiddleClick互斥
  67. TsMutex gDXMiddleClickMutex(TS_MIDDLECLICKEVEN);
  68. //WheelDown互斥
  69. TsMutex gDXWheelDownMutex(TS_WHEELDOWNEVEN);
  70. //WheelUp互斥
  71. TsMutex gDXWheelUpMutex(TS_WHEELUPEVEN);
  72. //Capture互斥
  73. TsMutex gDXCaptureMutex(TS_CAPTUREEVEN);
  74. //LockInput互斥
  75. TsMutex gDXLockInputMutex(TS_LOCKINPUTEVEN);
  76. //Ocr互斥
  77. TsMutex gDXOcrMutex(TS_OCREVEN);
  78. //SetDict互斥
  79. TsMutex gDXSetDictMutex(TS_SETDICTEVEN);
  80. //UseDict互斥
  81. TsMutex gDXUseDictMutex(TS_USEDICTEVEN);
  82. //ClearDict互斥
  83. TsMutex gDXClearDictMutex(TS_CLEARDICTEVEN);
  84. //FindStr互斥
  85. TsMutex gDXFindStrMutex(TS_FINDSTREVEN);
  86. //GetNowDict互斥
  87. TsMutex gDXGetNowDictMutex(TS_GETNOWDICTEVEN);
  88. //CaptureGif互斥
  89. TsMutex gDXCaptureGifMutex(TS_CAPTUREGIFEVEN);
  90. //EnumWindow互斥
  91. TsMutex gDXEnumWindowMutex(TS_ENUMWINDOWEVEN);
  92. //EnumWindowByProcess互斥
  93. TsMutex gDXEnumWindowByProcessMutex(TS_ENUMWINDOWBYPROCESSEVEN);
  94. //EnumProcess互斥
  95. TsMutex gDXEnumProcessMutex(TS_ENUMPROCESSEVEN);
  96. //FindData
  97. TsMutex gDXFindDataMutex(TS_FINDDATAEVEN);
  98. //FindDouble
  99. TsMutex gDXFindDoubleMutex(TS_FINDDOUBLEEVEN);
  100. //FindFloat
  101. TsMutex gDXFindFloatMutex(TS_FINDFLOATEVEN);
  102. //FindInt
  103. TsMutex gDXFindIntMutex(TS_FINDINTEVEN);
  104. //FindString
  105. TsMutex gDXFindStringMutex(TS_FINDSTRINGEVEN);
  106. TsMutex gDXMySleepMutex(TS_MYSLEEPEVEN);
  107. //GetScreenData
  108. TsMutex gDXMyGetScreenDataMutex(TS_MYGETSCREENDATAEVEN);
  109. //MoveToEx
  110. TsMutex gDXMoveToExMutex(TS_MOVETOEXEVEN);
  111. extern myGetTickCount my_myGetTickCount;
  112. extern mySleep my_sleep;
  113. //DLL所在的位置
  114. extern TCHAR gDLLFolder[MAX_PATH + 1];
  115. int Loginlog(wchar_t* macode) //统计使用人数
  116. {
  117. {
  118. {
  119. HINTERNET internetopen = InternetOpen(L"TC", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
  120. if (internetopen == NULL)
  121. {
  122. return 0;
  123. }
  124. wchar_t url[MAX_PATH] = { 0 };
  125. swprintf(url, L"http://www.tyuyan.com/tongjiversion.aspx?version=2.5&maccode=%s", macode);
  126. HINTERNET internetopenurl = InternetOpenUrl(internetopen, url, NULL, 0, INTERNET_FLAG_RELOAD, 0);
  127. if (internetopenurl == NULL)
  128. {
  129. InternetCloseHandle(internetopen);
  130. return 0;
  131. }
  132. InternetCloseHandle(internetopenurl);
  133. InternetCloseHandle(internetopen);
  134. }
  135. }
  136. }
  137. // CTSPlugInterFace
  138. STDMETHODIMP CTSPlugInterFace::BindWindow(LONG hwnd, BSTR display, BSTR mouse, BSTR keypad, LONG mode, LONG* nret)
  139. {
  140. // TODO: 在此添加实现代码
  141. TsMutexlock ts_mutexlock(&gDXbindMutex);
  142. gDxObj.m_mousekeyhwnd = (HWND)hwnd;
  143. gDxObj.m_hwnd = (HWND)hwnd;
  144. *nret = false;
  145. VMPBEGIN //VMP保护
  146. //if(!TSRuntime::IsVipLogin)
  147. // {
  148. // //::GetTickCount();
  149. // int bret=TSRuntime::VipLogin(L"",0,false); //试用验证
  150. // if(bret<=0)
  151. // {
  152. // INT64 t=0;
  153. // if(my_myGetTickCount)
  154. // t=my_myGetTickCount();
  155. // else
  156. // t=::GetTickCount();
  157. // if(t==TSRuntime::checkthreadtime||abs((int)(t-TSRuntime::checkthreadtime))>=60*1000*10||TSRuntime::checkthreadtime==0) //校验线程是否被挂起或者GetTickCount被人下钩子
  158. // {
  159. // gDxObj.SendMsg(TS_UNBIND);
  160. // Sleep(200);
  161. // gDxObj.UnBind();
  162. // Sleep(200);
  163. // gDxObj.SendMsg(TS_UNBIND);
  164. // Sleep(200);
  165. // gDxObj.UnBind();
  166. // if(TSRuntime::IsStartProtect)
  167. // TSRuntime::StartProtect(0,L"");
  168. // *nret=0;
  169. // TSRuntime::h_checkthread=NULL;
  170. // return S_OK;
  171. // }
  172. //
  173. // }
  174. // }
  175. DWORD displayMode = NULL, keyMode = NULL, mouseMode = NULL;
  176. //TSRuntime::add_log( "获得模式 外部 :%s",display);
  177. gDxObj.BindMode = 0;
  178. gDxObj.m_keyMode = 0;
  179. gDxObj.m_mouseMode = 0;
  180. TSRuntime::getMode(mouse, keypad, display, mouseMode, keyMode, displayMode);
  181. if (displayMode == -1 || keyMode == -1 || mouseMode == -1)
  182. return false;
  183. gDxObj.m_displayMode = displayMode;
  184. gDxObj.m_keyMode = keyMode;
  185. gDxObj.m_mouseMode = mouseMode;
  186. gDxObj.BindMode = mode;
  187. gDxObj.m_mousekeyhwnd = (HWND)hwnd;
  188. bool sucee = false;
  189. if ((gDxObj.m_displayMode & DISPLAY_DX_3D) == DISPLAY_DX_3D || (gDxObj.m_mouseMode & MOUSE_API) == MOUSE_API || (gDxObj.m_keyMode & KEY_API) == KEY_API)
  190. {
  191. sucee = gDxObj.bind(gDxObj.m_hwnd, 0, 0, gDxObj.m_displayMode, (BIND_MODE)gDxObj.BindMode);
  192. if (sucee == false && ::IsWindow(gDxObj.m_hwnd))//如果绑定失败,这里调用一次解绑动作
  193. gDxObj.UnBind();
  194. *nret = sucee;
  195. }
  196. else
  197. *nret = true;
  198. if ((gDxObj.m_displayMode & DISPLAY_GDI) == DISPLAY_GDI || (gDxObj.m_displayMode & DISPLAY_DX2) == DISPLAY_DX2)
  199. {
  200. //TSRuntime::add_log( "DISPLAY_GDI");
  201. //TSRuntime::add_log( "gdi模式找图初始化");
  202. //GDI模式需要修改WINDOW样式
  203. //遍历获取父窗口句柄
  204. HWND parenthwnd = 0;
  205. HWND hparent = 0;
  206. bool findparent = false;
  207. do {
  208. if (parenthwnd == 0)
  209. parenthwnd = GetParent(gDxObj.m_hwnd);
  210. else
  211. {
  212. hparent = GetParent(parenthwnd);
  213. if (hparent != 0 && hparent != parenthwnd)
  214. {
  215. //gDxObj.m_parenthwnd=hparent;
  216. //TSRuntime::add_log( "gDxObj.m_parenthwnd:%d",gDxObj.m_parenthwnd);
  217. hwnd = (LONG)hparent;
  218. findparent = true;
  219. }
  220. parenthwnd = hparent;
  221. }
  222. } while (parenthwnd != NULL);
  223. char pszBinWindow_GDIWINDOW[MAX_PATH] = { 0 };
  224. sprintf(pszBinWindow_GDIWINDOW, "%s%d", TS_BINDWINDOW_GDIWINDOW, gDxObj.nPid);
  225. SetPropA((HWND)hwnd, pszBinWindow_GDIWINDOW, (HANDLE)1); //设置绑定标识符
  226. typedef bool(__stdcall* myGetLayeredWindowAttributes)(
  227. HWND hwnd,
  228. COLORREF* pcrKey,
  229. BYTE* pbAlpha,
  230. DWORD* pdwFlags);
  231. myGetLayeredWindowAttributes obj_GetLayeredWindowAttributes = NULL;
  232. typedef bool(__stdcall* mySetLayeredWindowAttributes)(
  233. HWND hwnd,
  234. COLORREF pcrKey,
  235. BYTE pbAlpha,
  236. DWORD pdwFlags);
  237. mySetLayeredWindowAttributes obj_SetLayeredWindowAttributes = NULL;
  238. HINSTANCE hlibrary;
  239. hlibrary = LoadLibrary(_T("user32.dll"));
  240. obj_GetLayeredWindowAttributes = (myGetLayeredWindowAttributes)GetProcAddress(hlibrary, "GetLayeredWindowAttributes");
  241. obj_SetLayeredWindowAttributes = (mySetLayeredWindowAttributes)GetProcAddress(hlibrary, "SetLayeredWindowAttributes");
  242. DWORD dwExStyle = GetWindowLong((HWND)hwnd, GWL_EXSTYLE);
  243. gDxObj.GDI_dwExStyle = dwExStyle;
  244. COLORREF crKey = 0;
  245. BYTE bAlpha = 0;
  246. DWORD dwFlags = 0;
  247. bool ret = obj_GetLayeredWindowAttributes((HWND)hwnd, &crKey, &bAlpha, &dwFlags);
  248. //GDI:crKey=0xff00ff,bAlpha=0,dwFlags=1;//DX2:crKey=0;bAlpha=0XFF;dwFlags=2;
  249. if (gDxObj.m_displayMode & DISPLAY_GDI)
  250. {
  251. crKey = 0xff00ff;
  252. bAlpha = 0;
  253. dwFlags = LWA_COLORKEY;
  254. ::SetWindowLong((HWND)hwnd, GWL_EXSTYLE, 0x80100);
  255. }
  256. else if (gDxObj.m_displayMode & DISPLAY_DX2)
  257. {
  258. crKey = 0;
  259. bAlpha = 0XFF;
  260. dwFlags = LWA_ALPHA;
  261. ::SetWindowLong((HWND)hwnd, GWL_EXSTYLE, 0x80100);
  262. }
  263. obj_SetLayeredWindowAttributes((HWND)hwnd, crKey, bAlpha, dwFlags);
  264. ::UpdateWindow((HWND)hwnd);
  265. Sleep(100); //疑问 这里等1秒是等待窗口刷新
  266. gDxObj.m_dwExStyle = dwExStyle;
  267. //GDI模式需要修改WINDOW样式
  268. }
  269. else if (gDxObj.m_displayMode & DISPLAY_NORMAL)
  270. {
  271. gDxObj.m_hwnd = GetDesktopWindow();
  272. if (::IsWindow((HWND)hwnd))
  273. gDxObj.m_parenthwnd = (HWND)hwnd;
  274. else
  275. gDxObj.m_parenthwnd = gDxObj.m_hwnd;//桌面句柄;
  276. }
  277. gDxObj.InitGdiNormal();
  278. if (sucee || *nret == true)
  279. gDxObj.m_isBind = true;
  280. VMPEND
  281. //TSRuntime::add_log( "TS_BIND-end");
  282. return S_OK;
  283. }
  284. STDMETHODIMP CTSPlugInterFace::BindWindowEx(LONG hwnd, BSTR display, BSTR mouse, BSTR keypad, BSTR publics, LONG mode, LONG* nret)
  285. {
  286. // TODO: 在此添加实现代码
  287. return S_OK;
  288. }
  289. STDMETHODIMP CTSPlugInterFace::UnBindWindow(LONG* nret)
  290. {
  291. TsMutexlock ts_mutexlock(&gDXUnbindMutex);
  292. //TSRuntime::g_DxObj.SendMsg(TS_UNBIND);
  293. if (gDxObj.m_isBind)
  294. {
  295. gDxObj.SendMsg(TS_UNBIND);
  296. Sleep(200);
  297. gDxObj.UnBind();
  298. gDxObj.m_isBind = false;
  299. if (!TSRuntime::IsLoginlog)
  300. {
  301. Loginlog(TSRuntime::MachineCode);
  302. TSRuntime::IsLoginlog = true;
  303. }
  304. }
  305. *nret = 1;
  306. // TODO: 在此添加实现代码
  307. return S_OK;
  308. }
  309. STDMETHODIMP CTSPlugInterFace::KeyDown(LONG vk_code, LONG* nret)
  310. {
  311. TsMutexlock ts_mutexlock(&gDXKeyDownMutex);
  312. // TODO: 在此添加实现代码
  313. if (vk_code == VK_MENU)
  314. {
  315. //TSRuntime::g_IsSYSKEY=true;
  316. gDxObj.g_IsSYSKEY = true;
  317. }
  318. if ((gDxObj.m_keyMode & KEY_NORMAL) == KEY_NORMAL)//判断是否是前台模式
  319. {
  320. if (TSRuntime::SetSimModeType == 0)
  321. TSRuntime::g_KeyBoard.keyDown(vk_code);
  322. }
  323. else
  324. {
  325. if (gDxObj.g_IsSYSKEY && vk_code != VK_MENU)
  326. *nret = PostMessage(gDxObj.m_mousekeyhwnd, WM_SYSKEYDOWN, vk_code, 1 << 29);
  327. gDxObj.SendMsg(TS_KEYDOWN, vk_code);
  328. //*nret=PostMessage(TSRuntime::g_DxObj.m_hwnd,WM_SYSKEYDOWN,vk_code,1<<29);
  329. if (gDxObj.m_keyMode & KEY_WINDOW)
  330. PostMessage(gDxObj.m_mousekeyhwnd, WM_KEYDOWN, vk_code, TSRuntime::retrunLparamDown(vk_code));
  331. //TSRuntime::g_DxObj.SendMsg(WM_KEYDOWN,vk_code);
  332. }
  333. *nret = 1;
  334. return S_OK;
  335. }
  336. STDMETHODIMP CTSPlugInterFace::KeyUp(LONG vk_code, LONG* nret)
  337. {
  338. TsMutexlock ts_mutexlock(&gDXKeyUpMutex);
  339. // TODO: 在此添加实现代码
  340. if (vk_code == VK_MENU)
  341. {
  342. //TSRuntime::g_IsSYSKEY=false;
  343. gDxObj.g_IsSYSKEY = false;
  344. }
  345. if ((gDxObj.m_keyMode & KEY_NORMAL) == KEY_NORMAL)//判断是否是前台模式
  346. {
  347. if (TSRuntime::SetSimModeType == 0)
  348. TSRuntime::g_KeyBoard.keyUp(vk_code);
  349. }
  350. else
  351. {
  352. if (TSRuntime::g_IsSYSKEY)
  353. *nret = ::PostMessage(gDxObj.m_mousekeyhwnd, WM_SYSKEYUP, vk_code, 0);
  354. *nret = gDxObj.SendMsg(TS_KEYUP, vk_code);
  355. // *nret=::PostMessage(TSRuntime::g_DxObj.m_hwnd,WM_SYSKEYUP,vk_code,0);
  356. //*nret=TSRuntime::g_DxObj.SendMsg(TS_KEYUP,vk_code);
  357. if (gDxObj.m_keyMode & KEY_WINDOW)
  358. //TSRuntime::g_DxObj.SendMsg(WM_KEYUP,vk_code);
  359. PostMessage(gDxObj.m_mousekeyhwnd, WM_KEYUP, vk_code, (0xC0000000 | TSRuntime::retrunLparamDown(vk_code)));
  360. }
  361. *nret = 1;
  362. return S_OK;
  363. }
  364. STDMETHODIMP CTSPlugInterFace::KeyPress(LONG vk_code, LONG* nret)
  365. {
  366. TsMutexlock ts_mutexlock(&gDXKeyPressMutex);
  367. // TODO: 在此添加实现代码
  368. if ((gDxObj.m_keyMode & KEY_NORMAL) == KEY_NORMAL)//判断是否是前台模式
  369. {
  370. if (TSRuntime::SetSimModeType == 0)
  371. {
  372. TSRuntime::g_KeyBoard.delaytime = gDxObj.NormalKeysleep;
  373. TSRuntime::g_KeyBoard.keyPress(vk_code);
  374. }
  375. }
  376. else
  377. {
  378. if (gDxObj.g_IsSYSKEY && vk_code != VK_MENU)
  379. *nret = PostMessage(gDxObj.m_mousekeyhwnd, WM_SYSKEYDOWN, vk_code, 1 << 29);
  380. else
  381. *nret = gDxObj.SendMsg(TS_KEYDOWN, vk_code);
  382. if (gDxObj.m_keyMode & KEY_WINDOW)
  383. PostMessage(gDxObj.m_mousekeyhwnd, WM_KEYDOWN, vk_code, TSRuntime::retrunLparamDown(vk_code));
  384. if (gDxObj.m_keyMode & KEY_WINDOW) //window模式默认延时))
  385. {
  386. if (gDxObj.IsTSEnableRealKeypad)
  387. Sleep(gDxObj.TSRealKeyMousSleepTime(1));
  388. else
  389. Sleep(gDxObj.WindowsKeyMouseClicksleep);
  390. }
  391. else
  392. {
  393. if (gDxObj.IsTSEnableRealKeypad)
  394. Sleep(gDxObj.TSRealKeyMousSleepTime(1));
  395. else
  396. Sleep(gDxObj.KeyDownsleep);
  397. }
  398. *nret = gDxObj.SendMsg(TS_KEYUP, vk_code);
  399. if (gDxObj.m_keyMode & KEY_WINDOW)
  400. PostMessage(gDxObj.m_mousekeyhwnd, WM_KEYUP, vk_code, (0xC0000000 | TSRuntime::retrunLparamDown(vk_code)));
  401. }
  402. *nret = 1;
  403. return S_OK;
  404. }
  405. STDMETHODIMP CTSPlugInterFace::LeftDown(LONG* nret)
  406. {
  407. // TODO: 在此添加实现代码
  408. TsMutexlock ts_mutexlock(&gDXLeftDownMutex);
  409. if ((gDxObj.m_mouseMode & MOUSE_NORMAL) == MOUSE_NORMAL)
  410. {
  411. //
  412. if (TSRuntime::SetSimModeType == 0)//普通模式
  413. TSRuntime::g_Mouse.leftDown();
  414. }
  415. else
  416. {
  417. if (gDxObj.m_mouseMode & MOUSE_WINDOW)
  418. {
  419. SendMessage(gDxObj.m_mousekeyhwnd, WM_SETFOCUS, (WPARAM)gDxObj.m_mousekeyhwnd, 0);
  420. SendMessage(gDxObj.m_mousekeyhwnd, WM_CAPTURECHANGED, (WPARAM)gDxObj.m_mousekeyhwnd, 0);
  421. PostMessage(gDxObj.m_mousekeyhwnd, WM_LBUTTONDOWN, 1, MAKELPARAM(gDxObj.LastMouseMoveX, gDxObj.LastMouseMoveY));
  422. }
  423. else
  424. *nret = gDxObj.SendMsg(TS_LBUTTONDOWN, 1, MAKELPARAM(gDxObj.LastMouseMoveX, gDxObj.LastMouseMoveY));
  425. }
  426. *nret = 1;
  427. return S_OK;
  428. }
  429. STDMETHODIMP CTSPlugInterFace::LeftUp(LONG* nret)
  430. {
  431. // TODO: 在此添加实现代
  432. TsMutexlock ts_mutexlock(&gDXLeftUpMutex);
  433. if ((gDxObj.m_mouseMode & MOUSE_NORMAL) == MOUSE_NORMAL)
  434. {
  435. //TSRuntime::g_Mouse.leftUp();
  436. if (TSRuntime::SetSimModeType == 0)//普通模式
  437. TSRuntime::g_Mouse.leftUp();
  438. }
  439. else
  440. {
  441. if (gDxObj.m_mouseMode & MOUSE_WINDOW)
  442. {
  443. PostMessage(gDxObj.m_mousekeyhwnd, WM_LBUTTONUP, 0, MAKELPARAM(gDxObj.LastMouseMoveX, gDxObj.LastMouseMoveY));
  444. SendMessage(gDxObj.m_mousekeyhwnd, WM_CAPTURECHANGED, 0, 0);
  445. }
  446. else
  447. *nret = gDxObj.SendMsg(TS_LBUTTOUP, 0, MAKELPARAM(gDxObj.LastMouseMoveX, gDxObj.LastMouseMoveY));
  448. }
  449. *nret = 1;
  450. return S_OK;
  451. }
  452. STDMETHODIMP CTSPlugInterFace::LeftClick(LONG* nret)
  453. {
  454. TsMutexlock ts_mutexlock(&gDXLeftClickMutex);
  455. // TODO: 在此添加实现代码
  456. if ((gDxObj.m_mouseMode & MOUSE_NORMAL) == MOUSE_NORMAL)
  457. {
  458. TSRuntime::g_Mouse.delaytimes = gDxObj.NormalClicksleep;
  459. if (TSRuntime::SetSimModeType == 0)//普通模式
  460. TSRuntime::g_Mouse.leftClick();
  461. }
  462. else
  463. {
  464. if (gDxObj.m_mouseMode & MOUSE_WINDOW)
  465. {
  466. SendMessage(gDxObj.m_mousekeyhwnd, WM_SETFOCUS, (WPARAM)gDxObj.m_mousekeyhwnd, 0);
  467. SendMessage(gDxObj.m_mousekeyhwnd, WM_CAPTURECHANGED, (WPARAM)gDxObj.m_mousekeyhwnd, 0);
  468. PostMessage(gDxObj.m_mousekeyhwnd, WM_LBUTTONDOWN, 1, MAKELPARAM(gDxObj.LastMouseMoveX, gDxObj.LastMouseMoveY));
  469. }
  470. else
  471. *nret = gDxObj.SendMsg(TS_LBUTTONDOWN, 1, MAKELPARAM(gDxObj.LastMouseMoveX, gDxObj.LastMouseMoveY));
  472. if (gDxObj.m_mouseMode & MOUSE_WINDOW) //window模式默认延时
  473. {
  474. if (gDxObj.IsTSEnableRealMouse)
  475. Sleep(gDxObj.TSRealKeyMousSleepTime(0));
  476. else
  477. Sleep(gDxObj.WindowsKeyMouseClicksleep);
  478. }
  479. else
  480. {
  481. if (gDxObj.IsTSEnableRealMouse)
  482. Sleep(gDxObj.TSRealKeyMousSleepTime(0));
  483. else
  484. Sleep(gDxObj.MouseClicksleep); //dx模式默认延时
  485. }
  486. if (gDxObj.m_mouseMode & MOUSE_WINDOW)
  487. {
  488. PostMessage(gDxObj.m_mousekeyhwnd, WM_LBUTTONUP, 0, MAKELPARAM(gDxObj.LastMouseMoveX, gDxObj.LastMouseMoveY));
  489. SendMessage(gDxObj.m_mousekeyhwnd, WM_CAPTURECHANGED, 0, 0);
  490. }
  491. else
  492. *nret = gDxObj.SendMsg(TS_LBUTTOUP, 0, MAKELPARAM(gDxObj.LastMouseMoveX, gDxObj.LastMouseMoveY));
  493. }
  494. *nret = 1;
  495. return S_OK;
  496. }
  497. STDMETHODIMP CTSPlugInterFace::MoveTo(LONG x, LONG y, LONG* nret)
  498. {
  499. TsMutexlock ts_mutexlock(&gDXMoveToMutex);
  500. // TODO: 在此添加实现代码
  501. POINT pos;
  502. pos.x = x;
  503. pos.y = y;
  504. if (gDxObj.IsTSEnableRealMouse)
  505. {
  506. if (IsWindow(gDxObj.m_hwnd))
  507. {
  508. ::ClientToScreen(gDxObj.m_mousekeyhwnd, &pos);
  509. gDxObj.TSEnableRealMouse(pos.x, pos.y);
  510. gDxObj.LastMouseMoveX = pos.x;
  511. gDxObj.LastMouseMoveY = pos.y;
  512. }
  513. else
  514. {
  515. gDxObj.TSEnableRealMouse(x, y);
  516. gDxObj.LastMouseMoveX = x;
  517. gDxObj.LastMouseMoveY = y;
  518. }
  519. }
  520. else
  521. {
  522. if ((gDxObj.m_mouseMode & MOUSE_NORMAL) == MOUSE_NORMAL)
  523. {
  524. if (IsWindow(gDxObj.m_hwnd))
  525. {
  526. ::ClientToScreen(gDxObj.m_mousekeyhwnd, &pos);
  527. if (TSRuntime::SetSimModeType == 0)//普通模式
  528. ::SetCursorPos(pos.x, pos.y);
  529. gDxObj.LastMouseMoveX = pos.x;
  530. gDxObj.LastMouseMoveY = pos.y;
  531. }
  532. else
  533. {
  534. //::SetCursorPos(x,y);
  535. if (TSRuntime::SetSimModeType == 0)//普通模式
  536. ::SetCursorPos(x, y);
  537. gDxObj.LastMouseMoveX = x;
  538. gDxObj.LastMouseMoveY = y;
  539. }
  540. }
  541. else
  542. {
  543. if (gDxObj.m_mouseMode & MOUSE_WINDOW)
  544. PostMessage(gDxObj.m_mousekeyhwnd, WM_MOUSEMOVE, 0, MAKELPARAM(x, y));
  545. else
  546. {
  547. *nret = gDxObj.SendMsg(TS_MOUSEMOVE, 0, MAKELPARAM(x, y));
  548. //*nret=gDxObj.SendMsg(TS_MOUSEMOVEOVER);
  549. }
  550. gDxObj.LastMouseMoveX = x;
  551. gDxObj.LastMouseMoveY = y;
  552. }
  553. }
  554. *nret = 1;
  555. return S_OK;
  556. }
  557. //int addr=0;
  558. STDMETHODIMP CTSPlugInterFace::FindPic(LONG x1, LONG y1, LONG x2, LONG y2, BSTR pic_name, BSTR delta_color, DOUBLE sim, LONG dir, VARIANT* intX, VARIANT* intY, LONG* nret)
  559. { //
  560. TsMutexlock ts_mutexlock(&gDXFindPicMutex);
  561. LONG x = -1, y = -1, ret = -1;
  562. if (x1 >= x2 || y1 >= y2)
  563. {
  564. if (TSRuntime::IsShowErrorMsg)
  565. MessageBox(NULL, L"传入坐标已越界!", L"TS", NULL);
  566. return S_OK;
  567. }
  568. //ret=TSRuntime::g_DxObj.findPic(x1,y1,x2,y2,pic_name,delta_color,sim,dir,x,y);
  569. ret = gDxObj.findPic(x1, y1, x2, y2, pic_name, delta_color, sim, dir, x, y);
  570. intX->vt = VT_I4;
  571. intY->vt = VT_I4;
  572. intX->lVal = x;
  573. intY->lVal = y;
  574. if (x == -1 || y == -1)
  575. ret = -1;
  576. *nret = ret;
  577. //TSRuntime::add_log( "findPicture,X:%d,Y:%d",x,y);
  578. //TSRuntime::add_log( "findPicture,X:%d,Y:%d,add:%d",x,y,++addr);
  579. return S_OK;
  580. }
  581. STDMETHODIMP CTSPlugInterFace::RightClick(LONG* nret)
  582. {
  583. TsMutexlock ts_mutexlock(&gDXRightClickMutex);
  584. // TODO: 在此添加实现代码
  585. if ((gDxObj.m_mouseMode & MOUSE_NORMAL) == MOUSE_NORMAL)
  586. {
  587. TSRuntime::g_Mouse.delaytimes = gDxObj.NormalClicksleep;
  588. //TSRuntime::g_Mouse.rightClick();
  589. if (TSRuntime::SetSimModeType == 0)//普通模式
  590. TSRuntime::g_Mouse.rightClick();
  591. }
  592. else
  593. {
  594. if (gDxObj.m_mouseMode & MOUSE_WINDOW)
  595. {
  596. PostMessage(gDxObj.m_mousekeyhwnd, WM_RBUTTONDOWN, 1, MAKELPARAM(gDxObj.LastMouseMoveX, gDxObj.LastMouseMoveY));
  597. SendMessage(gDxObj.m_mousekeyhwnd, WM_SETFOCUS, (WPARAM)gDxObj.m_hwnd, 0);
  598. SendMessage(gDxObj.m_mousekeyhwnd, WM_CAPTURECHANGED, (WPARAM)gDxObj.m_mousekeyhwnd, 0);
  599. }
  600. else
  601. *nret = gDxObj.SendMsg(TS_RBUTTONDOWN, 1, MAKELPARAM(gDxObj.LastMouseMoveX, gDxObj.LastMouseMoveY));
  602. if (gDxObj.m_mouseMode & MOUSE_WINDOW) //window模式默认延时
  603. {
  604. if (gDxObj.IsTSEnableRealMouse)
  605. Sleep(gDxObj.TSRealKeyMousSleepTime(0));
  606. else
  607. Sleep(gDxObj.WindowsKeyMouseClicksleep);
  608. }
  609. else
  610. {
  611. if (gDxObj.IsTSEnableRealMouse)
  612. Sleep(gDxObj.TSRealKeyMousSleepTime(0));
  613. else
  614. Sleep(gDxObj.MouseClicksleep); //dx模式默认延时
  615. }
  616. if (gDxObj.m_mouseMode & MOUSE_WINDOW)
  617. {
  618. PostMessage(gDxObj.m_mousekeyhwnd, WM_RBUTTONUP, 0, MAKELPARAM(gDxObj.LastMouseMoveX, gDxObj.LastMouseMoveY));
  619. SendMessage(gDxObj.m_mousekeyhwnd, WM_CAPTURECHANGED, 0, 0);
  620. }
  621. else
  622. *nret = gDxObj.SendMsg(TS_RBUTTONUP, 0, MAKELPARAM(gDxObj.LastMouseMoveX, gDxObj.LastMouseMoveY));
  623. }
  624. *nret = 1;
  625. return S_OK;
  626. }
  627. STDMETHODIMP CTSPlugInterFace::RightDown(LONG* nret)
  628. {
  629. // TODO: 在此添加实现代码
  630. TsMutexlock ts_mutexlock(&gDXRightDownMutex);
  631. if ((gDxObj.m_mouseMode & MOUSE_NORMAL) == MOUSE_NORMAL)
  632. {
  633. //TSRuntime::g_Mouse.rightDown();
  634. if (TSRuntime::SetSimModeType == 0)//普通模式
  635. TSRuntime::g_Mouse.rightDown();
  636. }
  637. else
  638. {
  639. if (gDxObj.m_mouseMode & MOUSE_WINDOW)
  640. {
  641. PostMessage(gDxObj.m_mousekeyhwnd, WM_RBUTTONDOWN, 1, MAKELPARAM(gDxObj.LastMouseMoveX, gDxObj.LastMouseMoveY));
  642. SendMessage(gDxObj.m_mousekeyhwnd, WM_SETFOCUS, (WPARAM)gDxObj.m_hwnd, 0);
  643. SendMessage(gDxObj.m_mousekeyhwnd, WM_CAPTURECHANGED, (WPARAM)gDxObj.m_mousekeyhwnd, 0);
  644. }
  645. else
  646. *nret = gDxObj.SendMsg(TS_RBUTTONDOWN, 1, MAKELPARAM(gDxObj.LastMouseMoveX, gDxObj.LastMouseMoveY));
  647. }
  648. *nret = 1;
  649. return S_OK;
  650. }
  651. STDMETHODIMP CTSPlugInterFace::FindColor(LONG x1, LONG y1, LONG x2, LONG y2, BSTR color, DOUBLE sim, LONG dir, VARIANT* intX, VARIANT* intY, LONG* nret)
  652. {
  653. // TODO: 在此添加实现代码
  654. TsMutexlock ts_mutexlock(&gDXFindColorMutex);
  655. if (x1 >= x2 || y1 >= y2)
  656. {
  657. MessageBox(NULL, L"传入坐标已越界!", L"TS", NULL);
  658. return S_OK;
  659. }
  660. //wchar_t* p=0;
  661. DWORD ncolor = 0x100;
  662. //ncolor=::wcstol(color,&p,16);
  663. //int r=0,g=0,b=0;
  664. //r=GetRValue(ncolor);
  665. //g=GetGValue(ncolor);
  666. //b=GetBValue(ncolor);
  667. //swprintf(color,L"%x%x%x",r,g,b);//将传入的RGB颜色值转换为BGR进行找色
  668. //ncolor=::wcstol(color,&p,16);
  669. LONG x = -1, y = -1, ret;
  670. //TSRuntime::add_log("FindColor:_wtoi:%x",ncolor);
  671. //ret=TSRuntime::g_DxObj.findColor(x1,y1,x2,y2,ncolor,sim,dir,x,y);
  672. ret = gDxObj.findColor(x1, y1, x2, y2, ncolor, sim, dir, x, y, color);
  673. intX->vt = VT_I4;
  674. intY->vt = VT_I4;
  675. intX->lVal = x;
  676. intY->lVal = y;
  677. *nret = ret;
  678. return S_OK;
  679. }
  680. STDMETHODIMP CTSPlugInterFace::RightUp(LONG* nret)
  681. {
  682. // TODO: 在此添加实现代码
  683. TsMutexlock ts_mutexlock(&gDXRightUpMutex);
  684. if ((gDxObj.m_mouseMode & MOUSE_NORMAL) == MOUSE_NORMAL)
  685. {
  686. //TSRuntime::g_Mouse.rightUp();
  687. if (TSRuntime::SetSimModeType == 0)//普通模式
  688. TSRuntime::g_Mouse.rightUp();
  689. }
  690. else
  691. {
  692. if (gDxObj.m_mouseMode & MOUSE_WINDOW)
  693. {
  694. PostMessage(gDxObj.m_mousekeyhwnd, WM_RBUTTONUP, 0, MAKELPARAM(gDxObj.LastMouseMoveX, gDxObj.LastMouseMoveY));
  695. SendMessage(gDxObj.m_mousekeyhwnd, WM_CAPTURECHANGED, 0, 0);
  696. }
  697. else
  698. *nret = gDxObj.SendMsg(TS_RBUTTONUP, 0, MAKELPARAM(gDxObj.LastMouseMoveX, gDxObj.LastMouseMoveY));
  699. }
  700. *nret = 1;
  701. return S_OK;
  702. }
  703. STDMETHODIMP CTSPlugInterFace::GetColor(LONG x, LONG y, BSTR* RetStrColor)
  704. {
  705. // TODO: 在此添加实现代码
  706. TsMutexlock ts_mutexlock(&gDXGetColorMutex);
  707. //TSRuntime::g_DxObj.GetColor(x,y,*RetStrColor);
  708. //memset(TSRuntime::RetStr,0,MAX_PATH);
  709. gDxObj.GetColor(x, y, TSRuntime::RetStr);
  710. CComBSTR newbstr;
  711. newbstr.Append(TSRuntime::RetStr);
  712. newbstr.CopyTo(RetStrColor);
  713. //_variant_t strVar();
  714. //*RetStrColor=strVar.bstrVal;//_bstr_t(TSRuntime::RetStr)
  715. return S_OK;
  716. }
  717. STDMETHODIMP CTSPlugInterFace::GetCursorShape(BSTR* RetCursorShape)
  718. {
  719. // TODO: 在此添加实现代码
  720. TsMutexlock ts_mutexlock(&gDXGetCursorShapeMutex);
  721. DWORD mouseshape = 0;
  722. if ((gDxObj.m_mouseMode & MOUSE_NORMAL) == MOUSE_NORMAL)
  723. {
  724. TSRuntime::g_Mouse.getmouseshape(mouseshape);
  725. }
  726. else
  727. mouseshape = gDxObj.SendMsg(TS_GETMOUSESHARE, 0, 0);
  728. if (mouseshape)
  729. {
  730. memset(TSRuntime::RetStr, 0, MAX_PATH);
  731. swprintf(TSRuntime::RetStr, L"%x", mouseshape);
  732. _variant_t strVar(TSRuntime::RetStr);
  733. *RetCursorShape = strVar.bstrVal;
  734. }
  735. return S_OK;
  736. }
  737. STDMETHODIMP CTSPlugInterFace::SetPath(BSTR path, LONG* nret)
  738. {
  739. // TODO: 在此添加实现代码
  740. TsMutexlock ts_mutexlock(&gDXSetPathMutex);
  741. //*nret=TSRuntime::g_DxObj.TSSetpath(path);
  742. *nret = gDxObj.TSSetpath(path);
  743. *nret = 1;
  744. return S_OK;
  745. }
  746. STDMETHODIMP CTSPlugInterFace::TSGuardProtect(LONG enable, BSTR type, LONG* nret)
  747. {
  748. // TODO: 在此添加实现代码
  749. // TsMutexlock ts_mutexlock(&gDXbindMutex);
  750. VMPBEGIN //VMP保护
  751. if (!TSRuntime::IsVipLogin)
  752. {
  753. if (TSRuntime::IsRegLogin == false && TSRuntime::IsVipLogin == false)//TS盾不允许试用
  754. {
  755. *nret = 0;
  756. return S_OK;
  757. }
  758. INT64 t = 0;
  759. if (my_myGetTickCount)
  760. t = my_myGetTickCount();
  761. else
  762. t = ::GetTickCount();
  763. if (t == TSRuntime::checkthreadtime || abs((int)(t - TSRuntime::checkthreadtime)) >= 60 * 1000 * 10 || TSRuntime::checkthreadtime == 0) //校验线程是否被挂起或者GetTickCount被人下钩子
  764. {
  765. if (TSRuntime::IsStartProtect)
  766. TSRuntime::StartProtect(0, 0, -1);//Pid
  767. *nret = 0;
  768. TSRuntime::h_checkthread = NULL;
  769. return S_OK;
  770. }
  771. }
  772. TSRuntime::IsProid = wcstol(type, 0, 10);
  773. *nret = TSRuntime::StartProtect(enable, 0);
  774. VMPEND
  775. return S_OK;
  776. }
  777. STDMETHODIMP CTSPlugInterFace::KeyPressStr(BSTR key_str, LONG delay, LONG* nret)
  778. {
  779. // TODO: 在此添加实现代码
  780. TsMutexlock ts_mutexlock(&gDXKeyPressStrMutex);
  781. if ((gDxObj.m_keyMode & KEY_NORMAL) == KEY_NORMAL)//判断是否是前台模式
  782. {
  783. if (TSRuntime::SetSimModeType == 0)
  784. TSRuntime::g_KeyBoard.sendkeyString(key_str, delay);
  785. }
  786. else
  787. {
  788. int len = wcslen(key_str);
  789. for (int i = 0; i < len; i++)
  790. {
  791. // * nret=TSRuntime::g_DxObj.SendMsg(TS_CHAR,key_str[i]);
  792. gDxObj.SendMsg(TS_CHAR, key_str[i]);
  793. if (gDxObj.m_keyMode & KEY_WINDOW)
  794. gDxObj.SendMsg(WM_CHAR, i);
  795. Sleep(delay);
  796. }
  797. }
  798. //std::string dd=gDxObj.pData->tt;
  799. *nret = 1;
  800. return S_OK;
  801. }
  802. STDMETHODIMP CTSPlugInterFace::SendString(LONG hwnd, BSTR str, LONG* nret)
  803. {
  804. // TODO: 在此添加实现代码
  805. TsMutexlock ts_mutexlock(&gDXSendStringMutex);
  806. int len = wcslen(str);
  807. //MessageBoxA(NULL,tts,tts,NULL);
  808. for (int i = 0; i < len; i++)
  809. {
  810. *nret = ::SendMessage((HWND)hwnd, WM_CHAR, (WPARAM)str[i], (LPARAM)1);
  811. Sleep(10);
  812. }
  813. *nret = 1;
  814. return S_OK;
  815. }
  816. STDMETHODIMP CTSPlugInterFace::SendString2(LONG hwnd, BSTR str, LONG* nret)
  817. {
  818. // TODO: 在此添加实现代码
  819. TsMutexlock ts_mutexlock(&gDXSendString2Mutex);
  820. int len = wcslen(str);
  821. for (int i = 0; i < len; i++)
  822. {
  823. *nret = ::PostMessage((HWND)hwnd, WM_CHAR, (WPARAM)str[i], (LPARAM)1);
  824. Sleep(10);
  825. }
  826. *nret = 1;
  827. return S_OK;
  828. }
  829. STDMETHODIMP CTSPlugInterFace::KeyPressChar(BSTR key_str, LONG* nret)
  830. {
  831. // TODO: 在此添加实现代码
  832. TsMutexlock ts_mutexlock(&gDXKeyPressCharMutex);
  833. for (int i = 0; i < 0x100; i++)
  834. {
  835. if (TSRuntime::KeyPressCharMap[i])
  836. {
  837. if (wcscmp(TSRuntime::KeyPressCharMap[i], _wcslwr(key_str)) == 0)
  838. {
  839. if ((gDxObj.m_keyMode & KEY_NORMAL) == KEY_NORMAL)//判断是否是前台模式
  840. {
  841. if (TSRuntime::SetSimModeType == 0)
  842. {
  843. TSRuntime::g_KeyBoard.delaytime = gDxObj.NormalKeysleep;
  844. TSRuntime::g_KeyBoard.keyPress(i);
  845. }
  846. }
  847. else
  848. {
  849. //if(TSRuntime::g_IsSYSKEY&&wcscmp(L"alt",TSRuntime::KeyPressCharMap[i])!=0)
  850. if (gDxObj.g_IsSYSKEY && wcscmp(L"alt", TSRuntime::KeyPressCharMap[i]) != 0 && gDxObj.m_keyMode & KEY_WINDOW)
  851. *nret = PostMessage(gDxObj.m_mousekeyhwnd, WM_SYSKEYDOWN, i, 1 << 29);
  852. //*nret=PostMessage(TSRuntime::g_DxObj.m_hwnd,WM_SYSKEYDOWN,i,1<<29);
  853. //*nret=TSRuntime::g_DxObj.SendMsg(TS_KEYDOWN,i);
  854. *nret = gDxObj.SendMsg(TS_KEYDOWN, i);
  855. if (gDxObj.m_keyMode & KEY_WINDOW)
  856. //TSRuntime::g_DxObj.SendMsg(WM_KEYDOWN,i,TSRuntime::retrunLparamDown(i));
  857. PostMessage(gDxObj.m_mousekeyhwnd, WM_KEYDOWN, i, TSRuntime::retrunLparamDown(i));
  858. if (gDxObj.m_keyMode & KEY_WINDOW) //window模式默认延时))
  859. {
  860. if (gDxObj.IsTSEnableRealKeypad)
  861. Sleep(gDxObj.TSRealKeyMousSleepTime(1));
  862. else
  863. Sleep(gDxObj.WindowsKeyMouseClicksleep);
  864. }
  865. else
  866. {
  867. if (gDxObj.IsTSEnableRealKeypad)
  868. Sleep(gDxObj.TSRealKeyMousSleepTime(1));
  869. else
  870. Sleep(gDxObj.KeyDownsleep);
  871. }
  872. //*nret=TSRuntime::g_DxObj.SendMsg(TS_KEYUP,i);
  873. *nret = gDxObj.SendMsg(TS_KEYUP, i);
  874. if (gDxObj.m_keyMode & KEY_WINDOW)
  875. //TSRuntime::g_DxObj.SendMsg(WM_KEYUP,i,(0xC0000000|TSRuntime::retrunLparamDown(i)));
  876. PostMessage(gDxObj.m_mousekeyhwnd, WM_KEYUP, i, (0xC0000000 | TSRuntime::retrunLparamDown(i)));
  877. }
  878. break;
  879. }
  880. }
  881. }
  882. *nret = 1;
  883. return S_OK;
  884. }
  885. STDMETHODIMP CTSPlugInterFace::KeyDownChar(BSTR key_str, LONG* nret)
  886. {
  887. // TODO: 在此添加实现代码
  888. TsMutexlock ts_mutexlock(&gDXKeyDownMutex);
  889. if (wcscmp(L"alt", _wcslwr(key_str)) == 0)
  890. {
  891. //TSRuntime::g_IsSYSKEY=true;
  892. gDxObj.g_IsSYSKEY = true;
  893. }
  894. for (int i = 0; i < 0x100; i++)
  895. {
  896. if (TSRuntime::KeyPressCharMap[i])
  897. {
  898. if (wcscmp(TSRuntime::KeyPressCharMap[i], _wcslwr(key_str)) == 0)
  899. {
  900. if ((gDxObj.m_keyMode & KEY_NORMAL) == KEY_NORMAL)//判断是否是前台模式
  901. {
  902. if (TSRuntime::SetSimModeType == 0)
  903. TSRuntime::g_KeyBoard.keyDown(i);
  904. }
  905. else
  906. {
  907. if (gDxObj.g_IsSYSKEY && wcscmp(L"alt", TSRuntime::KeyPressCharMap[i]) != 0)
  908. *nret = PostMessage(gDxObj.m_mousekeyhwnd, WM_SYSKEYDOWN, i, 1 << 29);
  909. *nret = gDxObj.SendMsg(TS_KEYDOWN, i);
  910. if (gDxObj.m_keyMode & KEY_WINDOW)
  911. //TSRuntime::g_DxObj.SendMsg(WM_KEYDOWN,i);
  912. PostMessage(gDxObj.m_mousekeyhwnd, WM_KEYDOWN, i, TSRuntime::retrunLparamDown(i));
  913. }
  914. break;
  915. }
  916. }
  917. }
  918. *nret = 1;
  919. return S_OK;
  920. }
  921. STDMETHODIMP CTSPlugInterFace::KeyUpChar(BSTR key_str, LONG* nret)
  922. {
  923. // TODO: 在此添加实现代码
  924. TsMutexlock ts_mutexlock(&gDXKeyUpMutex);
  925. if (wcscmp(L"alt", _wcslwr(key_str)) == 0)
  926. gDxObj.g_IsSYSKEY = false;
  927. for (int i = 0; i < 0x100; i++)
  928. {
  929. if (TSRuntime::KeyPressCharMap[i] != NULL)
  930. {
  931. if (wcscmp(TSRuntime::KeyPressCharMap[i], _wcslwr(key_str)) == 0)
  932. {
  933. if ((gDxObj.m_keyMode & KEY_NORMAL) == KEY_NORMAL)//判断是否是前台模式
  934. {
  935. if (TSRuntime::SetSimModeType == 0)
  936. TSRuntime::g_KeyBoard.keyUp(i);
  937. }
  938. else
  939. {
  940. *nret = gDxObj.SendMsg(TS_KEYUP, i);
  941. if (gDxObj.m_keyMode & KEY_WINDOW)
  942. //TSRuntime::g_DxObj.SendMsg(WM_KEYUP,i);
  943. PostMessage(gDxObj.m_mousekeyhwnd, WM_KEYUP, i, (0xC0000000 | TSRuntime::retrunLparamDown(i)));
  944. }
  945. break;
  946. }
  947. }
  948. }
  949. *nret = 1;
  950. return S_OK;
  951. }
  952. STDMETHODIMP CTSPlugInterFace::GetCursorPos(VARIANT* x, VARIANT* y, LONG* nret)
  953. {
  954. // TODO: 在此添加实现代码
  955. TsMutexlock ts_mutexlock(&gDXGetCursorPosMutex);
  956. //LONG lParam=0;
  957. //lParam=TSRuntime::g_DxObj.SendMsg(TS_GETCURSORPOS);
  958. //lParam=gDxObj.SendMsg(TS_GETCURSORPOS);
  959. x->vt = VT_I4;
  960. y->vt = VT_I4;
  961. x->lVal = gDxObj.LastMouseMoveX;
  962. y->lVal = gDxObj.LastMouseMoveY;
  963. *nret = 1;
  964. ////if(lParam)
  965. //{
  966. // x->lVal=(short)LOWORD(lParam);
  967. // y->lVal=(short)HIWORD(lParam);
  968. // * nret=1;
  969. //}
  970. //else
  971. //* nret=0;
  972. return S_OK;
  973. }
  974. STDMETHODIMP CTSPlugInterFace::MoveR(LONG rx, LONG ry, LONG* rnet)
  975. {
  976. // TODO: 在此添加实现代码
  977. TsMutexlock ts_mutexlock(&gDXMoveRMutex);
  978. POINT pos;
  979. pos.x = rx + gDxObj.LastMouseMoveX;
  980. pos.y = ry + gDxObj.LastMouseMoveY;
  981. if (gDxObj.IsTSEnableRealMouse)
  982. {
  983. if (IsWindow(gDxObj.m_hwnd))
  984. {
  985. ::ScreenToClient(gDxObj.m_mousekeyhwnd, &pos);
  986. gDxObj.TSEnableRealMouse(pos.x, pos.y);
  987. gDxObj.LastMouseMoveX = pos.x;
  988. gDxObj.LastMouseMoveY = pos.y;
  989. }
  990. else
  991. {
  992. gDxObj.TSEnableRealMouse(rx + gDxObj.LastMouseMoveX, ry + gDxObj.LastMouseMoveY);
  993. gDxObj.LastMouseMoveX = rx + gDxObj.LastMouseMoveX;
  994. gDxObj.LastMouseMoveY = ry + gDxObj.LastMouseMoveY;
  995. }
  996. }
  997. else
  998. {
  999. if ((gDxObj.m_mouseMode & MOUSE_NORMAL) == MOUSE_NORMAL)
  1000. {
  1001. if (IsWindow(gDxObj.m_hwnd))
  1002. {
  1003. ::ClientToScreen(gDxObj.m_mousekeyhwnd, &pos);
  1004. if (TSRuntime::SetSimModeType == 0)//普通模式
  1005. ::SetCursorPos(pos.x, pos.y);
  1006. gDxObj.LastMouseMoveX = pos.x;
  1007. gDxObj.LastMouseMoveY = pos.y;
  1008. }
  1009. else
  1010. {
  1011. if (TSRuntime::SetSimModeType == 0)//普通模式
  1012. TSRuntime::g_Mouse.mouseMvrelative(rx, ry);
  1013. gDxObj.LastMouseMoveX = rx + gDxObj.LastMouseMoveX;
  1014. gDxObj.LastMouseMoveY = ry + gDxObj.LastMouseMoveY;
  1015. }
  1016. }
  1017. else
  1018. {
  1019. if (gDxObj.m_mouseMode & MOUSE_WINDOW)
  1020. {
  1021. PostMessage(gDxObj.m_mousekeyhwnd, WM_MOUSEMOVE, 0, MAKELPARAM(rx + gDxObj.LastMouseMoveX, ry + gDxObj.LastMouseMoveY));
  1022. }
  1023. else
  1024. {
  1025. *rnet = gDxObj.SendMsg(TS_MOUSER, 0, MAKELPARAM(rx, ry));
  1026. }
  1027. gDxObj.LastMouseMoveX = rx + gDxObj.LastMouseMoveX;
  1028. gDxObj.LastMouseMoveY = ry + gDxObj.LastMouseMoveY;
  1029. }
  1030. }
  1031. //*rnet=gDxObj.SendMsg(TS_MOUSEMOVEOVER);
  1032. //*rnet=TSRuntime::g_DxObj.SendMsg(TS_MOUSER,0,MAKELPARAM(rx,ry));
  1033. //*rnet=TSRuntime::g_DxObj.SendMsg(TS_MOUSEMOVEOVER);
  1034. *rnet = 1;
  1035. return S_OK;
  1036. }
  1037. STDMETHODIMP CTSPlugInterFace::Ver(BSTR* retver)
  1038. {
  1039. // TODO: 在此添加实现代码
  1040. //_variant_t strVar(TS_VERSION);
  1041. //*retver=strVar.bstrVal;
  1042. CComBSTR newbstr;
  1043. newbstr.Append(TS_VERSION);
  1044. newbstr.CopyTo(retver);
  1045. return S_OK;
  1046. }
  1047. STDMETHODIMP CTSPlugInterFace::GetPath(BSTR* retpath)
  1048. {
  1049. // TODO: 在此添加实现代码
  1050. //_variant_t strVar(TSRuntime::SetPath);
  1051. //strVar.bstrVal;
  1052. // TsMutexlock ts_mutexlock(&gDXbindMutex);
  1053. CComBSTR newbstr;
  1054. newbstr.Append(gDxObj.m_SetPath);
  1055. newbstr.CopyTo(retpath);
  1056. return S_OK;
  1057. }
  1058. STDMETHODIMP CTSPlugInterFace::MiddleClick(LONG* nret)
  1059. {
  1060. // TODO: 在此添加实现代码
  1061. TsMutexlock ts_mutexlock(&gDXMiddleClickMutex);
  1062. if ((gDxObj.m_mouseMode & MOUSE_NORMAL) == MOUSE_NORMAL)
  1063. {
  1064. TSRuntime::g_Mouse.delaytimes = gDxObj.NormalClicksleep;
  1065. //TSRuntime::g_Mouse.middleClick();
  1066. if (TSRuntime::SetSimModeType == 0)//普通模式
  1067. TSRuntime::g_Mouse.middleClick();
  1068. }
  1069. else
  1070. {
  1071. if (gDxObj.m_mouseMode & MOUSE_WINDOW)
  1072. PostMessage(gDxObj.m_mousekeyhwnd, WM_MBUTTONUP, 1, 0);
  1073. *nret = gDxObj.SendMsg(TS_MBUTTONDOWN, 1, MAKELPARAM(gDxObj.LastMouseMoveX, gDxObj.LastMouseMoveY));
  1074. if (gDxObj.m_mouseMode & MOUSE_WINDOW) //window模式默认延时
  1075. {
  1076. if (gDxObj.IsTSEnableRealMouse)
  1077. Sleep(gDxObj.TSRealKeyMousSleepTime(0));
  1078. else
  1079. Sleep(gDxObj.WindowsKeyMouseClicksleep);
  1080. }
  1081. else
  1082. {
  1083. if (gDxObj.IsTSEnableRealMouse)
  1084. Sleep(gDxObj.TSRealKeyMousSleepTime(0));
  1085. else
  1086. Sleep(gDxObj.MouseClicksleep); //dx模式默认延时
  1087. }
  1088. PostMessage(gDxObj.m_mousekeyhwnd, WM_MBUTTONUP, 0, 0);
  1089. *nret = gDxObj.SendMsg(TS_MBUTTONUP);
  1090. }
  1091. *nret = 1;
  1092. return S_OK;
  1093. }
  1094. STDMETHODIMP CTSPlugInterFace::WheelDown(LONG* nret)
  1095. {
  1096. // TODO: 在此添加实现代码
  1097. TsMutexlock ts_mutexlock(&gDXWheelDownMutex);
  1098. if ((gDxObj.m_mouseMode & MOUSE_NORMAL) == MOUSE_NORMAL)
  1099. {
  1100. TSRuntime::g_Mouse.mouseSheetDown();
  1101. }
  1102. else
  1103. {
  1104. if (gDxObj.m_mouseMode & MOUSE_WINDOW)
  1105. PostMessage(gDxObj.m_mousekeyhwnd, WM_MOUSEWHEEL, 0xff880000, 0);
  1106. *nret = gDxObj.SendMsg(TS_MOUSEWHEEL, 0xff880000, 0);
  1107. }
  1108. *nret = 1;
  1109. return S_OK;
  1110. }
  1111. STDMETHODIMP CTSPlugInterFace::WheelUp(LONG* nret)
  1112. {
  1113. // TODO: 在此添加实现代码
  1114. TsMutexlock ts_mutexlock(&gDXWheelUpMutex);
  1115. if ((gDxObj.m_mouseMode & MOUSE_NORMAL) == MOUSE_NORMAL)
  1116. {
  1117. TSRuntime::g_Mouse.mouseSheetUp();
  1118. }
  1119. else
  1120. {
  1121. if (gDxObj.m_mouseMode & MOUSE_WINDOW)
  1122. PostMessage(gDxObj.m_mousekeyhwnd, WM_MOUSEWHEEL, 0x780000, 0);
  1123. *nret = gDxObj.SendMsg(TS_MOUSEWHEEL, 0x780000, 0);
  1124. }
  1125. *nret = 1;
  1126. return S_OK;
  1127. }
  1128. STDMETHODIMP CTSPlugInterFace::Capture(LONG x1, LONG y1, LONG x2, LONG y2, BSTR file, LONG* nret)
  1129. {
  1130. // TODO: 在此添加实现代码
  1131. TsMutexlock ts_mutexlock(&gDXCaptureMutex);
  1132. //VMPBEGIN //VMP保护
  1133. //if(!TSRuntime::IsVipLogin)
  1134. // {
  1135. // int bret=TSRuntime::VipLogin(L"",0,false); //试用验证
  1136. // if(bret<=0)
  1137. // {
  1138. // INT64 t=0;
  1139. // if(my_myGetTickCount)
  1140. // t=my_myGetTickCount();
  1141. // else
  1142. // t=::GetTickCount();
  1143. // if(t==TSRuntime::checkthreadtime||abs((int)(t-TSRuntime::checkthreadtime))>=60*1000*10||TSRuntime::checkthreadtime==0) //校验线程是否被挂起或者GetTickCount被人下钩子
  1144. // {
  1145. // gDxObj.SendMsg(TS_UNBIND);
  1146. // Sleep(200);
  1147. // gDxObj.UnBind();
  1148. // Sleep(200);
  1149. // gDxObj.SendMsg(TS_UNBIND);
  1150. // Sleep(200);
  1151. // gDxObj.UnBind();
  1152. // if(TSRuntime::IsStartProtect)
  1153. // TSRuntime::StartProtect(0,L"");
  1154. // *nret=0;
  1155. // TSRuntime::h_checkthread=NULL;
  1156. // return S_OK;
  1157. // }
  1158. // }
  1159. // }
  1160. // VMPEND
  1161. if (x1 >= x2 || y1 >= y2)
  1162. {
  1163. if (TSRuntime::IsShowErrorMsg)
  1164. MessageBox(NULL, L"传入坐标已越界!", L"TS", NULL);
  1165. return S_OK;
  1166. }
  1167. *nret = gDxObj.Capture(x1, y1, x2, y2, file, D3DXIFF_BMP);
  1168. //* nret=TSRuntime::g_DxObj.Capture(x1,y1,x2,y2,file,D3DXIFF_BMP);
  1169. return S_OK;
  1170. }
  1171. STDMETHODIMP CTSPlugInterFace::CaptureJpg(LONG x1, LONG y1, LONG x2, LONG y2, BSTR file, LONG* nret)
  1172. {
  1173. // TODO: 在此添加实现代码
  1174. TsMutexlock ts_mutexlock(&gDXCaptureMutex);
  1175. if (x1 >= x2 || y1 >= y2)
  1176. {
  1177. if (TSRuntime::IsShowErrorMsg)
  1178. MessageBox(NULL, L"传入坐标已越界!", L"TS", NULL);
  1179. return S_OK;
  1180. }
  1181. *nret = gDxObj.Capture(x1, y1, x2, y2, file, D3DXIFF_JPG);
  1182. //* nret=TSRuntime::g_DxObj.Capture(x1,y1,x2,y2,file,D3DXIFF_JPG);
  1183. return S_OK;
  1184. }
  1185. STDMETHODIMP CTSPlugInterFace::CapturePng(LONG x1, LONG y1, LONG x2, LONG y2, BSTR file, LONG* nret)
  1186. {
  1187. // TODO: 在此添加实现代码
  1188. TsMutexlock ts_mutexlock(&gDXCaptureMutex);
  1189. if (x1 >= x2 || y1 >= y2)
  1190. {
  1191. if (TSRuntime::IsShowErrorMsg)
  1192. MessageBox(NULL, L"传入坐标已越界!", L"TS", NULL);
  1193. return S_OK;
  1194. }
  1195. *nret = gDxObj.Capture(x1, y1, x2, y2, file, D3DXIFF_PNG);
  1196. //* nret=TSRuntime::g_DxObj.Capture(x1,y1,x2,y2,file,D3DXIFF_PNG);
  1197. return S_OK;
  1198. }
  1199. STDMETHODIMP CTSPlugInterFace::LockInput(LONG lock, LONG* nret)
  1200. {
  1201. // TODO: 在此添加实现代码
  1202. TsMutexlock ts_mutexlock(&gDXLockInputMutex);
  1203. //* nret=TSRuntime::g_DxObj.SendMsg(TS_LOCKINPUT,lock);
  1204. *nret = gDxObj.SendMsg(TS_LOCKINPUT, lock);
  1205. *nret = 1;
  1206. return S_OK;
  1207. }
  1208. STDMETHODIMP CTSPlugInterFace::Ocr(LONG x1, LONG y1, LONG x2, LONG y2, BSTR color_format, FLOAT sim, BSTR* retstr)
  1209. {
  1210. // TODO: 在此添加实现代码
  1211. TsMutexlock ts_mutexlock(&gDXOcrMutex);
  1212. if (wcslen(color_format) == 0)
  1213. return S_OK;
  1214. if (x1 >= x2 || y1 >= y2)
  1215. {
  1216. if (TSRuntime::IsShowErrorMsg)
  1217. MessageBox(NULL, L"传入坐标已越界!", L"TS", NULL);
  1218. return S_OK;
  1219. }
  1220. //TSRuntime::g_DxObj.Ocr(x1,y1,x2,y2,color_format,sim);
  1221. gDxObj.Ocr(x1, y1, x2, y2, color_format, sim);
  1222. //TSRuntime::add_log( "TSRuntime::pData->RetString:%s",TSRuntime::pData->RetString);
  1223. CComBSTR newbstr;
  1224. if (gDxObj.pData)
  1225. //*retstr=_bstr_t();
  1226. newbstr.Append(gDxObj.pData->RetString);
  1227. else
  1228. //*retstr=_bstr_t();
  1229. newbstr.Append(gDxObj.m_Retstr);
  1230. newbstr.CopyTo(retstr);
  1231. return S_OK;
  1232. }
  1233. STDMETHODIMP CTSPlugInterFace::SetDict(LONG index, BSTR file, LONG* nret)
  1234. {
  1235. // TODO: 在此添加实现代码
  1236. TsMutexlock ts_mutexlock(&gDXSetDictMutex);
  1237. //*nret=TSRuntime::g_DxObj.TSSetDict(index,file);
  1238. *nret = gDxObj.TSSetDict(index, file);
  1239. return S_OK;
  1240. }
  1241. STDMETHODIMP CTSPlugInterFace::UseDict(LONG index, LONG* nret)
  1242. {
  1243. // TODO: 在此添加实现代码
  1244. TsMutexlock ts_mutexlock(&gDXUseDictMutex);
  1245. //*nret=TSRuntime::g_DxObj.TSUseDict(index);
  1246. *nret = gDxObj.TSUseDict(index);
  1247. return S_OK;
  1248. }
  1249. STDMETHODIMP CTSPlugInterFace::ClearDict(LONG index, LONG* nret)
  1250. {
  1251. // TODO: 在此添加实现代码
  1252. TsMutexlock ts_mutexlock(&gDXClearDictMutex);
  1253. if (index >= 0 && index < 20 && index != gDxObj.NowUsingDictIndex)
  1254. {
  1255. if (gDxObj.MyDictCount[index] != NULL)
  1256. {
  1257. gDxObj.nMyDictCountsize[index] = 0;
  1258. gDxObj.nMaxStrHight[index] = 0;
  1259. delete[] gDxObj.MyDictCount[index];
  1260. gDxObj.MyDictCount[index] = NULL;
  1261. *nret = 1;
  1262. }
  1263. }
  1264. *nret = 0;
  1265. return S_OK;
  1266. }
  1267. STDMETHODIMP CTSPlugInterFace::FindStr(LONG x1, LONG y1, LONG x2, LONG y2, BSTR string, BSTR color_format, FLOAT sim, VARIANT* intX, VARIANT* intY, LONG* nret)
  1268. {
  1269. // TODO: 在此添加实现代码
  1270. TsMutexlock ts_mutexlock(&gDXFindStrMutex);
  1271. LONG x = -1, y = -1, ret = -1;
  1272. if (x1 >= x2 || y1 >= y2)
  1273. {
  1274. if (TSRuntime::IsShowErrorMsg)
  1275. MessageBox(NULL, L"传入坐标已越界!", L"TS", NULL);
  1276. return S_OK;
  1277. }
  1278. ret = gDxObj.Findstr(x1, y1, x2, y2, string, color_format, sim, x, y, 0);
  1279. intX->vt = VT_I4;
  1280. intY->vt = VT_I4;
  1281. intX->lVal = x;
  1282. intY->lVal = y;
  1283. if (x == -1 || y == -1)
  1284. ret = -1;
  1285. *nret = ret;
  1286. return S_OK;
  1287. }
  1288. STDMETHODIMP CTSPlugInterFace::FindStrFast(LONG x1, LONG y1, LONG x2, LONG y2, BSTR string, BSTR color_format, FLOAT sim, VARIANT* intX, VARIANT* intY, LONG* nret)
  1289. {
  1290. // TODO: 在此添加实现代码
  1291. TsMutexlock ts_mutexlock(&gDXFindStrMutex);
  1292. //TSRuntime::add_log("FindStrFast-start:操作窗口句柄:%d",gDxObj.m_hwnd);
  1293. LONG x = -1, y = -1, ret = -1;
  1294. if (x1 >= x2 || y1 >= y2)
  1295. {
  1296. if (TSRuntime::IsShowErrorMsg)
  1297. MessageBox(NULL, L"传入坐标已越界!", L"TS", NULL);
  1298. return S_OK;
  1299. }
  1300. ret = gDxObj.Findstr(x1, y1, x2, y2, string, color_format, sim, x, y, 1);
  1301. intX->vt = VT_I4;
  1302. intY->vt = VT_I4;
  1303. intX->lVal = x;
  1304. intY->lVal = y;
  1305. if (x == -1 || y == -1)
  1306. ret = -1;
  1307. *nret = ret;
  1308. //TSRuntime::add_log("FindStrFast-end:操作窗口句柄:%d",gDxObj.m_hwnd);
  1309. return S_OK;
  1310. }
  1311. STDMETHODIMP CTSPlugInterFace::GetNowDict(LONG* nret)
  1312. {
  1313. // TODO: 在此添加实现代码
  1314. TsMutexlock ts_mutexlock(&gDXGetNowDictMutex);
  1315. *nret = gDxObj.NowUsingDictIndex;
  1316. return S_OK;
  1317. }
  1318. STDMETHODIMP CTSPlugInterFace::GetBasePath(BSTR* retpath)
  1319. {
  1320. //TsMutexlock ts_mutexlock(&gDXbindMutex);
  1321. // TODO: 在此添加实现代码
  1322. //*retpath=_bstr_t(gDLLFolder);
  1323. CComBSTR newbstr;
  1324. newbstr.Append(gDLLFolder);
  1325. newbstr.CopyTo(retpath);
  1326. return S_OK;
  1327. }
  1328. STDMETHODIMP CTSPlugInterFace::IsDisplayDead(LONG x1, LONG y1, LONG x2, LONG y2, LONG t, LONG* bret)
  1329. {
  1330. // TODO: 在此添加实现代码
  1331. TsMutexlock ts_mutexlock(&gDXFindPicMutex);
  1332. LONG x = -1, y = -1, ret = -1;
  1333. if (x1 >= x2 || y1 >= y2)
  1334. {
  1335. if (TSRuntime::IsShowErrorMsg)
  1336. MessageBox(NULL, L"传入坐标已越界!", L"TS", NULL);
  1337. return S_OK;
  1338. }
  1339. ret = gDxObj.IsDisplayDead(x1, y1, x2, y2, t);
  1340. *bret = ret;
  1341. return S_OK;
  1342. }
  1343. STDMETHODIMP CTSPlugInterFace::FindPicEx(LONG x1, LONG y1, LONG x2, LONG y2, BSTR pic_name, BSTR delta_color, DOUBLE sim, LONG dir, BSTR* retstring)
  1344. {
  1345. // TODO: 在此添加实现代码
  1346. TsMutexlock ts_mutexlock(&gDXFindPicMutex);
  1347. LONG x = -1, y = -1;
  1348. if (x1 >= x2 || y1 >= y2)
  1349. {
  1350. if (TSRuntime::IsShowErrorMsg)
  1351. MessageBox(NULL, L"传入坐标已越界!", L"TS", NULL);
  1352. return S_OK;
  1353. }
  1354. wchar_t retstr[MAX_PATH * 100] = { 0 };
  1355. gDxObj.findPic(x1, y1, x2, y2, pic_name, delta_color, sim, dir, x, y, retstr);
  1356. //*retstring=_bstr_t(retstr);
  1357. CComBSTR newbstr;
  1358. newbstr.Append(retstr);
  1359. newbstr.CopyTo(retstring);
  1360. return S_OK;
  1361. }
  1362. STDMETHODIMP CTSPlugInterFace::FindStrEx(LONG x1, LONG y1, LONG x2, LONG y2, BSTR string, BSTR color_format, DOUBLE sim, BSTR* retstring)
  1363. {
  1364. // TODO: 在此添加实现代码
  1365. TsMutexlock ts_mutexlock(&gDXFindStrMutex);
  1366. LONG x = -1, y = -1;
  1367. if (x1 >= x2 || y1 >= y2)
  1368. {
  1369. if (TSRuntime::IsShowErrorMsg)
  1370. MessageBox(NULL, L"传入坐标已越界!", L"TS", NULL);
  1371. return S_OK;
  1372. }
  1373. wchar_t retstr[MAX_PATH * 100] = { 0 };
  1374. gDxObj.Findstr(x1, y1, x2, y2, string, color_format, sim, x, y, 0, retstr);
  1375. //*retstring=_bstr_t(retstr);
  1376. CComBSTR newbstr;
  1377. newbstr.Append(retstr);
  1378. newbstr.CopyTo(retstring);
  1379. return S_OK;
  1380. }
  1381. STDMETHODIMP CTSPlugInterFace::FindStrFastEx(LONG x1, LONG y1, LONG x2, LONG y2, BSTR string, BSTR color_format, DOUBLE sim, BSTR* retstring)
  1382. {
  1383. // TODO: 在此添加实现代码
  1384. TsMutexlock ts_mutexlock(&gDXFindStrMutex);
  1385. LONG x = -1, y = -1;
  1386. if (x1 >= x2 || y1 >= y2)
  1387. {
  1388. if (TSRuntime::IsShowErrorMsg)
  1389. MessageBox(NULL, L"传入坐标已越界!", L"TS", NULL);
  1390. return S_OK;
  1391. }
  1392. wchar_t retstr[MAX_PATH * 100] = { 0 };
  1393. gDxObj.Findstr(x1, y1, x2, y2, string, color_format, sim, x, y, 1, retstr);
  1394. //*retstring=_bstr_t(retstr);
  1395. CComBSTR newbstr;
  1396. newbstr.Append(retstr);
  1397. newbstr.CopyTo(retstring);
  1398. return S_OK;
  1399. }
  1400. STDMETHODIMP CTSPlugInterFace::CaptureGif(LONG x1, LONG y1, LONG x2, LONG y2, BSTR file, LONG delay, LONG time, LONG* nret)
  1401. {
  1402. TsMutexlock ts_mutexlock(&gDXCaptureGifMutex);
  1403. // TODO: 在此添加实现代码
  1404. *nret = gDxObj.CaptureGif(x1, y1, x2, y2, file, delay, time);
  1405. return S_OK;
  1406. }
  1407. STDMETHODIMP CTSPlugInterFace::DownCpu(LONG rate, LONG* nret)
  1408. {
  1409. // TODO: 在此添加实现代码
  1410. *nret = gDxObj.DownCpu(rate);
  1411. return S_OK;
  1412. }
  1413. STDMETHODIMP CTSPlugInterFace::SetKeypadDelay(BSTR type, LONG delay, LONG* nret)
  1414. {
  1415. // TODO: 在此添加实现代码
  1416. if ((gDxObj.m_keyMode & KEY_NORMAL) == KEY_NORMAL)
  1417. gDxObj.NormalKeysleep = delay;
  1418. else if (gDxObj.m_keyMode & KEY_WINDOW) //window模式默认延时)
  1419. gDxObj.WindowsKeyMouseClicksleep = delay;
  1420. else
  1421. gDxObj.KeyDownsleep = delay;
  1422. *nret = 1;
  1423. return S_OK;
  1424. }
  1425. STDMETHODIMP CTSPlugInterFace::SetMouseDelay(BSTR type, LONG delay, LONG* nret)
  1426. {
  1427. // TODO: 在此添加实现代码
  1428. if ((gDxObj.m_mouseMode & MOUSE_NORMAL) == MOUSE_NORMAL)
  1429. gDxObj.NormalClicksleep = delay;
  1430. else if (gDxObj.m_mouseMode & MOUSE_WINDOW) //window模式默认延时
  1431. gDxObj.WindowsKeyMouseClicksleep = delay;
  1432. else
  1433. gDxObj.MouseClicksleep = delay;
  1434. *nret = 1;
  1435. return S_OK;
  1436. }
  1437. STDMETHODIMP CTSPlugInterFace::CmpColor(LONG x, LONG y, BSTR color, DOUBLE sim, LONG* nret)
  1438. {
  1439. // TODO: 在此添加实现代码
  1440. TsMutex gDXGetColorMutex(TS_GETCOLOREVEN);
  1441. *nret = gDxObj.CmpColor(x, y, color, sim);
  1442. return S_OK;
  1443. }
  1444. STDMETHODIMP CTSPlugInterFace::SendStringIme(BSTR str, LONG* nret)
  1445. {
  1446. // TODO: 在此添加实现代码
  1447. TsMutexlock ts_mutexlock(&gDXSendStringImeMutex);
  1448. if (wcslen(str) > 1024)
  1449. {
  1450. *nret = 0;
  1451. return S_OK;
  1452. }
  1453. memset(gDxObj.pData->pmsg, 0, 2048);
  1454. USES_CONVERSION;
  1455. strcpy(gDxObj.pData->pmsg, W2A(str));
  1456. gDxObj.SendMsg(TS_SENDSTRINGIME);
  1457. *nret = 1;
  1458. return S_OK;
  1459. }
  1460. STDMETHODIMP CTSPlugInterFace::FindColorEx(LONG x1, LONG y1, LONG x2, LONG y2, BSTR color, DOUBLE sim, LONG dir, BSTR* retstring)
  1461. {
  1462. // TODO: 在此添加实现代码
  1463. TsMutexlock ts_mutexlock(&gDXFindColorMutex);
  1464. if (x1 >= x2 || y1 >= y2)
  1465. {
  1466. if (TSRuntime::IsShowErrorMsg)
  1467. MessageBox(NULL, L"传入坐标已越界!", L"TS", NULL);
  1468. return S_OK;
  1469. }
  1470. DWORD ncolor = 0x100;
  1471. LONG x = -1, y = -1;
  1472. wchar_t retstr[MAX_PATH * 4] = { 0 };
  1473. gDxObj.findColor(x1, y1, x2, y2, ncolor, sim, dir, x, y, color, retstr);
  1474. //*retstring=_bstr_t(retstr);
  1475. CComBSTR newbstr;
  1476. newbstr.Append(retstr);
  1477. newbstr.CopyTo(retstring);
  1478. return S_OK;
  1479. }
  1480. STDMETHODIMP CTSPlugInterFace::EnumWindow(LONG parent, BSTR title, BSTR class_name, LONG filter, BSTR* retstr)
  1481. {
  1482. // TODO: 在此添加实现代码
  1483. TsMutexlock ts_mutexlock(&gDXEnumWindowMutex);
  1484. wchar_t retstring[MAX_PATH * 200] = { 0 };
  1485. gWindowObj.TSEnumWindow((HWND)parent, title, class_name, filter, retstring);
  1486. //*retstr=_bstr_t(retstring);
  1487. CComBSTR newbstr;
  1488. newbstr.Append(retstring);
  1489. newbstr.CopyTo(retstr);
  1490. return S_OK;
  1491. }
  1492. STDMETHODIMP CTSPlugInterFace::EnumWindowByProcess(BSTR process_name, BSTR title, BSTR class_name, LONG filter, BSTR* retstring)
  1493. {
  1494. // TODO: 在此添加实现代码
  1495. TsMutexlock ts_mutexlock(&gDXEnumWindowByProcessMutex);
  1496. wchar_t retstr[MAX_PATH * 200] = { 0 };
  1497. gWindowObj.TSEnumWindow((HWND)0, title, class_name, filter, retstr, process_name);
  1498. //*retstring=_bstr_t(retstr);
  1499. CComBSTR newbstr;
  1500. newbstr.Append(retstr);
  1501. newbstr.CopyTo(retstring);
  1502. return S_OK;
  1503. }
  1504. STDMETHODIMP CTSPlugInterFace::EnumProcess(BSTR name, BSTR* retstring)
  1505. {
  1506. // TODO: 在此添加实现代码
  1507. TsMutexlock ts_mutexlock(&gDXEnumProcessMutex);
  1508. wchar_t retstr[MAX_PATH * 100] = { 0 };
  1509. gWindowObj.TSEnumProcess(name, retstr);
  1510. //*retstring=_bstr_t(retstr);
  1511. CComBSTR newbstr;
  1512. newbstr.Append(retstr);
  1513. newbstr.CopyTo(retstring);
  1514. return S_OK;
  1515. }
  1516. STDMETHODIMP CTSPlugInterFace::ClientToScreen(LONG ClientToScreen, VARIANT* x, VARIANT* y, LONG* bret)
  1517. {
  1518. // TODO: 在此添加实现代码
  1519. x->vt = VT_I4;
  1520. y->vt = VT_I4;
  1521. *bret = gWindowObj.TSClientToScreen(ClientToScreen, x->lVal, y->lVal);
  1522. return S_OK;
  1523. }
  1524. STDMETHODIMP CTSPlugInterFace::FindWindow(BSTR class_name, BSTR title, LONG* rethwnd)
  1525. {
  1526. // TODO: 在此添加实现代码
  1527. gWindowObj.TSFindWindow(class_name, title, *rethwnd);
  1528. return S_OK;
  1529. }
  1530. STDMETHODIMP CTSPlugInterFace::FindWindowByProcess(BSTR process_name, BSTR class_name, BSTR title, LONG* rethwnd)
  1531. {
  1532. // TODO: 在此添加实现代码
  1533. gWindowObj.TSFindWindowByProcess(class_name, title, *rethwnd, process_name);
  1534. return S_OK;
  1535. }
  1536. STDMETHODIMP CTSPlugInterFace::FindWindowByProcessId(LONG process_id, BSTR class_name, BSTR title, LONG* rethwnd)
  1537. {
  1538. // TODO: 在此添加实现代码
  1539. gWindowObj.TSFindWindowByProcess(class_name, title, *rethwnd, NULL, process_id);
  1540. return S_OK;
  1541. }
  1542. STDMETHODIMP CTSPlugInterFace::FindWindowEx(LONG parent, BSTR class_name, BSTR title, LONG* rethwnd)
  1543. {
  1544. // TODO: 在此添加实现代码
  1545. gWindowObj.TSFindWindow(class_name, title, *rethwnd, parent);
  1546. return S_OK;
  1547. }
  1548. STDMETHODIMP CTSPlugInterFace::GetClientRect(LONG hwnd, VARIANT* x1, VARIANT* y1, VARIANT* x2, VARIANT* y2, LONG* nret)
  1549. {
  1550. // TODO: 在此添加实现代码
  1551. x1->vt = VT_I4;
  1552. y1->vt = VT_I4;
  1553. x2->vt = VT_I4;
  1554. y2->vt = VT_I4;
  1555. *nret = gWindowObj.TSGetClientRect(hwnd, x1->lVal, y1->lVal, x2->lVal, y2->lVal);
  1556. return S_OK;
  1557. }
  1558. STDMETHODIMP CTSPlugInterFace::GetClientSize(LONG hwnd, VARIANT* width, VARIANT* height, LONG* nret)
  1559. {
  1560. // TODO: 在此添加实现代码
  1561. width->vt = VT_I4;
  1562. height->vt = VT_I4;
  1563. *nret = gWindowObj.TSGetClientSize(hwnd, width->lVal, height->lVal);
  1564. return S_OK;
  1565. }
  1566. STDMETHODIMP CTSPlugInterFace::GetForegroundFocus(LONG* rethwnd)
  1567. {
  1568. // TODO: 在此添加实现代码
  1569. *rethwnd = (LONG)::GetFocus();
  1570. return S_OK;
  1571. }
  1572. STDMETHODIMP CTSPlugInterFace::GetForegroundWindow(LONG* rethwnd)
  1573. {
  1574. // TODO: 在此添加实现代码
  1575. *rethwnd = (LONG)::GetForegroundWindow();
  1576. return S_OK;
  1577. }
  1578. STDMETHODIMP CTSPlugInterFace::GetMousePointWindow(LONG* rethwnd)
  1579. {
  1580. // TODO: 在此添加实现代码
  1581. //::Sleep(2000);
  1582. gWindowObj.TSGetMousePointWindow(*rethwnd);
  1583. return S_OK;
  1584. }
  1585. STDMETHODIMP CTSPlugInterFace::GetPointWindow(LONG x, LONG y, LONG* rethwnd)
  1586. {
  1587. // TODO: 在此添加实现代码
  1588. gWindowObj.TSGetMousePointWindow(*rethwnd, x, y);
  1589. return S_OK;
  1590. }
  1591. STDMETHODIMP CTSPlugInterFace::GetProcessInfo(LONG pid, BSTR* retstring)
  1592. {
  1593. // TODO: 在此添加实现代码
  1594. wchar_t retstr[MAX_PATH] = { 0 };
  1595. gWindowObj.TSGetProcessInfo(pid, retstr);
  1596. //* retstring=_bstr_t(retstr);
  1597. CComBSTR newbstr;
  1598. newbstr.Append(retstr);
  1599. newbstr.CopyTo(retstring);
  1600. return S_OK;
  1601. }
  1602. STDMETHODIMP CTSPlugInterFace::GetSpecialWindow(LONG flag, LONG* rethwnd)
  1603. {
  1604. // TODO: 在此添加实现代码
  1605. *rethwnd = 0;
  1606. if (flag == 0)
  1607. *rethwnd = (LONG)GetDesktopWindow();
  1608. else if (flag == 1)
  1609. {
  1610. *rethwnd = (LONG)::FindWindow(L"Shell_TrayWnd", NULL);
  1611. }
  1612. return S_OK;
  1613. }
  1614. STDMETHODIMP CTSPlugInterFace::GetWindow(LONG hwnd, LONG flag, LONG* nret)
  1615. {
  1616. // TODO: 在此添加实现代码
  1617. gWindowObj.TSGetWindow(hwnd, flag, *nret);
  1618. return S_OK;
  1619. }
  1620. STDMETHODIMP CTSPlugInterFace::GetWindowClass(LONG hwnd, BSTR* retstring)
  1621. {
  1622. // TODO: 在此添加实现代码
  1623. wchar_t classname[MAX_PATH] = { 0 };
  1624. ::GetClassName((HWND)hwnd, classname, MAX_PATH);
  1625. //* retstring=_bstr_t(classname);
  1626. CComBSTR newbstr;
  1627. newbstr.Append(classname);
  1628. newbstr.CopyTo(retstring);
  1629. return S_OK;
  1630. }
  1631. STDMETHODIMP CTSPlugInterFace::GetWindowProcessId(LONG hwnd, LONG* nretpid)
  1632. {
  1633. // TODO: 在此添加实现代码
  1634. DWORD pid = 0;
  1635. ::GetWindowThreadProcessId((HWND)hwnd, &pid);
  1636. *nretpid = pid;
  1637. return S_OK;
  1638. }
  1639. STDMETHODIMP CTSPlugInterFace::GetWindowProcessPath(LONG hwnd, BSTR* retstring)
  1640. {
  1641. // TODO: 在此添加实现代码
  1642. DWORD pid = 0;
  1643. ::GetWindowThreadProcessId((HWND)hwnd, &pid);
  1644. wchar_t process_path[MAX_PATH] = { 0 };
  1645. gWindowObj.GetProcesspath(pid, process_path);
  1646. //* retstring=_bstr_t(process_path);
  1647. CComBSTR newbstr;
  1648. newbstr.Append(process_path);
  1649. newbstr.CopyTo(retstring);
  1650. return S_OK;
  1651. }
  1652. STDMETHODIMP CTSPlugInterFace::GetWindowRect(LONG hwnd, VARIANT* x1, VARIANT* y1, VARIANT* x2, VARIANT* y2, LONG* nret)
  1653. {
  1654. // TODO: 在此添加实现代码
  1655. x1->vt = VT_I4;
  1656. x2->vt = VT_I4;
  1657. y1->vt = VT_I4;
  1658. y2->vt = VT_I4;
  1659. RECT winrect;
  1660. *nret = ::GetWindowRect((HWND)hwnd, &winrect);
  1661. x1->intVal = winrect.left;
  1662. y1->intVal = winrect.top;
  1663. x2->intVal = winrect.right;
  1664. y2->intVal = winrect.bottom;
  1665. return S_OK;
  1666. }
  1667. STDMETHODIMP CTSPlugInterFace::GetWindowState(LONG hwnd, LONG flag, LONG* rethwnd)
  1668. {
  1669. // TODO: 在此添加实现代码
  1670. *rethwnd = gWindowObj.TSGetWindowState(hwnd, flag);
  1671. return S_OK;
  1672. }
  1673. STDMETHODIMP CTSPlugInterFace::GetWindowTitle(LONG hwnd, BSTR* rettitle)
  1674. {
  1675. // TODO: 在此添加实现代码
  1676. wchar_t title[MAX_PATH] = { 0 };
  1677. ::GetWindowText((HWND)hwnd, title, MAX_PATH);
  1678. //* rettitle=_bstr_t(title);
  1679. CComBSTR newbstr;
  1680. newbstr.Append(title);
  1681. newbstr.CopyTo(rettitle);
  1682. return S_OK;
  1683. }
  1684. STDMETHODIMP CTSPlugInterFace::MoveWindow(LONG hwnd, LONG x, LONG y, LONG* nret)
  1685. {
  1686. // TODO: 在此添加实现代码
  1687. RECT winrect;
  1688. ::GetWindowRect((HWND)hwnd, &winrect);
  1689. int width = winrect.right - winrect.left;
  1690. int hight = winrect.bottom - winrect.top;
  1691. *nret = ::MoveWindow((HWND)hwnd, x, y, width, hight, false);
  1692. return S_OK;
  1693. }
  1694. STDMETHODIMP CTSPlugInterFace::ScreenToClient(LONG hwnd, VARIANT* x, VARIANT* y, LONG* nret)
  1695. {
  1696. // TODO: 在此添加实现代码
  1697. x->vt = VT_I4;
  1698. y->vt = VT_I4;
  1699. POINT point;
  1700. *nret = ::ScreenToClient((HWND)hwnd, &point);
  1701. x->intVal = point.x;
  1702. y->intVal = point.y;
  1703. return S_OK;
  1704. }
  1705. STDMETHODIMP CTSPlugInterFace::SendPaste(LONG hwnd, LONG* nret)
  1706. {
  1707. // TODO: 在此添加实现代码
  1708. *nret = gWindowObj.TSSendPaste(hwnd);
  1709. return S_OK;
  1710. }
  1711. STDMETHODIMP CTSPlugInterFace::SetClientSize(LONG hwnd, LONG width, LONG hight, LONG* nret)
  1712. {
  1713. // TODO: 在此添加实现代码
  1714. *nret = gWindowObj.TSSetWindowSize(hwnd, width, hight);
  1715. return S_OK;
  1716. }
  1717. STDMETHODIMP CTSPlugInterFace::SetWindowState(LONG hwnd, LONG flag, LONG* nret)
  1718. {
  1719. // TODO: 在此添加实现代码
  1720. *nret = gWindowObj.TSSetWindowState(hwnd, flag);
  1721. return S_OK;
  1722. }
  1723. STDMETHODIMP CTSPlugInterFace::SetWindowSize(LONG hwnd, LONG width, LONG height, LONG* nret)
  1724. {
  1725. // TODO: 在此添加实现代码
  1726. *nret = gWindowObj.TSSetWindowSize(hwnd, width, height, 1);
  1727. return S_OK;
  1728. }
  1729. STDMETHODIMP CTSPlugInterFace::SetWindowText(LONG hwnd, BSTR title, LONG* nret)
  1730. {
  1731. // TODO: 在此添加实现代码
  1732. //*nret=gWindowObj.TSSetWindowState(hwnd,flag);
  1733. *nret = ::SetWindowText((HWND)hwnd, title);
  1734. return S_OK;
  1735. }
  1736. STDMETHODIMP CTSPlugInterFace::SetWindowTransparent(LONG hwnd, LONG trans, LONG* nret)
  1737. {
  1738. // TODO: 在此添加实现代码
  1739. *nret = gWindowObj.TSSetWindowTransparent(hwnd, trans);
  1740. return S_OK;
  1741. }
  1742. STDMETHODIMP CTSPlugInterFace::SetClipboard(BSTR value, LONG* nret)
  1743. {
  1744. // TODO: 在此添加实现代码
  1745. *nret = gWindowObj.TSSetClipboard(value);
  1746. return S_OK;
  1747. }
  1748. STDMETHODIMP CTSPlugInterFace::GetClipboard(BSTR* retstring)
  1749. {
  1750. // TODO: 在此添加实现代码
  1751. wchar_t retstr[MAX_PATH * 4] = { 0 };
  1752. gWindowObj.TSGetClipboard(retstr);
  1753. //*retstring=_bstr_t(retstr);
  1754. CComBSTR newbstr;
  1755. newbstr.Append(retstr);
  1756. newbstr.CopyTo(retstring);
  1757. return S_OK;
  1758. }
  1759. STDMETHODIMP CTSPlugInterFace::DoubleToData(DOUBLE value, BSTR* retstring)
  1760. {
  1761. // TODO: 在此添加实现代码
  1762. wchar_t retstr[MAX_PATH] = { 0 };
  1763. gMemoryObj.TSValueTypeToData(0, retstr, value);
  1764. //*retstring=_bstr_t(retstr);
  1765. CComBSTR newbstr;
  1766. newbstr.Append(retstr);
  1767. newbstr.CopyTo(retstring);
  1768. return S_OK;
  1769. }
  1770. STDMETHODIMP CTSPlugInterFace::FloatToData(FLOAT value, BSTR* retstring)
  1771. {
  1772. // TODO: 在此添加实现代码
  1773. wchar_t retstr[MAX_PATH] = { 0 };
  1774. gMemoryObj.TSValueTypeToData(1, retstr, NULL, value);
  1775. //*retstring=_bstr_t(retstr);
  1776. CComBSTR newbstr;
  1777. newbstr.Append(retstr);
  1778. newbstr.CopyTo(retstring);
  1779. return S_OK;
  1780. }
  1781. STDMETHODIMP CTSPlugInterFace::IntToData(LONG value, LONG type, BSTR* retstring)
  1782. {
  1783. // TODO: 在此添加实现代码
  1784. wchar_t retstr[MAX_PATH] = { 0 };
  1785. gMemoryObj.TSValueTypeToData(2, retstr, NULL, NULL, value, NULL, type);
  1786. //*retstring=_bstr_t(retstr);
  1787. CComBSTR newbstr;
  1788. newbstr.Append(retstr);
  1789. newbstr.CopyTo(retstring);
  1790. return S_OK;
  1791. }
  1792. STDMETHODIMP CTSPlugInterFace::StringToData(BSTR value, LONG type, BSTR* retstring)
  1793. {
  1794. // TODO: 在此添加实现代码
  1795. wchar_t retstr[MAX_PATH] = { 0 };
  1796. gMemoryObj.TSValueTypeToData(3, retstr, NULL, NULL, NULL, value, type);
  1797. //*retstring=_bstr_t(retstr);
  1798. CComBSTR newbstr;
  1799. newbstr.Append(retstr);
  1800. newbstr.CopyTo(retstring);
  1801. return S_OK;
  1802. }
  1803. STDMETHODIMP CTSPlugInterFace::FindData(LONG hwnd, BSTR addr_range, BSTR data, BSTR* retstring)
  1804. {
  1805. TsMutexlock ts_mutexlock(&gDXFindDataMutex);
  1806. // TODO: 在此添加实现代码
  1807. //wchar_t retstr[MAX_PATH*200]={0};
  1808. //gMemoryObj.TSFindData(hwnd,addr_range,data,retstr);
  1809. //*retstring=_bstr_t(retstr);
  1810. wchar_t retstr[MAX_PATH * 1024] = { 0 };
  1811. CComBSTR newbstr;
  1812. gMemoryObj.TSFindData(hwnd, addr_range, data, retstr);
  1813. newbstr.Append(retstr);
  1814. newbstr.CopyTo(retstring);
  1815. return S_OK;
  1816. }
  1817. STDMETHODIMP CTSPlugInterFace::FindDouble(LONG hwnd, BSTR addr_range, DOUBLE double_value_min, DOUBLE double_value_max, BSTR* retstring)
  1818. {
  1819. TsMutexlock ts_mutexlock(&gDXFindDoubleMutex);
  1820. // TODO: 在此添加实现代码
  1821. //wchar_t retstr[MAX_PATH*200]={0};
  1822. //gMemoryObj.TSFindDouble(hwnd,addr_range,retstr,double_value_min,double_value_max);
  1823. //*retstring=_bstr_t(retstr);
  1824. wchar_t retstr[MAX_PATH * 1024] = { 0 };
  1825. CComBSTR newbstr;
  1826. gMemoryObj.TSFindDouble(hwnd, addr_range, retstr, double_value_min, double_value_max);
  1827. newbstr.Append(retstr);
  1828. newbstr.CopyTo(retstring);
  1829. return S_OK;
  1830. }
  1831. STDMETHODIMP CTSPlugInterFace::FindFloat(LONG hwnd, BSTR addr_range, FLOAT float_value_min, FLOAT float_value_max, BSTR* retstring)
  1832. {
  1833. TsMutexlock ts_mutexlock(&gDXFindFloatMutex);
  1834. // TODO: 在此添加实现代码
  1835. wchar_t retstr[MAX_PATH * 1024] = { 0 };
  1836. CComBSTR newbstr;
  1837. gMemoryObj.TSFindFloat(hwnd, addr_range, retstr, float_value_min, float_value_max);
  1838. newbstr.Append(retstr);
  1839. newbstr.CopyTo(retstring);
  1840. return S_OK;
  1841. }
  1842. STDMETHODIMP CTSPlugInterFace::FindInt(LONG hwnd, BSTR addr_range, LONG int_value_min, LONG int_value_max, LONG type, BSTR* retstring)
  1843. {
  1844. TsMutexlock ts_mutexlock(&gDXFindIntMutex);
  1845. // TODO: 在此添加实现代码
  1846. //wchar_t retstr[MAX_PATH*200]={0};
  1847. //gMemoryObj.TSFindInt(hwnd,addr_range,retstr,int_value_min,int_value_max,type);
  1848. //*retstring=_bstr_t(retstr);
  1849. wchar_t retstr[MAX_PATH * 1024] = { 0 };
  1850. CComBSTR newbstr;
  1851. gMemoryObj.TSFindInt(hwnd, addr_range, retstr, int_value_min, int_value_max, type);
  1852. newbstr.Append(retstr);
  1853. newbstr.CopyTo(retstring);
  1854. return S_OK;
  1855. }
  1856. STDMETHODIMP CTSPlugInterFace::FindString(LONG hwnd, BSTR addr_range, BSTR string_value, LONG type, BSTR* retstring)
  1857. {
  1858. TsMutexlock ts_mutexlock(&gDXFindStringMutex);
  1859. // TODO: 在此添加实现代码
  1860. //wchar_t retstr[MAX_PATH*200]={0};
  1861. //gMemoryObj.TSFindString(hwnd,addr_range,retstr,string_value,type);
  1862. //*retstring=_bstr_t(retstr);
  1863. wchar_t retstr[MAX_PATH * 1024] = { 0 };
  1864. CComBSTR newbstr;
  1865. gMemoryObj.TSFindString(hwnd, addr_range, retstr, string_value, type);
  1866. newbstr.Append(retstr);
  1867. newbstr.CopyTo(retstring);
  1868. return S_OK;
  1869. }
  1870. STDMETHODIMP CTSPlugInterFace::ReadData(LONG hwnd, BSTR addr, LONG len, BSTR* retstring)
  1871. {
  1872. // TODO: 在此添加实现代码
  1873. wchar_t retstr[MAX_PATH] = { 0 };
  1874. gMemoryObj.TSReadData(hwnd, addr, retstr, len);
  1875. //*retstring=_bstr_t(retstr);
  1876. CComBSTR newbstr;
  1877. newbstr.Append(retstr);
  1878. newbstr.CopyTo(retstring);
  1879. return S_OK;
  1880. }
  1881. STDMETHODIMP CTSPlugInterFace::OcrEx(LONG x1, LONG y1, LONG x2, LONG y2, BSTR color_format, DOUBLE sim, BSTR* retstring)
  1882. {
  1883. // TODO: 在此添加实现代码
  1884. TsMutexlock ts_mutexlock(&gDXOcrMutex);
  1885. if (wcslen(color_format) == 0)
  1886. return S_OK;
  1887. if (x1 >= x2 || y1 >= y2)
  1888. {
  1889. if (TSRuntime::IsShowErrorMsg)
  1890. MessageBox(NULL, L"传入坐标已越界!", L"TS", NULL);
  1891. return S_OK;
  1892. }
  1893. //TSRuntime::g_DxObj.Ocr(x1,y1,x2,y2,color_format,sim);
  1894. gDxObj.Ocr(x1, y1, x2, y2, color_format, sim, 1);
  1895. //TSRuntime::add_log( "TSRuntime::pData->RetString:%s",TSRuntime::pData->RetString);
  1896. CComBSTR newbstr;
  1897. if (gDxObj.pData)
  1898. //*retstring=_bstr_t(gDxObj.pData->RetString);
  1899. newbstr.Append(gDxObj.pData->RetString);
  1900. else
  1901. //*retstring=_bstr_t(TSRuntime::RetStr);
  1902. newbstr.Append(gDxObj.m_Retstr);
  1903. newbstr.CopyTo(retstring);
  1904. return S_OK;
  1905. }
  1906. STDMETHODIMP CTSPlugInterFace::ReadDouble(LONG hwnd, BSTR addr, DOUBLE* retdouble)
  1907. {
  1908. // TODO: 在此添加实现代码
  1909. float fvalue = 0;
  1910. gMemoryObj.TSReadDouble(hwnd, addr, *retdouble, fvalue);
  1911. return S_OK;
  1912. }
  1913. STDMETHODIMP CTSPlugInterFace::ReadFloat(LONG hwnd, BSTR addr, FLOAT* retfloat)
  1914. {
  1915. // TODO: 在此添加实现代码
  1916. DOUBLE dvalue = 0;
  1917. gMemoryObj.TSReadDouble(hwnd, addr, dvalue, *retfloat, 1);
  1918. return S_OK;
  1919. }
  1920. STDMETHODIMP CTSPlugInterFace::ReadInt(LONG hwnd, BSTR addr, LONG type, LONG* retint)
  1921. {
  1922. // TODO: 在此添加实现代码
  1923. int ivalue = 0;
  1924. short svalue = 0;
  1925. BYTE bvalue = 0;
  1926. gMemoryObj.TSReadInt(hwnd, addr, ivalue, svalue, bvalue, type);
  1927. if (type == 0)
  1928. *retint = ivalue;
  1929. else if (type == 1)
  1930. *retint = svalue;
  1931. else if (type == 2)
  1932. *retint = bvalue;
  1933. return S_OK;
  1934. }
  1935. STDMETHODIMP CTSPlugInterFace::ReadString(LONG hwnd, BSTR addr, LONG type, LONG len, BSTR* retstring)
  1936. {
  1937. // TODO: 在此添加实现代码
  1938. wchar_t retstr[MAX_PATH] = { 0 };
  1939. gMemoryObj.TSReadString(hwnd, addr, retstr, len, type);
  1940. //*retstring=_bstr_t(retstr);
  1941. CComBSTR newbstr;
  1942. newbstr.Append(retstr);
  1943. newbstr.CopyTo(retstring);
  1944. return S_OK;
  1945. }
  1946. STDMETHODIMP CTSPlugInterFace::TerminateProcess(LONG pid, LONG* bret)
  1947. {
  1948. // TODO: 在此添加实现代码
  1949. *bret = gMemoryObj.TSTerminateProcess(pid);
  1950. return S_OK;
  1951. }
  1952. STDMETHODIMP CTSPlugInterFace::VirtualAllocEx(LONG hwnd, LONG addr, LONG size, LONG type, LONG* bret)
  1953. {
  1954. // TODO: 在此添加实现代码
  1955. LONG retaddr = addr;
  1956. gMemoryObj.TSVirtualAllocEx(hwnd, retaddr, size, type);
  1957. *bret = retaddr;
  1958. return S_OK;
  1959. }
  1960. STDMETHODIMP CTSPlugInterFace::VirtualFreeEx(LONG hwnd, LONG addr, LONG* bret)
  1961. {
  1962. // TODO: 在此添加实现代码
  1963. *bret = gMemoryObj.TSVirtualFreeEx(hwnd, addr);
  1964. return S_OK;
  1965. }
  1966. STDMETHODIMP CTSPlugInterFace::WriteDouble(LONG hwnd, BSTR addr, DOUBLE v, LONG* bret)
  1967. {
  1968. // TODO: 在此添加实现代码
  1969. *bret = gMemoryObj.TSWriteDouble(hwnd, addr, v);
  1970. return S_OK;
  1971. }
  1972. STDMETHODIMP CTSPlugInterFace::WriteFloat(LONG hwnd, BSTR addr, FLOAT v, LONG* bret)
  1973. {
  1974. // TODO: 在此添加实现代码
  1975. *bret = gMemoryObj.TSWriteDouble(hwnd, addr, 0, v);
  1976. return S_OK;
  1977. }
  1978. STDMETHODIMP CTSPlugInterFace::WriteInt(LONG hwnd, BSTR addr, LONG type, LONG v, LONG* bret)
  1979. {
  1980. // TODO: 在此添加实现代码
  1981. int ivalue = 0;
  1982. short svalue = 0;
  1983. BYTE bvalue = 0;
  1984. if (type == 0) //0 : 32位
  1985. ivalue = v;
  1986. else if (type == 1)//1 : 16 位
  1987. svalue = v;
  1988. else if (type == 2) //2 : 8位
  1989. bvalue = v;
  1990. *bret = gMemoryObj.TSWriteInt(hwnd, addr, ivalue, svalue, bvalue);
  1991. return S_OK;
  1992. }
  1993. STDMETHODIMP CTSPlugInterFace::WriteString(LONG hwnd, BSTR addr, LONG type, BSTR v, LONG* bret)
  1994. {
  1995. // TODO: 在此添加实现代码
  1996. *bret = gMemoryObj.TSWriteString(hwnd, addr, v, type);
  1997. return S_OK;
  1998. }
  1999. STDMETHODIMP CTSPlugInterFace::WriteData(LONG hwnd, BSTR addr, BSTR data, LONG* nret)
  2000. {
  2001. // TODO: 在此添加实现代码
  2002. *nret = gMemoryObj.TSWriteData(hwnd, addr, data);
  2003. return S_OK;
  2004. }
  2005. STDMETHODIMP CTSPlugInterFace::IsBind(LONG hwnd, LONG* nret)
  2006. {
  2007. // TODO: 在此添加实现代码
  2008. if (::IsWindow((HWND)hwnd) == false)
  2009. {
  2010. *nret = 0;
  2011. return S_OK;
  2012. }
  2013. if (gDxObj.m_isBind == true)
  2014. {
  2015. *nret = 1;
  2016. return S_OK;
  2017. }
  2018. //DWORD nPid=0;
  2019. //::GetWindowThreadProcessId((HWND)hwnd,&nPid);
  2020. char pszBinWindow_SetWindowHook[MAX_PATH] = { 0 };
  2021. sprintf(pszBinWindow_SetWindowHook, "%s%d", TS_BINDWINDOW_SETWINDOWHOOK, gDxObj.nPid);
  2022. HANDLE hbindprop = GetPropA((HWND)hwnd, pszBinWindow_SetWindowHook);
  2023. char pszBinWindow_IME[MAX_PATH] = { 0 };
  2024. sprintf(pszBinWindow_IME, "%s%d", TS_BINDWINDOW_IME, gDxObj.nPid);
  2025. HANDLE hbindIMEprop = GetPropA((HWND)hwnd, pszBinWindow_IME);
  2026. char pszBinWindow_IME101[MAX_PATH] = { 0 };
  2027. sprintf(pszBinWindow_IME101, "%s%d", TS_BINDWINDOW_IME101, gDxObj.nPid);
  2028. HANDLE hbindIMEprop101 = GetPropA((HWND)hwnd, pszBinWindow_IME101);
  2029. char pszBinWindow_GDIWINDOW[MAX_PATH] = { 0 };
  2030. sprintf(pszBinWindow_GDIWINDOW, "%s%d", TS_BINDWINDOW_GDIWINDOW, gDxObj.nPid);
  2031. HANDLE hbindGdiWindow = GetPropA((HWND)hwnd, pszBinWindow_GDIWINDOW);
  2032. if (hbindGdiWindow == NULL)
  2033. {
  2034. //遍历获取父窗口句柄
  2035. HWND parenthwnd = 0;
  2036. HWND hparent = 0;
  2037. do {
  2038. if (parenthwnd == 0)
  2039. parenthwnd = GetParent((HWND)hwnd);
  2040. else
  2041. {
  2042. hparent = GetParent(parenthwnd);
  2043. if (hparent != 0 && hparent != parenthwnd)
  2044. {
  2045. hwnd = (LONG)hparent;
  2046. }
  2047. parenthwnd = hparent;
  2048. }
  2049. } while (parenthwnd != NULL);
  2050. //::GetWindowThreadProcessId((HWND)hwnd,&nPid);
  2051. char pszBinWindow_GDIWINDOW[MAX_PATH] = { 0 };
  2052. sprintf(pszBinWindow_GDIWINDOW, "%s%d", TS_BINDWINDOW_GDIWINDOW, gDxObj.nPid);
  2053. hbindGdiWindow = GetPropA((HWND)hwnd, pszBinWindow_GDIWINDOW);
  2054. }
  2055. if (hbindprop == NULL && hbindIMEprop == NULL && hbindIMEprop101 == NULL && hbindGdiWindow == NULL)
  2056. *nret = 0;
  2057. else
  2058. *nret = 1;
  2059. return S_OK;
  2060. }
  2061. STDMETHODIMP CTSPlugInterFace::FindFloatEx(LONG hwnd, BSTR addr_range, FLOAT float_value_min, FLOAT float_value_max, LONG step, LONG multi_thread, LONG mode, BSTR* retstring)
  2062. {
  2063. // TODO: 在此添加实现代码
  2064. TsMutexlock ts_mutexlock(&gDXFindFloatMutex);
  2065. wchar_t retstr[MAX_PATH * 1024] = { 0 };
  2066. CComBSTR newbstr;
  2067. gMemoryObj.TSFindFloat(hwnd, addr_range, retstr, float_value_min, float_value_max, multi_thread);
  2068. newbstr.Append(retstr);
  2069. newbstr.CopyTo(retstring);
  2070. return S_OK;
  2071. }
  2072. STDMETHODIMP CTSPlugInterFace::FindDoubleEx(LONG hwnd, BSTR addr_range, DOUBLE double_value_min, DOUBLE double_value_max, LONG step, LONG multi_thread, LONG mode, BSTR* retstring)
  2073. {
  2074. // TODO: 在此添加实现代码
  2075. TsMutexlock ts_mutexlock(&gDXFindDoubleMutex);
  2076. wchar_t retstr[MAX_PATH * 1024] = { 0 };
  2077. CComBSTR newbstr;
  2078. gMemoryObj.TSFindDouble(hwnd, addr_range, retstr, double_value_min, double_value_max, multi_thread);
  2079. newbstr.Append(retstr);
  2080. newbstr.CopyTo(retstring);
  2081. return S_OK;
  2082. }
  2083. STDMETHODIMP CTSPlugInterFace::FindIntEx(LONG hwnd, BSTR addr_range, LONG int_value_min, LONG int_value_max, LONG type, LONG step, LONG multi_thread, LONG mode, BSTR* retstring)
  2084. {
  2085. // TODO: 在此添加实现代码
  2086. TsMutexlock ts_mutexlock(&gDXFindIntMutex);
  2087. wchar_t retstr[MAX_PATH * 1024] = { 0 };
  2088. CComBSTR newbstr;
  2089. gMemoryObj.TSFindInt(hwnd, addr_range, retstr, int_value_min, int_value_max, type, multi_thread);
  2090. newbstr.Append(retstr);
  2091. newbstr.CopyTo(retstring);
  2092. return S_OK;
  2093. }
  2094. STDMETHODIMP CTSPlugInterFace::FindDataEx(LONG hwnd, BSTR addr_range, BSTR data, LONG step, LONG multi_thread, LONG mode, BSTR* retstring)
  2095. {
  2096. // TODO: 在此添加实现代码
  2097. TsMutexlock ts_mutexlock(&gDXFindDataMutex);
  2098. wchar_t retstr[MAX_PATH * 1024] = { 0 };
  2099. CComBSTR newbstr;
  2100. gMemoryObj.TSFindData(hwnd, addr_range, data, retstr, multi_thread);
  2101. newbstr.Append(retstr);
  2102. newbstr.CopyTo(retstring);
  2103. return S_OK;
  2104. }
  2105. STDMETHODIMP CTSPlugInterFace::FindStringEx(LONG hwnd, BSTR addr_range, BSTR string_value, LONG type, LONG step, LONG multi_thread, LONG mode, BSTR* retstring)
  2106. {
  2107. // TODO: 在此添加实现代码
  2108. TsMutexlock ts_mutexlock(&gDXFindStringMutex);
  2109. wchar_t retstr[MAX_PATH * 1024] = { 0 };
  2110. CComBSTR newbstr;
  2111. gMemoryObj.TSFindString(hwnd, addr_range, retstr, string_value, type, multi_thread);
  2112. newbstr.Append(retstr);
  2113. newbstr.CopyTo(retstring);
  2114. return S_OK;
  2115. }
  2116. STDMETHODIMP CTSPlugInterFace::GetModuleBaseAddr(LONG hwnd, BSTR modulename, LONG* nret)
  2117. {
  2118. // TODO: 在此添加实现代码
  2119. DWORD pid = 0;
  2120. ::GetWindowThreadProcessId((HWND)hwnd, &pid);
  2121. *nret = TSRuntime::GetRemoteModuleBaseAddr(modulename, pid);
  2122. return S_OK;
  2123. }
  2124. STDMETHODIMP CTSPlugInterFace::GetCommandLine(LONG hwnd, BSTR* retstring)
  2125. {
  2126. // TODO: 在此添加实现代码;
  2127. wchar_t argv[MAX_PATH] = { 0 };
  2128. gMemoryObj.TSGetCmdLine(hwnd, argv);
  2129. //*retstring=_bstr_t(argv);
  2130. CComBSTR newbstr;
  2131. newbstr.Append(argv);
  2132. newbstr.CopyTo(retstring);
  2133. return S_OK;
  2134. }
  2135. STDMETHODIMP CTSPlugInterFace::AsmAdd(BSTR asm_ins, LONG* nret)
  2136. {
  2137. // TODO: 在此添加实现代码
  2138. *nret = gMemoryObj.TSAsmAdd(asm_ins);
  2139. return S_OK;
  2140. }
  2141. STDMETHODIMP CTSPlugInterFace::AsmCall(LONG hwnd, LONG mode, LONG* nret)
  2142. {
  2143. // TODO: 在此添加实现代码
  2144. *nret = gMemoryObj.TSAsmCall(hwnd, mode);
  2145. return S_OK;
  2146. }
  2147. STDMETHODIMP CTSPlugInterFace::AsmClear(LONG* nret)
  2148. {
  2149. // TODO: 在此添加实现代码
  2150. gMemoryObj.TSAsmClear();
  2151. *nret = 1;
  2152. return S_OK;
  2153. }
  2154. STDMETHODIMP CTSPlugInterFace::AsmCode(LONG base_addr, BSTR* retstring)
  2155. {
  2156. // TODO: 在此添加实现代码
  2157. wchar_t retstr[MAX_PATH * 10] = { 0 };
  2158. //std::string retstr;
  2159. gMemoryObj.TSAsmCode(base_addr, retstr);
  2160. //*retstring=_bstr_t(retstr);
  2161. CComBSTR newbstr;
  2162. newbstr.Append(retstr);
  2163. newbstr.CopyTo(retstring);
  2164. return S_OK;
  2165. }
  2166. STDMETHODIMP CTSPlugInterFace::Assemble(BSTR asm_code, LONG base_addr, LONG is_upper, BSTR* retstring)
  2167. {
  2168. // TODO: 在此添加实现代码
  2169. wchar_t retstr[MAX_PATH * 10] = { 0 };
  2170. gMemoryObj.TSAssemble(asm_code, base_addr, is_upper, retstr);
  2171. //*retstring=_bstr_t(retstr);
  2172. CComBSTR newbstr;
  2173. newbstr.Append(retstr);
  2174. newbstr.CopyTo(retstring);
  2175. return S_OK;
  2176. }
  2177. STDMETHODIMP CTSPlugInterFace::MatchPicName(BSTR pic_name, BSTR* retstring)
  2178. {
  2179. // TODO: 在此添加实现代码
  2180. wchar_t retstr[MAX_PATH * 10] = { 0 };
  2181. gDxObj.TSMatchPicName(pic_name, retstr);
  2182. //*retstring=_bstr_t(retstr);
  2183. CComBSTR newbstr;
  2184. newbstr.Append(retstr);
  2185. newbstr.CopyTo(retstring);
  2186. return S_OK;
  2187. }
  2188. STDMETHODIMP CTSPlugInterFace::SetShowErrorMsg(LONG show, LONG* nret)
  2189. {
  2190. // TODO: 在此添加实现代码
  2191. TSRuntime::IsShowErrorMsg = show;
  2192. *nret = 1;
  2193. return S_OK;
  2194. }
  2195. STDMETHODIMP CTSPlugInterFace::Reg(BSTR reg_code, LONG type, LONG* nret)
  2196. {
  2197. // TODO: 在此添加实现代码
  2198. VMPBEGIN
  2199. //::GetModuleHandle(L"TSPlug.dll");
  2200. int ret = TSRuntime::VipLogin(reg_code, type);
  2201. if (ret > 0 && type == 0)//特权验证
  2202. {
  2203. TSRuntime::IsVipLogin = true;
  2204. ret = 1;
  2205. }
  2206. else if (ret > 0 && type == 1)//注册验证
  2207. {
  2208. TSRuntime::IsRegLogin = true;
  2209. ret = 1;
  2210. }
  2211. *nret = ret;
  2212. VMPEND
  2213. return S_OK;
  2214. }
  2215. STDMETHODIMP CTSPlugInterFace::GetMachineCode(BSTR* retstring)
  2216. {
  2217. // TODO: 在此添加实现代码
  2218. wchar_t machinecode[MAX_PATH] = { 0 };
  2219. gDxObj.TSGetMachineCode(machinecode);
  2220. //* retstring=_bstr_t(machinecode);
  2221. CComBSTR newbstr;
  2222. newbstr.Append(machinecode);
  2223. newbstr.CopyTo(retstring);
  2224. return S_OK;
  2225. }
  2226. STDMETHODIMP CTSPlugInterFace::TSGuardProtectToHide(LONG enble, LONG* nret)
  2227. {
  2228. // TODO: 在此添加实现代码
  2229. VMPBEGIN //VMP保护
  2230. if (!TSRuntime::IsVipLogin)
  2231. {
  2232. if (TSRuntime::IsRegLogin == false && TSRuntime::IsVipLogin == false)//TS盾不允许试用
  2233. {
  2234. *nret = 0;
  2235. return S_OK;
  2236. }
  2237. INT64 t = 0;
  2238. if (my_myGetTickCount)
  2239. t = my_myGetTickCount();
  2240. else
  2241. t = ::GetTickCount();
  2242. if (t == TSRuntime::checkthreadtime || abs((int)(t - TSRuntime::checkthreadtime)) >= 60 * 1000 * 10 || TSRuntime::checkthreadtime == 0) //校验线程是否被挂起或者GetTickCount被人下钩子
  2243. {
  2244. if (TSRuntime::IsStartProtect)
  2245. TSRuntime::StartProtect(0, 0, -1);
  2246. *nret = 0;
  2247. TSRuntime::h_checkthread = NULL;
  2248. return S_OK;
  2249. }
  2250. }
  2251. *nret = TSRuntime::StartProtect(enble, 1);
  2252. //TSRuntime::add_log( "TSRuntime::IsVipLogin:%d,*nret:%d",TSRuntime::IsVipLogin,*nret);
  2253. VMPEND
  2254. return S_OK;
  2255. }
  2256. STDMETHODIMP CTSPlugInterFace::TSGuardProtectToHide2(LONG enable, LONG* nret)
  2257. {
  2258. // TODO: 在此添加实现代码
  2259. VMPBEGIN //VMP保护
  2260. if (!TSRuntime::IsVipLogin)
  2261. {
  2262. if (TSRuntime::IsRegLogin == false && TSRuntime::IsVipLogin == false)//TS盾不允许试用
  2263. {
  2264. *nret = 0;
  2265. return S_OK;
  2266. }
  2267. INT64 t = 0;
  2268. if (my_myGetTickCount)
  2269. t = my_myGetTickCount();
  2270. else
  2271. t = ::GetTickCount();
  2272. if (t == TSRuntime::checkthreadtime || abs((int)(t - TSRuntime::checkthreadtime)) >= 60 * 1000 * 10 || TSRuntime::checkthreadtime == 0) //校验线程是否被挂起或者GetTickCount被人下钩子
  2273. {
  2274. if (TSRuntime::IsStartProtect)
  2275. TSRuntime::StartProtect(0, 0, -1);
  2276. *nret = 0;
  2277. TSRuntime::h_checkthread = NULL;
  2278. return S_OK;
  2279. }
  2280. }
  2281. *nret = TSRuntime::StartProtect(enable, 2);
  2282. //TSRuntime::add_log( "TSRuntime::IsVipLogin:%d,*nret:%d",TSRuntime::IsVipLogin,*nret);
  2283. VMPEND
  2284. return S_OK;
  2285. }
  2286. STDMETHODIMP CTSPlugInterFace::TSGuardProtectToNP(LONG enable, LONG* nret)
  2287. {
  2288. // TODO: 在此添加实现代码
  2289. VMPBEGIN //VMP保护
  2290. if (!TSRuntime::IsVipLogin)
  2291. {
  2292. if (TSRuntime::IsRegLogin == false && TSRuntime::IsVipLogin == false)//TS盾不允许试用
  2293. {
  2294. *nret = 0;
  2295. return S_OK;
  2296. }
  2297. INT64 t = 0;
  2298. if (my_myGetTickCount)
  2299. t = my_myGetTickCount();
  2300. else
  2301. t = ::GetTickCount();
  2302. if (t == TSRuntime::checkthreadtime || abs((int)(t - TSRuntime::checkthreadtime)) >= 60 * 1000 * 10 || TSRuntime::checkthreadtime == 0) //校验线程是否被挂起或者GetTickCount被人下钩子
  2303. {
  2304. if (TSRuntime::IsStartProtect)
  2305. TSRuntime::StartProtect(0, 0, -1);
  2306. *nret = 0;
  2307. TSRuntime::h_checkthread = NULL;
  2308. return S_OK;
  2309. }
  2310. }
  2311. TSRuntime::InitialWindowsVersion();
  2312. if (TSRuntime::IsWin7X64 == false)
  2313. TSRuntime::StartProtect(enable, 0);
  2314. if (TSRuntime::IsStartProtect == true || TSRuntime::IsWin7X64 == true)
  2315. {
  2316. TSRuntime::IsNpProtect = true;
  2317. *nret = true;
  2318. }
  2319. //TSRuntime::add_log( "TSRuntime::IsVipLogin:%d,*nret:%d",TSRuntime::IsVipLogin,*nret);
  2320. VMPEND
  2321. return S_OK;
  2322. }
  2323. STDMETHODIMP CTSPlugInterFace::Delay(LONG mis, LONG* nret)
  2324. {
  2325. // TODO: 在此添加实现代码
  2326. //TsMutexlock ts_mutexlock(&gDXMySleepMutex);
  2327. gDxObj.mysleep(mis);
  2328. *nret = 1;
  2329. return S_OK;
  2330. }
  2331. STDMETHODIMP CTSPlugInterFace::FindStrS(LONG x1, LONG y1, LONG x2, LONG y2, BSTR string, BSTR color_format, DOUBLE sim, VARIANT* intX, VARIANT* intY, BSTR* retstring)
  2332. {
  2333. // TODO: 在此添加实现代码
  2334. TsMutexlock ts_mutexlock(&gDXFindStrMutex);
  2335. LONG x = -1, y = -1, ret = -1;
  2336. if (x1 >= x2 || y1 >= y2)
  2337. {
  2338. if (TSRuntime::IsShowErrorMsg)
  2339. MessageBox(NULL, L"传入坐标已越界!", L"TS", NULL);
  2340. return S_OK;
  2341. }
  2342. wchar_t retstr[MAX_PATH * 100] = { 0 };
  2343. ret = gDxObj.Findstr(x1, y1, x2, y2, string, color_format, sim, x, y, 0, retstr, 2);
  2344. intX->vt = VT_I4;
  2345. intY->vt = VT_I4;
  2346. intX->lVal = x;
  2347. intY->lVal = y;
  2348. if (x == -1 || y == -1)
  2349. ret = -1;
  2350. CComBSTR newbstr;
  2351. newbstr.Append(retstr);
  2352. newbstr.CopyTo(retstring);
  2353. return S_OK;
  2354. }
  2355. STDMETHODIMP CTSPlugInterFace::FindStrFastS(LONG x1, LONG y1, LONG x2, LONG y2, BSTR string, BSTR color_format, DOUBLE sim, VARIANT* intX, VARIANT* intY, BSTR* retstring)
  2356. {
  2357. // TODO: 在此添加实现代码
  2358. TsMutexlock ts_mutexlock(&gDXFindStrMutex);
  2359. LONG x = -1, y = -1, ret = -1;
  2360. if (x1 >= x2 || y1 >= y2)
  2361. {
  2362. if (TSRuntime::IsShowErrorMsg)
  2363. MessageBox(NULL, L"传入坐标已越界!", L"TS", NULL);
  2364. return S_OK;
  2365. }
  2366. wchar_t retstr[MAX_PATH * 100] = { 0 };
  2367. ret = gDxObj.Findstr(x1, y1, x2, y2, string, color_format, sim, x, y, 1, retstr, 2);
  2368. intX->vt = VT_I4;
  2369. intY->vt = VT_I4;
  2370. intX->lVal = x;
  2371. intY->lVal = y;
  2372. if (x == -1 || y == -1)
  2373. ret = -1;
  2374. CComBSTR newbstr;
  2375. newbstr.Append(retstr);
  2376. newbstr.CopyTo(retstring);
  2377. return S_OK;
  2378. }
  2379. STDMETHODIMP CTSPlugInterFace::FindStrExS(LONG x1, LONG y1, LONG x2, LONG y2, BSTR string, BSTR color_format, DOUBLE sim, BSTR* retstring)
  2380. {
  2381. // TODO: 在此添加实现代码
  2382. TsMutexlock ts_mutexlock(&gDXFindStrMutex);
  2383. LONG x = -1, y = -1, ret = -1;
  2384. if (x1 >= x2 || y1 >= y2)
  2385. {
  2386. if (TSRuntime::IsShowErrorMsg)
  2387. MessageBox(NULL, L"传入坐标已越界!", L"TS", NULL);
  2388. return S_OK;
  2389. }
  2390. wchar_t retstr[MAX_PATH * 100] = { 0 };
  2391. ret = gDxObj.Findstr(x1, y1, x2, y2, string, color_format, sim, x, y, 0, retstr, 1);
  2392. CComBSTR newbstr;
  2393. newbstr.Append(retstr);
  2394. newbstr.CopyTo(retstring);
  2395. return S_OK;
  2396. }
  2397. STDMETHODIMP CTSPlugInterFace::FindStrFastExS(LONG x1, LONG y1, LONG x2, LONG y2, BSTR string, BSTR color_format, DOUBLE sim, BSTR* retstring)
  2398. {
  2399. // TODO: 在此添加实现代码
  2400. TsMutexlock ts_mutexlock(&gDXFindStrMutex);
  2401. LONG x = -1, y = -1, ret = -1;
  2402. if (x1 >= x2 || y1 >= y2)
  2403. {
  2404. if (TSRuntime::IsShowErrorMsg)
  2405. MessageBox(NULL, L"传入坐标已越界!", L"TS", NULL);
  2406. return S_OK;
  2407. }
  2408. wchar_t retstr[MAX_PATH * 100] = { 0 };
  2409. ret = gDxObj.Findstr(x1, y1, x2, y2, string, color_format, sim, x, y, 1, retstr, 1);
  2410. CComBSTR newbstr;
  2411. newbstr.Append(retstr);
  2412. newbstr.CopyTo(retstring);
  2413. return S_OK;
  2414. }
  2415. STDMETHODIMP CTSPlugInterFace::FindPicS(LONG x1, LONG y1, LONG x2, LONG y2, BSTR pic_name, BSTR delta_color, DOUBLE sim, LONG dir, VARIANT* intX, VARIANT* intY, BSTR* retstring)
  2416. {
  2417. // TODO: 在此添加实现代码
  2418. TsMutexlock ts_mutexlock(&gDXFindPicMutex);
  2419. LONG x = -1, y = -1;
  2420. if (x1 >= x2 || y1 >= y2)
  2421. {
  2422. if (TSRuntime::IsShowErrorMsg)
  2423. MessageBox(NULL, L"传入坐标已越界!", L"TS", NULL);
  2424. return S_OK;
  2425. }
  2426. wchar_t retstr[MAX_PATH * 100] = { 0 };
  2427. gDxObj.findPic(x1, y1, x2, y2, pic_name, delta_color, sim, dir, x, y, retstr, 2);
  2428. intX->vt = VT_I4;
  2429. intY->vt = VT_I4;
  2430. intX->lVal = x;
  2431. intY->lVal = y;
  2432. CComBSTR newbstr;
  2433. newbstr.Append(retstr);
  2434. newbstr.CopyTo(retstring);
  2435. return S_OK;
  2436. }
  2437. STDMETHODIMP CTSPlugInterFace::FindPicExS(LONG x1, LONG y1, LONG x2, LONG y2, BSTR pic_name, BSTR delta_color, DOUBLE sim, LONG dir, BSTR* retstring)
  2438. {
  2439. // TODO: 在此添加实现代码
  2440. TsMutexlock ts_mutexlock(&gDXFindPicMutex);
  2441. LONG x = -1, y = -1;
  2442. if (x1 >= x2 || y1 >= y2)
  2443. {
  2444. if (TSRuntime::IsShowErrorMsg)
  2445. MessageBox(NULL, L"传入坐标已越界!", L"TS", NULL);
  2446. return S_OK;
  2447. }
  2448. wchar_t retstr[MAX_PATH * 100] = { 0 };
  2449. gDxObj.findPic(x1, y1, x2, y2, pic_name, delta_color, sim, dir, x, y, retstr, 1);
  2450. CComBSTR newbstr;
  2451. newbstr.Append(retstr);
  2452. newbstr.CopyTo(retstring);
  2453. return S_OK;
  2454. }
  2455. STDMETHODIMP CTSPlugInterFace::SetDictPwd(BSTR pwd, LONG* nret)
  2456. {
  2457. // TODO: 在此添加实现代码
  2458. int len = wcslen(pwd);
  2459. if (len > 0 && len < MAX_PATH)
  2460. {
  2461. wcscpy(TSRuntime::SetDictPwdString, pwd);
  2462. *nret = 1;
  2463. }
  2464. return S_OK;
  2465. }
  2466. STDMETHODIMP CTSPlugInterFace::SetPicPwd(BSTR pwd, LONG* nret)
  2467. {
  2468. // TODO: 在此添加实现代码
  2469. int len = wcslen(pwd);
  2470. if (len > 0 && len < MAX_PATH)
  2471. {
  2472. wcscpy(TSRuntime::SetPicPwdString, pwd);
  2473. if (gDxObj.pData)
  2474. {
  2475. wcscpy(gDxObj.pData->SetPicPwdString, pwd);
  2476. gDxObj.SendMsg(TS_SETPICPWD);
  2477. }
  2478. *nret = 1;
  2479. }
  2480. return S_OK;
  2481. }
  2482. STDMETHODIMP CTSPlugInterFace::LeftDoubleClick(LONG* nret)
  2483. {
  2484. // TODO: 在此添加实现代码
  2485. TsMutexlock ts_mutexlock(&gDXLeftDownMutex);
  2486. if ((gDxObj.m_mouseMode & MOUSE_NORMAL) == MOUSE_NORMAL)
  2487. {
  2488. TSRuntime::g_Mouse.delaytimes = gDxObj.NormalClicksleep;
  2489. //TSRuntime::g_Mouse.leftDoubleClick();
  2490. if (TSRuntime::SetSimModeType == 0)//普通模式
  2491. TSRuntime::g_Mouse.leftDoubleClick();
  2492. }
  2493. else
  2494. {
  2495. if (gDxObj.m_mouseMode & MOUSE_WINDOW)
  2496. {
  2497. SendMessage(gDxObj.m_mousekeyhwnd, WM_SETFOCUS, (WPARAM)gDxObj.m_mousekeyhwnd, 0);
  2498. SendMessage(gDxObj.m_mousekeyhwnd, WM_CAPTURECHANGED, (WPARAM)gDxObj.m_mousekeyhwnd, 0);
  2499. PostMessage(gDxObj.m_mousekeyhwnd, WM_LBUTTONDBLCLK, 1, MAKELPARAM(gDxObj.LastMouseMoveX, gDxObj.LastMouseMoveY));
  2500. }
  2501. else
  2502. *nret = gDxObj.SendMsg(TS_LBUTTONDOWN, WM_LBUTTONDBLCLK, MAKELPARAM(gDxObj.LastMouseMoveX, gDxObj.LastMouseMoveY));
  2503. }
  2504. return S_OK;
  2505. }
  2506. STDMETHODIMP CTSPlugInterFace::FreeProcessMemory(LONG hwnd, LONG* nret)
  2507. {
  2508. // TODO: 在此添加实现代码
  2509. *nret = gMemoryObj.TSFreeProcessMemory(hwnd);
  2510. return S_OK;
  2511. }
  2512. STDMETHODIMP CTSPlugInterFace::TSDXGraphicProtect(LONG enable, LONG* nret)
  2513. {
  2514. // TODO: 在此添加实现代码
  2515. VMPBEGIN //VMP保护
  2516. if (!TSRuntime::IsVipLogin)
  2517. {
  2518. if (TSRuntime::IsRegLogin == false && TSRuntime::IsVipLogin == false)//TS盾不允许试用
  2519. {
  2520. *nret = 0;
  2521. return S_OK;
  2522. }
  2523. INT64 t = 0;
  2524. if (my_myGetTickCount)
  2525. t = my_myGetTickCount();
  2526. else
  2527. t = ::GetTickCount();
  2528. if (t == TSRuntime::checkthreadtime || abs((int)(t - TSRuntime::checkthreadtime)) >= 60 * 1000 * 10 || TSRuntime::checkthreadtime == 0) //校验线程是否被挂起或者GetTickCount被人下钩子
  2529. {
  2530. if (TSRuntime::IsStartProtect)
  2531. TSRuntime::StartProtect(0, 0, -1);
  2532. *nret = 0;
  2533. TSRuntime::h_checkthread = NULL;
  2534. return S_OK;
  2535. }
  2536. }
  2537. gDxObj.Isgraphicprotect = enable;
  2538. if (gDxObj.pData)
  2539. {
  2540. if (enable == 1)
  2541. {
  2542. gDxObj.pData->isgraphicprotect = true;
  2543. gDxObj.Isgraphicprotect = true;
  2544. Sleep(100);//等待游戏内部图色数据刷新
  2545. }
  2546. *nret = gDxObj.SendMsg(TS_ISGRAPHICPROTECT, enable);
  2547. gDxObj.pData->ispichook = enable;
  2548. }
  2549. *nret = 1;
  2550. VMPEND
  2551. return S_OK;
  2552. }
  2553. STDMETHODIMP CTSPlugInterFace::TSDXKmProtect(LONG enable, BSTR type, LONG* nret)
  2554. {
  2555. // TODO: 在此添加实现代码
  2556. VMPBEGIN //VMP保护
  2557. if (!TSRuntime::IsVipLogin)
  2558. {
  2559. if (TSRuntime::IsRegLogin == false && TSRuntime::IsVipLogin == false)//TS盾不允许试用
  2560. {
  2561. *nret = 0;
  2562. return S_OK;
  2563. }
  2564. INT64 t = 0;
  2565. if (my_myGetTickCount)
  2566. t = my_myGetTickCount();
  2567. else
  2568. t = ::GetTickCount();
  2569. if (t == TSRuntime::checkthreadtime || abs((int)(t - TSRuntime::checkthreadtime)) >= 60 * 1000 * 10 || TSRuntime::checkthreadtime == 0) //校验线程是否被挂起或者GetTickCount被人下钩子
  2570. {
  2571. if (TSRuntime::IsStartProtect)
  2572. TSRuntime::StartProtect(0, 0, -1);
  2573. *nret = 0;
  2574. TSRuntime::h_checkthread = NULL;
  2575. return S_OK;
  2576. }
  2577. }
  2578. gDxObj.Isdxkmprotect = enable;
  2579. if (wcsicmp(type, L"dx.anti.api") == 0)
  2580. gDxObj.Isdxantiapi = true;
  2581. else
  2582. gDxObj.Isdxantiapi = false;
  2583. *nret = 1;
  2584. VMPEND
  2585. return S_OK;
  2586. }
  2587. STDMETHODIMP CTSPlugInterFace::CheckFontSmooth(LONG* nret)
  2588. {
  2589. // TODO: 在此添加实现代码
  2590. HKEY Reg_type = HKEY_LOCAL_MACHINE;
  2591. HKEY hKey = NULL;
  2592. wchar_t tempstr[MAX_PATH * 2] = { 0 };
  2593. DWORD size = MAX_PATH * sizeof(wchar_t), dwType = 0;
  2594. LONG bret = 0;
  2595. if (RegOpenKeyEx(HKEY_CURRENT_USER, L"Control Panel\\Desktop", 0, KEY_WRITE | KEY_READ, &hKey) == ERROR_SUCCESS)
  2596. {
  2597. if (RegQueryValueEx(hKey, L"FontSmoothing", NULL, &dwType, (LPBYTE)tempstr, &size) == ERROR_SUCCESS)
  2598. {
  2599. if (_wtoi(tempstr) == 2)
  2600. bret = 1;
  2601. }
  2602. }
  2603. *nret = bret;
  2604. return S_OK;
  2605. }
  2606. STDMETHODIMP CTSPlugInterFace::DisableFontSmooth(LONG* nret)
  2607. {
  2608. // TODO: 在此添加实现代码
  2609. HKEY Reg_type = HKEY_LOCAL_MACHINE;
  2610. HKEY hKey = NULL;
  2611. LONG bret = 0;
  2612. if (RegOpenKeyEx(HKEY_CURRENT_USER, L"Control Panel\\Desktop", 0, KEY_WRITE | KEY_READ, &hKey) == ERROR_SUCCESS)
  2613. {
  2614. if (RegSetValueEx(hKey, L"FontSmoothing", NULL, REG_SZ, (LPBYTE)L"0", sizeof(wchar_t) * 2) == ERROR_SUCCESS)
  2615. bret = 1;
  2616. }
  2617. *nret = bret;
  2618. return S_OK;
  2619. }
  2620. STDMETHODIMP CTSPlugInterFace::GetScreenData(LONG x1, LONG y1, LONG x2, LONG y2, LONG* RetAddr)
  2621. {
  2622. // TODO: 在此添加实现代码
  2623. TsMutexlock ts_mutexlock(&gDXMyGetScreenDataMutex);
  2624. LONG x = -1, y = -1, ret = -1;
  2625. if (x1 >= x2 || y1 >= y2)
  2626. {
  2627. if (TSRuntime::IsShowErrorMsg)
  2628. MessageBox(NULL, L"传入坐标已越界!", L"TS", NULL);
  2629. return S_OK;
  2630. }
  2631. gDxObj.TSGetScreenData(x1, y1, x2, y2);
  2632. *RetAddr = (ULONG)gDxObj.ColorDataInfo;
  2633. return S_OK;
  2634. }
  2635. STDMETHODIMP CTSPlugInterFace::EnableRealMouse(ULONG enable, ULONG mousedelay, ULONG mousestep, ULONG* nret)
  2636. {
  2637. // TODO: 在此添加实现代码
  2638. if (enable)
  2639. {
  2640. gDxObj.IsTSEnableRealMouse = true;
  2641. gDxObj.mousedelay = mousedelay;
  2642. gDxObj.mousestep = mousestep;
  2643. }
  2644. else
  2645. {
  2646. gDxObj.IsTSEnableRealMouse = false;
  2647. gDxObj.mousedelay = 0;
  2648. gDxObj.mousestep = 0;
  2649. }
  2650. *nret = 1;
  2651. return S_OK;
  2652. }
  2653. STDMETHODIMP CTSPlugInterFace::EnableRealKeypad(ULONG enable, ULONG* nret)
  2654. {
  2655. // TODO: 在此添加实现代码
  2656. if (enable)
  2657. gDxObj.IsTSEnableRealKeypad = true;
  2658. else
  2659. gDxObj.IsTSEnableRealKeypad = false;
  2660. *nret = 1;
  2661. return S_OK;
  2662. }
  2663. STDMETHODIMP CTSPlugInterFace::MoveToEx(ULONG x, ULONG y, ULONG w, ULONG h, BSTR* retstring)
  2664. {
  2665. // TODO: 在此添加实现代码
  2666. TsMutexlock ts_mutexlock(&gDXMoveToExMutex);
  2667. wchar_t retstr[16] = { 0 };
  2668. gDxObj.TSMoveToEx(x, y, w, h, retstr);
  2669. CComBSTR newbstr;
  2670. newbstr.Append(retstr);
  2671. newbstr.CopyTo(retstring);
  2672. return S_OK;
  2673. }
  2674. STDMETHODIMP CTSPlugInterFace::CheckUAC(ULONG* nret)
  2675. {
  2676. // TODO: 在此添加实现代码
  2677. HKEY Reg_type = HKEY_LOCAL_MACHINE;
  2678. HKEY hKey = NULL;
  2679. DWORD size = sizeof(DWORD), dwType = 0, retvalue = 0;
  2680. LONG bret = 0;
  2681. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", 0, KEY_WRITE | KEY_READ, &hKey) == ERROR_SUCCESS)
  2682. {
  2683. if (RegQueryValueEx(hKey, L"ConsentPromptBehaviorAdmin", NULL, &dwType, (LPBYTE)&retvalue, &size) == ERROR_SUCCESS)
  2684. {
  2685. if (retvalue != 0)
  2686. bret = 1;
  2687. }
  2688. }
  2689. *nret = bret;
  2690. return S_OK;
  2691. }
  2692. STDMETHODIMP CTSPlugInterFace::SetUAC(ULONG enable, ULONG* nret)
  2693. {
  2694. // TODO: 在此添加实现代码
  2695. HKEY Reg_type = HKEY_LOCAL_MACHINE;
  2696. HKEY hKey = NULL;
  2697. LONG bret = 0;
  2698. DWORD vlaue = 0;
  2699. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", 0, KEY_WRITE | KEY_READ, &hKey) == ERROR_SUCCESS)
  2700. {
  2701. if (enable == 0)//关闭
  2702. {
  2703. if (RegSetValueEx(hKey, L"ConsentPromptBehaviorAdmin", NULL, REG_DWORD, (LPBYTE)&vlaue, sizeof(DWORD)) == ERROR_SUCCESS)
  2704. bret = 1;
  2705. }
  2706. else//打开
  2707. {
  2708. vlaue = 2;
  2709. if (RegSetValueEx(hKey, L"ConsentPromptBehaviorAdmin", NULL, REG_DWORD, (LPBYTE)&vlaue, sizeof(DWORD)) == ERROR_SUCCESS)
  2710. bret = 1;
  2711. }
  2712. }
  2713. *nret = bret;
  2714. return S_OK;
  2715. }
  2716. STDMETHODIMP CTSPlugInterFace::WaitKey(ULONG vk_code, ULONG time_out, ULONG* nret)
  2717. {
  2718. // TODO: 在此添加实现代码
  2719. *nret = TSRuntime::g_KeyBoard.waitkeypress(vk_code, time_out);
  2720. return S_OK;
  2721. }
  2722. STDMETHODIMP CTSPlugInterFace::FindMultiColor(ULONG x1, ULONG y1, ULONG x2, ULONG y2, BSTR first_color, BSTR offset_color, DOUBLE sim, ULONG dir, VARIANT* intX, VARIANT* intY, ULONG* nret)
  2723. {
  2724. // TODO: 在此添加实现代码
  2725. TsMutexlock ts_mutexlock(&gDXFindColorMutex);
  2726. if (x1 >= x2 || y1 >= y2)
  2727. {
  2728. MessageBox(NULL, L"传入坐标已越界!", L"TS", NULL);
  2729. return S_OK;
  2730. }
  2731. //wchar_t* p=0;
  2732. DWORD ncolor = 0x100;
  2733. LONG x = -1, y = -1, ret;
  2734. //TSRuntime::add_log("FindColor:_wtoi:%x",ncolor);
  2735. //ret=TSRuntime::g_DxObj.findColor(x1,y1,x2,y2,ncolor,sim,dir,x,y);
  2736. ret = gDxObj.findColor(x1, y1, x2, y2, ncolor, sim, dir, x, y, first_color, NULL, offset_color);
  2737. intX->vt = VT_I4;
  2738. intY->vt = VT_I4;
  2739. intX->lVal = x;
  2740. intY->lVal = y;
  2741. *nret = ret;
  2742. return S_OK;
  2743. }
  2744. STDMETHODIMP CTSPlugInterFace::FindMultiColorEx(ULONG x1, ULONG y1, ULONG x2, ULONG y2, BSTR first_color, BSTR offset_color, DOUBLE sim, ULONG dir, BSTR* retstring)
  2745. {
  2746. // TODO: 在此添加实现代码
  2747. TsMutexlock ts_mutexlock(&gDXFindColorMutex);
  2748. if (x1 >= x2 || y1 >= y2)
  2749. {
  2750. if (TSRuntime::IsShowErrorMsg)
  2751. MessageBox(NULL, L"传入坐标已越界!", L"TS", NULL);
  2752. return S_OK;
  2753. }
  2754. DWORD ncolor = 0x100;
  2755. LONG x = -1, y = -1;
  2756. wchar_t retstr[MAX_PATH * 5] = { 0 };
  2757. gDxObj.findColor(x1, y1, x2, y2, ncolor, sim, dir, x, y, first_color, retstr, offset_color);
  2758. //*retstring=_bstr_t(retstr);
  2759. CComBSTR newbstr;
  2760. newbstr.Append(retstr);
  2761. newbstr.CopyTo(retstring);
  2762. return S_OK;
  2763. }
  2764. STDMETHODIMP CTSPlugInterFace::SetSimMode(ULONG mode, ULONG* nret)
  2765. {
  2766. // TODO: 在此添加实现代码
  2767. return S_OK;
  2768. }