Question About Edit Boxes

This is a discussion on Question About Edit Boxes within the Windows Programming forums, part of the Platform Specific Boards category; When I initialize my edit box, I want to have vertical and horizontal scroll bars. The code I have now ...

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    73

    Question About Edit Boxes

    When I initialize my edit box, I want to have vertical and horizontal scroll bars. The code I have now only makes vertical scrollbars. Here is my code, how do I make a horizontal scrollbar with my edit box?
    Code:
    edit_box = CreateWindow("EDIT",NULL,WS_CHILD | WS_VISIBLE | 
    ES_AUTOHSCROLL | ES_AUTOVSCROLL | ES_LEFT | ES_MULTILINE | 
    ES_NOHIDESEL | WS_VSCROLL | WS_HSCROLL | WS_BORDER | 
    ES_WANTRETURN, 0, 0, rect.right, rect.bottom, hWnd, (HMENU)EDIT_BOX, 
    ((LPCREATESTRUCT)lParam)->hInstance, NULL);

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    Does the scroll bar appear if you type in a really long line where it would be necessary?

  3. #3
    Registered User
    Join Date
    Dec 2004
    Posts
    73
    no, it does not
    i've attatched a picture of my program, and how it gives me a vertical scrollbar and not a horizontal one.
    Attached Images Attached Images  
    Last edited by ElWhapo; 12-30-2004 at 12:56 PM.

  4. #4
    Handy Andy andyhunter's Avatar
    Join Date
    Dec 2004
    Posts
    540
    Are you sure that they are not there? If there is no need for a scroll windows will usually gray it out like displayed below. Additionally if you type some text and resize the window usually the scroll will become enabled (also displayed below). In case you need additional help here is a little sample.
    Attached Images Attached Images   
    Attached Files Attached Files
    i don't think most standard compilers support programmers with more than 4 red boxes - Misplaced

    It is my sacred duity to stand in the path of the flood of ignorance and blatant stupidity... - quzah

    Such pointless tricks ceased to be interesting or useful when we came down from the trees and started using higher level languages. - Salem

  5. #5
    Registered User
    Join Date
    Dec 2004
    Posts
    73
    I found the problem. I didn't make my window large enough to view the bottom scrollbar. I shouldn't have made my edit box have a size either. Thank you.

  6. #6
    Registered User
    Join Date
    Dec 2004
    Posts
    73
    How do you make it so that your edit box resizes along with your window?

  7. #7
    Registered User
    Join Date
    Dec 2004
    Posts
    1
    when the window is resized, a WM_SIZE msg is posted.

  8. #8
    Registered User
    Join Date
    Dec 2004
    Posts
    73
    I get that, I'm just wondering if there is a way to make my edit box resize when a user resizes the window. The only way I can think of is to delete the edit box and save the text as a buffer and then get the current rect of the screen and create it again. Is there an easier way?

  9. #9
    Handy Andy andyhunter's Avatar
    Join Date
    Dec 2004
    Posts
    540
    What exactly do you mean, like getting smaller when the window gets smaller? Like autowrapping text so you don't need a scrollbar?

    If you want to autowrap then this:
    Code:
    hwndEdit = CreateWindow (TEXT ("edit"), NULL,
                             WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL | //<---------------both H and V scrolls
                                       WS_BORDER | ES_LEFT | ES_MULTILINE | 
    								   ES_AUTOHSCROLL | ES_AUTOVSCROLL,//<-------------------Auto scrolling
                             0, 0, 0, 0, hwnd, (HMENU) ID_EDIT,
                             ((LPCREATESTRUCT) lParam) -> hInstance, NULL) ;
    Should be this:
    Code:
    hwndEdit = CreateWindow (TEXT ("edit"), NULL,
                             WS_CHILD | WS_VISIBLE |  WS_VSCROLL | //<---------------Just V scroll
                                       WS_BORDER | ES_LEFT | ES_MULTILINE  
    								 | ES_AUTOVSCROLL,//<-------------------Auto scrolling(vertical only)
                             0, 0, 0, 0, hwnd, (HMENU) ID_EDIT,
                             ((LPCREATESTRUCT) lParam) -> hInstance, NULL) ;
    If you mean simply autoresizing the example prog I gave you did that, its contained in the WM_SIZE message like so:

    Code:
    MoveWindow (hwndEdit, 0, 0, LOWORD (lParam), HIWORD (lParam), TRUE) ; //Place edit control in top left of window
    //resizes to size of window
    So if you know a specific size you want to remake your window simply change these parameters:
    LOWORD(lParam) - width
    HIWORD(lParam) - height

    Happy coding!
    Last edited by andyhunter; 12-30-2004 at 01:58 PM.
    i don't think most standard compilers support programmers with more than 4 red boxes - Misplaced

    It is my sacred duity to stand in the path of the flood of ignorance and blatant stupidity... - quzah

    Such pointless tricks ceased to be interesting or useful when we came down from the trees and started using higher level languages. - Salem

  10. #10
    Registered User
    Join Date
    Dec 2004
    Posts
    73
    That worked thank you. I have another question. I set my program so that when you click on a text file it opens my program. The problem is when it opens my program nothing appears. How do I make it so when I open my program I check to see if I clicked on a file to open it, and then display the text of that file?

  11. #11
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    Check the third parameter passed to the WinMain() function.

  12. #12
    Registered User
    Join Date
    Dec 2004
    Posts
    73
    how would i check wParam for a text file? can you show me an example please? thanks.

    I have another question. When I load a file using the text program I made, nothing happens. But when I resize my window suddenly it shows up. How can I make the program resize itself, or just make the program go to WM_SIZE.
    Last edited by ElWhapo; 12-30-2004 at 05:39 PM.

  13. #13
    Handy Andy andyhunter's Avatar
    Join Date
    Dec 2004
    Posts
    540
    Third parameter to WinMain which is a LPSTR which represents the command line windows used to call your program. In the event it was for opening a file like you are talking about the command line is the full path and filename of the file to open.

    Happy Coding!

    [edit]

    Why don't you post the relevant code so we can all see what you are doing.

    [/edit]
    Last edited by andyhunter; 12-31-2004 at 07:49 AM.
    i don't think most standard compilers support programmers with more than 4 red boxes - Misplaced

    It is my sacred duity to stand in the path of the flood of ignorance and blatant stupidity... - quzah

    Such pointless tricks ceased to be interesting or useful when we came down from the trees and started using higher level languages. - Salem

  14. #14
    Registered User
    Join Date
    May 2002
    Posts
    132
    Perhaps get the HWND to your edit control and call UpdateWindow(hEdit)? this might fix your problem of the text not showing up after loading a file.

  15. #15
    Registered User
    Join Date
    Dec 2004
    Posts
    73
    Thanks. Both worked. As soon as I finish this text program I'll post it here because you guys practically wrote the whole thing. I'm sure I'll have some more questions, so thanks again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Edit box question
    By learning110 in forum Windows Programming
    Replies: 6
    Last Post: 03-28-2003, 08:16 PM
  2. Edit Boxes
    By ColdFire in forum Windows Programming
    Replies: 2
    Last Post: 02-13-2002, 02:54 PM
  3. please help visual c++ edit control boxes
    By alcoholic in forum C++ Programming
    Replies: 3
    Last Post: 02-05-2002, 02:39 PM
  4. edit boxes
    By face_master in forum Windows Programming
    Replies: 2
    Last Post: 01-25-2002, 05:47 PM
  5. Password Edit Boxes
    By Unregistered in forum Windows Programming
    Replies: 1
    Last Post: 08-27-2001, 03:40 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21