printf("%08X\n",shwnd);//用spy++测试了,句柄值是对的
DWORD cmdpid;
GetWindowThreadProcessId(cmd,&cmdpid);//当前控制台PID
DWORD notepid;
GetWindowThreadProcessId(shwnd,¬epid);//输入栏PID
AttachThreadInput(cmdpid,notepid,TRUE);//连接控制台和记事本输入栏两个线程
SetFocus(fhwnd);//焦点转移到输入栏
printf("%08X",SetFocus(fhwnd));//此处输出0,调用失败
keybd_event('A',0,0,0);//发送消息
keybd_event('A',0,KEYEVENTF_KEYUP,0);
AttachThreadInput(cmdpid,notepid,FALSE);//释放连接
getchar();
return 0;