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

📄 transctldlgdlg.cpp

📁 有背景的对话框上
💻 CPP
字号:
// TransCtlDlgDlg.cpp : implementation file
//

#include "stdafx.h"
#include "TransCtlDlg.h"
#include "TransCtlDlgDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CTransCtlDlgDlg dialog

CTransCtlDlgDlg::CTransCtlDlgDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CTransCtlDlgDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CTransCtlDlgDlg)
		// 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);

	m_hBmBkgnd = NULL;
	m_hBrCtl[0] = NULL;
	m_hBrCtl[1] = NULL;
	m_hBrCtl[2] = NULL;
	m_hBrCtl[3] = NULL;
}

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

BEGIN_MESSAGE_MAP(CTransCtlDlgDlg, CDialog)
	//{{AFX_MSG_MAP(CTransCtlDlgDlg)
	ON_WM_PAINT()
	ON_WM_DESTROY()
	//}}AFX_MSG_MAP
	ON_MESSAGE( WM_CTLCOLORSTATIC, OnCtlColorStatic )
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTransCtlDlgDlg message handlers

BOOL CTransCtlDlgDlg::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
	
	CenterWindow(GetDesktopWindow());	// center to the hpc screen

	// TODO: Add extra initialization here

	m_hBmBkgnd = ::LoadBitmap( AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_BKGND) );

	if( m_hBmBkgnd )
	{
		m_hBrCtl[0] = GetBkBrush( GetSafeHwnd(), IDC_GROUPBOX, m_hBmBkgnd );
		m_hBrCtl[1] = GetBkBrush( GetSafeHwnd(), IDC_STATIC_TEXT, m_hBmBkgnd );
		m_hBrCtl[2] = GetBkBrush( GetSafeHwnd(), IDC_RADIO1, m_hBmBkgnd );
		m_hBrCtl[3] = GetBkBrush( GetSafeHwnd(), IDC_CHECK1, m_hBmBkgnd );
	}
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

#define _X(x)	(x.left)
#define _Y(x)	(x.top)
#define _W(x)	(x.right - x.left)
#define _H(x)	(x.bottom - x.top)

//**************************************************************************************
//
//	GetBkBrush( HWND hWnd, UINT nID, HBITMAP hBmBk )
//  
//	Creates Background brush for the control specified by nID
//	according to its position in the parent dialog window.
//
//	hWnd [in]: Handle to the parent window
//  nID [in]: Control ID
//  hBmBk [in]: Bitmap handle of the parent dialog's background image
//
//
//**************************************************************************************

HBRUSH CTransCtlDlgDlg::GetBkBrush( HWND hWnd, UINT nID, HBITMAP hBmBk )
{
	HWND hWndCtrl;

	hWndCtrl = ::GetDlgItem( hWnd, nID );
	
	HBRUSH	hBrushCtrl = NULL;

	if( NULL != hWndCtrl )
	{
		RECT rcCtrl;

		::GetWindowRect( hWndCtrl, &rcCtrl );
		::ScreenToClient(hWnd, (LPPOINT)&rcCtrl);
		::ScreenToClient(hWnd, ((LPPOINT)&rcCtrl)+1);

		HDC hDC = ::GetDC(hWnd);

		HDC hMemDCBk = CreateCompatibleDC( hDC );
		HDC hMemDCCtrl = CreateCompatibleDC( hDC );

		HBITMAP hBmCtrl = CreateCompatibleBitmap( hDC, _W(rcCtrl), _H(rcCtrl) );

		HBITMAP hBmOldBk;
		HBITMAP hBmOldCtrl;

		hBmOldBk = (HBITMAP) ::SelectObject( hMemDCBk, hBmBk );
		hBmOldCtrl = (HBITMAP) ::SelectObject( hMemDCCtrl, hBmCtrl );

		::BitBlt( hMemDCCtrl, 0, 0, _W(rcCtrl), _H(rcCtrl), hMemDCBk, _X(rcCtrl), _Y(rcCtrl), SRCCOPY );

		::SelectObject(hMemDCCtrl, hBmOldCtrl );
		::SelectObject(hMemDCBk, hBmOldBk );
		
		hBrushCtrl = ::CreatePatternBrush( hBmCtrl );

		DeleteObject( hBmCtrl );

		::DeleteDC( hMemDCBk );
		::DeleteDC( hMemDCCtrl );
		::ReleaseDC( hWnd, hDC );
	}

	return hBrushCtrl;
}


void CTransCtlDlgDlg::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// Draw our own background image

	CDC memDC;
	CBitmap bmBkgnd;
	bmBkgnd.Attach( m_hBmBkgnd );

	memDC.CreateCompatibleDC(&dc);
	CBitmap *pOldBm = memDC.SelectObject( &bmBkgnd );

	BITMAP bm;
	bmBkgnd.GetObject(sizeof(bm), &bm);
	

	dc.BitBlt(0, 0, bm.bmWidth, bm.bmHeight, &memDC, 0, 0, SRCCOPY );
	memDC.SelectObject( pOldBm );
	bmBkgnd.Detach();


	
	// Do not call CDialog::OnPaint() for painting messages
}

LRESULT CTransCtlDlgDlg::OnCtlColorStatic(WPARAM wParam, LPARAM lParam)
{
	HDC hDCStatic = (HDC) wParam;
	HWND hWndCtrl = (HWND) lParam;
	
	UINT nID = ::GetDlgCtrlID( hWndCtrl );
	
	::SetBkMode( hDCStatic, TRANSPARENT );
	
	switch( nID )
	{
	case IDC_GROUPBOX:		return (LRESULT)m_hBrCtl[0];
	case IDC_STATIC_TEXT:	return (LRESULT)m_hBrCtl[1];
	case IDC_RADIO1:		return (LRESULT)m_hBrCtl[2];
	case IDC_CHECK1:		return (LRESULT)m_hBrCtl[3];
	}
	
	return 0;
}

void CTransCtlDlgDlg::OnDestroy() 
{
	CDialog::OnDestroy();
	
	// Clean Up.. 
	::DeleteObject( m_hBmBkgnd );
	::DeleteObject( m_hBrCtl[0] );
	::DeleteObject( m_hBrCtl[1] );
	::DeleteObject( m_hBrCtl[2] );
	::DeleteObject( m_hBrCtl[3] );
}

⌨️ 快捷键说明

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