我看了MSDN中的解释和它给出的示例:// Using Attach and Detach to map to the MDI client window
class CMainFrame : public CMDIFrameWnd
{
...
public:
   CWnd  m_wndMDIClient;
}CMainFrame::~CMainFrame()
{
   // detach MDI client window
   m_wndMDIClient.Detach();
}int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
   if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
      return -1;   // attach MDI client window
   if (m_wndMDIClient.Attach(m_hWndMDIClient) == 0)
   {
      TRACE0("Failed to attach MDIClient.\n");
      return -1;      // fail to create
   }
}
可我还是不知道该怎么使用,有谁能帮忙吗?高分相送……

解决方案 »

  1.   

    window使用句柄来把持资源,窗体是一种资源,CWnd是这种资源的MFC的包装类,在Win32API中,HWnd是LONG型的,可以通过CWnd的ATTECH把一个HWND资源就附加到一个CWnd类里了,就是这样!
      

  2.   

    class CMainFrame : public CMDIFrameWnd
    {
    ...
    public:
       CWnd  m_wndMDIClient;
    }
    /////////////////////////
    CWnd  m_wndMDIClient;
    在这里的这个成员变量是干什么用的啊?
      

  3.   

    不是很明白你的意思..
    m_hWndMDIClient什么是候初始化的?http://expert.csdn.net/Expert/topic/1267/1267581.xml?temp=.644314
      

  4.   

    Attach的例子在msdn的哪个路径下啊?我怎么就找不着呢?
      

  5.   

    kingcom_xu(我的刀是杀不了人的)  :刀哥,这个attach函数是干什么用的?
      

  6.   

    CWnd::Attach  
    BOOL Attach( HWND hWndNew );Return ValueNonzero if successful; otherwise 0.ParametershWndNewSpecifies a handle to a Windows window.ResAttaches a Windows window to a CWnd object.Example// Using Attach and Detach to map to the MDI client window
    class CMainFrame : public CMDIFrameWnd
    {
    ...
    public:
       CWnd  m_wndMDIClient;
    }CMainFrame::~CMainFrame()
    {
       // detach MDI client window
       m_wndMDIClient.Detach();
    }int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
    {
       if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
          return -1;   // attach MDI client window
       if (m_wndMDIClient.Attach(m_hWndMDIClient) == 0)
       {
          TRACE0("Failed to attach MDIClient.\n");
          return -1;      // fail to create
       }
    }甜心MM你MFC也在学吗?~~~~~~~~~~~
    太可怕了
      

  7.   

    CWnd是一个窗口对象,普通情况下是生成实例后用Create创健去一个窗口实例,但也可以将这个窗口对象绑定到一个已经生成的窗口实例上,也就是用Attach,绑定之后你便可以用这个CWnd对象的成员函数和成员变量很方便的操纵"一个已经生成的窗口实例"
      

  8.   

    感觉就象是个别名,好象并没太大用途。。
    //////////////////////////////
    甜心MM你MFC也在学吗?~~~~~~~~~~~
    太可怕了
    /////////////////////
    我过两天就要去学MFC了,现在还在看《windows程序设计》。
      

  9.   

    非也!
    有了这个CWnd对象很多动作实现起来方便了很多...
      

  10.   

    1.not use CWnd
    Fun(HWND  hwnd)
    {
       
     MoveWindow(hwnd,0,0,100,100,true);
    }
    2.use CWndFun (HWND hwnd)
    {
    CWnd Wnd;
     Wnd.Attach(hwnd);
     Wnd.MoveWindow(0,0,100,100,true);
     Wnd.Detach();
    }