WS_VSCROLL, CreateWindow style works, SetWindowLong doesnt

佐手、 提交于 2019-12-12 11:18:43

问题


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);

回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/285587/ws-vscroll-createwindow-style-works-setwindowlong-doesnt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!