Send Messages to Other Windows Using Win32 API
Posted on In ProgrammingIt is simple for basic use. Just the example code. It is clear enough.
int SendMsgToOtherWindow( ) { // find window by name HWND wnd = FindWindow( 0, "计算器" ); if ( wnd == 0 ) return 0; // print the child window text HWND cwd = GetWindow( wnd, GW_CHILD ); while ( cwd ) { char buf[1024]; GetWindowText( cwd, buf, 1024 ); cout << buf << endl; int id = GetDlgCtrlID( cwd ); cout << id << endl; cwd = GetNextWindow( cwd, GW_HWNDNEXT ); } // close the window SendMessage( wnd, WM_CLOSE, 0, 0 ); return 0; }