CWindowImpl


template
class ATL_NO_VTABLE CWindowImpl :
 public CWindowImplBaseT< TBase, TWinTraits >
{
public:
 DECLARE_WND_CLASS(NULL)

 static LPCTSTR GetWndCaption()
 {
  return NULL;
 }

 HWND Create(
  _In_opt_ HWND hWndParent,
  _In_ _U_RECT rect = NULL,
  _In_opt_z_ LPCTSTR szWindowName = NULL,
  _In_ DWORD dwStyle = 0,
  _In_ DWORD dwExStyle = 0,
  _In_ _U_MENUorID MenuOrID = 0U,
  _In_opt_ LPVOID lpCreateParam = NULL)
 {
  if (T::GetWndClassInfo().m_lpszOrigName == NULL)
   T::GetWndClassInfo().m_lpszOrigName = GetWndClassName();
  ATOM atom = T::GetWndClassInfo().Register(&m_pfnSuperWindowProc);

  dwStyle = T::GetWndStyle(dwStyle);
  dwExStyle = T::GetWndExStyle(dwExStyle);

  // set caption
  if (szWindowName == NULL)
   szWindowName = T::GetWndCaption();

  return CWindowImplBaseT< TBase, TWinTraits >::Create(hWndParent, rect, szWindowName,
   dwStyle, dwExStyle, MenuOrID, atom, lpCreateParam);
 }
};

 


/////////////////////////////////////////////////////////////////////////////
// CWndClassInfo - Manages Windows class information

#define DECLARE_WND_CLASS(WndClassName) \
static ATL::CWndClassInfo& GetWndClassInfo() \
{ \
 static ATL::CWndClassInfo wc = \
 { \
  { sizeof(WNDCLASSEX), CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS, StartWindowProc, \
    0, 0, NULL, NULL, NULL, (HBRUSH)(COLOR_WINDOW + 1), NULL, WndClassName, NULL }, \
  NULL, NULL, IDC_ARROW, TRUE, 0, _T("") \
 }; \
 return wc; \
}

#define DECLARE_WND_CLASS_EX(WndClassName, style, bkgnd) \
static ATL::CWndClassInfo& GetWndClassInfo() \
{ \
 static ATL::CWndClassInfo wc = \
 { \
  { sizeof(WNDCLASSEX), style, StartWindowProc, \
    0, 0, NULL, NULL, NULL, (HBRUSH)(bkgnd + 1), NULL, WndClassName, NULL }, \
  NULL, NULL, IDC_ARROW, TRUE, 0, _T("") \
 }; \
 return wc; \
}

 

typedef _ATL_WNDCLASSINFOA CWndClassInfoA;
typedef _ATL_WNDCLASSINFOW CWndClassInfoW;
#ifdef UNICODE
#define CWndClassInfo CWndClassInfoW
#else
#define CWndClassInfo CWndClassInfoA
#endif

 

 


struct _ATL_WNDCLASSINFOW
{
 WNDCLASSEXW m_wc;
 LPCWSTR m_lpszOrigName;
 WNDPROC pWndProc;
 LPCWSTR m_lpszCursorID;
 BOOL m_bSystemCursor;
 ATOM m_atom;
 WCHAR m_szAutoName[5+sizeof(void*)*CHAR_BIT];

 ATOM Register(_In_ WNDPROC* p)
 {
  return AtlWinModuleRegisterWndClassInfoW(&_AtlWinModule, &_AtlBaseModule, this, p);
 }
};

 

typedef struct tagWNDCLASSEXW {
    UINT        cbSize;
    /* Win 3.x */
    UINT        style;
    WNDPROC     lpfnWndProc;
    int         cbClsExtra;
    int         cbWndExtra;
    HINSTANCE   hInstance;
    HICON       hIcon;
    HCURSOR     hCursor;
    HBRUSH      hbrBackground;
    LPCWSTR     lpszMenuName;
    LPCWSTR     lpszClassName;
    /* Win 4.0 */
    HICON       hIconSm;
} WNDCLASSEXW, *PWNDCLASSEXW, NEAR *NPWNDCLASSEXW, FAR *LPWNDCLASSEXW;


template
HWND CWindowImplBaseT< TBase, TWinTraits >::Create(HWND hWndParent, _U_RECT rect, LPCTSTR szWindowName,
  DWORD dwStyle, DWORD dwExStyle, _U_MENUorID MenuOrID, ATOM atom, LPVOID lpCreateParam)
{
BOOL result;
ATLASSUME(m_hWnd == NULL);


// Allocate the thunk structure here, where we can fail gracefully.
result = m_thunk.Init(NULL,NULL);
if (result == FALSE) {
SetLastError(ERROR_OUTOFMEMORY);
return NULL;
}


if(atom == 0)
return NULL;


_AtlWinModule.AddCreateWndData(&m_thunk.cd, this);


if(MenuOrID.m_hMenu == NULL && (dwStyle & WS_CHILD))
MenuOrID.m_hMenu = (HMENU)(UINT_PTR)this;
if(rect.m_lpRect == NULL)
rect.m_lpRect = &TBase::rcDefault;


HWND hWnd = ::CreateWindowEx(dwExStyle, MAKEINTATOM(atom), szWindowName,
dwStyle, rect.m_lpRect->left, rect.m_lpRect->top, rect.m_lpRect->right - rect.m_lpRect->left,
rect.m_lpRect->bottom - rect.m_lpRect->top, hWndParent, MenuOrID.m_hMenu,
_AtlBaseModule.GetModuleInstance(), lpCreateParam);


ATLASSUME(m_hWnd == hWnd);


return hWnd;
}

 

你可能感兴趣的:(组件)