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

📄 winctrl.cpp

📁 使用visual c++实现的usbview
💻 CPP
字号:
// WinCtrl.cpp : implementation file
//

#include "stdafx.h"
#include "WinCtrl.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// 表示可改变大小的图标ID
#ifndef OBM_SIZE
#define OBM_SIZE 32766
#endif

/////////////////////////////////////////////////////////////////////////////
// CWinCtrl dialog


CWinCtrl::CWinCtrl(CWnd* pParent /*=NULL*/)
	: CDialog(CWinCtrl::IDD, pParent)
{
	//{{AFX_DATA_INIT(CWinCtrl)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}

CWinCtrl::CWinCtrl(UINT nID, CWnd* pParent /*=NULL*/) : CDialog(nID, pParent)
, m_iClientWidth(0),
m_iClientHeight(0),
m_iMinWidth(0),
m_iMinHeight(0),
m_pControlArray(NULL),
m_iControlNumber(0),
m_bShowSizeIcon(TRUE)
{}
void CWinCtrl::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CWinCtrl)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CWinCtrl, CDialog)
	//{{AFX_MSG_MAP(CWinCtrl)
		// NOTE: the ClassWizard will add message map macros here
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CWinCtrl message handlers
BOOL CWinCtrl::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	// 设置对话框为可变大小的
	ModifyStyle(0, WS_SIZEBOX);
	
	// 以对话框的初始大小作为对话框的宽度和高度的最小值
	CRect rectDlg;
	GetWindowRect(rectDlg);
	m_iMinWidth = rectDlg.Width();
	m_iMinHeight = rectDlg.Height();
	
	// 得到对话框client区域的大小 
	CRect rectClient;
	GetClientRect(rectClient);
	m_iClientWidth = rectClient.Width();
	m_iClientHeight = rectClient.Height();
	
	// Load图标
	m_bmpSizeIcon.LoadOEMBitmap(OBM_SIZE);
	m_bmpSizeIcon.GetBitmap(&m_bitmap);
	
	// 创建显示图标的静态控件并放在对话框右下角
	m_wndSizeIcon.Create(NULL, WS_CHILD | WS_VISIBLE | SS_BITMAP, CRect(0, 0, m_bitmap.bmWidth, m_bitmap.bmHeight), this, 0);
	m_wndSizeIcon.SetBitmap(m_bmpSizeIcon);
	m_wndSizeIcon.MoveWindow(m_iClientWidth - m_bitmap.bmWidth, m_iClientHeight - m_bitmap.bmHeight, m_bitmap.bmWidth, m_bitmap.bmHeight);
	
	// 显示图标
	m_wndSizeIcon.ShowWindow(m_bShowSizeIcon);
	
	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}
void CWinCtrl::OnCancelMode() 
{
	CDialog::OnCancelMode();
	
	// TODO: Add your message handler code here
	
}

void CWinCtrl::OnCaptureChanged(CWnd *pWnd) 
{
	// TODO: Add your message handler code here
	
	CDialog::OnCaptureChanged(pWnd);
}

void CWinCtrl::OnSizing(UINT nSide, LPRECT lpRect)
{
	CDialog::OnSizing(nSide, lpRect);
	
	// 对话框不能小于初始大小
	
	int iWidth = lpRect->right - lpRect->left;
	int iHeight = lpRect->bottom - lpRect->top;
	
	if (iWidth <= m_iMinWidth)
		lpRect->right = lpRect->left + m_iMinWidth;
	
	if(iHeight <= m_iMinHeight)
		lpRect->bottom = lpRect->top + m_iMinHeight;
}

BOOL CWinCtrl::SetControlProperty(PDLGCTLINFO lp, int nElements)
{
	// 设置控件数组信息
	
	if (NULL == lp)
		return FALSE;
	
	if (nElements <= 0)
		return FALSE;
	
	m_pControlArray = lp;
	m_iControlNumber = nElements;
	
	return TRUE;
}

void CWinCtrl::OnSize(UINT nType, int cx, int cy) 
{
	CDialog::OnSize(nType, cx, cy);
	
	// 对话框宽度和高度的增量 
	int iIncrementX = cx - m_iClientWidth;
	int iIncrementY = cy - m_iClientHeight;
	
	// 最小化时增量为0
	if (nType == SIZE_MINIMIZED)
	{
		iIncrementX = iIncrementY = 0;
	}
	
	for (int i = 0; i < m_iControlNumber; i++)
	{
		CWnd *pWndCtrl = NULL;
		
		int iId = m_pControlArray[i].iId;
		int iFlag = m_pControlArray[i].iFlag;
		int iPercent = m_pControlArray[i].iPercent;
		
		// 无效值
		if ((iPercent < 0) || (iPercent > 100))
			continue;
		
		// 得到控件指针
		pWndCtrl = GetDlgItem(iId);
		if ((NULL != pWndCtrl) && IsWindow(pWndCtrl->GetSafeHwnd()))
		{
			CRect rectCtrl;
			pWndCtrl->GetWindowRect(rectCtrl);
			
			ScreenToClient(rectCtrl);
			
			int iLeft = rectCtrl.left;
			int iTop = rectCtrl.top;
			int iWidth = rectCtrl.Width();
			int iHeight = rectCtrl.Height();
			
			switch (iFlag)
			{
			case MOVEX: // X方向移动
				iLeft += (iIncrementX * iPercent / 100);
				break;
				
			case MOVEY: // Y方向移动
				iTop += (iIncrementY * iPercent / 100);
				break;
				
			case MOVEXY: // X方向和Y方向同时移动
				iLeft += (iIncrementX * iPercent / 100);
				iTop += (iIncrementY * iPercent / 100);
				break;
				
			case ELASTICX: // X方向改变大小
				iWidth += (iIncrementX * iPercent / 100);
				break;
				
			case ELASTICY: // Y方向改变大小
				iHeight += (iIncrementY * iPercent / 100);
				break;
				
			case ELASTICXY: // X方向和Y方向同时改变大小
				iWidth += (iIncrementX * iPercent / 100);
				iHeight += (iIncrementY * iPercent / 100);
				break;
				
			default:
			;
			}
			
			// 把控件移动到新位置
			pWndCtrl->MoveWindow(iLeft, iTop, iWidth, iHeight);
		}
	}
	
	// 把图标移动到对话框右下角
	if (IsWindow(m_wndSizeIcon.GetSafeHwnd()))
		m_wndSizeIcon.MoveWindow(cx - m_bitmap.bmWidth, cy - m_bitmap.bmHeight, m_bitmap.bmWidth, m_bitmap.bmHeight);
	
	// 记录对话框client区域的大小
	if (nType != SIZE_MINIMIZED)
	{
		m_iClientWidth = cx;
		m_iClientHeight = cy;
	}
}

void CWinCtrl::ShowSizeIcon(BOOL bShow /*=NULL*/)
{
	m_bShowSizeIcon = bShow;
}

⌨️ 快捷键说明

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