zoukankan      html  css  js  c++  java
  • win32编辑控件字体

    每次到用的时候就各种查资料,我这人记性又不好,遂记录下来:

    普通的编辑控件: 

    • 创建:HWND hText = CreateWindowW(L"EDIT", L"enter some text", WS_VISIBLE | WS_CHILD | ES_RIGHT, 500, 100, 200, 100, hWnd, NULL, NULL, NULL); (仅供参考)
    • 创建笔: 
      LOGFONT logfont; 
      ZeroMemory(&logfont, sizeof(LOGFONT));
      logfont.lfCharSet = DEFAULT_CHARSET;
      logfont.lfHeight = -20; 
      HFONT hFont = CreateFontIndirect(&logfont);
    • 设置文本大小: SendMessage(hText, WM_CTLCOLOREDIT, (WPARAM)hFont, TRUE);

    如果是改变文本颜色或者文本背景颜色,则在WM_CTLCOLOREDIT消息中设置

    case WM_CTLCOLOREDIT:
        {
    SetBkColor((HDC)wParam, RGB(40, 40, 40)); SetTextColor((HDC)wParam, RGB(
    255, 0, 255)); } break;

    如果是富文本控件,则复杂一点:

    设置文本背景颜色: 

     SendMessage(hedit, EM_SETBKGNDCOLOR, 0, RGB(40, 40, 40));

    设置文本颜色:

    CHARFORMAT2 format;
                memset(&format, 0, sizeof format);
    
                format.cbSize = sizeof(CHARFORMAT2);
                format.dwMask = CFM_COLOR | CFM_FACE;
                format.crTextColor = RGB(255, 0, 255);
                memcpy(format.szFaceName, L"Consolas", sizeof(L"Consolas"));
                if (SendMessage(hedit, EM_SETCHARFORMAT, SCF_DEFAULT, (LPARAM)&format) == 0) {
                    mb_err("Failed to set font.");
                }

    富文本控件的创建与设置具体可以参考: https://www.cnblogs.com/strive-sun/p/11778590.html

  • 相关阅读:
    KVC与KVO的进阶使用
    Qt之图形视图框架
    Qt之QRoundProgressBar(圆形进度条)
    Qt之绘制闪烁文本
    Qt之QCustomPlot(图形库)
    Qt之事件系统
    iOS 保持界面流畅的技巧
    iOS开发数据库SQLite的使用
    Qt之保持GUI响应
    Qt之QSS(QDarkStyleSheet)
  • 原文地址:https://www.cnblogs.com/strive-sun/p/12171614.html
Copyright © 2011-2022 走看看