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

📄 test3dlg.cpp

📁 电脑编程技巧和源码。很不错的。
💻 CPP
字号:
// Test3Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "Test3.h"
#include "Test3Dlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CTest3Dlg dialog

CTest3Dlg::CTest3Dlg(CWnd* pParent /*=NULL*/)
	: CDialog(CTest3Dlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CTest3Dlg)
		// 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 CTest3Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTest3Dlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CTest3Dlg, CDialog)
	//{{AFX_MSG_MAP(CTest3Dlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_RBUTTONDOWN()
	ON_WM_LBUTTONDOWN()
	ON_WM_CLOSE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTest3Dlg message handlers

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

	// 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
	
	m_bitmap.LoadBitmap(IDB_BITMAP1);
	m_ifRgnReady=FALSE;
	
	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 CTest3Dlg::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();
	}
	DrawBitmap();
}

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

LPRGNDATA CTest3Dlg::GetRgnData(CBitmap& Bitmap,COLORREF BkColor,int *nCount)
{
	CRgn rgn1,rgn2;
	CClientDC dc(this);
	CDC memDC;
	int x,y,s;
	BITMAP bm;
	if(Bitmap.m_hObject==NULL)return NULL;
	Bitmap.GetObject(sizeof(BITMAP),&bm);
	memDC.CreateCompatibleDC(&dc);
	CBitmap * oldBitmap=memDC.SelectObject(&Bitmap);
	for(y=0;y<bm.bmHeight;y++)
	{
		x=0;
		while(x<bm.bmWidth)
		{
			while(BkColor==memDC.GetPixel(x,y)&&x<bm.bmWidth)x++;
			if(x==bm.bmWidth)break;
			s=x;
			while(BkColor!=memDC.GetPixel(x,y)&&x<bm.bmWidth)x++;
			if(rgn1.m_hObject==NULL)
				rgn1.CreateRectRgn(s,y,x,y+1);
			else{
				rgn2.CreateRectRgn(s,y,x,y+1);
				rgn1.CombineRgn(&rgn1,&rgn2,RGN_OR);
				rgn2.DeleteObject();
			}
		}
	}
	memDC.SelectObject(oldBitmap);
	LPRGNDATA lpRgnData;
	*nCount=rgn1.GetRegionData(NULL,0);
	lpRgnData=(LPRGNDATA)new BYTE[*nCount];
	rgn1.GetRegionData(lpRgnData,*nCount);
	return lpRgnData;
}

void CTest3Dlg::DrawBitmap()
{
	BITMAP bm;
	m_bitmap.GetObject(sizeof(BITMAP),&bm);
	CClientDC dc(this);
	CDC memDC;
	memDC.CreateCompatibleDC(&dc);
	CBitmap * oldbitmap=memDC.SelectObject(&m_bitmap);
	dc.BitBlt(0,0,bm.bmWidth,bm.bmHeight,&memDC,0,0,SRCCOPY);
	memDC.SelectObject(oldbitmap);
}


void CTest3Dlg::OnRButtonDown(UINT nFlags, CPoint point) 
{
	CDialog::OnRButtonDown(nFlags, point);
	PostMessage(WM_CLOSE);
}

void CTest3Dlg::OnLButtonDown(UINT nFlags, CPoint point) 
{
	if(!m_ifRgnReady)
	{
		CClientDC dc(this);
		CBitmap bitmap;
		bitmap.LoadBitmap(IDB_BITMAP2);
		CRgn rgn;
		m_rgndata=GetRgnData(bitmap,dc.GetBkColor(),&m_size);
		rgn.CreateFromData(NULL,m_size,m_rgndata);
		SetWindowRgn(rgn,TRUE);
		m_ifRgnReady=TRUE;
	}
	else PostMessage(WM_SYSCOMMAND,0xf012);

	CDialog::OnLButtonDown(nFlags, point);
}

void CTest3Dlg::OnClose() 
{
	if(m_ifRgnReady)delete []m_rgndata;	
	CDialog::OnClose();
}

⌨️ 快捷键说明

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