Don't specify ES_AUTOHSCROLL when creating the text box. You can remove the style later using Get/SetWindowLong. It needs to be ES_MULTILINE as well, though.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You". -- Linus Torvalds
You use GetWindowLong with GWL_STYLe to retrieve the style, then modify it using the bitwise operators, and use SetWindowLong with GWL_STYLE to set it back again
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You". -- Linus Torvalds
Originally posted by parksie You use GetWindowLong with GWL_STYLe to retrieve the style, then modify it using the bitwise operators, and use SetWindowLong with GWL_STYLE to set it back again
So lets say you have:
Code:
LONG cStyle = GetWindowLong(hwnd, GWL_STYLE);
// cStyle now equals WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL | ES_MULTILINE
// how to do bitwise operation? & | ^ ~
SetWindowLong(hwnd, GWL_STYLE, cStyle);
Originally posted by CornedBee prog_tom: specify the ES_WANTRETURN style
No, all you need is ES_MULTILINE.
Per MSDN:
Code:
Edit Styles
ES_AUTOHSCROLL Automatically scrolls text to the right by 10 characters
when the user types a character at the end of the line. When the user presses
the ENTER key, the control scrolls all text back to position 0.
ES_AUTOVSCROLL Automatically scrolls text up one page when the user presses
ENTER on the last line.
ES_MULTILINE Designates a multiple-line edit control. (The default is
single line.) If the ES_AUTOVSCROLL style is specified, the edit control
shows as many lines as possible and scrolls vertically when the user presses
the ENTER key. If ES_AUTOVSCROLL is not given, the edit control shows as many
lines as possible and beeps if ENTER is pressed when no more lines can be
displayed. If the ES_AUTOHSCROLL style is specified, the multiple-line edit
control automatically scrolls horizontally when the caret goes past the right
edge of the control. To start a new line, the user must press ENTER. If
ES_AUTOHSCROLL is not given, the control automatically wraps words to the
beginning of the next line when necessary; a new line is also started if
ENTER is pressed. The position of the wordwrap is determined by the window
size. If the window size changes, the wordwrap position changes and the text
is redisplayed. Multiple-line edit controls can have scroll bars. An edit
control with scroll bars processes its own scroll-bar messages. Edit controls
without scroll bars scroll as described above and process any scroll messages
sent by the parent window.
ES_WANTRETURN Specifies that a carriage return be inserted when the user
presses the ENTER key while entering text into a multiple-line edit control in
a dialog box. Without this style, pressing the ENTER key has the same effect
as pressing the dialog box’s default pushbutton. This style has no effect on a
single-line edit control.
Ok, now I've got the time.
In C/C++ are four bitwise operators: bitwise AND (&), bitwise OR(|), bitwise XOR (^) and bitwise NOT (~).
There are also the operators << and >> that have got something to do with bits, but those are the bitSHIFT operators.
The bitwise operators use their logical equivalent on each bit of the two operands.
This is my example bitfield:
10101010
= 0xAA
= 170
This is the second:
00001111
= 0x0F
= 15
so we have:
10101010
00001111
now each bitwise operator uses it's operation on the bits in a row
effect of &
10101010
00001111
------------
00001010
only if BOTH bits are 1, the resulting bit is 1
effect of |
10101010
00001111
------------
10101111
if EITHER ONE OR BOTH of the bits is 1, the result is 1
effect of ^
10101010
00001111
------------
10100101
if EITHER ONE, but NOT BOTH of the bits are 1, the result is 1
The bitwise NOT is the only one that takes only one operand, it simply inverts every bit.
10101010 -> 01010101
Many constants of windows are hexadecimal values that represent a single bit in a 32-bit integer, like
0x00000001
0x00000002
0x00000004
0x00000008
0x00000010
0x00000020
0x00000040
0x00000080
You can combine as many of those as you want. To combine values, use the bitwise OR (|).
WS_BORDER | WS_POPUP
To test if a specific value is set, use the bitwise AND (&).
if(style & WS_POPUP)
This is because it switches of every other bit, if the result is not 0, this bit must have been set.
To flip a bit, use bitwise XOR (^).
style ^= WS_BORDER;
If WS_BORDER was set, it will now be unset, if it was unset, it will now be set.
To switch a bit reliably off, use bitwise AND (&) and bitwise NOT (~).
style &= ~WS_CHILD;
Well, that's it, you should now even be able to write your own functions that use this method. You probably knew much of this already, but this way others can learn, too.
Have fun.
P.S. I hate me when I do this...
All the buzzt CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Now the only problem is getting the text box to refresh
so that the scroll bar disappears. It will disappear when the
window is resized, but I need to add a line of code to
refresh the text box. Also, I'm not sure how to make the text
wrap like a multiline textbox without a horizontal scroll bar.
Basically, I want it to work like Word Wrap on Notepad. Here is
the project if it will help.