offline
- PoP
- Ugledni građanin
- Pridružio: 17 Apr 2003
- Poruke: 420
- Gde živiš: Pozega
|
Jesam. evo:
// GraphicsDlg.h : header file
//
#if !defined(AFX_GRAPHICSDLG_H__B2C59088_BF55_4F03_80E0_61CC245D5D81__INCLUDED_)
#define AFX_GRAPHICSDLG_H__B2C59088_BF55_4F03_80E0_61CC245D5D81__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
/////////////////////////////////////////////////////////////////////////////
// CGraphicsDlg dialog
class CGraphicsDlg : public CDialog
{
// Construction
public:
CGraphicsDlg(CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(CGraphicsDlg)
enum { IDD = IDD_GRAPHICS_DIALOG };
int m_iColor;
int m_iShape;
int m_iTool;
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CGraphicsDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
HICON m_hIcon;
// Generated message map functions
//{{AFX_MSG(CGraphicsDlg)
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
afx_msg void OnExit();
afx_msg void OnRSelection();
afx_msg void OnOnRSelection();
afx_msg void OnRcred();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
private:
CPaintDialog paint;
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_GRAPHICSDLG_H__B2C59088_BF55_4F03_80E0_61CC245D5D81__INCLUDED_)
// GraphicsDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Graphics.h"
#include "PaintDialog.h"
#include "GraphicsDlg.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()
/////////////////////////////////////////////////////////////////////////////
// CGraphicsDlg dialog
CGraphicsDlg::CGraphicsDlg(CWnd* pParent /*=NULL*/)
: CDialog(CGraphicsDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CGraphicsDlg)
m_iColor = -1;
m_iShape = -1;
m_iTool = -1;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CGraphicsDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CGraphicsDlg)
DDX_Radio(pDX, IDC_RCBLACK, m_iColor);
DDX_Radio(pDX, IDC_RSLINE, m_iShape);
DDX_Radio(pDX, IDC_RTPEN, m_iTool);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CGraphicsDlg, CDialog)
//{{AFX_MSG_MAP(CGraphicsDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_EXIT, OnExit)
ON_BN_CLICKED(IDC_RTPEN, OnRSelection)
ON_BN_CLICKED(IDC_RTBRUSH, OnOnRSelection)
ON_BN_CLICKED(IDC_RTBITMAP, OnOnRSelection)
ON_BN_CLICKED(IDC_RSLINE, OnOnRSelection)
ON_BN_CLICKED(IDC_RSCIRCLE, OnOnRSelection)
ON_BN_CLICKED(IDC_RSSQUARE, OnOnRSelection)
ON_BN_CLICKED(IDC_RCBLACK, OnOnRSelection)
ON_BN_CLICKED(IDC_RCBLUE, OnOnRSelection)
ON_BN_CLICKED(IDC_RCGREEN, OnOnRSelection)
ON_BN_CLICKED(IDC_RCCYAN, OnOnRSelection)
ON_BN_CLICKED(IDC_RCMAGENTA, OnRSelection)
ON_BN_CLICKED(IDC_RCYELLOW, OnRSelection)
ON_BN_CLICKED(IDC_RCWHITE, OnRSelection)
ON_BN_CLICKED(IDC_RCRED, OnRSelection)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CGraphicsDlg message handlers
BOOL CGraphicsDlg::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);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// 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
// TODO: Add extra initialization here
m_iColor=0;
m_iTool=0;
m_iShape=0;
UpdateData(FALSE);
paint.Create(IDD_PAINT_DLG,this);
paint.ShowWindow(SW_SHOW);
return TRUE; // return TRUE unless you set the focus to a control
}
void CGraphicsDlg::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 CGraphicsDlg::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 CGraphicsDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CGraphicsDlg::OnExit()
{
// TODO: Add your control notification handler code here
OnOK();
}
void CGraphicsDlg::OnRSelection()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
paint.Invalidate();
}
void CGraphicsDlg::OnOnRSelection()
{
// TODO: Add your control notification handler code here
OnRSelection();
}
// PaintDialog.cpp : implementation file
//
#include "stdafx.h"
#include "Graphics.h"
#include "PaintDialog.h"
#include "GraphicsDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
const COLORREF CPaintDialog::m_crColors[8]=
{
RGB(0,0,0),
RGB(0,0,255),
RGB(0,255,0),
RGB(0,255,255),
RGB(255,0,0),
RGB(255,0,255),
RGB(255,255,0),
RGB(255,255,255)
};
/////////////////////////////////////////////////////////////////////////////
// CPaintDialog dialog
CPaintDialog::CPaintDialog(CWnd* pParent /*=NULL*/)
: CDialog(CPaintDialog::IDD, pParent)
{
//{{AFX_DATA_INIT(CPaintDialog)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CPaintDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPaintDialog)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
void CPaintDialog::DrawLine(CPaintDC *pdc,int iColor)
{
CPen lSolidPen(PS_SOLID,1,m_crColors[iColor]);
CPen lDotPen(PS_DOT,1,m_crColors[iColor]);
CPen lDashPen(PS_DASH,1,m_crColors[iColor]);
CPen lDashDotPen(PS_DASHDOT,1,m_crColors[iColor]);
CPen lDashDotDotPen(PS_DASHDOTDOT,1,m_crColors[iColor]);
CPen lNullPen(PS_NULL,1,m_crColors[iColor]);
CPen lInsidePen(PS_INSIDEFRAME,1,m_crColors[iColor]);
CRect lRect;
GetClientRect(lRect);
lRect.NormalizeRect();
CPoint pStart;
CPoint pEnd;
int liDist=lRect.Height()/8;
CPen*loldPen;
pStart.y=lRect.top;
pStart.x=lRect.left;
pEnd.y=pStart.y;
pEnd.x=lRect.right;
int i;
for(i=0;i<7;i++)
{
switch(i)
{
case 0:
loldPen=pdc->SelectObject(&lSolidPen);break;
case 1:
pdc->SelectObject(&lDotPen);break;
case 2:
pdc->SelectObject(&lDashPen);break;
case 3:
pdc->SelectObject(&lDashDotPen);break;
case 4:
pdc->SelectObject(&lDashDotDotPen);break;
case 5:
pdc->SelectObject(&lNullPen);break;
case 6:
pdc->SelectObject(&lInsidePen);
}
pStart.y=pStart.y+liDist;
pEnd.y=pStart.y;
pdc->MoveTo(pStart);
pdc->LineTo(pEnd);
}
pdc->SelectObject(loldPen);
}
BEGIN_MESSAGE_MAP(CPaintDialog, CDialog)
//{{AFX_MSG_MAP(CPaintDialog)
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPaintDialog message handlers
void CPaintDialog::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
CGraphicsDlg *pWnd=(CGraphicsDlg*)GetParent();
if(pWnd)
{
if(pWnd->m_iTool==2)
{
}
else
{
if(pWnd->m_iShape==0)
DrawLine(&dc,pWnd->m_iColor);
}
}
// Do not call CDialog::OnPaint() for painting messages
}
#if !defined(AFX_PAINTDIALOG_H__3AECC8DC_530E_4E18_A627_F6C9B291AA2D__INCLUDED_)
#define AFX_PAINTDIALOG_H__3AECC8DC_530E_4E18_A627_F6C9B291AA2D__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// PaintDialog.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// CPaintDialog dialog
class CPaintDialog : public CDialog
{
// Construction
public:
CPaintDialog(CWnd* pParent = NULL); // standard constructor
static const COLORREF m_crColors[8];
// Dialog Data
//{{AFX_DATA(CPaintDialog)
enum { IDD = IDD_PAINT_DLG };
// NOTE: the ClassWizard will add data members here
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CPaintDialog)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(CPaintDialog)
afx_msg void OnPaint();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
private:
void DrawLine(CPaintDC *pdc,int iColor);
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_PAINTDIALOG_H__3AECC8DC_530E_4E18_A627_F6C9B291AA2D__INCLUDED_)
|