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

📄 resizedialog.h

📁 图像处理的压缩算法
💻 H
📖 第 1 页 / 共 2 页
字号:
		}
		return ny;
	}
	// return right of control
	
	/// ---- CPY 9/6/03 v7.5686 RESIZEING_CLEAN_UP
	BOOL OnMinMaxInfo(int &nMinTrackX, int &nMinTrackY)
	{
		nMinTrackY = GetTotalHeight(true);
		nMinTrackX = GetTotalWidth(true);
		return TRUE;
	}
	virtual BYTE GetPanelsOrientation()
	{
		return PANEL_ORIENT_NONE;
	}
	void DisableOnSize(bool bDisable = true)
	{
		m_bDoNotHandleOnSize = bDisable;
	}	
	int StretchControlHeight(uint nID, int nx, int ny, int cy, int nGap = -1)
	{
		Control btn = GetItem(nID);
		if(nGap < 0)
			nGap = m_nEdge;
		if(btn && btn.Visible)
		{
			RECT rr, r1;
			btn.GetWindowRect(&r1);
			rr.left = nx;
			rr.top = ny;
			rr.right = nx + RECT_WIDTH(r1);
			rr.bottom = cy - nGap;
			btn.MoveWindow(&rr, m_bRepaintWhenMove);
			nx = rr.right;
		}
		return nx;
	}
	int StretchControlLeftRight(uint nIDLeft, int nIDRight, int nx, int ny, int cx, int nGap = -1)
	{
		Control btnLeft = GetItem(nIDLeft);
		Control btnRight = GetItem(nIDRight);
		if(nGap < 0)
			nGap = m_nEdge;

		RECT rr,r1;
		int ncxReduction = 0, ny1 = 0;
		if(btnRight && btnRight.Visible)
		{
			btnRight.GetWindowRect(&r1);
			ncxReduction = RECT_WIDTH(r1);
			rr.right = cx - nGap;
			rr.left = rr.right - RECT_WIDTH(r1);
			rr.top = ny;
			rr.bottom = ny + RECT_HEIGHT(r1);
			btnRight.MoveWindow(&rr, m_bRepaintWhenMove);
			ny1 = rr.bottom;
		}
		cx -= ncxReduction;	
			
		if(btnLeft && btnLeft.Visible)
		{
			btnLeft.GetWindowRect(&r1);
			rr.left = nx;
			rr.top = ny;
			rr.right = cx - nGap;
			rr.bottom = ny + RECT_HEIGHT(r1);
			btnLeft.MoveWindow(&rr, m_bRepaintWhenMove);
			ny = rr.bottom;
		}
		return ny > ny1? ny:ny1;
	}
		
	// return the gap between controls that might be used by caller
	// for repositioning of other controls
	// bRight = true for arrange along the right edge, = false will arrange along bottom
	int ArrangeMainItemAndControls(uint nButtonIDs[], uint nMainItemID, bool bRight = true, int cx = 0, int cy = 0)
	{		
		RECT r1, r2;
		m_wndDlg.GetClientRect(&r1);
		if(0==cx)
			cx = RECT_WIDTH(r1);
		if(0==cy)
			cy = RECT_HEIGHT(r1);
		
		Button btn1 = GetItem(nButtonIDs[0]);
		btn1.GetWindowRect(&r1);
		int nBtnWidth = r1.right - r1.left;
		int nBtnHeight= r1.bottom - r1.top;
		m_wndDlg.ScreenToClient(&r1);
		int nEdge = m_nEdge;
		
		Control cMainItem = GetItem(nMainItemID);
		cMainItem.GetWindowRect(&r1);
		m_wndDlg.ScreenToClient(&r1);
		if(bRight)
		{
			r1.bottom = cy - nEdge;
			r1.right = cx - nBtnWidth - 2*nEdge;
		}
		else
		{
			r1.right = cx - nEdge;
			r1.bottom = cy - nBtnHeight - 2*nEdge;
		}
		
		cMainItem.MoveWindow(&r1, m_bRepaintWhenMove);
		
		int ii = 0;
		if(bRight)
		{
			r2.left = r1.right + nEdge;
			r2.top = nEdge;
			r2.right = r2.left + nBtnWidth;
			r2.bottom = r2.top + nBtnHeight;
		}
		else
		{
			r2.top = r1.bottom + nEdge;;
			r2.right = cx - nEdge;
			r2.left = r2.right - nBtnWidth;
			r2.bottom = cy - nEdge;
		}
		
		while(nButtonIDs[ii] > 0)
		{
			Control btn = GetItem(nButtonIDs[ii]);
			if(btn && btn.Visible)
			{
				btn.GetWindowRect(&r1);
				if(bRight)
				{
					r2.bottom = r2.top + RECT_HEIGHT(r1);
					btn.MoveWindow(&r2, m_bRepaintWhenMove);
					r2.top = r2.bottom + nEdge;
				}
				else
				{
					r2.left = r2.right - RECT_WIDTH(r1);
					btn.MoveWindow(&r2, m_bRepaintWhenMove);
					r2.right = r2.left - nEdge;
				}
			}
			ii++;
		}
		return nEdge;
	}
	void ResizeDlgToBottomOfControl(int nID)
	{
		RECT r1, rtDlg;
		m_wndDlg.GetWindowRect(&rtDlg);
		m_wndDlg.ScreenToClient(&rtDlg);
		Control cc = GetItem(nID);
		cc.GetWindowRect(&r1);
		m_wndDlg.ScreenToClient(&r1);
		rtDlg.bottom = r1.bottom + r1.left; // assume item is next to edge so can use left as gap to bottom
		m_wndDlg.ClientToScreen(&rtDlg);	
		m_wndDlg.MoveWindow(&rtDlg);
	}
	//nRefID to be used to measure the gap between controls, m_nEdge
	BOOL OnInitDialog(int nRefID = 0)
	{
		m_wndDlg = GetWindow();
		m_nEdge = GetSystemMetrics(SM_CXSIZEFRAME);
		if(nRefID)
		{
			RECT r1;
			if(GetControlClientRect(nRefID, r1))
				m_nEdge = r1.left;
		}
		SaveDlgHeight();//--- CPY 9/6/03 v7.5686 RESIZEING_CLEAN_UP
		return TRUE;
	}
	void UpdateWindow(bool bInvalidate = true)
	{
		if(bInvalidate)
			InvalidateRect(GetSafeHwnd(), NULL, TRUE);
		UpdateWindow(GetSafeHwnd());
	}
private:
	// x y factor, ignore if = 0
	// otherwise compare with screen after using factor as ratio
	bool isDlgSmallerThenScreen(double xFactor, double yFactor)
	{
		bool bXSmaller = xFactor == 0 || xFactor * GetSystemMetrics(SM_CXSCREEN) > GetDlgExtent(false) ? true:false;
		bool bYSmaller = yFactor == 0 || yFactor * GetSystemMetrics(SM_CYSCREEN) > GetDlgExtent(true) ? true:false;
		return bXSmaller && bYSmaller ? true:false;
	}
	/////////// checkbox and save/restore
	void rememberCheckBoxes(LPCSTR lpcszDlgName, int nID1, int nID2 = 0, int nID3 = 0, int nID4 = 0, int nID5 = 0, int nID6 = 0, int nID7 = 0, int nID8 = 0)
	{
		m_strRegSectionCheckBoxesName = lpcszDlgName;
		m_vnCheckBoxIDs.SetSize(0);
		m_vnCheckBoxIDs.Add(nID1);
		if(nID2)
		{
			m_vnCheckBoxIDs.Add(nID2);
			if(nID3)
			{
				m_vnCheckBoxIDs.Add(nID3);
				if(nID4)
				{
					m_vnCheckBoxIDs.Add(nID4);
					if(nID5)
					{
						m_vnCheckBoxIDs.Add(nID5);
						if(nID6)
						{
							m_vnCheckBoxIDs.Add(nID6);
							if(nID7)
							{
								m_vnCheckBoxIDs.Add(nID7);
								if(nID8)
									m_vnCheckBoxIDs.Add(nID8);
							}
						}
					}
				}
						
			}
		}
	}
	// width and height of a group of controls
	// based on [0] item
	int getControlGroupExtent(uint nIDs[], bool bWidth)
	{
		if(NULL == nIDs)
			return 0;
		
		int nCntrlID = nIDs[0];
		if(nCntrlID)
		{
			Control cntrl = GetItem(nCntrlID);
			if(cntrl)
			{
				RECT rect;
				cntrl.GetWindowRect(&rect);
				if(bWidth)
					return RECT_WIDTH(rect);
				else
					return RECT_HEIGHT(rect);
			}
		}
		return 0;
	}
	//---- CPY 9/6/03 v7.5686 RESIZEING_CLEAN_UP
	int getNumOfPanels()
	{
		return m_nNumPanels;
	}
	bool resizePanelsOnDlgResize(int cx, int cy)
	{
		if(m_bDoNotHandleOnSize)
			return false;

		BYTE bOrient = GetPanelsOrientation();
		int  nExpand = 0;
		if(bOrient == PANEL_ORIENT_VERTICAL)
			nExpand = cy - m_nDlgHight;
		else
		{
			return false; // later, other orientation
		}
		if(0 == nExpand)
			return true;
		int  nDenom = 0;
		int nSizeDiff[MAX_ALLOWED_PANELS];
		int	nOldHeight[MAX_ALLOWED_PANELS];
		for(int ii = 0; ii < getNumOfPanels(); ii++)
		{
			nSizeDiff[ii] = m_parrPanels[ii]->IsResize(nExpand > 0?true:false)? 1:0;
			nOldHeight[ii] = m_parrPanels[ii]->GetHeight();
			if(nSizeDiff[ii])
				nDenom += nOldHeight[ii];
		}
		if(nDenom <= 0)
			return false; // nothing to do
		double dDenom = nDenom;
		for(ii = 0; ii < getNumOfPanels(); ii++)
		{
			if(nSizeDiff[ii])
				nSizeDiff[ii] = nExpand * nOldHeight[ii]/dDenom;
		} 
		for(ii = 0; ii < getNumOfPanels(); ii++)
		{
			if(nSizeDiff[ii])
			{
				if(PANEL_ORIENT_VERTICAL == bOrient)
					m_parrPanels[ii]->SetHeight(nOldHeight[ii] + nSizeDiff[ii]); 
				else
				{
					// later, other orientation
				}
			}
		}
		return true;
	}
	//---- end CPY 9/6/03 v7.5686 RESIZEING_CLEAN_UP
protected:
	void LoadCheckBoxSettings(LPCSTR lpcszDlgName, int nID1, int nID2 = 0, int nID3 = 0, int nID4 = 0, int nID5 = 0, int nID6 = 0, int nID7 = 0, int nID8 = 0)
	{
		rememberCheckBoxes(lpcszDlgName, nID1, nID2, nID3, nID4, nID5, nID6, nID7, nID8);
		
		if(m_vnCheckBoxIDs.GetSize() > 0 && !m_strRegSectionCheckBoxesName.IsEmpty())
		{
			vector<byte> vbCheckSettings;
			if(load_default_checkboxes(m_strRegSectionCheckBoxesName, vbCheckSettings))
			{
				bool bCheck;
				for(int ii = 0; ii < m_vnCheckBoxIDs.GetSize(); ii++)
				{
					if(ii < vbCheckSettings.GetSize())
						bCheck = vbCheckSettings[ii];
					else
						bCheck = false;
					
					Button btnCheck = m_wndDlg.GetDlgItem(m_vnCheckBoxIDs[ii]);
					if(btnCheck)
						btnCheck.Check = bCheck;
				}
			}
		}
	}
	void SaveSizeOfPanels()
	{
		for(int ii = 0; ii < getNumOfPanels(); ii++)
		{
			string strClassName 	= m_parrPanels[ii]->GetRuntimeClass();
			SaveSetting(strClassName, m_parrPanels[ii]->GetHeight());
		}
	}
	void LoadSizeOfPanels()
	{
		for(int ii = 0; ii < getNumOfPanels(); ii++)
		{
			string strClassName 	= m_parrPanels[ii]->GetRuntimeClass();
			int nDefaultSize 	= m_parrPanels[ii]->GetHeight(true);
				
			m_parrPanels[ii]->SetHeight(LoadSetting(strClassName, nDefaultSize));
		}
		
		m_bDoNotHandleOnSize = false;// OK to allow OnSize handling now
	}
	void SaveCheckBoxSettings()
	{
		if(m_vnCheckBoxIDs.GetSize() > 0 && !m_strRegSectionCheckBoxesName.IsEmpty())
		{
			vector<byte> vbCheckSettings;
			bool bCheck = false;
			for(int ii = 0; ii < m_vnCheckBoxIDs.GetSize(); ii++)
			{
				Button btnCheck = m_wndDlg.GetDlgItem(m_vnCheckBoxIDs[ii]);
				if(btnCheck)
					bCheck = btnCheck.Check;
				else
					bCheck = false;
				vbCheckSettings.Add(bCheck);
			}
			save_default_checkboxes(m_strRegSectionCheckBoxesName, vbCheckSettings);
		}
	}
	// if called after LoadCheckBoxSettings, can skip lpcszDlgName
	DWORD LoadSetting(LPCSTR lpcszValName, DWORD dwDefault = 0, LPCSTR lpcszDlgName = NULL)
	{
		string strSecName = lpcszValName;
		if(strSecName.IsEmpty())
			strSecName = m_strRegSectionCheckBoxesName;
		
		DWORD dwVal = dwDefault;
		if(dlg_load_registry(strSecName, lpcszValName, dwVal))
			return dwVal;
		
		return dwDefault;
	}
	void SaveSetting(LPCSTR lpcszValName, DWORD dwVal, LPCSTR lpcszDlgName = NULL)
	{
		string strSecName = lpcszValName;
		if(strSecName.IsEmpty())
			strSecName = m_strRegSectionCheckBoxesName;
		
		dlg_save_to_registry(strSecName, lpcszValName, dwVal);
	}
private:
	int				m_nEdge;
	vector<uint>	m_vnCheckBoxIDs; // connect to registry
	string			m_strRegSectionCheckBoxesName;// for saving and reading bits
	bool			m_bRepaintWhenMove;
	/// ---- TD 8-26-03 RESIZING
	bool	m_bDoNotHandleOnSize;	
	int		m_nDlgHight;
	int		m_nNumPanels;
	ResizeControl *m_parrPanels[MAX_ALLOWED_PANELS];	/// ---- TD 8-26-03 RESIZING
	/// ----
protected:
	Window	m_wndDlg;
	
};

⌨️ 快捷键说明

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