我写了个类(CLed),在别的类中不能访问我写的类的成员函数?
基于对话框的
估计出错在CClientDC dcl(this);?
为什么不能这样用呢?
小弟谢过!
class CLed : public CWnd
void CLed::draw_LedA(int add)
{
CClientDC dcl(this);
// CPen penBlue(PS_SOLID, 5, RGB(255, 255, 255));
      //  CPen* pOldPen =dcl.SelectObject(&penBlue);   // and a solid red brush
  // CBrush  brushRed(RGB(m_clorled[0], 0, 0));
  // CBrush* pOldBrush = dcl.SelectObject(&brushRed);
  // dc.Rectangle(20,20,100,100);
   CPoint pts[6];
  
   pts[0].x = 54+add;
   pts[0].y = 21;   pts[1].x = 66+add;
   pts[1].y = 14;   pts[2].x = 165+add;
   pts[2].y = 14;   pts[3].x = 174+add;
   pts[3].y = 21;   pts[4].x = 159+add;
   pts[4].y = 38;   pts[5].x = 69+add;
   pts[5].y = 38;
   dcl.Polygon(pts, 6);
}
void CCledDlg::OnButton1() 
{
// TODO: Add your control notification handler code here
CLed led;
led.draw_LedA(0);
}

解决方案 »

  1.   

    draw_LedA 是public?头声音文件 贴出业,报什么错?
      

  2.   

    CLed led;
    ----------------
    至少需要Create窗口
    通常需要显示出来才有绘制的必要:) 
      

  3.   

    顶楼上, 有可能是该函数不是public。所以不能访问, 
      

  4.   

    呵呵问题解决!void CLed::draw_LedA(int add)
    {
    CClientDC dcl(AfxGetApp()->m_pMainWnd);
    // CPen penBlue(PS_SOLID, 5, RGB(255, 255, 255));
          //  CPen* pOldPen =dcl.SelectObject(&penBlue);   // and a solid red brush
       CBrush  brushRed(RGB(m_clorled[0], 0, 0));
       CBrush* pOldBrush = dcl.SelectObject(&brushRed);
      // dc.Rectangle(20,20,100,100);
       CPoint pts[6];
      
       pts[0].x = 54+add;
       pts[0].y = 21;   pts[1].x = 66+add;
       pts[1].y = 14;   pts[2].x = 165+add;
       pts[2].y = 14;   pts[3].x = 174+add;
       pts[3].y = 21;   pts[4].x = 159+add;
       pts[4].y = 38;   pts[5].x = 69+add;
       pts[5].y = 38;
       dcl.Polygon(pts, 6);
    }
      

  5.   

    有你这样用DC的吗,你应该把它作为一个参数传入void CLed::draw_LedA(int add,CDC* pDC)
    {
    }