本文介绍了如何使用CSplitterWnd显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有拆分窗口的项目  CSplitterWnd。


客户区被拆分为2x2子区域:


BOOL CMainFrame :: OnCreateClient(LPCREATESTRUCT / * lpcs * /,

CCreateContext * pContext)

{

if(!m_wndSplitter.CreateStatic(this,2,2))

返回false;

m_wndSplitter.CreateView(0,0,RUNTIME_CLASS(CmyView1) ),CSize(300,300),pContext);

m_wndSplitter.CreateView(0,1,RUNTIME_CLASS(CmyView2),CSize (300,300),pContext);

m_wndSplitter.CreateView(1,0,RUNTIME_CLASS(CmyView3),CSize(300, 100),pContext);

m_wndSplitter.CreateView(1,1,RUNTIME_CLASS(CmyView4),CSize(300,100), pContext);



返回true;

}


I需要在其中一个中显示图像,例如第一个,CmyView1是CView的子类,我在其中调用SetDIBitsToDevice来显示图像:


void CmyView1 :: OnDraw(CDC * pDC)

{


SetDIBitsToDevice(pDC-> GetSafeHdc(),dwidth ,0,dwidth,

dheight,0,0,0,dheight,imagedata,bmi,

DIB_RGB_COLORS);

}


但是,虽然调用了CMainFrame中的Invalidate和UpdateWindow,但没有显示任何内容。


相同的代码在另一个项目中有效没有CSplitterWnd。


以下代码可以绘制一个圆圈,所以我认为pDC没问题:


void CmyView2 :: OnDraw(CDC * pDC)

{


CPen笔(PS_SOLID,1,RGB(0,0,255));

CPen * pOldPen = pDC-> SelectObject( & pen);

pDC-> Ellipse(100,100,300,300);

}


但是为什么SetDIBitsToDevice不起作用?


可能与CSplitterWnd有关吗?如何使用  CSplitterWnd显示图像?


提前致谢!



解决方案


Hi, I have a project with split window CSplitterWnd.

The Client area is splitted into 2x2 sub areas:

BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT /*lpcs*/,
CCreateContext* pContext)
{
if (!m_wndSplitter.CreateStatic(this, 2, 2))
return false;
m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CmyView1), CSize(300, 300), pContext);
m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CmyView2), CSize(300, 300), pContext);
m_wndSplitter.CreateView(1, 0, RUNTIME_CLASS(CmyView3), CSize(300, 100), pContext);
m_wndSplitter.CreateView(1, 1, RUNTIME_CLASS(CmyView4), CSize(300, 100), pContext);

return true;
}

I need to display an image in one of them, for example, the first one, and CmyView1 is subclass of CView, in which I call SetDIBitsToDevice to show the image:

void CmyView1::OnDraw(CDC* pDC)
{

SetDIBitsToDevice(pDC->GetSafeHdc(), dwidth, 0, dwidth,
dheight, 0, 0, 0, dheight, imagedata, bmi,
DIB_RGB_COLORS);

}

However, nothing is displayed although Invalidate and UpdateWindow from CMainFrame are called.

Same codes work in another project without CSplitterWnd.

And the following codes can draw a circle so I think pDC is ok:

void CmyView2::OnDraw(CDC* pDC)
{

CPen pen(PS_SOLID, 1, RGB(0, 0, 255));
CPen* pOldPen = pDC->SelectObject(&pen);
pDC->Ellipse(100, 100, 300, 300);

}

But why SetDIBitsToDevice does not work?

May it be related to CSplitterWnd? How to display an image with CSplitterWnd?

Thanks in advance!

解决方案


这篇关于如何使用CSplitterWnd显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 22:28