|
// TVCreditsDlg.cpp : implementation file
//
#include "stdafx.h"
#include "CreditsDlg.h"
#include "CreditsThread.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// drawable area of the dialog
#define SCREEN_LEFT 16
#define SCREEN_TOP 16
#define SCREEN_RIGHT 326
#define SCREEN_BOTTOM 257
// button to dismiss dialog
#define BUTTON_TOP_Y 267
#define BUTTON_BOTTOM_Y 290
#define BUTTON_LEFT_X 239
#define BUTTON_RIGHT_X 332
/////////////////////////////////////////////////////////////////////////////
// CCreditsDlg dialog
CCreditsDlg::CCreditsDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCreditsDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCreditsDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_pDC = NULL;
}
void CCreditsDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCreditsDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCreditsDlg, CDialog)
//{{AFX_MSG_MAP(CCreditsDlg)
ON_WM_LBUTTONDOWN()
ON_WM_DESTROY()
ON_WM_CREATE()
ON_BN_CLICKED(IDC_CHK_WAITVRT, OnChkWaitvrt)
ON_BN_CLICKED(IDC_RDO_DOWN, OnRdoDown)
ON_BN_CLICKED(IDC_RDO_PAUSE, OnRdoPause)
ON_BN_CLICKED(IDC_RDO_UP, OnRdoUp)
ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_DELAY, OnDeltaposSpinDelay)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCreditsDlg message handlers
void CCreditsDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
CDialog::OnLButtonDown(nFlags, point);
// see if they clicked on our button to dismiss the dialog
if((point.x >= BUTTON_LEFT_X) && (point.x <= BUTTON_RIGHT_X))
{
if((point.y >= BUTTON_TOP_Y) && (point.y <= BUTTON_BOTTOM_Y))
{
CDialog::OnOK();
return;
}
}
PostMessage(WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM(point.x, point.y));
}
BOOL CCreditsDlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_rectScreen.SetRect(SCREEN_LEFT, SCREEN_TOP, SCREEN_RIGHT, SCREEN_BOTTOM);
CSpinButtonCtrl* pSpin = (CSpinButtonCtrl*)GetDlgItem(IDC_SPIN_DELAY);
pSpin->SetRange(0, 1000);
pSpin->SetPos(25);
((CButton*)GetDlgItem(IDC_RDO_UP))->SetCheck(1);
StartThread();
return TRUE;
}
void CCreditsDlg::OnDestroy()
{
KillThread();
delete m_pDC;
m_pDC = NULL;
CDialog::OnDestroy();
}
void CCreditsDlg::StartThread()
{
m_pThread = new CCreditsThread(this, m_pDC->GetSafeHdc(), m_rectScreen);
if (m_pThread == NULL)
return;
ASSERT_VALID(m_pThread);
m_pThread->m_pThreadParams = NULL;
// Create Thread in a suspended state so we can set the Priority
// before it starts getting away from us
if (!m_pThread->CreateThread(CREATE_SUSPENDED))
{
delete m_pThread;
return;
}
// thread priority has been set at idle priority to keep from bogging
// down other apps that may also be running.
VERIFY(m_pThread->SetThreadPriority(THREAD_PRIORITY_IDLE));
// Now the thread can run wild
m_pThread->ResumeThread();
}
void CCreditsDlg::KillThread()
{
// tell thread to shutdown
VERIFY(SetEvent(m_pThread->m_hEventKill));
// wait for thread to finish shutdown
VERIFY(WaitForSingleObject(m_pThread->m_hThread, INFINITE) == WAIT_OBJECT_0);
delete m_pThread;
}
int CCreditsDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDialog::OnCreate(lpCreateStruct) == -1)
return -1;
// m_pDC must be initialized here instead of the constructor
// because the HWND isn't created until Create is called.
m_pDC = new CClientDC(this);
return 0;
}
void CCreditsDlg::OnChkWaitvrt()
{
BOOL bWait = ((CButton*)GetDlgItem(IDC_CHK_WAITVRT))->GetCheck();
m_pThread->SetWaitVRT(bWait);
}
void CCreditsDlg::OnRdoDown()
{
m_pThread->SetScrollDirection(CGDIThread::SCROLL_DOWN);
}
void CCreditsDlg::OnRdoPause()
{
m_pThread->SetScrollDirection(CGDIThread::SCROLL_PAUSE);
}
void CCreditsDlg::OnRdoUp()
{
m_pThread->SetScrollDirection(CGDIThread::SCROLL_UP);
}
void CCreditsDlg::OnDeltaposSpinDelay(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
m_pThread->SetDelay(pNMUpDown->iPos + pNMUpDown->iDelta);
*pResult = 0;
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.