wndclass.cbClsExtra 和
wndclass.cbWndExtra
到底有何用处  ? 
什么时候才用?

解决方案 »

  1.   

    from MSDN: title is "About Window Classes"Extra Class Memory
    The system maintains a WNDCLASSEX structure internally for each window class in the system. When an application registers a window class, it can direct the system to allocate and append a number of additional bytes of memory to the end of the WNDCLASSEX structure. This memory is called extra class memory and is shared by all windows belonging to the class. Use the extra class memory to store any information pertaining to the class. Because extra memory is allocated from the system's local heap, an application should use extra class memory sparingly. The RegisterClassEx function fails if the amount of extra class memory requested is greater than 40 bytes. If an application requires more than 40 bytes, it should allocate its own memory and store a pointer to the memory in the extra class memory.The SetClassWord and SetClassLong functions copy a value to the extra class memory. To retrieve a value from the extra class memory, use the GetClassWord and GetClassLong functions. The cbClsExtra member of the WNDCLASSEX structure specifies the amount of extra class memory to allocate. An application that doesn't use extra class memory must initialize the cbClsExtra member to zero. Extra Window Memory
    The system maintains an internal data structure for each window. When registering a window class, an application can specify a number of additional bytes of memory, called extra window memory. When creating a window of the class, the system allocates and appends the specified amount of extra window memory to the end of the window's structure. An application can use this memory to store window-specific data. Because extra memory is allocated from the system's local heap, an application should use extra window memory sparingly. With system version 4.0 or later, the RegisterClassEx function fails if the amount of extra window memory requested is greater than 40 bytes. If an application requires more than 40 bytes, it should allocate its own memory and store a pointer to the memory in the extra window memory.The SetWindowLong function copies a value to the extra memory. The GetWindowLong function retrieves a value from the extra memory. The cbWndExtra member of the WNDCLASSEX structure specifies the amount of extra window memory to allocate. An application that doesn't use the memory must initialize cbWndExtra to zero. 
      

  2.   

    一般的:
    wndclass.cbClsExtra =0;
    wndclass.cbWndExtra =0; 就可以了!大多时候是用在MDI应用程序中的,作为扩展存储区来使用的,等于为
    每个窗口类分配一块 new char[n]
      

  3.   

    那 =sizeof(long)是什么意思呢?在什么情况下这样做
      

  4.   

    是这样用的(我不是高手,不过这个问题我会:)),
    wndclass.cbWndExtra =0;
    其实是申明这个WNDCLASS不需要额外的空间。

    wndclass.cbWndExtra=sizeof(long);
    那么这个WNDCLASS留了long大小的空间给你。
    你可以使用SetWindowLong来设置;使用GetWindowLong来读取。就如同CListCtrl的SetItemData和GetItemData一样。
      

  5.   

    如果
    wndclass.cbWndExtra=0;
    就不能用SetWindowLong这个函数来对这个窗口类进行设置了吗?