#include <windows.h> char om[262144]; BOOL CALLBACK EnumWindowProc(HWND hWnd,LPARAM lParam); BOOL CALLBACK EnumChildWindowProc(HWND hWnd,LPARAM lParam); int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd) { HWND nphWnd=::FindWindow("notepad",NULL); if(nphWnd) { ::EnumWindows(EnumWindowProc,0);//枚举窗口 ::EnumChildWindows(nphWnd,EnumChildWindowProc,0); } return 0; } BOOL CALLBACK EnumWindowProc(HWND hWnd,LPARAM lParam)//枚举窗口的回调函数 { char temp1[256]; char WinClassName[256]; ::GetClassName(hWnd,WinClassName,255);//获得类名 DWORD pID=0; ::GetWindowThreadProcessId(hWnd,(LPDWORD)&pID);//获得进程ID ::GetWindowText(hWnd,temp1,255);//获得窗口标题 ::wsprintf(om,"%s%s%s%s%s%s%d",om,"\r\nclassname: ",WinClassName,",wintext: ",temp1,",ID:",pID); return true; } BOOL CALLBACK EnumChildWindowProc(HWND hWnd,LPARAM lParam) { char temp1[256]; if(hWnd) { ::GetClassName(hWnd,temp1,255); if(!::strcmp(temp1,"Edit")) { ::SendMessage(hWnd,WM_SETTEXT,0,(LPARAM)om); return 0; } } return true; }