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

📄 tabctrlex.hpp

📁 j2me is based on j2mepolish, client & server for mobile application.
💻 HPP
字号:

//         Copyright E骾n O'Callaghan 2006 - 2007.
// Distributed under the Boost Software License, Version 1.0.
//    (See accompanying file LICENSE_1_0.txt or copy at
//          http://www.boost.org/LICENSE_1_0.txt)

#ifndef TAB_CTRLEX_HPP_INCLUDED
#define TAB_CTRLEX_HPP_INCLUDED

#include "StdAfx.hpp"

#include "TabPage.hpp"

namespace WTLx
{

class TabCtrlEx : 
	public ATL::CWindowImpl<TabCtrlEx, WTL::CTabCtrl>,
	public WTL::CMessageFilter
{
	typedef TabCtrlEx thisClass;
	typedef ATL::CWindowImpl<thisClass, WTL::CTabCtrl> implClass;

	struct TabPage
	{
		TabPage() :
			hWnd(0),
			msgFilter(NULL)
		{}

		template <class T>
		TabPage(TabPageImpl<T>& tabPage) :
			hWnd(tabPage),
			msgFilter(&tabPage)
		{}

		HWND hWnd;
		WTL::CMessageFilter* msgFilter;
	};

public:
	TabCtrlEx() :
		currentPage_(0)
	{}

    BEGIN_MSG_MAP_EX(TabCtrlEx)
		MSG_WM_SIZE(OnSize)

		REFLECTED_NOTIFY_CODE_HANDLER_EX(TCN_SELCHANGE, OnSelChange)

        DEFAULT_REFLECTION_HANDLER()
    END_MSG_MAP()

	virtual BOOL PreTranslateMessage(MSG* pMsg)
	{
		if (::IsWindow(m_hWnd))
		{
			assert(pages_[GetCurSel()].msgFilter);
		
			return pages_[GetCurSel()].msgFilter->PreTranslateMessage(pMsg);
		}

		return false;
	}

	void Attach(HWND hWndNew)
	{
		ATLASSERT(::IsWindow(hWndNew));
        implClass::SubclassWindow(hWndNew);
	}

	void SetCurrentPage(unsigned index)
	{
		if (currentPage_)
			::ShowWindow(currentPage_, SW_HIDE);

		if (!pages_.empty())
		{
			currentPage_ = pages_[index].hWnd;
			::ShowWindow(currentPage_, SW_SHOW);

			RECT rect;
			GetClientRect(&rect);
			AdjustRect(false, &rect);

			::SetWindowPos(currentPage_, HWND_TOP, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top, 0);
		}
	}

	LRESULT OnSelChange(LPNMHDR lpHdr)
	{
		SetCurrentPage(GetCurSel());

		return 0;
	}

	void OnSize(UINT, WTL::CSize)
	{
		WTL::CRect rect;
		GetClientRect(rect);
		AdjustRect(false, rect);

		::MoveWindow(currentPage_, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top, true);
	}

	template <class T>
	void AddPage(TabPageImpl<T>& tabPage, std::wstring wndText)
	{
		TCITEM tie = { TCIF_TEXT, 0, 0, const_cast<wchar_t*>(wndText.c_str()), 0, -1, 0 };
		InsertItem(pages_.size(), &tie);

		pages_.push_back(TabPage(tabPage));
	}

	HWND GetCurrentPage() const	{ return currentPage_; }

protected:
	std::vector<TabPage> pages_;
	HWND currentPage_;
};

}

#endif // TAB_CTRLEX_HPP_INCLUDED

⌨️ 快捷键说明

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