我用IsWindow函数来判断一个窗口是否存在,今天仔细阅读MSDN上的解释,对里面的一段话不理解,希望有人给我通一下:
Res
An application should not use IsWindow for a window that it did not create because the window could be destroyed after this function was called. Further, because window handles are recycled the handle could even point to a different window. 这是什么意思呢?是不是IsWindow一般不能乱用?

解决方案 »

  1.   

    这段话在哪里的? 我怎么没找到.它说IsWindow 这人函数不应该用在一个 创建之后又被删除了,之后还没有重新创建的窗口之上. 因为一个窗口句柄会被回收并可能指派给另一个完全不同的窗口. 不知道理解得对不对
      

  2.   

    不对啊,楼上,你把because看成before了,这是在msdn上的原话。我全部考在下面了:
    IsWindow
    The IsWindow function determines whether the specified window handle identifies an existing window. BOOL IsWindow(
      HWND hWnd   // handle to window
    );
    Parameters
    hWnd 
    [in] Handle to the window to test. 
    Return Values
    If the window handle identifies an existing window, the return value is nonzero.If the window handle does not identify an existing window, the return value is zero. Res
    An application should not use IsWindow for a window that it did not create because the window could be destroyed after this function was called. Further, because window handles are recycled the handle could even point to a different window. 
      

  3.   

    不要对模态的window使用IsWindow
      

  4.   

    给出一段代码,希望对你有所启示:
    if(m_MyDialog.GetSafeHwnd()==NULL)
      m_MyDialog.Create(/*具体参数我就不写了*/);
    m_MyDialog.ShowWindow(SW_SHOW);
    判断当前指针为什么类,可以用GetRuntimeClass();