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

📄 aaadlg.cpp

📁 这是书上的代码
💻 CPP
字号:
// vcd2mpgDlg.cpp : implementation file
//

#include "stdafx.h"
#include "aaa.h"
#include "aaadlg.h"
#include "time.h"
#include "stdio.h"
#include "stdlib.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CAaaDlg dialog

#define HORIZONTAL	0
#define VERTICAL	1

CAaaDlg::CAaaDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CAaaDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CAaaDlg)
	m_wHeight = 0;
	m_wStreamID = 0;
	m_wWidth = 0;
	m_wSequenceOrder = 0;
	m_dwMaxRate = 0;
	m_dwMinRate = 0;
	m_wHeight2 = 0;
	m_dwMaxRate2 = 0;
	m_dwMinRate2 = 0;
	m_wSequenceOrder2 = 0;
	m_wStreamID2 = 0;
	m_wWidth2 = 0;
	m_bHorizontal = FALSE;
	m_bVertical = FALSE;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

	m_wOrigrinWidth=0;
	m_wReducedWidth=0;

	m_wOrigrinHeight=0;
	m_wReducedHeight=0;

	m_maxRange=100;
}

CAaaDlg::~CAaaDlg()
{
}

void CAaaDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAaaDlg)
	DDX_Text(pDX, IDC_HEIGHT, m_wHeight);
	DDX_Text(pDX, IDC_STREAM_ID, m_wStreamID);
	DDX_Text(pDX, IDC_WIDTH, m_wWidth);
	DDX_Text(pDX, IDC_SEQUENCE_ORDER, m_wSequenceOrder);
	DDX_Text(pDX, IDC_MAX_RATE, m_dwMaxRate);
	DDX_Text(pDX, IDC_MIN_RATE, m_dwMinRate);
	DDX_Text(pDX, IDC_HEIGHT2, m_wHeight2);
	DDX_Text(pDX, IDC_MAX_RATE2, m_dwMaxRate2);
	DDX_Text(pDX, IDC_MIN_RATE2, m_dwMinRate2);
	DDX_Text(pDX, IDC_SEQUENCE_ORDER2, m_wSequenceOrder2);
	DDX_Text(pDX, IDC_STREAM_ID2, m_wStreamID2);
	DDX_Text(pDX, IDC_WIDTH2, m_wWidth2);
	DDX_Check(pDX, IDC_HORIZONTAL, m_bHorizontal);
	DDX_Check(pDX, IDC_VERTICAL, m_bVertical);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAaaDlg, CDialog)
	//{{AFX_MSG_MAP(CAaaDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_BN_CLICKED(IDC_HORIZONTAL, OnHorizontal)
	ON_BN_CLICKED(IDC_VERTICAL, OnVertical)
	ON_BN_CLICKED(IDC_BEGIN_SIMULATE, OnBeginSimulate)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CAaaDlg message handlers
BOOL CAaaDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	CenterWindow(NULL);

	m_screenWidth  = GetSystemMetrics(SM_CXSCREEN);
	m_screenHeight = GetSystemMetrics(SM_CYSCREEN);

	WINDOWPLACEMENT* lpwndpl=new WINDOWPLACEMENT;
	GetWindowPlacement(lpwndpl);
	m_wOrigrinWidth  = lpwndpl->rcNormalPosition.right;
	m_wOrigrinWidth -= lpwndpl->rcNormalPosition.left;
	m_wOrigrinHeight  = lpwndpl->rcNormalPosition.bottom;
	m_wOrigrinHeight -= lpwndpl->rcNormalPosition.top;
	
	LPRECT lpRect1,lpRect2;
	lpRect1=new RECT;
	lpRect2=new RECT;
	GetDlgItem(IDC_PROGRESS_BAR)->GetWindowRect(lpRect1);
	GetDlgItem(IDC_STREAM_ID)->GetWindowRect(lpRect2);
		
	lpwndpl->rcNormalPosition.right=(lpRect1->right+lpRect2->left)/2;
	m_wReducedWidth  = lpwndpl->rcNormalPosition.right;
	m_wReducedWidth -= lpwndpl->rcNormalPosition.left;

	GetDlgItem(IDC_PROGRESS_BAR)->GetWindowRect(lpRect1);
	GetDlgItem(IDC_SEQUENCE_ORDER2)->GetWindowRect(lpRect2);
	lpwndpl->rcNormalPosition.bottom=(lpRect1->bottom+lpRect2->top)/2;
	m_wReducedHeight  = lpwndpl->rcNormalPosition.bottom;
	m_wReducedHeight -= lpwndpl->rcNormalPosition.top;

	delete lpRect1;
	delete lpRect2;

	if(m_bHorizontal == TRUE)
	{
		lpwndpl->rcNormalPosition.right  = lpwndpl->rcNormalPosition.left;
		lpwndpl->rcNormalPosition.right += m_wOrigrinWidth;

		lpwndpl->rcNormalPosition.bottom  = lpwndpl->rcNormalPosition.top;
		lpwndpl->rcNormalPosition.bottom += m_wReducedHeight;
	}
	else
	{
		lpwndpl->rcNormalPosition.right  = lpwndpl->rcNormalPosition.left;
		lpwndpl->rcNormalPosition.right += m_wReducedWidth;

		lpwndpl->rcNormalPosition.bottom  = lpwndpl->rcNormalPosition.top;
		lpwndpl->rcNormalPosition.bottom += m_wReducedHeight;
	}

	if(m_bVertical == TRUE)
	{
		lpwndpl->rcNormalPosition.right  = lpwndpl->rcNormalPosition.left;
		lpwndpl->rcNormalPosition.right += m_wReducedWidth;

		lpwndpl->rcNormalPosition.bottom  = lpwndpl->rcNormalPosition.top;
		lpwndpl->rcNormalPosition.bottom += m_wOrigrinHeight;
	}
	else
	{
		lpwndpl->rcNormalPosition.right  = lpwndpl->rcNormalPosition.left;
		lpwndpl->rcNormalPosition.right += m_wReducedWidth;

		lpwndpl->rcNormalPosition.bottom  = lpwndpl->rcNormalPosition.top;
		lpwndpl->rcNormalPosition.bottom += m_wReducedHeight;
	}

	SetWindowPlacement(lpwndpl);

	m_pProgressCtrl=(CProgressCtrl*)GetDlgItem(IDC_PROGRESS_BAR);
	m_pProgressCtrl->SetRange(0,m_maxRange);

	this->SetWindowText("  伸展自如的对话框");

	SetDlgItemText(IDC_STATIC11,"Now Waiting ...");
	SetDlgItemText(IDC_WELCOME,"欢迎使用");

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon

	UpdateData(FALSE);

	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CAaaDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CAaaDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CAaaDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CAaaDlg::OnOK() 
{
	// TODO: Add extra validation here
	UpdateData(TRUE);

	CDialog::OnOK();
}

void CAaaDlg::OnHorizontal() 
{
	// TODO: Add your control notification handler code here
	m_bHorizontal = !m_bHorizontal;

	UpdateData(FALSE);

	WINDOWPLACEMENT* lpwndpl=new WINDOWPLACEMENT;
	GetWindowPlacement(lpwndpl);

	if(m_bHorizontal == TRUE)
	{
		lpwndpl->rcNormalPosition.right  = lpwndpl->rcNormalPosition.left;
		lpwndpl->rcNormalPosition.right += m_wOrigrinWidth;
/*
		lpwndpl->rcNormalPosition.bottom  = lpwndpl->rcNormalPosition.top;
		lpwndpl->rcNormalPosition.bottom += m_wReducedHeight;
*/
	}
	else
	{
		lpwndpl->rcNormalPosition.right  = lpwndpl->rcNormalPosition.left;
		lpwndpl->rcNormalPosition.right += m_wReducedWidth;
/*
		lpwndpl->rcNormalPosition.bottom  = lpwndpl->rcNormalPosition.top;
		lpwndpl->rcNormalPosition.bottom += m_wReducedHeight;
*/
	}

	SetWindowPlacement(lpwndpl);

	delete lpwndpl;

}

void CAaaDlg::OnVertical() 
{
	// TODO: Add your control notification handler code here
	m_bVertical = !m_bVertical;

	UpdateData(FALSE);

	WINDOWPLACEMENT* lpwndpl=new WINDOWPLACEMENT;
	GetWindowPlacement(lpwndpl);

	if(m_bVertical == TRUE)
	{
/*
		lpwndpl->rcNormalPosition.right  = lpwndpl->rcNormalPosition.left;
		lpwndpl->rcNormalPosition.right += m_wReducedWidth;
*/

		lpwndpl->rcNormalPosition.bottom  = lpwndpl->rcNormalPosition.top;
		lpwndpl->rcNormalPosition.bottom += m_wOrigrinHeight;
	}
	else
	{
/*
		lpwndpl->rcNormalPosition.right  = lpwndpl->rcNormalPosition.left;
		lpwndpl->rcNormalPosition.right += m_wReducedWidth;
*/

		lpwndpl->rcNormalPosition.bottom  = lpwndpl->rcNormalPosition.top;
		lpwndpl->rcNormalPosition.bottom += m_wReducedHeight;
	}

	SetWindowPlacement(lpwndpl);

	delete lpwndpl;
}

void CAaaDlg::OnBeginSimulate() 
{
	// TODO: Add your control notification handler code here
	srand((unsigned)time(NULL));

	char temp[10];

	SetDlgItemText(IDC_STATIC11,"Now Beginning ...");
	for(int i=0;i<m_maxRange;i++)
	{
		m_pProgressCtrl->SetPos(i);
		m_wSequenceOrder = m_wSequenceOrder2 = i;
		m_wStreamID = m_wStreamID2 = rand();
		m_wHeight = m_wHeight2 = rand();
		m_wWidth = m_wWidth2 = rand();
		m_dwMaxRate = m_dwMaxRate2 = rand();
		m_dwMinRate = m_dwMinRate2 = rand();
		switch(i%4)
		{
		case 0:
			sprintf(temp,"欢 迎 使 用");
			break;
		case 1:
			sprintf(temp,"迎 使 用 欢");
			break;
		case 2:
			sprintf(temp,"使 用 欢 迎");
			break;
		case 3:
			sprintf(temp,"用 欢 迎 使");
			break;
		}
		SetDlgItemText(IDC_WELCOME,temp);
		UpdateData(FALSE);
		UpdateWindow();
		Sleep(50);
	}
	SetDlgItemText(IDC_WELCOME,"欢 迎 使 用");
	SetDlgItemText(IDC_STATIC11,"Now Finnished ...");
}

⌨️ 快捷键说明

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