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

📄 rounddlg.cpp

📁 不可多得的例程资源
💻 CPP
字号:
// RoundDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Round.h"
#include "RoundDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CRoundDlg dialog

CRoundDlg::CRoundDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CRoundDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CRoundDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

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

BEGIN_MESSAGE_MAP(CRoundDlg, CDialog)
	//{{AFX_MSG_MAP(CRoundDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_NCHITTEST()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CRoundDlg message handlers

BOOL CRoundDlg::OnInitDialog()
{
	CDialog::OnInitDialog();
	
	CRect rcDialog;
	//创建对象
	GetClientRect(&rcDialog );
	// 创建区域并赋予对话框.
	CRgn rgn;
	//直接从RECT结构定义的椭圆形区域
	rgn.CreateEllipticRgn (0 , 0 , rcDialog.Width( ) , rcDialog.Height ( ) );
	//设置区域
	SetWindowRgn( (HRGN) rgn ,TRUE );
	
	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 CRoundDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // 设备环境

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

		// 在客户区的光标
		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;

		// 画标
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{	
		CPaintDC dc(this); // device context for painting
		//在设备环境画无边框对话框
		dc.SelectStockObject(NULL_PEN);
		CRect rect;
		GetClientRect (rect);
		CBrush brush;
		// 用来填充颜色的画刷
		CBrush *pBrushOld;
		brush.CreateSolidBrush(RGB(0,0,255));
		pBrushOld=dc.SelectObject(&brush);
		dc.Ellipse(rect);
		dc.SelectObject(pBrushOld);
	}
}

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

UINT CRoundDlg::OnNcHitTest(CPoint point) 
{
	//Let user move window by click anywhere on the window .
	//当单击对话框的客户区时能够移动对话框
	UINT nHitTest=CDialog::OnNcHitTest (point);
	return (nHitTest == HTCLIENT)? HTCAPTION: nHitTest;
}

⌨️ 快捷键说明

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