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

📄 yakiddlg.cpp

📁 C:Documents and SettingsAdministrator桌面VC++多媒体特效制作百例CHAR03DisplayDIB
💻 CPP
字号:
// yakiddlg.cpp : implementation file
//

#include "stdafx.h"
#include "yakidawn.h"
#include "yakiddlg.h"
#include "dibapi.h"

#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CYakidawnDlg dialog

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

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

/////////////////////////////////////////////////////////////////////////////
// CYakidawnDlg message handlers

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

	//Create a CFile object for the DIB file.
	CFile dibFile("yakidawn.bmp", CFile::modeRead);

	//Read the DIB file into memory. 
	hdib = ::ReadDIBFile(dibFile);
	if (!hdib)
		{
		MessageBox("Error reading DIB file.", MB_OK, NULL);
		return TRUE;
		}

	//Create a logical palette from the DIB file's palette.
	palette = new CPalette;
	if (palette == NULL)
	{
		//If we can't create the CPalette object,
		//we must be really low on memory.
		::GlobalFree((HGLOBAL) hdib);
		hdib = NULL;
		AfxMessageBox("Not enough memory for palette.");
	}

	if (::CreateDIBPalette(hdib, palette) == NULL)
		AfxMessageBox("Error creating palette from DIB.", MB_OK, NULL);
	
	//Get the bitmap size.
	LPSTR lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) hdib);
	int cxDIB = (int) ::DIBWidth(lpDIB);
	int cyDIB = (int) ::DIBHeight(lpDIB);
	::GlobalUnlock((HGLOBAL) hdib);

	//Make the window the same size as the bitmap.
	SetWindowPos(&wndTop, 0, 0, cxDIB, cyDIB, SWP_NOMOVE);
	CenterWindow();
	
	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 CYakidawnDlg::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
	{
		CPaintDC dc(this); // device context for painting.

		//Set the output and DIB rectangle sizes to be
		//equal to the bitmap size.
		CRect outputRect;
		CRect DIBRect;
		DIBRect.left = DIBRect.top = 0;
		LPSTR lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) hdib);
		DIBRect.right = (int) ::DIBWidth(lpDIB);
		DIBRect.bottom = (int) ::DIBHeight(lpDIB);    
		::GlobalUnlock((HGLOBAL) hdib);
		outputRect = DIBRect;
		
		//Select and realize the palette.
		dc.SelectPalette(palette, FALSE);
		dc.RealizePalette();

		//Display the bitmap.
		if (::PaintDIB(dc.m_hDC, &outputRect, hdib, &DIBRect, palette) == NULL)
			MessageBox("Error painting DIB");
	}
}

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

⌨️ 快捷键说明

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