www.pudn.com > CCreditsCtrl_demo.rar > CreditsDlgDlg.cpp


// CreditsDlgDlg.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "CreditsDlg.h" 
#include "CreditsDlgDlg.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CCreditsDlgDlg dialog 
 
CCreditsDlgDlg::CCreditsDlgDlg(CWnd* pParent /*=NULL*/) 
	: CDialog(CCreditsDlgDlg::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(CCreditsDlgDlg) 
		// 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 CCreditsDlgDlg::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CCreditsDlgDlg) 
		// NOTE: the ClassWizard will add DDX and DDV calls here 
	//}}AFX_DATA_MAP 
} 
 
BEGIN_MESSAGE_MAP(CCreditsDlgDlg, CDialog) 
	//{{AFX_MSG_MAP(CCreditsDlgDlg) 
	ON_WM_PAINT() 
	ON_WM_QUERYDRAGICON() 
	ON_BN_CLICKED(IDC_BACKGROUND, OnBackground) 
	ON_BN_CLICKED(IDC_SLOW, OnSlow) 
	ON_BN_CLICKED(IDC_USERSCROLL, OnUserscroll) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CCreditsDlgDlg message handlers 
 
BOOL CCreditsDlgDlg::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 
 
	srand((unsigned)time(NULL)); 
	 
	// initialize credits control... 
 
	// Content 
	CString s; 
	s = ""; 
	s += "Demo Stuff 

"; s += " Color:
yeeeeeeeeeehaaaaa
"; s += " Font:
Comic Sans MS
Courier New
Tahoma
"; s += " Size:
WHOOOOOOW
"; s += " Styles:
bold italic underline strikeout
"; s += " Background:
Blue Red Brown Ghost Font
"; s += " Alignment:
right
center
left
"; s += " Vertical Alignment:
topmiddlebottomBIG
"; s += " Resource Bitmap:
red border
"; s += " Links:
Click Me!
notepad
www.w3c.org
devix@devix.cjb.net
Click Hereimage link:
"; s += "CCreditsCtrl

About

Coded in January 2001
by Marc Richarmemail: devix@devix.cjb.net
web: http://devix.cjb.net

Credits

Thanks to The Code Project for being
the coolest VC++/MFC site out there!
"; // Content Data m_wndCredits.FormatDataString(s,IDB_BITMAP1,IDB_BITMAP1,(long)CCreditsDlgDlg::TestFunction,(long)CCreditsDlgDlg::TestFunction,(long)this,(long)CCreditsDlgDlg::TestFunction2,IDB_BITMAP2); // use our own function for background drawing m_wndCredits.m_pBackgroundPaint = CCreditsDlgDlg::DrawCreditsBackground; m_wndCredits.m_dwBackgroundPaintLParam = TRUE; // as our background is going to be black, use black as default transparent color m_wndCredits.m_crInternalTransparentColor = RGB(0,0,0); // now, we're ready to begin... create the window m_wndCredits.Create(WS_EX_CLIENTEDGE,WS_VISIBLE|WS_CHILD,IDC_PLACEHOLDER,this,0,IDC_SMILEY,0); // for details on what more can be customized, RTFM. // default options ((CButton*)GetDlgItem(IDC_BACKGROUND))->SetCheck(TRUE); ((CButton*)GetDlgItem(IDC_USERSCROLL))->SetCheck(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 CCreditsDlgDlg::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 CCreditsDlgDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } // this is our custom background drawing function... // it's probably not the most beatifull background effect, but it does // demonstrate how custom background drawing should/could be done.. enjoy void CCreditsDlgDlg::DrawCreditsBackground(CDC *pDC, RECT rect, BOOL bAnimate, DWORD lParam) { static int on1,on2,oon1,oon2; pDC->FillSolidRect(&rect,0x00000000); // uncomment the following lines if you like small green squares :) // pDC->SetBkColor(0x000000); // CBrush bgBrush; // bgBrush.CreateHatchBrush(HS_CROSS,RGB(0,70,30)); // pDC->FillRect(&rect,&bgBrush); if(bAnimate || (!lParam)) // return now if we are not supposed to do the animation return; int n1,n2; n1 = rand()*200/RAND_MAX-100; n2 = rand()*200/RAND_MAX-100; // 2/10 chance of (prehaps) making some wild stuff on one of the curves if(rand() < RAND_MAX/10) n1 = rand()*400/RAND_MAX-200; else if(rand() < RAND_MAX/10) n2 = rand()*400/RAND_MAX-200; POINT points1[4] = { rect.right,0, (rect.right-rect.left)/2+n1,(rect.bottom-rect.top)/2, (rect.right-rect.left)/2,(rect.bottom-rect.top)/2-n1, 0,rect.bottom }; POINT points2[4] = { 0,0, (rect.right-rect.left)/2-n2,(rect.bottom-rect.top)/2, (rect.right-rect.left)/2,(rect.bottom-rect.top)/2-n2, rect.right,rect.bottom }; POINT opoints1[4] = { rect.right,0, (rect.right-rect.left)/2+on1,(rect.bottom-rect.top)/2, (rect.right-rect.left)/2,(rect.bottom-rect.top)/2-on1, 0,rect.bottom }; POINT opoints2[4] = { 0,0, (rect.right-rect.left)/2-on2,(rect.bottom-rect.top)/2, (rect.right-rect.left)/2,(rect.bottom-rect.top)/2-on2, rect.right,rect.bottom }; POINT oopoints1[4] = { rect.right,0, (rect.right-rect.left)/2+oon1,(rect.bottom-rect.top)/2, (rect.right-rect.left)/2,(rect.bottom-rect.top)/2-oon1, 0,rect.bottom }; POINT oopoints2[4] = { 0,0, (rect.right-rect.left)/2-oon2,(rect.bottom-rect.top)/2, (rect.right-rect.left)/2,(rect.bottom-rect.top)/2-oon2, rect.right,rect.bottom }; CPen wpen(PS_SOLID,1,RGB(150,220,255)); CPen pen(PS_SOLID,2,RGB(50,100,255)); CPen open(PS_SOLID,1,RGB(50,100,255)); CPen oopen(PS_SOLID,1,RGB(0,30,150)); CPen *pOldPen = pDC->SelectObject(&oopen); pDC->PolyBezier(oopoints1,4); pDC->PolyBezier(oopoints2,4); pDC->SelectObject(&open); pDC->PolyBezier(opoints1,4); pDC->PolyBezier(opoints2,4); pDC->SelectObject(&pen); pDC->PolyBezier(points1,4); pDC->PolyBezier(points2,4); pDC->SelectObject(&wpen); pDC->PolyBezier(points1,4); pDC->PolyBezier(points2,4); pDC->SelectObject(pOldPen); oon1 = on1; oon2 = on2; on1 = n1; on2 = n2; } void CCreditsDlgDlg::TestFunction(LPCTSTR lpszArg) { if(lpszArg == NULL) AfxMessageBox("(null)"); else AfxMessageBox(lpszArg); } void CCreditsDlgDlg::TestFunction2(LPCTSTR lpszArg) { static int cnt = 1; CCreditsDlgDlg *pDlg = (CCreditsDlgDlg*)atol(lpszArg); pDlg->m_wndCredits.m_nTimerSpeed = cnt==0 ? 30 : cnt * 40; if(++cnt > 3) cnt = 0; } void CCreditsDlgDlg::OnBackground() { m_wndCredits.m_dwBackgroundPaintLParam = (DWORD)((CButton*)GetDlgItem(IDC_BACKGROUND))->GetCheck(); } void CCreditsDlgDlg::OnSlow() { m_wndCredits.m_nTimerSpeed = ((CButton*)GetDlgItem(IDC_SLOW))->GetCheck() ? 80 : 40; } void CCreditsDlgDlg::OnUserscroll() { m_wndCredits.m_bCanScroll = ((CButton*)GetDlgItem(IDC_USERSCROLL))->GetCheck(); }