Is it possible to set extended styles on Edit control (simple Edit, not Rich Edit)? For example, I want to set the extended style to WS_EX_ZOOMABLE | WS_EX_ALLOWEOL_ALL. The creation of the control is as follows:
HWND hEdit = CreateWindowExW(
ES_EX_ZOOMABLE | ES_EX_ALLOWEOL_ALL,
L"EDIT",
L"",
WS_BORDER | WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL,
0, 0, 100, 100,
hWndMain, (HMENU)ID_EDIT, hInstance, NULL
);
The problem is that none of the extended styles work. The EOL is still CR LF and the control isn't zoomable.
As noted in comments, edit control extended styles are set by sending the control an
EM_SETEXTENDEDSTYLEmessage:You pass the style bits you want to modify as the
wParamargument (the mask) and you pass the new values of these bits as thelParamargument. This allows you to both set and clear styles using a single call, without having to query for the previous values of these styles. This is a very common pattern used by many APIs.If you only want to enable these styles, set
wParamandlParamto the same values, as I did in the code sample above.If you want to clear style bits, leave out the ones you want to clear from the
lParamargument. E. g. to setES_EX_ZOOMABLEbut clearES_EX_ALLOWEOL_ALL:To clear both bits:
Manifest requirements
For the extended styles to actually work, you need to specify version 6.0 of the common controls in the application manifest. One of the easiest ways to do this is to insert the following compiler directive in your code, typically in the precompiled header file:
Background information
This is likely how the control handles
EM_SETEXTENDEDSTYLEin terms of bit-wise operations:wParam, using bit-wise NOT (~).currentExStyle, using bitwise AND (&). This clears all these bits fromcurrentExStylethat were initially set forwParam.|), set the bits that were passed forlParam.