2013-04-05 67 views
-2

我無法從成員函數CAboutDlg::OnLButtonDown訪問私有成員變量。 當我試圖分配一個新的值ellipseColor我得到undeclared identifier錯誤。當我嘗試通過類CCSIT861a3VasilkovskiyDlg::ellipseColor訪問它時,編譯器說它是無法訪問的。成員變量 - 未定義和不可訪問

我錯過了什麼,以及如何訪問/修改這些變量?

頭文件:

#pragma once 


// CCSIT861a3VasilkovskiyDlg dialog 
class CCSIT861a3VasilkovskiyDlg : public CDialogEx 
{ 
// Construction 
public: 
    CCSIT861a3VasilkovskiyDlg(CWnd* pParent = NULL); // standard constructor 

// Dialog Data 
    enum { IDD = IDD_CSIT861A3VASILKOVSKIY_DIALOG }; 

    protected: 
    virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support 


// Implementation 
protected: 
    HICON m_hIcon; 

    // Generated message map functions 
    virtual BOOL OnInitDialog(); 
    afx_msg void OnSysCommand(UINT nID, LPARAM lParam); 
    afx_msg void OnPaint(); 
    afx_msg HCURSOR OnQueryDragIcon(); 
    DECLARE_MESSAGE_MAP() 
private: 
    COLORREF ellipseColor; 
    COLORREF centerRectColor; 
    COLORREF rightRectColor; 
    CRect centerRect; 
    CRect rightRect; 
    CSize ellipse; 
    bool mouseCaptured; 
}; 

實現文件:

#include "stdafx.h" 
#include "CSIT861a3 Vasilkovskiy.h" 
#include "CSIT861a3 VasilkovskiyDlg.h" 
#include "afxdialogex.h" 

#ifdef _DEBUG 
#define new DEBUG_NEW 
#endif 


// CAboutDlg dialog used for App About 

class CAboutDlg : public CDialogEx 
{ 
public: 
    CAboutDlg(); 

// Dialog Data 
    enum { IDD = IDD_ABOUTBOX }; 

    protected: 
    virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support 

// Implementation 
protected: 
    DECLARE_MESSAGE_MAP() 
public: 
    afx_msg void OnLButtonDown(UINT nFlags, CPoint point); 
    afx_msg void OnLButtonUp(UINT nFlags, CPoint point); 
    afx_msg void OnMouseMove(UINT nFlags, CPoint point); 
}; 

CAboutDlg::CAboutDlg() : CDialogEx(CAboutDlg::IDD) 
{ 
} 

void CAboutDlg::DoDataExchange(CDataExchange* pDX) 
{ 
    CDialogEx::DoDataExchange(pDX); 
} 

BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx) 
    ON_WM_LBUTTONDOWN() 
    ON_WM_LBUTTONUP() 
    ON_WM_MOUSEMOVE() 
END_MESSAGE_MAP() 


// CCSIT861a3VasilkovskiyDlg dialog 




CCSIT861a3VasilkovskiyDlg::CCSIT861a3VasilkovskiyDlg(CWnd* pParent /*=NULL*/) 
    : CDialogEx(CCSIT861a3VasilkovskiyDlg::IDD, pParent) 
{ 
    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); 

    ellipseColor = RGB(255, 0, 0); 
    centerRectColor = RGB(0, 0, 0); 
    rightRectColor = RGB(255, 0, 0); 
    centerRect.left = 40; 
    centerRect.top = 20; 
    centerRect.right = 55; 
    centerRect.bottom = 80; 
    rightRect.left = 75; 
    rightRect.top = 35; 
    rightRect.right = 90; 
    rightRect.bottom = 50; 
    ellipse.cx = 10; 
    ellipse.cy = 10; 
    mouseCaptured = false; 
} 

void CCSIT861a3VasilkovskiyDlg::DoDataExchange(CDataExchange* pDX) 
{ 
    CDialogEx::DoDataExchange(pDX); 
} 

BEGIN_MESSAGE_MAP(CCSIT861a3VasilkovskiyDlg, CDialogEx) 
    ON_WM_SYSCOMMAND() 
    ON_WM_PAINT() 
    ON_WM_QUERYDRAGICON() 
END_MESSAGE_MAP() 


// CCSIT861a3VasilkovskiyDlg message handlers 

BOOL CCSIT861a3VasilkovskiyDlg::OnInitDialog() 
{ 
    CDialogEx::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) 
    { 
     BOOL bNameValid; 
     CString strAboutMenu; 
     bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX); 
     ASSERT(bNameValid); 
     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 

    return TRUE; // return TRUE unless you set the focus to a control 
} 

void CCSIT861a3VasilkovskiyDlg::OnSysCommand(UINT nID, LPARAM lParam) 
{ 
    if ((nID & 0xFFF0) == IDM_ABOUTBOX) 
    { 
     CAboutDlg dlgAbout; 
     dlgAbout.DoModal(); 
    } 
    else 
    { 
     CDialogEx::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 CCSIT861a3VasilkovskiyDlg::OnPaint() 
{ 
    //Create pen and pointer to the old pen 
    CPen blackPen; 
    blackPen.CreatePen(PS_SOLID, 1, RGB (0, 0, 0)); 

    //Create a bursh 
    CBrush blackBrush(centerRectColor); 
    CBrush redBrush(rightRectColor); 
    CBrush hatchRedBrush(HS_CROSS, ellipseColor); 

    //Set up object for painting 
    CPaintDC dc (this); 
    CRect rect; 
    GetClientRect (&rect); 
    dc.SetMapMode (MM_ANISOTROPIC); 
    dc.SetWindowExt (100, 100); 
    dc.SetViewportExt (rect.Width(), rect.Height()); 


    //select pen 
    dc.SelectObject(&blackPen); 

    //Rectangle red interior color 
    dc.SelectObject(&redBrush); 
    dc.Rectangle(rightRect); //(75, 35, 90, 50); 

    //Rectangel black interior 
    dc.SelectObject(&blackBrush);//Select Brush 
    dc.Rectangle(centerRect);//(40, 20, 55, 80); 

    //Ellipse 
    dc.SelectObject(&hatchRedBrush);//Select Brush 
    dc.Ellipse(ellipse.cx, ellipse.cy, (ellipse.cx) + 10, (ellipse.cy) + 10);//10, 10, 20, 20); 

    if (IsIconic()) 
    { 
     CPaintDC dc(this); // device context for painting 

     SendMessage(WM_ICONERASEBKGND, reinterpret_cast<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 
    { 
     CDialogEx::OnPaint(); 
    } 
} 

// The system calls this function to obtain the cursor to display while the user drags 
// the minimized window. 
HCURSOR CCSIT861a3VasilkovskiyDlg::OnQueryDragIcon() 
{ 
    return static_cast<HCURSOR>(m_hIcon); 
} 



void CAboutDlg::OnLButtonDown(UINT nFlags, CPoint point) 
{ 
    // TODO: Add your message handler code here and/or call default 
    //SetCapture(); 
    CClientDC dc(this); 
    CRect rect; 
    GetClientRect(&rect); 
    dc.SetMapMode(MM_ANISOTROPIC); 
    dc.SetWindowExt(100, 100); 
    dc.SetViewportExt(rect.Width(), rect.Height()); 
    CRect rectEllipse(10, 10, 20, 20); 



    CDialogEx::OnLButtonDown(nFlags, point); 
} 


void CAboutDlg::OnLButtonUp(UINT nFlags, CPoint point) 
{ 
    // TODO: Add your message handler code here and/or call default 
    ReleaseCapture(); 
    CDialogEx::OnLButtonUp(nFlags, point); 
} 


void CAboutDlg::OnMouseMove(UINT nFlags, CPoint point) 
{ 
    // TODO: Add your message handler code here and/or call default 

    CDialogEx::OnMouseMove(nFlags, point); 
} 

回答

1

OnLButtonDown()CAboutDlg成員函數,但您嘗試訪問privateCCSIT861a3VasilkovskiyDlgstatic數據成員,這是一個不同的類。

你大概意思有功能OnLButtonDown()OnLButtonUp()OnMouseMove()作爲CCSIT861a3VasilkovskiyDlg成員函數,而不是作爲CAboutDlg成員函數。

+0

感謝您的支持。 – Zzz 2013-04-05 21:29:48

+0

@Azzi:很高興幫助 – 2013-04-05 21:30:05