CClientDC dc(this)-如果窗口打开,这会失败吗? [英] CClientDC dc(this) -- does this fail if window is open?

查看:59
本文介绍了CClientDC dc(this)-如果窗口打开,这会失败吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.

我已经实现了一个自定义工具提示,下面是代码.下面是绘制提示时最终调用taht的功能.

CClientDC dc(this);
DrawTip(&dc);

void CustomToolTipPlain::DrawTip(CDC *pDC)
{
	if (pDC)
	{
		BITMAP	bm;
		m_tipImage->GetBitmap(&bm);
		CDC		dcMem;
		dcMem.CreateCompatibleDC(pDC);
		CBitmap *oldBitmap = dcMem.SelectObject(m_tipImage);
		pDC->BitBlt(0, 0, bm.bmWidth, bm.bmHeight, &dcMem, 0, 0, SRCCOPY);
		dcMem.SelectObject(oldBitmap);
	}
}



还有另一个功能

void CustomToolTip::OnTimer(UINT)
{
    if (!MouseInTipArea())
    {
        HideTip();
    }
    else
    {
        ShowWindow(SW_SHOW);
    }
}



现在,在甚至调用CClientDC dc(this)之前调用Ontimer函数的情况下;并完成绘图(DrawTip(& dc);
)

在这种情况下,我的工具提示始终为空白,并且没有任何内容.它只是显示OnTimer的ShowWindow(SW_SHOW)函数中的空白窗口.

从调试中可以清楚地看到对CClientDC dc(this);的调用.打开窗口时,将给出空白的dc值.这是真的吗,你们认为这是原因吗?所以我的问题是:

是否CClientDC dc(this);当打开客户端窗口时失败? >将具有有效值.


通常,会从OnPaint()处理函数中调用DrawTip()之类的函数.您在哪里调用此函数?

无论如何,要回答您的问题,是的,在打开窗口时可以使用CClientDC.你检查过位图了吗?您是否验证它已加载?您检查位图尺寸了吗?


Hello everyone.

I have implemented a custom tooltip below is the code. Below is the function taht is called at last while drawing the tip.

CClientDC dc(this);
DrawTip(&dc);

void CustomToolTipPlain::DrawTip(CDC *pDC)
{
	if (pDC)
	{
		BITMAP	bm;
		m_tipImage->GetBitmap(&bm);
		CDC		dcMem;
		dcMem.CreateCompatibleDC(pDC);
		CBitmap *oldBitmap = dcMem.SelectObject(m_tipImage);
		pDC->BitBlt(0, 0, bm.bmWidth, bm.bmHeight, &dcMem, 0, 0, SRCCOPY);
		dcMem.SelectObject(oldBitmap);
	}
}



There is also another function

void CustomToolTip::OnTimer(UINT)
{
    if (!MouseInTipArea())
    {
        HideTip();
    }
    else
    {
        ShowWindow(SW_SHOW);
    }
}



Now in the situation where the Ontimer function is called before even calling the CClientDC dc(this); and finishing the drawing (DrawTip(&dc);
)

My tooltip is always blank in this situation and it doesn''t draw anything. It just shows a blank window from the ShowWindow(SW_SHOW) function of the OnTimer.

From the debugging its clear that the call to CClientDC dc(this); is giving a blank dc value when the window is open. Is this true,do you guys think this is the reason? So my question is:

Does CClientDC dc(this); fails when the client windows is open?

解决方案

From what you have posted above it looks like you are calling CClientDC dc(this); from outside of any class or function where this would have a valid value.


Usually a function like DrawTip() would be called from the OnPaint() handler. Where are you calling this function?

In any case, to answer your question, yes, it''s ok to use CClientDC when the window is open. Have you checked the bitmap? Did you verify it was loaded? Did you check the bitmap dimensions?


这篇关于CClientDC dc(this)-如果窗口打开,这会失败吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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