What is the code to SendMessage( ) a textbox and eliminate the
horizontal scroll bar if it has one and will it make the text wrap?
Printable View
What is the code to SendMessage( ) a textbox and eliminate the
horizontal scroll bar if it has one and will it make the text wrap?
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.
How to make an EDIT with Scrollbars?
ES_AUTOHSCROLL and ES_AUTOVSCROLL :rolleyes:
styles used:
WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL | ES_MULTILINE | ES_WANTRETURN
I want the box to have the scroll bar unless the user decides he
doesn' t want it and then the text will wrap.
I just need the parameters to specify in SetWindowLong( ) to
remove the scroll bar.
This doesn't seem to work:
SetWindowLong(hwndEdit, NULL, WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_MULTILINE | ES_WANTRETURN);
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 :)
they don't show scrollbars, just allow it to scroll.Quote:
Originally posted by parksie
ES_AUTOHSCROLL and ES_AUTOVSCROLL :rolleyes:
use WS_HSCROLL | WS_VSCROLL to see scroll bars.
Oh okay then. Mine always seemed to have scroll bars but oh well - probably me being silly along the way.
However, the GWL_STYLE thingie is what you need :)
I can't press ENTER, i mean when I press it, it won't change a new line...
did you have ES_MULTILINE in there when you made the edit box?
So lets say you have:Quote:
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 :)
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);
prog_tom: specify the ES_WANTRETURN style
No, all you need is ES_MULTILINE.Quote:
Originally posted by CornedBee
prog_tom: specify the ES_WANTRETURN style
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.
How do you do this?Quote:
Originally posted by wey97:
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 to remove WS_HSCROLL? & | ^ ~
SetWindowLong(hwnd, GWL_STYLE, cStyle);
I'll answer soon, but I have to go
Cya later
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...
Ok, this works:
Now the only problem is getting the text box to refreshCode:LONG wStyle = GetWindowLong(hwndText, GWL_STYLE);
wStyle ^= WS_HSCROLL;
SetWindowLong(hwndText, GWL_STYLE, wStyle);
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.
thanks