Problem sa Dialog klasama ili sta?

Problem sa Dialog klasama ili sta?

offline
  • PoP  Male
  • Ugledni građanin
  • Pridružio: 17 Apr 2003
  • Poruke: 420
  • Gde živiš: Pozega

Dakle radim (MFC) program po (Visul C++6) knjizi. Program se sastoji iz dva dijaloga. U prvom(CGraphicsDlg) su kontrole, drugi(PaintDialog) sluzi za iscrtavanje oblika odredjenih pomocu kontrola prvog dijaloga. Dakle
deklarisem drugu klasu:
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); };
potom ukljucujem .h u .cpp od oba dijaloga (do ovde je sve jasno), a onda
citiram:
"...da dodate drugu dijalog klasu kao promenljivu, tip promenljive je isti kao druga dijalog klasa dakle CPaintDlg, ime m_dlgPaint, a promenljiva treba da bude deklarisana kao private".
Ja sam to uradio ovako:
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;    };
Mada smatram da sam dobro shvatio predhodni citat, (bolje da je dao liniju koda nego s..o pola strane o tome sta treba i kako da se deklarise) pri kompilaciji javlja sledece tri greske:
d:\radni\c++\graphics\graphicsdlg.h(50) : error C2146: syntax error : missing ';' before identifier 'paint' d:\radni\c++\graphics\graphicsdlg.h(50) : error C2501: 'CPaintDialog' : missing storage-class or type specifiers d:\radni\c++\graphics\graphicsdlg.h(50) : error C2501: 'paint' : missing storage-class or type specifiers

sve tri se odnose na:

private:
CPaintDialog paint;

deklaraciju. Dva dana vec pokusavam da skontam sta je problem... Mislim
CPaintDialog je klasa, what a f...? Problem sam "premostio" tako sto sam paint promenjivu deklarisao kao CDialog, ali u daljem toku programa treba da kontrolama iz GraphicsDialog-a uticem na desavanja u paintDialog-u, sto pomocu paint promenljive nije moguce... Ako moze neko da pomogne?[/code]



Registruj se da bi učestvovao u diskusiji. Registrovanim korisnicima se NE prikazuju reklame unutar poruka.
offline
  • Pridružio: 18 Apr 2003
  • Poruke: 5001
  • Gde živiš: Beograd

A stavio si #include naredbu sa imenom fajla gde ti se nalazi CPaintDialog? Ja ovako ne vidim nsita cudno, uploaduj cele cpp i h fajlove.



offline
  • PoP  Male
  • 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_)

offline
  • Pridružio: 18 Apr 2003
  • Poruke: 5001
  • Gde živiš: Beograd

Unutar "GraphicsDlg.h" fajla nemas #include "PaintDialog.h"

offline
  • PoP  Male
  • Ugledni građanin
  • Pridružio: 17 Apr 2003
  • Poruke: 420
  • Gde živiš: Pozega

Hvala puno!Ulepsao si mi dan Smile
Neverovatno da knjiga ima gresku tog tipa.... izricito daje listing za oba .cpp:
#include "stdafx.h" #include "Graphics.h" #include "PaintDialog.h" #include "GraphicsDlg.h"
ali .h ne pominje.
Ustvari u GraphicsDlg.cpp i ne treba include....

offline
  • Pridružio: 18 Apr 2003
  • Poruke: 5001
  • Gde živiš: Beograd

PoP ::Hvala puno!Ulepsao si mi dan Smile
Nema na cemu Smile

PoP ::Ustvari u GraphicsDlg.cpp i ne treba include....
Da, ne treba include unutar .cpp fajla ako postoji unutar prethodno include-ovanog .h fajla.

Ko je trenutno na forumu
 

Ukupno su 1123 korisnika na forumu :: 39 registrovanih, 5 sakrivenih i 1079 gosta   ::   [ Administrator ] [ Supermoderator ] [ Moderator ] :: Detaljnije

Najviše korisnika na forumu ikad bilo je 3466 - dana 01 Jun 2021 17:07

Korisnici koji su trenutno na forumu:
Korisnici trenutno na forumu: A.R.Chafee.Jr., antonije64, Areal84, babaroga, Bobrock1, bokisha253, bozo13, dushan, flash12, Georgius, Griffon vulture, hooraay, Kriglord, krkalon, Krvava Devetka, kybonacci, laurusri, Leonov, Lieutenant, Lošmi, mercedesamg, milutin134, nebkv, ninareflex, Oscar, pein, procesor, raptorsi, ruger357, Sirius, Srky Boy, stalja, stegonosa, Trpe Grozni, Vladko, VP6919, Webb, wolf431, yrraf