我看了MSDN中的描述:If the function succeeds, the return value is the handle to the window that previously had the keyboard focus. If the hWnd parameter is invalid or the window is not attached to the calling thread's message queue, the return value is NULL. To get extended error information, call GetLastError.说有两种情况会失败:
1 hWnd parameter is invalid 
2 the window is not attached to the calling thread's message queue我看了,不是第二种情况。
我想知道,什么叫“hWnd parameter is invalid ”,而且我调用GetLastError返回0.

解决方案 »

  1.   

    就是句柄是不可用的
    可能是对应的window已经销毁了
      

  2.   

    我知道是这个意思,对应的窗口也没销毁, GetLastError返回0,MSDN上的描述不详,我不知道为什么会失败。我想让他得到焦点的窗口是一个listbox.大家帮忙看看是什么原因
      

  3.   

    是不是在OnInitDialog中调用的,
    如果是要返回FALSE才行
      

  4.   

    不是的,不是对话框上的LISTbox,是一个CWnd窗口上的listbox, 不知道跟父窗口的风格有没有关系
      

  5.   

    SetFocus以后别的窗口又改回去了
      

  6.   

    应该不是吧,它的onSetFocus根本就没被调用