// TestScreenDlg.cpp : implementation file
//
#include "stdafx.h"
#include "TestScreen.h"
#include "TestScreenDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTestScreenDlg dialog
CTestScreenDlg::CTestScreenDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTestScreenDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CTestScreenDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
iTestIndex = 0;
}
void CTestScreenDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTestScreenDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTestScreenDlg, CDialog)
//{{AFX_MSG_MAP(CTestScreenDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_KEYDOWN()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTestScreenDlg message handlers
BOOL CTestScreenDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
ShowWindow(SW_SHOWMAXIMIZED);
PaintBox1();
return TRUE; // return TRUE unless you set the focus to a control
}
void CTestScreenDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// 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 CTestScreenDlg::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();
CPaintDC dc(this); // device context for painting
}
}
HCURSOR CTestScreenDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CTestScreenDlg::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
COLORREF crColor;
if(nChar==VK_SPACE ) {
//Invalidate(FALSE);
switch (iTestIndex % 11) {
case 0 :
PaintBar2();
break;
case 1 :
PaintBar1(0x000001);
break;
case 2 :
PaintBar1(0x000100);
break;
case 3 :
PaintBar1(0x010000);
break;
case 4 :
PaintBar1(0x010101);
break;
case 5 :
PaintBar3(0x000001);
break;
case 6 :
PaintBar3(0x000100);
break;
case 7 :
PaintBar3(0x010000);
break;
case 8 :
PaintBar3(0x010101);
break;
case 9 :
PaintBar4();
break;
case 10 :
PaintBox1();
break;
default :
break;
}
iTestIndex++;
}
CDialog::OnKeyDown(nChar, nRepCnt, nFlags);
}
void CTestScreenDlg::PaintBar1(COLORREF rgbColor)
{
int i;
unsigned char bColor;
COLORREF crColor;
CClientDC dc(this);
CRect R;
GetClientRect(R);
CPen myPen;
for (i=0; i<R.Width(); i++) {
bColor = 255.0/R.Width()*i;
myPen.CreatePen(PS_SOLID, 1, rgbColor*bColor);
dc.SelectObject(myPen);
dc.MoveTo(i,0);
dc.LineTo(i, R.Height());
myPen.DeleteObject();
}
ShowLogo();
}
void CTestScreenDlg::PaintBox1()
{
int i;
unsigned char bColor;
COLORREF crColor;
CClientDC dc(this);
CRect R;
GetClientRect(R);
CPen myPen;
for (i=0; i<256; i++) {
// top line
myPen.CreatePen(PS_SOLID, 1, (255-i)*0x010101);
dc.SelectObject(myPen);
dc.MoveTo(i,i);
dc.LineTo(R.Width()-i, i);
// bottom kine
dc.MoveTo(i,R.Height() - i);
dc.LineTo(R.Width()-i, R.Height()-i);
// left line
dc.MoveTo(i, i);
dc.LineTo(i, R.Height()-i);
// right line
dc.MoveTo(R.Width() - i, i);
dc.LineTo(R.Width() - i, R.Height()-i+1);
myPen.DeleteObject();
}
dc.FillSolidRect(256,256,R.Width()-511, R.Height()-511, 0);
int cx = (R.Width()-511- 20 )/17;
int cy = (R.Height()-511 - 10);
for (i=0; i<8; i++) {
dc.FillSolidRect(256+10+i*cx, 256 + 5, cx, cy, 0x010101*i*25+0x101010);
}
dc.FillSolidRect(256+10+8*cx, 256 + 5, cx, cy, 0x010101*8*25+0x101010);
for (i=0; i<8; i++) {
dc.FillSolidRect(256+10+(i+9)*cx, 256 + 5, cx, cy, 0x010101*(7-i)*25+0x101010);
}
ShowLogo();
}
void CTestScreenDlg::PaintBar2()
{
int i;
unsigned char bColor;
COLORREF crColor;
CClientDC dc(this);
CRect R;
GetClientRect(R);
CPen myPen;
for (i=0; i<R.Width()/4; i++) {
// red line
bColor = 255*4*i/R.Width();
myPen.CreatePen(PS_SOLID, 1, bColor*0x000001);
dc.SelectObject(myPen);
dc.MoveTo(i, 0);
dc.LineTo(i, R.Height());
myPen.DeleteObject();
// green kine
myPen.CreatePen(PS_SOLID, 1, bColor*0x000100);
dc.SelectObject(myPen);
dc.MoveTo(i+R.Width()/4, 0);
dc.LineTo(i+R.Width()/4, R.Height());
myPen.DeleteObject();
// blue line
myPen.CreatePen(PS_SOLID, 1, bColor*0x010000);
dc.SelectObject(myPen);
dc.MoveTo(i+R.Width()/2, 0);
dc.LineTo(i+R.Width()/2, R.Height());
myPen.DeleteObject();
// black-white line
myPen.CreatePen(PS_SOLID, 1, bColor*0x010101);
dc.SelectObject(myPen);
dc.MoveTo(i+R.Width()*3/4, 0);
dc.LineTo(i+R.Width()*3/4, R.Height());
myPen.DeleteObject();
}
ShowLogo();
}
void CTestScreenDlg::PaintBar3(COLORREF rgbColor)
{
int i;
unsigned char bColor;
COLORREF crColor;
CClientDC dc(this);
CRect R;
GetClientRect(R);
dc.FillSolidRect(0, 0, R.Width(), R.Height(), 0xFFAF3F);
CPen myPen;
for (i=0; i<256; i++) {
dc.FillSolidRect((R.Width()-768)/2 + i*3, 200, 3, R.Height()-400, i*rgbColor);
}
ShowLogo();
}
void CTestScreenDlg::PaintBar4()
{
int i;
unsigned char bColor;
COLORREF crColor;
CClientDC dc(this);
CRect R;
GetClientRect(R);
dc.FillSolidRect(0, 0, R.Width(), R.Height(), 0xFFAF3F);
CPen myPen;
for (i=0; i<256; i++) {
dc.FillSolidRect((R.Width()-768)/2 + i + 0, 200, 1, R.Height()-400, i*0x000001);
dc.FillSolidRect((R.Width()-768)/2 + i + 256, 200, 1, R.Height()-400, i*0x000100);
dc.FillSolidRect((R.Width()-768)/2 + i + 512, 200, 1, R.Height()-400, i*0x010000);
}
ShowLogo();
}
void CTestScreenDlg::ShowLogo()
{
CClientDC dc(