Question

When i do

wnd = CreateWindow("EDIT", 0,
    WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | ES_MULTILINE | 
    ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN,
    x, y, w, h,
    parentWnd,
    NULL, NULL, NULL);

everything is fine, however if i remove the WS_VSCROLL and WS_HSCROLL then do the below, i do not get them thus have incorrect window. Why? Not only do i get an incorrect window it is unusable if both WS_VSCROLL and WS_HSCROLL are missing

style = WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | ES_MULTILINE |
    ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN;
SetWindowLong(wnd, GWL_STYLE, style);
Was it helpful?

Solution

Some control styles cannot be changed after window creation. The ES_AUTOHSCROLL style (which essentially controls word wrapping) is one of them; this is stated (somewhat indirectly) by the MSDN section on Edit Control Styles. You can set the bits using SetWindowLong(), but the control will either ignore them or behave erratically.

The only way to do this cleanly is to recreate the edit control using the required styles. This is actually what Notepad does when you toggle the "Word Wrap" setting.

OTHER TIPS

You can do it with ShowScrollBar() function. You may also find interesting the function EnableScrollBar() if you want to enable/disable scroll bars of a window. Best regards.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top