本文實例講述了C++獲得其他程序窗體控件中信息的方法。分享給大家供大家參考。具體分析如下:
這里演示了獲得其他程序窗體控件信息的方法,
用FindWindow API找到文本框句柄,用SendMessage(WM_GETTEXT)獲得文本
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
#include <windows.h> BOOL CALLBACK EnumChildProc( HWND hWnd, LPARAM lParam); int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { char className[]= "notepad" ; HWND hWnd=::FindWindow(className,NULL); if (hWnd) { ::EnumChildWindows(hWnd,EnumChildProc,0); return 0; } MessageBox(NULL, "fail!" , "fail" ,MB_OK); return 0; } BOOL CALLBACK EnumChildProc( HWND hWnd, LPARAM lParam) { char temp1[256],temp2[256]; ::GetClassName(hWnd,temp1,255); if (!:: strcmp (temp1, "Edit" )) { ::SendMessage(hWnd,WM_GETTEXT, sizeof (temp2)/ sizeof ( char ),( LPARAM )temp2); //EDIT的句柄,消息,接收緩沖區大小,接收緩沖區指針 ::MessageBox(NULL,temp2, "get" ,MB_OK); return 0; } ::wsprintf(temp2, "classname: %s" ,temp1); MessageBox(NULL,temp2, "cwnd" ,MB_OK); return true ; } |
希望本文所述對大家的C++程序設計有所幫助。