博客
关于我
VS2010/MFC编程入门之四十八(字体和文本输出:文本输出)
阅读量:72 次
发布时间:2019-02-25

本文共 3668 字,大约阅读时间需要 12 分钟。

MFC????????????

?MFC???????????????????????????????????????????????????????????????

??????

????????????????????????????????????Windows??????????????????????????????????????????????????

?????????????????

  • ??????
  • ?????
  • ????????
  • 1. ??????

    ?????????????????????????????????????????????????????????????????????????????CFont????????????????????GetTextMetrics?????????

    BOOL GetTextMetrics(__in HDC hdc, __out LPTEXTMETRIC lptm);

    TEXTMETRIC??????????

    • tmHeight?????
    • tmAscent??????????
    • tmDescent??????????
    • tmInternalLeading??tmHeight??????????????
    • tmExternalLeading????
    • tmAveCharWidth????????
    • tmMaxCharWidth????????
    • tmWeight??????
    • tmOverhang???????????
    • tmDigitizedAspectX?????????x???
    • tmDigitizedAspectY?????????y???
    • tmFirstChar??????????
    • tmLastChar???????????
    • tmDefaultChar???????????
    • tmBreakChar?????????
    • tmItalic??0????????
    • tmUnderlined??0?????????
    • tmStruckOut??0??????????
    • tmPitchAndFamily?????????
    • tmCharSet????

    2. ?????

    ????????????????????????????????

    ?????????

    ??????????????GetTextExtentPoint32?????????

    BOOL GetTextExtentPoint32(__in HDC hdc, __in LPCTSTR lpString, __in int c, __out LP.SIZE lpSize);

    ????????????????????????

    ?????????????

    ??GetTextMetrics??????????????????????????????????

    3. ????????

    ?????TextOut???????????TextOut????????

    BOOL TextOut(__in HDC hdc, __in int nXStart, __in int nYStart, __in LPCTSTR lpString, __in int cbString);

    ???CDC??TextOut?????????????

    virtual BOOL TextOut(int x, int y, LPCTSTR lpszString, int nCount);BOOL TextOut(int x, int y, const CString& str);

    ????????????

    ????????MFC??????????????????????????

    ????
  • ????????MFC??????Example48?

  • ???????????IDD_EXAMPLE48_DIALOG?????????????

  • ?Example48Dlg.h????CExample48????????

  • int m_nTextX; // ???????????x??int m_nTextY; // ???????????y??CFont m_newFont;CFont* m_pOldFont;
    1. ?CExample48Dlg???????????????
    2. CExample48Dlg::CExample48Dlg(CWnd* pParent /*=NULL*/){    CDialogEx(CExample48Dlg::IDD, pParent);    m_nTextX = 260;    m_nTextY = 10;    m_pOldFont = NULL;}
      1. ?OnInitDialog????????????
      2. BOOL CExample48Dlg::OnInitDialog(){    CDialogEx::OnInitDialog();    // ?????18????    m_newFont.CreatePointFont(180, _T("??"));    m_pOldFont = (CFont*)dc.SelectObject(&m_newFont);    // ?????    SetTimer(1, 200, NULL);    return TRUE;}
        1. ??OnPaint????????????
        2. void CExample48Dlg::OnPaint(){    if (IsIconic())    {        CPaintDC dc(this);        dc.SendMessage(WM_ICONERASEBKGND, reinterpret_cast
          (dc.GetSafeHdc()), 0); int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; dc.DrawIcon(x, y, m_hIcon); } else { CPaintDC dc(this); // ?????????? m_pOldFont = (CFont*)dc.SelectObject(&m_newFont); dc.SetBkMode(TRANSPARENT); dc.SetTextColor(RGB(255, 0, 0)); dc.TextOut(m_nTextX, 10, _T("????????")); dc.SetTextColor(RGB(0, 255, 0)); dc.TextOut(10, m_nTextY, _T("????www.jizhuomi.com")); dc.SelectObject(m_pOldFont); CDialogEx::OnPaint(); }}
          1. ?Class View???CExample48Dlg?????Properties?????????Messages?????WM_TIMER???????????CExample48Dlg::OnTimer(UINT_PTR nIDEvent)?????????????
          2. void CExample48Dlg::OnTimer(UINT_PTR nIDEvent){    LOGFONT logFont;    m_newFont.GetLogFont(&logFont);    // ????    m_nTextX -= 5;    if (m_nTextX < 10)    {        m_nTextX = 260;    }    // ????    m_nTextY += abs(logFont.lfHeight);    if (m_nTextY > 260)    {        m_nTextY = 10;    }    Invalidate();    CDialogEx::OnTimer(nIDEvent);}
            ????

            ????????????????????????????????200ms?????????????????????????????????????????

    转载地址:http://mou.baihongyu.com/

    你可能感兴趣的文章
    python 多线程与GIL
    查看>>
    python 字符串中特定字符替换,截取
    查看>>
    Python 字符串总结
    查看>>
    python 字符串显示中文_Python字符串开头的b"、u"、r"与中文乱码
    查看>>
    Python 字符串的几种拼装方式
    查看>>
    python 存入数据库bigint_python基础_MySQL的bigint类型
    查看>>
    python 学习 面向对象编程
    查看>>
    Python 学习日记第三篇 -- 字典
    查看>>
    Python 学习笔记(一)Data type
    查看>>
    python 安装echarts
    查看>>
    python 安装opencv及问题解决
    查看>>
    Python 安装程序:“写入文件 C:\Python27\pythonw.exe 时出错“
    查看>>
    Python 安装避坑指南:从入门到进阶
    查看>>
    Python 安装配置详解
    查看>>
    Python 常见的错误类型和继承关系
    查看>>
    python 常量_零基础学Python系列之一:Python的变量与常量
    查看>>
    Python 并发编程
    查看>>
    python 微信扫码登录_python实现微信第三方网站扫码登录(Django)
    查看>>
    Python 快速下载依赖
    查看>>
    python实现非参数统计的Cochran检验 (附完整源码)
    查看>>