向其它程序的控件发送字符串:
1 找到控件的父窗口
CWnd *m_pWHW = NULL; if( (m_pWHW = FindWindow( "class", "caption")) != NULL) { EnumChildWindows( m_pWHW->m_hWnd, mcb, 0); }
|
2 在回调函数中找到控件,并执行相应操作
int _stdcall mcb(HWND hwnd,LPARAM lParam) { char pname[128], pclass[128]; CString strName, strClass; GetWindowText( hwnd, pname, 64); GetClassNameA( hwnd, pclass, 64); strName = CString( pname); strClass = CString( pclass); if ( strName == "caption" && strClass == "class") { //::PostMessageA( hwnd, WM_CHAR, 'A', 0); ::SendMessage( hwnd, WM_SETTEXT, 0, LPARAM("your string")); //SetWindowTextA( hwnd, "your string"); } return 1; }
|
另:
1 SendMessage(hwnd, WM_COPY 0, 0);
SendMessage(hwnd, WM_CUT, 0, 0);
SendMessage(hwnd, WM_PASTE, 0, 0);
2 PostMessage将消息放入消息队列后马上返回,而SendMessage直到窗口过程处理完消息后才返回
阅读(9699) | 评论(0) | 转发(0) |