RichEdit控件设置默认字体时只对中文起作用,对英文不起作用的解决办法

对于微软的richedit控件,当你用如下代码设置其默认字体时,你会发现只对中文有效,对英文无效:

cf.cbSize = sizeof(CHARFORMAT);
::SendMessage(hWnd, EM_SETCHARFORMAT, SCF_DEFAULT, (LPARAM)&cf);

这个时候,你输入中英文混排的文字你会发现,只有中文字体设置生效了,英文却不起作用。要避免这个问题,必须再对richedit进行如下设置:

::SendMessage(hWnd, EM_SETLANGOPTIONS, 0, 0);

经测试得知RichEdit默认开启了IMF_AUTOFONT和IMF_DUALFONT,msdn上说:

IMF_AUTOFONT 

If this flag is set, the control automatically changes fonts when the user explicitly changes to a different keyboard layout. It is useful to turn off IMF_AUTOFONT for universal Unicode fonts. This option is turned on by default (1).

IMF_DUALFONT

If this flag is set, the control uses dual-font mode. Used for Asian language support. The control uses an English font for ASCII text and a Asian font for Asian text. This option is turned on by default (1).

see msdn:https://msdn.microsoft.com/en-us/library/windows/desktop/bb788040(v=vs.85).aspx

你可能感兴趣的:(RichEdit控件设置默认字体时只对中文起作用,对英文不起作用的解决办法)