似乎怎样对远程的控件文本操作,成了一个不大不小的问题。
尝试过VirtualAlloc+WriteProcessMemory+SendMessage似乎很不奏效。(对于list控件似乎很好用,但是edit、static之类的控件怎么弄都不成功)

于是为了某些程序能够实现操作远程控件文本的功能,特意写了一个动态链接库。似乎比较好用。

改dll其实没什么特别值得参考的地方。

大家拿来实用也好,拿代码来参考复制也罢,甚至权且当作是hook的例程反正回回帖子,捧捧人气就好!(广告云:“神州行,我看行”即为此理)

下附内容说明
=============================================================
修改远程窗口文本的动态连接库(未编译)

WRT.BAT文件为源代码+编译参数,放入已安装masm32的分区的任意目录中,双击编译。

输出:

LPTSTR __stdcall WGetRemoteTextA(HWND hWnd,LPTSTR sztext);
LPTSTR __stdcall WSetRemoteTextA(HWND hWnd,LPTSTR sztext);

第一个函数读取远程窗口文本
第二个函数写入远程窗口文本
两者都是stdcall的函数,它的返回值就是LPTSTR sztext。
---------------------------------------------------
注:
1、WRT是WRemoteText的缩写
2、代码中提供了UNICODE的部分,但是我没有用过UNICODE写过程序。不知道这样子会不会有错。所以comment了。
3、若要修改文件名,不要忘记把WRT.BAT中的环境变量也做相应的设置!
==================================================================
源代码:

代码:
;echo off ;cls ;goto make ;我从来没有用过UNICODE,担心出BUG。所以把原本定义UNICODE操作comment了。 MAXTEXTSIZE = 1000 .386 .model flat, stdcall option casemap :none include windows.inc include user32.inc include kernel32.inc includelib user32.lib includelib kernel32.lib .data   bset      dd 0 ;  bunicode    dd 0   readflag    dd 0   busying    dd 0  ;  if there is another program called this function,it will share the whole .data section.                ;  incase of these process call the DLL at the same time,we should make a var to record it.   finished    dd 0  ;  if the title changed   processid  dd 0  ;  the Target process id   threadid    dd 0   hhook      dd 0   htarget    dd 0  ;  Target window :)   targettext  db MAXTEXTSIZE+2 dup(?) .CODE   hInstance dd 0 LibMain proc hInstDLL:DWORD, reason:DWORD, unused:DWORD   .if reason == DLL_PROCESS_ATTACH     mov eax,hInstDLL     mov hInstance,eax   ;.elseif reason == DLL_PROCESS_DETACH   ;.elseif reason == DLL_THREAD_ATTACH   ;.elseif reason == DLL_THREAD_DETACH   .endif   mov eax,TRUE   ret 12 LibMain Endp WHookCall  proc ncode:DWORD,wParam:DWORD,lParam:DWORD     mov eax,finished     test eax,eax     jnz hookignore     invoke GetCurrentProcessId     cmp eax,processid     jne hookignore     .if bset == 0       invoke SendMessage,htarget,WM_GETTEXT,MAXTEXTSIZE,offset targettext     .else       invoke SendMessage,htarget,WM_SETTEXT,0,offset targettext     .endif     mov finished,1 hookignore:;   invoke CallNextHookEx,hhook,ncode,wParam,lParam   ret 12 WHookCall  endp WTextOperation  proc  hWnd:DWORD,sztext:DWORD wait0:   mov eax,busying   test eax,eax   jne wait0   invoke IsWindow,hWnd   je invalidhwnd   mov busying,1   invoke GetWindowThreadProcessId,hWnd,offset processid   mov threadid,eax   invoke GetLastError   test eax,eax   jne Expection ;偷懒点,不去考虑当前进程的窗口了 ;  invoke GetCurrentProcessId ;  .if processid == eax ;    .if bset == 0 ;      invoke SendMessage,htarget,WM_GETTEXT,MAXTEXTSIZE,sztext ;    .else ;      invoke SendMessage,htarget,WM_SETTEXT,0,sztext ;    .endif ;    jmp Expection ;  .endif   .if bset == 1 ;    .if bunicode == 0       invoke lstrcpynA,offset targettext,sztext,MAXTEXTSIZE ;    .else ;      invoke lstrcpynW,offset targettext,sztext,MAXTEXTSIZE/2 ;    .endif   .endif   mov finished,0   push hWnd   pop htarget   invoke SetWindowsHookEx,WH_CALLWNDPROC,offset WHookCall,hInstance,threadid   mov hhook,eax   invoke GetLastError   test eax,eax   jne Expection   invoke SendMessage,hWnd,WM_GETTEXTLENGTH,0,0   invoke GetLastError   test eax,eax   jne Expection notfinished:;   mov eax,finished   test eax,eax   je notfinished   invoke UnhookWindowsHookEx,hhook   mov hhook,0   .if bset==0 ;    .if bunicode == 0       invoke lstrcpynA,sztext,offset targettext,MAXTEXTSIZE ;    .else ;      invoke lstrcpynW,sztext,offset targettext,MAXTEXTSIZE/2 ;    .endif   .endif invalidhwnd:; Expection:;   mov busying,0   mov eax,sztext   ret 8 WTextOperation  endp ;    I do not know whether Win98 supports the  ;  Unicode. ;=================Unicode: ==================== ;WGetRemoteTextW  proc  hWnd:DWORD,sztext:DWORD ;  mov bset,0 ;  mov bunicode,1 ;  invoke WTextOperation,hWnd,sztext ;  ret 8 ;WGetRemoteTextW  endp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;WSetRemoteTextW  proc  hWnd:DWORD,sztext:DWORD ;  mov bset,1 ;  mov bunicode,1 ;  invoke WTextOperation,hWnd,sztext ;  ret 8 ;WSetRemoteTextW  endp ;================Ansi: ======================== WGetRemoteTextA  proc  hWnd:DWORD,sztext:DWORD   mov bset,0   ;mov bunicode,0   invoke WTextOperation,hWnd,sztext   ret 8 WGetRemoteTextA  endp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; WSetRemoteTextA  proc  hWnd:DWORD,sztext:DWORD   mov bset,1   ;mov bunicode,0   invoke WTextOperation,hWnd,sztext   ret 8 WSetRemoteTextA  endp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; End LibMain

 
:make
set this=WRT
set include=%include%;\masm32\include
set lib=%lib%;\masm32\lib
\masm32\bin\ml /c /coff /nologo %this%.bat
rem link option
if exist %this%.bat \masm32\bin\link /SUBSYSTEM:WINDOWS /DLL /NOLOGO /merge:.rdata=.text /section:.text,RWE /section:.data,rws /EXPORT:WSetRemoteTextA /EXPORT:WGetRemoteTextA %this%.obj
del %this%.obj
pause