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

📄 doeventsdlg.cpp

📁 c++系统开发实例精粹内附的80例源代码 环境:windows2000,c++6.0
💻 CPP
字号:
// doeventsDlg.cpp : implementation file
//

#include "stdafx.h"
#include "doevents.h"
#include "doeventsDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CDoeventsDlg dialog

CDoeventsDlg::CDoeventsDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CDoeventsDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDoeventsDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

   m_bStop       = FALSE;
   m_bIsWorking  = FALSE;
}

void CDoeventsDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDoeventsDlg)
	DDX_Control(pDX, IDPB_TASK, m_pbTask);
	DDX_Control(pDX, IDPG_PROGRESS, m_pgProgress);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CDoeventsDlg, CDialog)
	//{{AFX_MSG_MAP(CDoeventsDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDPB_TASK, OnTask)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDoeventsDlg message handlers

BOOL CDoeventsDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

// 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 CDoeventsDlg::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();
	}
}

HCURSOR CDoeventsDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

/* -------------------------------------------------------------------------
      Ok, call this to pump messages...
   ------------------------------------------------------------------------- */
void CDoeventsDlg::DoEvents()
{
	MSG msg;
	if (::PeekMessage(&msg,NULL,0,0,PM_REMOVE)) { //从Windows消息队列中取出消息
		if (msg.message== WM_QUIT)//如果消息为退出,发送退出消息
		{ 
			::PostQuitMessage(-1);
		} 
		if(!AfxGetApp()->PreTranslateMessage(&msg))//如果无法预处理消息
		{
			::TranslateMessage(&msg);//转换消息
			::DispatchMessage(&msg);//发送消息
		}
	}
	AfxGetApp()->OnIdle(0);AfxGetApp()->OnIdle(1);//消息队列为空时闲置一段时间
}

/* -------------------------------------------------------------------------
      Large Large task...
   ------------------------------------------------------------------------- */

void CDoeventsDlg::OnTask() 
{
   int iStep  = 0;
   m_pgProgress.SetRange(0, 500 );//设置进度条范围
   m_pgProgress.SetStep(1);//步长
   m_pgProgress.SetPos(0);//初始位置
   m_bIsWorking = TRUE;
   m_bStop      = FALSE;//是否停止工作
   m_pbTask.EnableWindow(FALSE);
   while(!m_bStop && iStep <= 500) {
      iStep++;      
      m_pgProgress.StepIt(); 
      Sleep(20);
      DoEvents();       // 二次消息循环函数
   }   
   m_bIsWorking = FALSE;
   m_pgProgress.SetPos(0);
   m_pbTask.EnableWindow(TRUE);
}

/* -------------------------------------------------------------------------
      Cancel button -> if the large task is working abort it, if not close
   the window
   ------------------------------------------------------------------------- */

void CDoeventsDlg::OnCancel() 
{
   if(!m_bIsWorking) {
      CDialog::OnCancel();
   } else {
      m_bStop = TRUE;
      AfxMessageBox("工作取消了", MB_OK | MB_ICONINFORMATION);
   }	   
}

⌨️ 快捷键说明

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