⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dynamicdialogtemplate.h

📁 一款最完整的工业组态软源代码
💻 H
📖 第 1 页 / 共 2 页
字号:
				// Default to "Static" control if no control class or atom is provided
				*pWordPtr++ = 0xFFFF;
				*pWordPtr++ = eClassAtom_Static;
			}

			// Title Array (text or resource id)
			if(text)
			{
				::CopyMemory(pWordPtr, text, textWordCount * sizeof(WORD));
				pWordPtr += textWordCount;

				// NOTE! "textWordCount" should include the
				//  terminating NUL (if its not a resource ID value)
			}
			else
			{
				// default to 0 length string
				*pWordPtr++ = 0;
			}

			// no creation data
			*pWordPtr++ = 0;

			m_bytesUsed = (size_t)((BYTE*)pWordPtr - (BYTE*)pDialogTemplate);

			::GlobalUnlock(m_hDialogTemplateMemory);
		}

		return true;
	}

	bool AddControl(
		    DWORD style, DWORD dwExtendedStyle,
			short x, short y, short cx, short cy,
			WORD id, const wchar_t* text,
			const wchar_t* classString)
	{
		return this->AddControl(style, dwExtendedStyle,
			x, y, cx, cy,
			id,
			text, text ? ::lstrlenW(text) + 1 : 0,
			classString, classString ? ::lstrlenW(classString) + 1 : 0);
	}
	bool AddControl(
		    DWORD style, DWORD dwExtendedStyle,
			const DynamicDialogItemSize dialogItemSize,
			WORD id, const wchar_t* text,
			const wchar_t* classString)
	{
		return this->AddControl(style, dwExtendedStyle,
			dialogItemSize.x, dialogItemSize.y, dialogItemSize.cx, dialogItemSize.cy,
			id,
			text, text ? ::lstrlenW(text) + 1 : 0,
			classString, classString ? ::lstrlenW(classString) + 1 : 0);
	}

	bool AddControl(
		    DWORD style, DWORD dwExtendedStyle,
			short x, short y, short cx, short cy,
			WORD id, const wchar_t* text,
			ClassAtom atom)
	{
		const long classAtomWordCount = 2;
		WORD classAtom[classAtomWordCount] = {0xFFFF, (WORD)atom};
		return this->AddControl(style, dwExtendedStyle,
			x, y, cx, cy,
			id,
			text, text ? ::lstrlenW(text) + 1 : 0,
			classAtom, classAtomWordCount);
	}
	bool AddControl(
		    DWORD style, DWORD dwExtendedStyle,
			const DynamicDialogItemSize dialogItemSize,
			WORD id, const wchar_t* text,
			ClassAtom atom)
	{
		const long classAtomWordCount = 2;
		WORD classAtom[classAtomWordCount] = {0xFFFF, (WORD)atom};
		return this->AddControl(style, dwExtendedStyle,
			dialogItemSize.x, dialogItemSize.y, dialogItemSize.cx, dialogItemSize.cy,
			id,
			text, text ? ::lstrlenW(text) + 1 : 0,
			classAtom, classAtomWordCount);
	}

	bool AddButtonControl(
		    DWORD style, DWORD dwExtendedStyle,
			short x, short y, short cx, short cy,
			WORD id, const wchar_t* text)
	{
		return this->AddControl(style, dwExtendedStyle, x, y, cx, cy,
			id, text, eClassAtom_Button);
	}
	bool AddButtonControl(
		    DWORD style, DWORD dwExtendedStyle,
			const DynamicDialogItemSize dialogItemSize,
			WORD id, const wchar_t* text)
	{
		return this->AddControl(style, dwExtendedStyle, dialogItemSize,
			id, text, eClassAtom_Button);
	}

	bool AddEditControl(
		    DWORD style, DWORD dwExtendedStyle,
			short x, short y, short cx, short cy,
			WORD id, const wchar_t* text)
	{
		return this->AddControl(style, dwExtendedStyle, x, y, cx, cy,
			id, text, eClassAtom_Edit);
	}
	bool AddEditControl(
		    DWORD style, DWORD dwExtendedStyle,
			const DynamicDialogItemSize dialogItemSize,
			WORD id, const wchar_t* text)
	{
		return this->AddControl(style, dwExtendedStyle, dialogItemSize,
			id, text, eClassAtom_Edit);
	}

	bool AddStaticControl(
		    DWORD style, DWORD dwExtendedStyle,
			short x, short y, short cx, short cy,
			WORD id, const wchar_t* text)
	{
		return this->AddControl(style, dwExtendedStyle, x, y, cx, cy,
			id, text, eClassAtom_Static);
	}
	bool AddStaticControl(
		    DWORD style, DWORD dwExtendedStyle,
			const DynamicDialogItemSize dialogItemSize,
			WORD id, const wchar_t* text)
	{
		return this->AddControl(style, dwExtendedStyle, dialogItemSize,
			id, text, eClassAtom_Static);
	}

	bool AddListBoxControl(
		    DWORD style, DWORD dwExtendedStyle,
			short x, short y, short cx, short cy,
			WORD id, const wchar_t* text)
	{
		return this->AddControl(style, dwExtendedStyle, x, y, cx, cy,
			id, text, eClassAtom_ListBox);
	}
	bool AddListBoxControl(
		    DWORD style, DWORD dwExtendedStyle,
			const DynamicDialogItemSize dialogItemSize,
			WORD id, const wchar_t* text)
	{
		return this->AddControl(style, dwExtendedStyle, dialogItemSize,
			id, text, eClassAtom_ListBox);
	}

	bool AddScrollBarControl(
		    DWORD style, DWORD dwExtendedStyle,
			short x, short y, short cx, short cy,
			WORD id, const wchar_t* text)
	{
		return this->AddControl(style, dwExtendedStyle, x, y, cx, cy,
			id, text, eClassAtom_ScrollBar);
	}
	bool AddScrollBarControl(
		    DWORD style, DWORD dwExtendedStyle,
			const DynamicDialogItemSize dialogItemSize,
			WORD id, const wchar_t* text)
	{
		return this->AddControl(style, dwExtendedStyle, dialogItemSize,
			id, text, eClassAtom_ScrollBar);
	}

	bool AddComboBoxControl(
		    DWORD style, DWORD dwExtendedStyle,
			short x, short y, short cx, short cy,
			WORD id, const wchar_t* text)
	{
		return this->AddControl(style, dwExtendedStyle, x, y, cx, cy,
			id, text, eClassAtom_ComboBox);
	}
	bool AddComboBoxControl(
		    DWORD style, DWORD dwExtendedStyle,
			const DynamicDialogItemSize dialogItemSize,
			WORD id, const wchar_t* text)
	{
		return this->AddControl(style, dwExtendedStyle, dialogItemSize,
			id, text, eClassAtom_ComboBox);
	}

	static inline unsigned short* Align_DWORD(unsigned short* pWordPtr)
	{
		ULONG ul = 3UL + PtrToUlong(pWordPtr);
		ul >>= 2;
		ul <<= 2;
		return (unsigned short*)ULongToPtr(ul);
	}
};

class CDynamicDialogExTemplate
{
};

// CDynamicDialogImpl is just like CDialogImpl, but it uses CDynamicDialogTemplate, and
//  DialogBoxIndirectParam instead of DialogBoxParam and
//  CreateDialogIndirectParam instead of CreateDialogParam

#if (_ATL_VER >= 0x0700)

// Important!  If ATL::CDialogImpl ever changes, reflect those changes here.
template <class T, class TBase = CWindow, class TDynamicDialogTemplate = CDynamicDialogTemplate>
class ATL_NO_VTABLE CDynamicDialogImpl : public CDialogImplBaseT< TBase >
{
protected:
	TDynamicDialogTemplate m_dynamicDialogTemplate;

public:
#ifdef _DEBUG
	bool m_bModal;
	CDynamicDialogImpl() : m_bModal(false) { }
#endif //_DEBUG
	// modal dialogs
	INT_PTR DoModal(HWND hWndParent = ::GetActiveWindow(), LPARAM dwInitParam = NULL)
	{
		ATLASSERT(m_hWnd == NULL);
		ATLASSERT((bool)m_dynamicDialogTemplate);
		_AtlWinModule.AddCreateWndData(&m_thunk.cd, (CDialogImplBaseT< TBase >*)this);
#ifdef _DEBUG
		m_bModal = true;
#endif //_DEBUG
		//return ::DialogBoxParam(_AtlBaseModule.GetResourceInstance(), MAKEINTRESOURCE(static_cast<T*>(this)->IDD),
		//			hWndParent, T::StartDialogProc, dwInitParam);
		return ::DialogBoxIndirectParam(_AtlBaseModule.GetResourceInstance(), m_dynamicDialogTemplate,
					hWndParent, T::StartDialogProc, dwInitParam);
	}
	BOOL EndDialog(int nRetCode)
	{
		ATLASSERT(::IsWindow(m_hWnd));
		ATLASSERT(m_bModal);	// must be a modal dialog
		return ::EndDialog(m_hWnd, nRetCode);
	}
	// modeless dialogs
	HWND Create(HWND hWndParent, LPARAM dwInitParam = NULL)
	{
		ATLASSERT(m_hWnd == NULL);
		ATLASSERT((bool)m_dynamicDialogTemplate);
		_AtlWinModule.AddCreateWndData(&m_thunk.cd, (CDialogImplBaseT< TBase >*)this);
#ifdef _DEBUG
		m_bModal = false;
#endif //_DEBUG
		//HWND hWnd = ::CreateDialogParam(_AtlBaseModule.GetResourceInstance(), MAKEINTRESOURCE(static_cast<T*>(this)->IDD),
		//			hWndParent, T::StartDialogProc, dwInitParam);
		HWND hWnd = ::CreateDialogIndirectParam(_AtlBaseModule.GetResourceInstance(), m_dynamicDialogTemplate,
					hWndParent, T::StartDialogProc, dwInitParam);
		ATLASSERT(m_hWnd == hWnd);
		return hWnd;
	}
	// for CComControl
	HWND Create(HWND hWndParent, RECT&, LPARAM dwInitParam = NULL)
	{
		return Create(hWndParent, dwInitParam);
	}
	BOOL DestroyWindow()
	{
		ATLASSERT(::IsWindow(m_hWnd));
		ATLASSERT(!m_bModal);	// must not be a modal dialog
		return ::DestroyWindow(m_hWnd);
	}
};

#endif // (_ATL_VER >= 0x0700)


#endif //__DynamicDialogTemplate_h__

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -