获得其他程序控件中的信息 WM_GETTEXT消息

获得其他程序控件中的信息,尤其跨进程,这个着实让我头疼捯饬了一阵,最后才明白只能通过WM_GETTEXT消息获取文本。

SendMessage(h, WM_GETTEXT, 260, Longint(@Caption));(h:要获取信息的控件句柄;Caption: array [0 .. MAX_PATH] of Char;)此消息即发送给系统并获取控件文本信息至Caption里。

以下是自己的代码:

View Code
 1 procedure TSSoUtils.InsertHwnd(h: HWND);
2 var
3 level, Num: integer;
4 Y: integer;
5 str: string;
6 ParentWnd: HWND;
7 ClassName: array [0 .. MAX_PATH] of Char;
8 Caption: array [0 .. MAX_PATH] of Char;
9 ParentClassName: array [0 .. MAX_PATH] of Char;
10 ParentCaption: array [0 .. MAX_PATH] of Char;
11 begin
12
13 Timer1.Enabled := FALSE;
14 Timer1.Enabled := TRUE;
15
16 // Sleep(100000);
17 Timer1.Interval := 2000;
18
19 Num := GetParents(h);
20 wnd_x[Num].level := GetNum(h); // 获取位于当前层的位置
21 Y := wnd_x[Num].level;
22 ParentWnd := GetParent(h);
23 GetClassName(h, ClassName, sizeof(ClassName));
24 // GetWindowText(h, Caption, sizeof(Caption));
25 GetClassName(ParentWnd, ParentClassName, sizeof(ParentClassName));
26 // GetWindowText(ParentWnd, ParentCaption, sizeof(ParentCaption));
27
28 SendMessage(h, WM_GETTEXT, 260, Longint(@Caption));
29 // 获得其他程序控件中的信息只能通过WM_GETTEXT消息获取文本
30 SendMessage(ParentWnd, WM_GETTEXT, 260, Longint(@ParentCaption));
31
32 OutputDebugString(pchar('Caption00: ' + Caption));
33 OutputDebugString(pchar('ClassName00: ' + ClassName));
34 OutputDebugString(pchar('ParentCaption00: ' + ParentCaption));
35 OutputDebugString(pchar('ParentClassName00: ' + ParentClassName));
36
37 InsertOpe(Num, Y, h, Caption, ClassName, ParentCaption, ParentClassName);
38
39 wnd_x[Num].Wnd_y[Y].h := h;
40
41 wnd_x[Num].level := wnd_x[Num].level - 1; str := string(Caption) + '' + string(ClassName) + '' + 'level:' +
42 inttostr(Num) + ' Y:' + inttostr(Y) + ' HWND:' + inttostr(h);
43 OutputDebugString(pchar(str));
44 end;


 

以下是参考的代码:

View Code
 1 #include <windows.h>
2 BOOL CALLBACK EnumChildProc(HWND hWnd,LPARAM lParam);
3 int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
4 {
5 char className[]="notepad";
6 HWND hWnd=::FindWindow(className,NULL);
7 if(hWnd)
8 {
9 ::EnumChildWindows(hWnd,EnumChildProc,0);
10 return 0;
11 }
12 MessageBox(NULL,"fail!","fail",MB_OK);
13 return 0;
14 }
15 BOOL CALLBACK EnumChildProc(HWND hWnd,LPARAM lParam)
16 {
17 char temp1[256],temp2[256];
18 ::GetClassName(hWnd,temp1,255);
19 if(!::strcmp(temp1,"Edit"))
20 {
21 ::SendMessage(hWnd,WM_GETTEXT,sizeof(temp2)/sizeof(char),(LPARAM)temp2);//EDIT的句柄,消息,接收缓冲区大小,接收缓冲区指针
22 ::MessageBox(NULL,temp2,"get",MB_OK);
23 return 0;
24 }
25 ::wsprintf(temp2,"classname: %s",temp1);
26 MessageBox(NULL,temp2,"cwnd",MB_OK);
27 return true;
28 }

 

转载于:https://www.cnblogs.com/IceKernel/archive/2012/02/29/2373101.html

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值