Send Messages to Other Windows Using Win32 API

It 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;
}

Eric Zhiqiang Ma

Eric is interested in building high-performance and scalable distributed systems and related technologies. The views or opinions expressed here are solely Eric's own and do not necessarily represent those of any third parties.

Leave a Reply

Your email address will not be published. Required fields are marked *