点击当前窗口(A)上的按钮使本窗口(A)失去焦点,并使另一窗口(B)获得焦点!如何实现,俺折腾半天,就是实现不了,HWND hWndA = this->GetSafeHwnd();
HWND hWndB = ::FindWindowEx(NULL,NULL,NULL,_T("FORM_B"));
if (hWndB!=NULL)
{
::SendMessage(hWndA,WM_KILLFOCUS,0,0);
                           ::SendMessage(hWndB,WM_SETFOCUS,0,0);
                           ::SendMessage(hWndB,WM_ACTIVATE,0,0);
}麻烦大家帮忙看看,

解决方案 »

  1.   

    GetActiveWindow()->EnableWindow(TRUE);
    这个都用上了,
    也不行,用了上面的那条语句后,
    A/B窗口好像都被激活了,
    但是,B并没有得到焦点,输入东西到B的Edit里依然不行,(虽然B的Edit有光标在闪动)
      

  2.   


    const WM_GETFOCUS = WM_USER + 101;
    HWND hWndA = this->GetSafeHwnd();
    HWND hWndB = ::FindWindowEx(NULL,NULL,NULL,_T("FORM_B"));
     if (hWndB!=NULL)
    {
    ::SendMessage(hWndB,WM_GETFOCUS,0,0);}窗口B中处理自定义消息
    LRESULT OnGetFocus(WPARAM wp, LPARAM lp)
    {
    SetFocus();
    return 0L;
    }
      

  3.   

    const int WM_GETFOCUS = WM_USER + 101;
    笔误
    试试上面的
      

  4.   

    刚刚试过了,SetForegroundWindow是可以的。如果不行的话,搂住看下B的窗口是不是最小化的?如果B的窗口是最小化的话,只要把它还原然后SetForegroundWindow就可以了。ps:我是用MS的计算器测试的。
      

  5.   

    ::SetForegroundWindow(hWnd);
    ::SetActiveWindow(hWnd);
    这个试试
      

  6.   

    AttachThreadInput + SetFocus,进行配合。示例:(不要照抄,请灵活使用)
    //Attach foreground window thread
    //to our threadAttachThreadInput(
        GetWindowThreadProcessId(
            ::GetForegroundWindow(),NULL),
        GetCurrentThreadId(),TRUE);//Do our stuff here ;-)SetForegroundWindow();
    SetFocus(); //Just playing safe
    //Detach the attached threadAttachThreadInput(
        GetWindowThreadProcessId(
            ::GetForegroundWindow(),NULL),
        GetCurrentThreadId(),FALSE);
      

  7.   

    HWND hWnd = ::FindWindow(NULL, MAIN_WINDOW_NAME);
    if(hWnd!=NULL)
    {

    if(::IsIconic(hWnd))
    ::ShowWindow(hWnd,SW_SHOWNORMAL);
    ::SetForegroundWindow(hWnd);
    ::SetActiveWindow(hWnd);

    }
    测试过了,是可以的,不知道是不是你要的效果
      

  8.   

    GetForegroundWindow或者BringWindowToTop都可以。调试看看是不是你FindWindow失败了。
      

  9.   

    写错了,是SetForegroundWindow