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

📄 wizard.cpp

📁 用VC 语言编写可以任意改变按钮的形状和颜色
💻 CPP
字号:
// Wizard.cpp : implementation file
//

#include "stdafx.h"
#include "CustomWizard.h"
#include "Wizard.h"
#include "Step1.h"

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

/////////////////////////////////////////////////////////////////////////////
// CWizard dialog


CWizard::CWizard(CWnd* pParent /*=NULL*/)
	: CDialog(CWizard::IDD, pParent)
{
	//{{AFX_DATA_INIT(CWizard)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	pPageLink=NULL;
	nPageCount=0;
	nCurrentPage=0;
	
}


void CWizard::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CWizard)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CWizard, CDialog)
	//{{AFX_MSG_MAP(CWizard)
	ON_BN_CLICKED(IDC_PREV, OnPrev)
	ON_BN_CLICKED(IDC_NEXT, OnNext)
	ON_BN_CLICKED(IDC_FINISH, OnFinish)
	ON_BN_CLICKED(IDC_CANCEL, OnCancel)
	ON_WM_DESTROY()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CWizard message handlers

void CWizard::AddPage(CDialog* pDialog, UINT nID)
{
	struct PAGELINK* pTemp = pPageLink;
	//插入新生成的结点
	struct PAGELINK* pNewPage = new PAGELINK;
	pNewPage->pDialog = pDialog;
	pNewPage->pDialog->Create(nID,this);
	
	// Is window created
	ASSERT(::IsWindow(pNewPage->pDialog->m_hWnd));
    // 检查每页的样式
	DWORD dwStyle = pNewPage->pDialog->GetStyle();
	ASSERT((dwStyle & WS_CHILD) != 0); //子窗体
	ASSERT((dwStyle & WS_BORDER) == 0); //无边界
	//显示
	pNewPage->pDialog->ShowWindow(SW_HIDE);
	pNewPage->pDialog->MoveWindow(rectPage);
	/*pNewPage->pDialog->SetWindowPos(&CWnd::wndTop,
		rectPage.left,rectPage.top,
		rectPage.Width(),rectPage.Height(),
		SWP_NOMOVE);*/
	pNewPage->Next=NULL;
	pNewPage->nNum=++nPageCount; //计数器加1
	if (pTemp)
	{
		while (pTemp->Next) pTemp=pTemp->Next; //移动链表末尾
		pTemp->Next=pNewPage;

	}
	else
		pPageLink=pNewPage; //若是第一个接点
}



void CWizard::OnCancel() 
{
	// TODO: Add your control notification handler code here
	if (AfxMessageBox(IDS_QUIT,MB_OKCANCEL|MB_ICONQUESTION)==IDCANCEL)
		return;   
	CDialog::OnCancel();
}

void CWizard::OnPrev() 
{
	// TODO: Add your control notification handler code here
	ShowPage(--nCurrentPage);
}

void CWizard::OnNext() 
{
	// TODO: Add your control notification handler code here

	ShowPage(++nCurrentPage);
}

void CWizard::OnFinish() 
{
	// TODO: Add your control notification handler code here
	AfxMessageBox("采用默认值完成向导");
	CDialog::OnOK();
}



void CWizard::ShowPage(UINT nPos)
{
	struct PAGELINK* pTemp=pPageLink;
	while(pTemp)
	{
		if (pTemp->nNum==nPos)
		{
			pTemp->pDialog->ShowWindow(SW_SHOW);
		}
		else
		    //不显示
			pTemp->pDialog->ShowWindow(SW_HIDE);
		pTemp=pTemp->Next;
	}
	if (nPos>=nPageCount)  //最后一页
	{
		nCurrentPage=nPageCount;
		SetWizButton(2);
		return;
	}
	if (nPos<=1) //首页 
	{
		nCurrentPage=1;
		SetWizButton(0);
		return;
	}
	//中间步
	SetWizButton(1);
}

void CWizard::SetWizButton(UINT uFlag)
{
	GetDlgItem(IDC_CANCEL)->EnableWindow(TRUE);
	GetDlgItem(IDC_PREV)->EnableWindow(TRUE);
	GetDlgItem(IDC_NEXT)->EnableWindow(TRUE);
	GetDlgItem(IDC_FINISH)->EnableWindow(TRUE);
	switch(uFlag)
	{
	case 0: //第一步
		GetDlgItem(IDC_PREV)->EnableWindow(FALSE);
		break;
	case 1: //中间步
		break;
	case 2://最后一步
		GetDlgItem(IDC_NEXT)->EnableWindow(FALSE);
		break;
	}
}

BOOL CWizard::OnInitDialog() 
{
	CDialog::OnInitDialog();
	//获得每页显示的范围
	CRect Rect1;
	GetWindowRect(&Rect1); //获得主窗口的位置
	int nCaption = ::GetSystemMetrics(SM_CYCAPTION);
	int nXEdge = ::GetSystemMetrics(SM_CXEDGE);
	int nYEdge = ::GetSystemMetrics(SM_CYEDGE);
	CRect Rect2;
	GetDlgItem(IDC_POS)->GetWindowRect(&Rect2); //获得框架的位置
	Rect1.top=Rect1.top+nCaption+nYEdge; //相对坐标
	Rect1.left=Rect1.left+2*nXEdge;
	//计算机位置
	rectPage.top=Rect2.top-Rect1.top;
	rectPage.left=Rect2.left-Rect1.left;
	rectPage.bottom=Rect2.bottom-Rect1.top;
	rectPage.right=Rect2.right-Rect1.left;

	//添加要显示的页
	CStep1* pStep1 = new CStep1;
	CStep2* pStep2 = new CStep2;
	CStep3* pStep3 = new CStep3;

	AddPage(pStep1, IDD_STEP1);
	AddPage(pStep2, IDD_STEP2);
	AddPage(pStep3, IDD_STEP3);

	//显示第一页
	ShowPage(1);

	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}

void CWizard::OnDestroy() 
{
	CDialog::OnDestroy();
	// TODO: Add your message handler code here
	//依次消除每页
	struct PAGELINK* pTemp = pPageLink;
	while(pTemp)
	{
		struct PAGELINK* pNextTemp = pTemp->Next;
		pTemp->pDialog->DestroyWindow();
		delete pTemp->pDialog;
		delete pTemp;
		pTemp = pNextTemp;
	}

}

⌨️ 快捷键说明

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