发送WM_SETFOCUS消息或者:
::SetFocus

解决方案 »

  1.   

    就是用WM_SETFOCUS产生的结果。而::setfocus用不成。
      

  2.   

    The SetFocus function sets the keyboard focus to the specified window. The window must be attached to the calling thread's message queue. 不是同一个进程的话可能因为输入模型而有点问题,你试一下以下步骤:
    1. 对目标窗口SetActiveWindow
    2. 对Edit发送WM_KILLFOCUS
    3. 对Button发送WM_SETFOCUS.
      

  3.   

    找到办法了,使用AttachThreadInput挂到目标线程上,然后::SetFocus,完了以后再解开挂接
      

  4.   

    HWND hActiveWnd,hHasFocusWnd;
        DWORD IDActive,IDthis;    BringWindowToTop((HWND)al_windowhandle);//使其成为focus之window    hActiveWnd=::GetForegroundWindow();//获取当前窗口handle
        
        IDthis=GetWindowThreadProcessId((HWND)al_windowhandle,NULL);//获取线程号
        IDActive=GetWindowThreadProcessId(hActiveWnd,NULL);//
        AttachThreadInput(IDActive,IDthis,TRUE);
        hHasFocusWnd=::GetFocus();//获取焦点
        AttachThreadInput(IDActive,IDthis,FALSE);al_windowhandle是我的窗口的handle
    还是没有用
      

  5.   

    HWND SetFocus(
      HWND hWnd   // handle to window to receive focus
    );
      

  6.   

    你需要的是控件的HWND, 而不是整个窗口的HWND,甚至前面的BringWindowToTop这些都不用假设你的控件HWND是hCtrl,那么
    AttachThreadInput(IDActive,IDthis,TRUE);
    // 这里应该是SetFocus
    ::SetFocus(hCtrl);
    AttachThreadInput(IDActive,IDthis,FALSE);