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

📄 constrain.h

📁 实时监控
💻 H
字号:
#ifndef _CONSTRAIN_H
#define _CONSTRAIN_H

template<class T>
class constrain: public T
{
public:
	enum CONSTRAIN_SIDES
	{
		NONE	= 0,

		LEFT	= 1,
		RIGHT	= 2,
		HORZ	= 3,

		TOP		= 4,
		BOTTOM	= 8,
		VERT	= 12,
		
		CLIENT	= 15,
	};

	constrain():l(0), r(0), t(0), b(0), w(0), h(0), sides(NONE)
	{
	}
	constrain& set_cons(int s, bool update = true)
	{
		sides = s;
		if( update )
			update_cons();

		return *this;
	}
	CONSTRAIN_SIDES get_cons() const {return sides;}
	constrain& save_cons()
	{
		CRect rc;
		CRect rcp;
		GetWindowRect(rc);
		GetParent()->GetClientRect(rcp);
		GetParent()->ClientToScreen(rcp);
		
		w = rc.Width();
		h = rc.Height();
		
		l = rc.left - rcp.left;
		r = rcp.right - rc.right;
		t = rc.top - rcp.top;
		b = rcp.bottom - rc.bottom;
		
		return *this;
	}
	constrain& update_cons()
	{
		if( !IsWindow(m_hWnd) )
			return *this;
		
		CRect rc(0, 0, w, h);
		CRect rcp;
//		GetWindowRect(rc);
//		GetParent()->ScreenToClient(rc);
		GetParent()->GetClientRect(rcp);

		if( sides & LEFT )
		{
			rc.left = rcp.left + l;
			rc.right = rc.left + w;
		}
		if( sides & RIGHT )
		{
			rc.right = rcp.right - r;
			if( (sides & LEFT) == 0 )
				rc.left = rc.right - w;
		}
		if( sides & TOP )
		{
			rc.top = rcp.top + t;
			rc.bottom = rc.top + h;
		}
		if( sides & BOTTOM )
		{
			rc.bottom = rcp.bottom - b;
			if( (sides & TOP) == 0 )
				rc.top = rc.bottom - h;
		}
		MoveWindow(rc);

		return *this;
	}
private:
	int l;
	int r;
	int t;
	int b;
	int w;
	int h;
	int sides;
};

#endif

⌨️ 快捷键说明

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