#pragma once
#ifndef _CDLG_TEMPLATE_H
#define _CDLG_TEMPLATE_H
#define DLG_TEMPLATE_BUFFER_MAX_LENGTH 1024

class CDlgTemplate
{
public:
	CDlgTemplate(int nBufferLength = DLG_TEMPLATE_BUFFER_MAX_LENGTH) {
		m_pBuffer = new WORD[nBufferLength];
	}
	~CDlgTemplate() {
		if (m_pBuffer)
		{
			delete[] m_pBuffer;
			m_pBuffer = nullptr;
		}
	}

private:
	WORD* m_pBuffer;

public:
	DLGTEMPLATE* CreateTemplate(DWORD dwStyle, CRect& rect, CString strCaption, DWORD dwStyleEx = 0)
	{
		WORD* pTemp = m_pBuffer;
		DLGTEMPLATE* pDlgTemp = (DLGTEMPLATE*)pTemp;

		// 对话框模版
		pDlgTemp->style = dwStyle;
		pDlgTemp->dwExtendedStyle = dwStyleEx;
		pDlgTemp->cdit = 0;

		pDlgTemp->cx = rect.Width();
		pDlgTemp->cy = rect.Height();
		pDlgTemp->x = (short)rect.left;
		pDlgTemp->y = (short)rect.top;
		pTemp = (WORD*)(pDlgTemp + 1);

		// 菜单
		*pTemp++ = 0;
		// class
		*pTemp++ = 0;
		// caption
		CStringW wstrCaption = strCaption;
		wcscpy_s((WCHAR*)pTemp, strCaption.GetLength()+1, wstrCaption);
		pTemp += strCaption.GetLength() + 1;

		// 设置字体
		*pTemp++ = 8; // 字体大小
		wcscpy_s((WCHAR*)pTemp, wcslen(L"MS Shell Dlg") + 1, L"MS Shell Dlg"); // 字体名称
		pTemp += wcslen(L"MS Shell Dlg") + 1;


		return pDlgTemp;
	}
};

#endif // _CDLG_TEMPLATE_H