home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Troubleshooting Netware Systems
/
CSTRIAL0196.BIN
/
attach
/
msj
/
v10n07
/
gdiobj.exe
/
GDIOBJ1.CPP
next >
Wrap
C/C++ Source or Header
|
1995-07-01
|
5KB
|
174 lines
//***************************************************************************
//
// GdiObj1 demonstrates basic pen and brush styles.
//
//***************************************************************************
#include <afxwin.h>
#include "gdiobj1.h"
CMyApp myApp;
/////////////////////////////////////////////////////////////////////////////
// CMyApp member functions
BOOL CMyApp::InitInstance ()
{
m_pMainWnd = new CMainWindow ();
m_pMainWnd->ShowWindow (m_nCmdShow);
m_pMainWnd->UpdateWindow ();
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CMainWindow message map and member functions
BEGIN_MESSAGE_MAP (CMainWindow, CFrameWnd)
ON_WM_CREATE ()
ON_WM_PAINT ()
END_MESSAGE_MAP ()
CMainWindow::CMainWindow ()
{
Create (NULL, "GdiObj1");
}
int CMainWindow::OnCreate (LPCREATESTRUCT lpCreateStruct)
{
TEXTMETRIC tm;
CDC* pDC = GetDC ();
pDC->GetTextMetrics (&tm);
m_cxChar = tm.tmAveCharWidth;
m_cyChar = tm.tmHeight;
ReleaseDC (pDC);
return 0;
}
void CMainWindow::OnPaint ()
{
CPaintDC dc (this);
ShowPenStyles (&dc, m_cxChar << 1, m_cyChar);
ShowPenWidths (&dc, m_cxChar << 1, m_cyChar * 15);
ShowBrushStyles (&dc, m_cxChar << 1, m_cyChar * 27);
}
void CMainWindow::ShowPenStyles (CDC* pDC, int x, int y)
{
CPen* pPen;
CPen* pOldPen;
struct STYLES styles[] = {
PS_SOLID, "PS_SOLID",
PS_DASH, "PS_DASH",
PS_DOT, "PS_DOT",
PS_DASHDOT, "PS_DASHDOT",
PS_DASHDOTDOT, "PS_DASHDOTDOT",
PS_NULL, "PS_NULL",
PS_INSIDEFRAME, "PS_INSIDEFRAME"
};
CString string = "Pen Styles";
pDC->TextOut (x, y, string);
int dy = (m_cyChar * 3) >> 1;
pDC->SetTextColor (RGB (255, 0, 0));
for (int i=0; i<7; i++) {
y += dy;
string = styles[i].szStyleName;
pDC->TextOut (x + (m_cxChar << 1), y, string);
pPen = new CPen (styles[i].nStyle, 1, RGB (255, 0, 0));
pOldPen = pDC->SelectObject (pPen);
pDC->MoveTo (x + (m_cxChar * 22), y + (m_cyChar >> 1));
pDC->LineTo (x + (m_cxChar * 46), y + (m_cyChar >> 1));
delete pDC->SelectObject (pOldPen);
}
}
void CMainWindow::ShowPenWidths (CDC* pDC, int x, int y)
{
CPen* pPen;
CPen* pOldPen;
int nPenWidths[] = { 2, 8, 16, 24 };
CString string = "Pen Widths";
pDC->SetTextColor (RGB (0, 0, 0));
pDC->TextOut (x, y, string);
int dy = m_cyChar << 1;
pDC->SetTextColor (RGB (0, 0, 255));
for (int i=0; i<4; i++) {
y += dy;
string.Format ("%d Pixels", nPenWidths[i]);
pDC->TextOut (x + (m_cxChar << 1), y, string);
pPen = new CPen (PS_SOLID, nPenWidths[i], RGB (0, 0, 255));
pOldPen = pDC->SelectObject (pPen);
pDC->MoveTo (x + (m_cxChar * 22), y + (m_cyChar >> 1));
pDC->LineTo (x + (m_cxChar * 46), y + (m_cyChar >> 1));
delete pDC->SelectObject (pOldPen);
}
}
void CMainWindow::ShowBrushStyles (CDC* pDC, int x, int y)
{
CBrush* pBrush;
CBrush* pOldBrush;
struct STYLES styles[] = {
HS_BDIAGONAL, "HS_BDIAGONAL",
HS_CROSS, "HS_CROSS",
HS_DIAGCROSS, "HS_DIAGCROSS",
HS_FDIAGONAL, "HS_FDIAGONAL",
HS_HORIZONTAL, "HS_HORIZONTAL",
HS_VERTICAL, "HS_VERTICAL"
};
CString string = "Brush Styles";
pDC->SetTextColor (RGB (0, 0, 0));
pDC->TextOut (x, y, string);
int dy = m_cyChar * 3;
for (int i=0; i<6; i++) {
y += dy;
string = styles[i].szStyleName;
pDC->TextOut (x + (m_cxChar << 1), y, string);
CRect rect (x + (m_cxChar * 22), y - m_cyChar,
x + (m_cxChar * 46), y + m_cyChar);
pBrush = new CBrush (styles[i].nStyle, RGB (0, 255, 0));
CPoint point (rect.left, rect.top);
pDC->LPtoDP (&point);
point.x &= 0x07;
point.y &= 0x07;
pDC->SetBrushOrg (point);
pOldBrush = pDC->SelectObject (pBrush);
pDC->Rectangle (rect);
delete pDC->SelectObject (pOldBrush);
}
y += dy;
string = "Solid";
pDC->TextOut (x + (m_cxChar << 1), y, string);
pBrush = new CBrush (RGB (0, 255, 0));
pOldBrush = pDC->SelectObject (pBrush);
pDC->Rectangle (x + (m_cxChar * 22), y - m_cyChar,
x + (m_cxChar * 46), y + m_cyChar);
delete pDC->SelectObject (pOldBrush);
}