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

普通的编辑控件: 

  • 创建: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

相关文章:

  • 2021-10-09
  • 2022-01-24
  • 2022-02-27
  • 2021-09-02
  • 2021-11-05
  • 2022-01-14
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-01
  • 2021-11-01
  • 2022-12-23
  • 2021-05-19
  • 2021-07-20
  • 2022-12-23
相关资源
相似解决方案