无法访问另一个类的成员函数内的CDC类成员? [英] Cannot Access the CDC class members inside the member function of another class?

查看:158
本文介绍了无法访问另一个类的成员函数内的CDC类成员?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CDC(SetPixel)函数无法在另一个类的成员函数中访问。



// OnPerformIBIT是我创建的成员函数

void CSplitterOne :: OnPerformIBIT()

{

The CDC (SetPixel) function cannot be accessible inside the member function of another class.

//OnPerformIBIT is a member function created by me
void CSplitterOne:: OnPerformIBIT()
{

CDC *myDC = GetDlgItem(IDC_PICBOX)->GetDC();

myDC->SetPixel(0, 0, RGB(0,0,0));
myDC->SetPixel(1, 1, RGB(0,0,0));
myDC->SetPixel(2, 2, RGB(0,0,0));
myDC->SetPixel(3, 3, RGB(0,0,0));
myDC->SetPixel(4, 4, RGB(0,0,0));
myDC->SetPixel(5, 5, RGB(0,0,0));
myDC->SetPixel(6, 6, RGB(0,0,0));



}



//在上面的函数中从MainFrm.cpp调用。在同一个函数中,我无法为CDC创建对象。它给出断言。我没有得到Window的句柄(hWnd)。

如果我在OnPaint()中做同样的事情就行了。请帮帮我。



// CSplitterOne是FormView类。


}

//In the above function is called from MainFrm.cpp. In the same function I cannot create the object for CDC. It give assertion. I am not get the Handle for Window (hWnd).
If I am do the same in thing in OnPaint() it works. Please Help me.

//CSplitterOne is FormView class.

推荐答案

看起来你正在打电话在尚未创建窗口的时刻GetDlgItem。然后它的m_hWnd仍为0并且你遇到了一个ASSERT。



你可以在调用getDlgItem之前通过测试m_hWnd来轻松验证这个假设。
It looks like you are calling GetDlgItem at a moment when the window has not been created yet. Then it''s m_hWnd is still 0 and you run into an ASSERT.

You can easily verify this assumption by testing m_hWnd before calling GetDlgItem.


这篇关于无法访问另一个类的成员函数内的CDC类成员?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆