使用函数CWnd::SubclassWindow( HWND hWnd )来子类化窗口hWnd,并且attach这个窗口到CWnd对象;我的理解是,通过CWnd对象来处理发送给窗口hWnd的消息,然后对消息处理的结果反映到窗口hWnd上;通过调用函数CWnd::SubclassWindow( HWND hWnd )之后,是不是Cwnd对象的窗口就是hWnd了呢?也就是说窗口对象CWnd的m_hwnd跟hWnd是同一个了呢?

解决方案 »

  1.   

    应该不是的吧,CWnd::SubclassWindow( HWND hWnd )应该只是完成了一个窗口的绑定工作,
    即将句柄为hWnd的窗口设置为CWnd的的子窗口,hWnd和m_hWnd应该不会是同一个东西
    看MSDN上的解释:
    Call this member function to "dynamically subclass" a window and attach it to this CWnd object. When a window is dynamically subclassed, windows messages will route through the CWnd’s message map and call message handlers in the CWnd’s class first. Messages that are passed to the base class will be passed to the default message handler in the window.This member function attaches the Windows control to a CWnd object and replaces the window’s WndProc and AfxWndProc functions. The function stores a pointer to the old WndProc in the CWnd object.
      

  2.   

    // The following example attaches an HWND to the CWindow object.
    HWND hWndFoo = ::GetDesktopWindow();
    CWindow fooWindow;
    fooWindow.Attach(hWndFoo);