這篇文章主要介紹了C++獲得其他程序窗體控件中信息的方法,涉及windows控件句柄的獲取技巧,需要的朋友可以參考下
本文實例講述了C++獲得其他程序窗體控件中信息的方法。分享給大家供大家參考。具體分析如下:
這里演示了獲得其他程序窗體控件信息的方法,
用FindWindow API找到文本框句柄,用SendMessage(WM_GETTEXT)獲得文本
- #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++程序設計有所幫助。
新聞熱點
疑難解答