470,643 Members | 1,364 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,643 developers. It's quick & easy.

How To Auto-Hide Scrollbars On Edit Control ? C++

SwissProgrammer
212 128KB
I was reading about How To Auto-Hide Scrollbars On Edit Control and I did not like the complicated ways that were suggested.

Subclass, custom, etc.


I am using
C++11.
CodeBlocks 17.12 .
32 bit.
I want to hide the scrollbar when not needed.
I want to show the scrollbar only when it is needed.

Would it be easier to CreateWindowExW two


Expand|Select|Wrap|Line Numbers
  1. h_BoxThatScrolls = CreateWindowExW
  2.             (
  3.                 WS_EX_CLIENTEDGE,
  4.                 L"edit",
  5.                 L"Lines of Stuff\r\n1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n10\r\n11\r\n12\r\n13\r\n14\r\n15\r\n16\r\n17\r\n18\r\n19\r\n20\r\n21\r\n22\r\n23\r\n24\r\n25\r\n26\r\n27\r\n28\r\n29\r\n30",
  6.                 WS_CHILD | ES_MULTILINE | ES_WANTRETURN | WS_VISIBLE | WS_VSCROLL | ES_AUTOVSCROLL,
  7.                 10, 10,
  8.                 100, 100,
  9.                 hwnd,
  10.                 (HMENU) BoxThatScrolls,
  11.                 GetModuleHandle( nullptr ),
  12.                 nullptr
  13.             );
and
Expand|Select|Wrap|Line Numbers
  1. h_NoScrollBox = CreateWindowExW
  2.             (
  3.                 WS_EX_CLIENTEDGE,
  4.                 L"edit",
  5.                 L"Lines of Stuff\r\n1\r\n2\r\n3",
  6.                 WS_CHILD | WS_VISIBLE | ES_AUTOVSCROLL | ES_MULTILINE,
  7.                 10, 10,
  8.                 100, 100,
  9.                 hwnd,
  10.                 (HMENU) NoScrollBox,
  11.                 GetModuleHandle( nullptr ),
  12.                 nullptr
  13.             );
Make the NoScrollBox visible.
Make the BoxThatScrolls invisible or hidden.
Make these the same size (width and height) and position them in the same place.


Put text into the NoScrollBox.

If the text (and whatever else is there) takes up more vertical room than the height of the NoScrollBox, put that stuff into the BoxThatScrolls. Make the NoScrollBox invisible. Make the BoxThatScrolls visible. Or set the zorder for that.
or
Maybe only use text and limit the length of each text line that I put in so that it will not go past the horizontal width of the edit window and then count the line returns ("\r\n") and if the line returns are above a certain total, use the BoxThatScrolls. That seems easy enough.



I am learning how to use CreateWindowExW and as I study it I have tried to get an easy answer (that I can easily understand) for this question.

Helpful comments, and of course code, are welcome.


Thank you.
Jan 1 '21 #1
0 1332

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by perspolis | last post: by
1 post views Thread by metridevkk | last post: by
2 posts views Thread by Mick_fae_Glesga | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.