已知窗口的句柄是一个unsigned int, 请问如何转换成HWND,然后可以通过CWnd的FromHandle函数获得一个CWnd对象?

解决方案 »

  1.   

    已知窗口的句柄是一个unsigned int, 请问如何转换成HWND这句话我不明白?HWND不就是句柄吗?
    前面加个(HWND)转换一下就行了CWnd wnd;
    wnd.FromHandle(your handle);
    ok
      

  2.   

    unsigned int ui = ...;
    HWND hWnd = (HWND)ui;if( IsWindow( hWnd ) )
    {
      使用CWnd的FromHandle就行了。
    }
      

  3.   

    有个额外的话题我需要提醒你
    static CWnd* PASCAL FromHandle( HWND hWnd );Returns a pointer to a CWnd object when given a handle to a window. If a CWnd object is not attached to the handle, a temporary CWnd object is created and attached. 
    The pointer may be temporary and should not be stored for later use.请仔细看MSDN,FromHandle返回的CWnd *不要尝试保存,超越一个消息保留的这个对象再次被使用的时候很有可能这个窗口对象已经被删除了。