还没有完全理解窗口句柄与窗口地址的区别。
比如说,我得到了某一个窗口的CWnd类型的地址,与得到HWND类型的句柄有什么区别?
请大虾赐教。

解决方案 »

  1.   

    一个是mfc封装的类一个是windows标准数据类型
      

  2.   

    窗口的CWnd类型的地址:是一个一般的地址,可以理解为是一个纯粹的指针
    HWND类型的句柄:是一个由系统维护的,一个安全的,带索引的,一个代表某类资源或对象,对 句柄是更安全的,更方便的,是MS 封装了的两个都是一个地址,从形式上看没有然后区别,其实任何一个变量最后都是由地址表示 上面是我的片面之词语,目的是 抛砖引玉~
      

  3.   

    Relationship Between a C++ Window Object and an HWND
     The window object is an object of the C++ CWnd class (or a derived class) that your program creates directly. It comes and goes in response to your program’s constructor and destructor calls. The Windows window, on the other hand, is an opaque handle to an internal Windows data structure that corresponds to a window and consumes system resources when present. A Windows window is identified by a “window handle” (HWND) and is created after the CWnd object is created by a call to the Create member function of class CWnd. The window may be destroyed either by a program call or by a user’s action. The window handle is stored in the window object’s m_hWnd member variable. The following figure shows the relationship between the C++ window object and the Windows window. Creating windows is discussed in Creating Windows. Destroying windows is discussed in Destroying Window Objects.
      

  4.   

    cwnd 的 m_hwnd就是这个窗口对象的HWND
    也可以通过GetSafeHwnd获得HWND
      

  5.   

    CWnd::CreateEx  
    BOOL CreateEx( DWORD dwExStyle, LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, int x, int y, int nWidth, int nHeight, HWND hwndParent, HMENU nIDorHMenu, LPVOID lpParam = NULL );给一个窗口发消息,其中就是hwnd
     LRESULT SendMessage(
      HWND hWnd,      // handle of destination window
      UINT Msg,       // message to send
      WPARAM wParam,  // first message parameter
      LPARAM lParam   // second message parameter
    );
    CWnd就是mfc中的窗口类,对应一个窗口, 也可以不对应一个具体的窗口