Results 1 to 17 of 17

Thread: textbox scroll bars

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    1,276

    Question textbox scroll bars

    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?

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  3. #3
    Fanatic Member prog_tom's Avatar
    Join Date
    May 2001
    Location
    Los Angeles and Little Rock
    Posts
    810

    Post How?

    How to make an EDIT with Scrollbars?

    prog_tom
    JOIN THE REVOLUTION!!!! Dual T3 backedup science community.
    http://physics.sviesoft.com/forum

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    ES_AUTOHSCROLL and ES_AUTOVSCROLL
    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

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    1,276
    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);

  6. #6
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    1,276
    Originally posted by parksie
    ES_AUTOHSCROLL and ES_AUTOVSCROLL
    they don't show scrollbars, just allow it to scroll.
    use WS_HSCROLL | WS_VSCROLL to see scroll bars.

  8. #8
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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 refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  9. #9
    Fanatic Member prog_tom's Avatar
    Join Date
    May 2001
    Location
    Los Angeles and Little Rock
    Posts
    810

    Post ES_AUTOVSCROLL

    I can't press ENTER, i mean when I press it, it won't change a new line...

    prog_tom
    JOIN THE REVOLUTION!!!! Dual T3 backedup science community.
    http://physics.sviesoft.com/forum

  10. #10
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    did you have ES_MULTILINE in there when you made the edit box?
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  11. #11

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    1,276
    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);

  12. #12
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    prog_tom: specify the ES_WANTRETURN style
    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.

  13. #13

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    1,276
    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.

  14. #14

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    1,276
    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);
    How do you do this?

  15. #15
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    I'll answer soon, but I have to go
    Cya later
    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.

  16. #16
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  17. #17

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    1,276
    Ok, this works:
    Code:
        LONG wStyle = GetWindowLong(hwndText, GWL_STYLE);
        wStyle ^= WS_HSCROLL;
        SetWindowLong(hwndText, GWL_STYLE, wStyle);
    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.

    thanks
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width