Thread: Need help with edit box and vert scroll

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    9

    Need help with edit box and vert scroll

    I've got a read only edit box I'm using to out put some data too using TextOutA and I created the window with WS_VSCROLL and ES_AUTOVSCROLL styles along with read only. However, once my output hits the bottom it keeps right on going and there is no scroll bar in the greyed out portion on the right. I did the calculations and added the ScrollWindow routines myself but the placemat for the scroll bars if just sitting there off to the right dormant.

    What am I overlooking? Everything I read said this thing was supposed to autoscroll but it doesn't. Petzold's examples use a hardcoded \r\n when the user hits it and none are read only examples.

    I could take out the style on the edit control and make the main window WS_VSCROLL and work from there I guess, but it's just bugging me now. Why cant this window scroll? Are read only edits allowed to scroll or what is the trick to enabling the scroll bar?

  2. #2
    Registered User mikeman118's Avatar
    Join Date
    Aug 2007
    Posts
    183
    Make sure that you specified the ES_MULTILINE style, otherwise I don't think it will work.

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    So far as I know, you need to do manual breaks because a text control won't wrap automatically.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Registered User
    Join Date
    Dec 2007
    Posts
    9
    Right I added \r\n to the end of the buffer and tried DrawTextA with DT_WORDBREAK, it formats just fine but no scroll.

    However, I'm about to pull my hair out with this thing, it's been 4 days now on such a simple sounding objective.

    EM_GETLINECOUNT doesnt work, nothing seems to work on this control if you output text to it in a buffer. I've wondered about streaming with a rich edit but another day's work for no results is not something I look forward to.

    The real problem I'm having is in the PAINTING of the edit control. When a window obscures mine, I of course loose the text and need to repaint the rect that was covered. However, every example I have found uses hard coded strings and just gets an index into the array and then redraws them.

    This is dynamic data, so I figured ok, I'll get the line count and then get the line starting at an index into my own array and textout again. Nope, not happening, getlinecount doesnt work with streamed lines, even if I add an \r\n onto the end of the line, it just doesnt see it.

    I am at my wit's end with this thing. A simple buffered output that I can later search on that can be repainted when a window obscures it without having to land a man on Pluto just to get it done, seems so easy. I even redesigned it today to a mdi and see if it will repaint properly. Nothing.

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I don't understand why you you just can't keep the data to be printed to the Textbox in memory or stored somewhere. Even if it's dynamic, you must have the data somewhere since you printed it once before, right?
    And what about the actual drawing - what's the reason you aren't just setting the text property of the textbox itself? It will redraw itself then.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Registered User
    Join Date
    Dec 2007
    Posts
    9
    Right, I'm going to have to keep it in a buffer but the problem is, non of the EM_GETLINE or any of the EM counting things work as it's seen as 1 big line of text I guess.

    Ok, set the text property?

    hEdit = CreateWindow ( __T ( "EDIT" ), NULL, WS_CHILD |
    WS_VISIBLE | WS_VSCROLL | ES_AUTOVSCROLL | ES_MULTILINE,
    0, 0, 0, 0, hwnd, 300, hInst, NULL ) ;


    I'm not familiar with a edit control auto redrawing itself and that's what I was after, what setting is that?

    I mean even if I could take a screebshot of the bounding rect and draw it back in LOL that would be nice but I didn't see a way to do that either. Keeping an index into the buffer and all is something I was trying to avoid.

    Oh and btw, yeah it's a buffer but it's only one I use for streaming, I set the size streamed in so I know how large it'll be and I just reuse it for the next read and output it each time to my edit box.
    Last edited by AndewWood; 12-15-2007 at 04:35 AM.

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I mean, through SetWindowText. You can set the textbox's text.
    EM_GETLINE:
    Copies a line of text from an edit control and places it in a specified buffer. You can send this message to either an edit control or a rich edit control.
    Basically means you need to set the text first using SetWindowText.

    I mean, if you set a text to an edit with SetWindowText, it will redraw itself automatically when it needs to (actually, it will always redraw itself, but in case it has any text, it will redraw the text of course).

    A screenshot is possible, too... I'm not sure how to do, but maybe something like getting the textbox's dc and bliting it to a bitmap? And then bliting it back?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    Registered User
    Join Date
    Dec 2007
    Posts
    9
    Yes blting it back, I was being funny and I looked into that earlier last night and it's not worth the performance hit.

    Yes SetWindowText, I used that and the flicker was so horrible it was unreadable. This data is coming in off my socket and I'm outputting the translated data to an edit box so the user can search and save it to disk, all the functions of an edit box.

    Mirc is the perfect example I keep neglecting to mention, just like Mirc does and I presently have it as a MDI. But you know how mirc can be scrolled back and forth and data added to it. I find it really hard to believe he's doing a SetWindowText with every incoming line of text?? Seems the buffer would eventually get too large for good function. But I can't find any examples like mirc out there, an edit box that can be searched, highlighted, saved to disk and redrawn.

    Also, using SetWindowText, you just keep updating the scrollbar to the bottom I assume?

    I appreciate your correspondence, Elysia and I apologize for my GUI newbiness, this is my weak area.

  9. #9
    Registered User
    Join Date
    Dec 2007
    Posts
    9
    After reading what you wrote and looking up some examples of SetWindowText on edits, I was thinking maybe I can continue using TextOut or DrawText while the window is at the top of the z pos but if it gets covered and then uncovered, I could do a GetWindowText and a SetWindowText and continue on processing my data with the GDI funcs.

    Maybe that wouldnt be as hard a hit on performance, what do you think?

    I just wish I had a good mirc example as yeah I need to switch text colors on some lines using ExtText and PolyText.

    I never dreamed this project would have turned into this *sigh*

  10. #10
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    The problem with what you're trying to do is that you need buffered writing so to speak. You need to do drawing to an off-screen buffer and then blit it to the screen. A textbox may not be the best for this.
    Anyway, search codeproject for such a thing - I know it exists!
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #11
    Registered User
    Join Date
    Dec 2007
    Posts
    9
    Incredibly, I fired up mirc and spy++ and you are right, mirc uses a static window on what appears to be a mdi frame. The names panels are listboxes, small edit window for input, static window for data with a scroll bar all inside a custom classed framed, probably mdi.


    I have been doing the wrong approach.

    Now how to repaint static texts. Ill report back final conclusions for readers and archive purposes.

    You're gonna love my next project, I have to make a web control in windows api like .net uses for the afxweb browser but I have to do it in straight api, I think using an IMonker not sure really. But I vowed it can be done!!

    Hope you are around for that and thanks so much for your time.

  12. #12
    Registered User
    Join Date
    Dec 2007
    Posts
    9
    As promised, I'm posting back my results. Turned out the user didn't desire a text print out but settled on the text file output version and wished more interface options where the output box resided. So the project went another direction.

    However, not one to settle on defeat and it still bugged me I could not get this working right, it was on my mind over the Holidays. I knew that I could make a huge array of arrays and keep adding the strings to it for display as most 101 versions of instruction show but not something feasible. I had tried DrawText and send keyboard input of VK_ENTER on each line but when you went to get text and redisplay, the enters didn't show up and it was a run on line.

    So I decided to revisit EM_REPLACESEL another method I had used and found the answer....

    Code:
    case WM_CREATE :
    hwndEdit = CreateWindowEx ( WS_EX_STATICEDGE, __T("edit"), NULL, 
                       WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL | ES_NOHIDESEL |
                       ES_AUTOVSCROLL | ES_LEFT | ES_MULTILINE | ES_READONLY,
                       0, 0, 0, 0, hwnd, (HMENU) ID_EDIT, hInst, NULL ) ;
    
    case WM_CTLCOLORSTATIC :
    if ( lParam == (LPARAM) hwndEdit )
    {
        SetBkColor ( (HDC) wParam, RGB ( 255, 255, 255 ) ) ;
        return (LRESULT) GetStockObject ( WHITE_BRUSH ) ;
    }
    
    case WM_APP :
    SendMessageA ( hwndEdit, EM_REPLACESEL, 0, szBuffer ) ;
    SendMessage ( hwndEdit, EM_REPLACESEL, 0, __T ( "\r\n" ) ) ;
    SendMessage ( hwndEdit, EM_SETSEL, -1, 0 ) ;

    EM_SETSEL with -1 in wParam was just like dooing the DrawText and SendInput using VK_ENTER to stay ahead of the text but the EM_REPLACESEL made the difference and there was no longer a need to read in the text and redraw it or handle the the scroll as it now works fine.

Popular pages Recent additions subscribe to a feed