为什么 SelectObject 被调用两次? [英] Why SelectObject is called twice?

查看:83
本文介绍了为什么 SelectObject 被调用两次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 MFC 中阅读了代码,但对下面的代码感到困惑:

I read code in MFC, but was confused with the code below:

void EditView::ResetDefaultFont()
{
    HFONT hFont = (HFONT)::GetStockObject(DEFAULT_GUI_FONT);
    CDC* pDC = GetDC();

    CFont* pFont = pDC->SelectObject(CFont::FromHandle(hFont));
    pDC->SelectObject(pFont);
    ::DeleteObject(hFont);

}

为什么CDC先选择默认字体(CFont* pFont = pDC->SelectObject(CFont::FromHandle(hFont));),然后再选择pFont?

Why CDC Select the default font first(CFont* pFont = pDC->SelectObject(CFont::FromHandle(hFont));), but select pFont again?

推荐答案

第一个 SelectObject 调用更改在设备上下文中选择的字体.

The first SelectObject call changes the font selected in the device context.

第二次 SelectObject 调用将字体重置为第一次调用之前的字体.

The second SelectObject call resets the font to whatever it was before the first call.

虽然这回答了第二个调用的为什么",这就是您要问的,但我不知道执行完整调用序列的意义何在.我在 MSDN Library 和本地 Visual Studio 2012 帮助中都没有找到 ResetDefaultFont 的文档结果.为了彻底,我在 VS 2012 中创建了一个新的默认 MFC 项目,并在从 CEditView 派生的类的构造函数中使用了标识符 ResetDefaultFont.它没有编译:没有.

While that answers the "why" for the second call, which is what you ask about, I do not have any idea what the point of doing the complete call sequence is. I find no documentation results for ResetDefaultFont, neither online in MSDN Library nor in the local Visual Studio 2012 help. Just to be thorough I created a new default MFC project in VS 2012, and used the identifier ResetDefaultFont in the constructor of a class derived from CEditView. It did not compile: no such.

所以,

你从哪里得到 ResetDefaultFont 函数的?

where did you get that ResetDefaultFont function from?

这篇关于为什么 SelectObject 被调用两次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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