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

📄 ropexdlg.cpp

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

#include "stdlib.h"
#include "stdafx.h"
#include "ropexp1.h"
#include "ropexdlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CRopexp1Dlg dialog

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

BEGIN_MESSAGE_MAP(CRopexp1Dlg, CDialog)
	//{{AFX_MSG_MAP(CRopexp1Dlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_LBN_SELCHANGE(IDC_ROPLIST, OnSelchangeRoplist)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CRopexp1Dlg message handlers

BOOL CRopexp1Dlg::OnInitDialog()
{
	CDialog::OnInitDialog();
	CenterWindow();
	
	//Fill the list box with ROP options.
	CListBox* pLB = (CListBox*) GetDlgItem(IDC_ROPLIST);
	pLB->AddString("SRCCOPY = 0xCC0020    S");
	pLB->AddString("SRCPAINT = 0xEE0086   DSo");
	pLB->AddString("SRCAND = 0x8800C6    DSa");
	pLB->AddString("SRCINVERT = 0x660046    DSx"); 
	pLB->AddString("SRCERASE = 0x440328    SDna");
	pLB->AddString("NOTSRCCOPY = 0x330008    Sn");
	pLB->AddString("NOTSRCERASE = 0x1100A6    DSon");
	pLB->AddString("MERGECOPY = 0xC000CA    PSa");
	pLB->AddString("MERGEPAINT = 0xBB0226    DSno");
	pLB->AddString("PATCOPY = 0xF00021    P");
	pLB->AddString("PATPAINT = 0xFB0A09    DPSnoo");
	pLB->AddString("PATINVERT = 0x5A0049    DPx");
	pLB->AddString("DSTINVERT = 0x550009    Dn");
	pLB->AddString("BLACKNESS = 0x000042    0");
	pLB->AddString("WHITENESS = 0xFF0062    1");
	pLB->AddString("MergeMask = 0xAC0744    SPDSxax");
	
	//Create the brush.
	myBrush = CreateTheBrush();
		
	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 CRopexp1Dlg::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();
	}
}

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

void CRopexp1Dlg::OnSelchangeRoplist() 
{
	//When the user changes the list box selection.
	CString ROPText;
	CDC* pDC = GetDC();

	//Retrieve the selected text in the list box.
	CListBox* pLB = (CListBox*) GetDlgItem(IDC_ROPLIST);
	pLB->GetText(pLB->GetCurSel(), ROPText);

	//Extract the hexadecimal portion of the text.
	ROPText = ROPText.Mid(ROPText.Find('=') + 1);

	//Convert hexadecimal string to a long integer.
	char *stopstring;
	long rop = strtol(ROPText, &stopstring, 16);

	//We must use the CDialog member function MapDialogRect()
	//to convert the dialog units to logical units. Note that we 
	//only care about the top left corners since icons are always
	//32 pixels on a side.
	CRect rectSrc(16,7,100,100);
	CRect rectDest(51,7,100,100);
	CRect rectBrush(104,7,200,200);
	CRect rectResult(145,7,200,200);
	MapDialogRect(rectSrc);
	MapDialogRect(rectDest);
	MapDialogRect(rectBrush);
	MapDialogRect(rectResult);

	//Make rectBrush point to a 32 pixel square rectangle.
	rectBrush.right = rectBrush.left + 31;
	rectBrush.bottom = rectBrush.top + 31;

	//Display our custom brush in rectBrush.
	HANDLE oldBrush = pDC->SelectObject(myBrush);
	pDC->Rectangle(&rectBrush);
	
	//Perform the blits. First copy one icon to the destination.
	pDC->BitBlt(rectResult.left, rectResult.top, 32, 32, pDC,rectSrc.left, rectSrc.top, SRCCOPY);

	//Then blit the second using using the selected mode.
	pDC->BitBlt(rectResult.left, rectResult.top, 32, 32, pDC,rectDest.left, rectDest.top, rop);

	//Restore the original brush.
	pDC->SelectObject(oldBrush);	
}

CBrush* CRopexp1Dlg::CreateTheBrush(void)
{
	CBrush* pBr = new CBrush;
	CBitmap bitmap;

	//Byte array for pixel values.
	BYTE pixels[32];

	//Initialize the array with alternating 1's and 0's
	//to obtain a 50% gray dither. Note that while a brush
	//is only 8x8 pixels, we require an array twice as large
	//because the CreateBitmap function requires scan rows
	//to be a multiple of 16 bits. The extra bits will be ignored
	//when the brush is created.
	for (int i = 0; i < 33; i += 4)
		{
		pixels[i] = 0x55;  	//Binary 01010101.
		pixels[i+1] = 0x55;
		pixels[i+2] = 0xAA;	//Binary 10101010.
		pixels[i+3] = 0xAA;
		}

	if (!bitmap.CreateBitmap(8, 8, 1, 1, pixels))
		{
		AfxMessageBox("Error creating bitmap");
		return NULL;
		}


	if (!pBr->CreatePatternBrush(&bitmap))
		{
		AfxMessageBox("Could not create brush.");
		return NULL;
		}

	return pBr;
}

⌨️ 快捷键说明

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