www.gusucode.com > VC++挂机锁屏系统源程序源码程序 > VC++挂机锁屏系统源程序源码程序\code\WRONGDlg.cpp

    // WRONGDlg.cpp : implementation file
//
/*----------------------------------------------------------------------------*/
//
//	文件:		WRONGDlg.cpp
//  版本:      1.0
//	作者:		蔡亦汤
//	创建时间:	2007 4 7
//  EMAIL:      caiyitang2003@163.com
/*----------------------------------------------------------------------------
/*
/* Copyright (C) 2007-2008 by  LeoSoftware
/* All Rights Reserved.
/*
/*----------------------------------------------------------------------------*/

///////////////////////////////////////功能说明 ////////////////////////////////////////
//错误提示窗口,可以设计显示标题内容,正文内容及其字体
////////////////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "LOCK.h"
#include "WRONGDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CWRONGDlg dialog


CWRONGDlg::CWRONGDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CWRONGDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CWRONGDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	//设计标题字体
	LOGFONT lf;
	memset(&lf, 0, sizeof(LOGFONT));
	lf.lfHeight = 18;    //字体大小
	strcpy(lf.lfFaceName ,"宋体");  //字体
	lf.lfUnderline = TRUE;    //字体下画线
	lf.lfWeight = FW_BOLD;    //字体粗细程度
	m_TitleFont.CreateFontIndirect(&lf);    //创建标题字体
 
	//设计正文内容字体
	lf.lfHeight = 16;
	strcpy(lf.lfFaceName ,"宋体");
	lf.lfUnderline = FALSE;
	lf.lfWeight = FW_BOLD;
	m_TextFont.CreateFontIndirect(&lf);
}
// Download by http://www.NewXing.com

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


BEGIN_MESSAGE_MAP(CWRONGDlg, CDialog)
	//{{AFX_MSG_MAP(CWRONGDlg)
	ON_WM_PAINT()
	ON_WM_TIMER()
	ON_WM_LBUTTONDOWN()
	ON_WM_ERASEBKGND()
	ON_WM_CLOSE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CWRONGDlg message handlers



void CWRONGDlg::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here

}

void CWRONGDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	if (nIDEvent == 1)
	OnClose();    //定时关闭窗口

	CDialog::OnTimer(nIDEvent);
}

void CWRONGDlg::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	OnClose();    //直接关闭窗口

	CDialog::OnLButtonDown(nFlags, point);
}

void CWRONGDlg::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
	KillTimer(1);    //销毁定时器
	OnCancel();      //关闭窗口
	//CDialog::OnClose();
}

BOOL CWRONGDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	SetTimer(1,2000,NULL);    //设置窗口显示时间为2秒

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

/////////////////////////////////////////////////////////////////////
// 函数:
//      CWRONGDlg::OnEraseBkgnd()
// 
// 描述:
//     
//		显示背景图片,填充窗口背景
//
// 返回:
//
//		[BOOL]	        -TRUE:显示背景图片,填充窗口背景
//
// 参数:
//
//		[pDC]			- 设备场景CDC的指针对象
//     
/////////////////////////////////////////////////////////////////////
BOOL CWRONGDlg::OnEraseBkgnd(CDC *pDC)
{
	CRect rect;
    GetClientRect(&rect);//得到窗体的大小
    CDC dcMem; 
    dcMem.CreateCompatibleDC(pDC); 
    CBitmap bmpBackground;
    bmpBackground.LoadBitmap(IDB_BITMAP_SYSMSG);//加载背景图片
    BITMAP bitMap;
    bmpBackground.GetBitmap(&bitMap);
    CBitmap *pbmpOld=dcMem.SelectObject(&bmpBackground);
    pDC->StretchBlt(0,0,rect.Width(),rect.Height(),&dcMem,0,0,bitMap.bmWidth,bitMap.bmHeight,SRCCOPY);
	
	//在(25,60)显示图片IDI_WRONG
	CPoint pt=CPoint(25,60);
	HICON hIcon = AfxGetApp()->LoadIcon(IDI_WRONG); 
	pDC->DrawIcon(pt, hIcon);

	CRect rcTitle = CRect(20, 35, rect.right, 55);    //标题的位置
	CFont *pOldFont = (CFont*)pDC->SelectObject(&m_TitleFont);
	UINT nFormat = DT_VCENTER|DT_SINGLELINE|DT_CENTER;  //标题显示风格
	pDC->SetTextColor(RGB(0,0,255));    //标题字体颜色
	pDC->DrawText(m_strTitle, &rcTitle, nFormat);    //显示标题内容

	//显示正文内容
	CRect rcText = CRect(70, 60, rect.right-8, rect.bottom-8);
	nFormat = DT_WORDBREAK|DT_LEFT;
	pDC->SelectObject(&m_TextFont);
	pDC->SetTextColor(RGB(255,0,0));
	pDC->DrawText(m_strText, &rcText, nFormat);

	pDC->SelectObject(pOldFont);
	m_TitleFont.DeleteObject();
	m_TextFont.DeleteObject();

	return TRUE;

}