Scrollbars in dialog

This is a discussion on Scrollbars in dialog within the Windows Programming forums, part of the Platform Specific Boards category; Hello! I don't know how to get vertical scrollbars in a dialog. To solve the problem, I dragged a listbox ...

  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    37

    Unhappy Scrollbars in dialog

    Hello!

    I don't know how to get vertical scrollbars in a dialog.
    To solve the problem, I dragged a listbox on it. But the process is very low when the text to be written is very long.

    I guess that it would be better to write directly on the dialog.

    Can anybody tell me, with an example, what I should do to get those famous scrollbars ?

    Thanks a lot.

    Kind regards.

    Frandy

  2. #2
    Registered User
    Join Date
    Nov 2004
    Location
    Slovenia, Europe
    Posts
    115
    You can use a simple resource editor - I recommend ResEd. You just put the scrollbar on a dialog an that's it
    [C++]
    IDE: DevC++ 4.9.9.2 (GCC 3.4.2)
    2nd compiler: g++ (GCC 3.4.3/4.0.0)
    3rd compiler: Borland 5.5
    [C#]
    IDE: Microsoft Visual C# Express 2005
    2nd IDE: SharpDevelop
    2nd compiler: csc in Command Prompt
    .NET Framework: 2.0
    [PHP]
    Core: 5.1.0 beta 3
    IDE: PHPEdit
    2nd IDE: Notepad
    Favourite extensions: exif,gd2,mysql
    Favourite PEAR packages: DB, XML_RSS, ID3
    Favourite databases: SQLite, MySQL

  3. #3
    Registered User
    Join Date
    Aug 2004
    Posts
    37
    Thanks for your info but I use Visual C++ 6!

    Regards

    Frandy

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,855
    You want to display large amounts of text on a dialog screen, how much, a page or a book?

    A static is for small amounts of text (~256 max) and won't scroll.

    An edit with multiline and vertical scroll will handle more. Disabled or read-only will stop user input. The edit will handle the scrolling. An edit is restricted to one font / style at a time. (ie notepad)
    A rich edit is harder to use but allows different formats (font ect) at the same time. (ie word)

    Or you could draw the text yourself using a DC and paint it to the dialog screen. A scrollbar control is used to get input and then you can ScrollDC() or redraw text in response.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  5. #5
    Registered User
    Join Date
    Aug 2004
    Posts
    37
    Thanks Novocain.
    I'm a beginner. So, could you illustrate the use of ScrollDC() with an example ?.

    Thanks again.

    Best regards

    Frandy

  6. #6
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,855
    >>I'm a beginner. So, could you illustrate the use of ScrollDC() with an example ?.

    only if you spell my name right.....

    If you are a beginner I advise the edit to start. Drawing DC's requires more advanced knowledge.

    Is there a reason an edit won't work?


    Else if you want to go the DC route.....

    When the dlg inits;
    //get dialogs DC
    GetDC(hDlg);
    //find area to create DC I use a Frame control and then
    GetClientArea(hFrame);
    //create our DC and bitmap
    //these are global or members, we need them while the dlg runs
    CreateCompatibleDC();
    CreateCompatibleBitmap();
    //put our BMP in the DC and catch return for later
    hOrgBmp = SelectObject( hCompDC, hCompBMP);
    //wipe DC ie paint white ( GetStockObject(WHITE_BRUSH) )
    FillRect();
    //clean up GDIs
    ReleaseDC();
    //delete any brush font ect
    //only after removing it from DC by replacing original GDI object
    DeleteObject()

    When the dlg closes;
    //return original bmp
    SelectObject( hCompDC, hOrgBMP);
    //clean up GDI
    DeleteDC(hCompDC);
    DeleteObject(hCompBMP);

    when dlg gets a paint msg;
    BeginPaint(hDlg, &PaintStruct);
    //draw our compDC to the screen
    BitBlt(PaintStruct.hdc,PaintStruct.rect.left,,,,,, ,hCompDC,PaintStruct.rect.left,,,,);
    EndPaint();

    All this and we still have not even drawn the text..........
    I suggest you search here for more code and start simple.
    ie draw a coloured box on the dlg

    What complier and language?
    ie MFC? C with WIN32 ect
    Last edited by novacain; 02-12-2005 at 10:27 PM.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  7. #7
    Registered User
    Join Date
    Aug 2004
    Posts
    37
    Thanks novacain.
    I use C with win32.
    All I need now is to learn how to use the ScrollDC() function. Please give me an example.
    I think I have the required knowledgeto follow you.

    Thanks again for your help.

    Best regards,

    Frandy

  8. #8
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,855
    OK.

    I will assume you have a working display and just need to scroll the DC on response to a WM_VSCROLL msg (sent to the parent of the scrollbar)
    Also that the DC has been created to the correct size to display all the text and that the text is already printed on it.

    When the text is drawn (or DC created) you can calc the area used for any given string and font (search here as this was asked recently).

    Set the Scrollbars min to zero and max to 100 (%). SetScrollInfo()

    On a WM_VSCROLL call GetScrollInfo() find the nPos (new position)


    this is not 100% but will give you an idea.....
    Code:
    BITMAP    BMP;
    
    GetObject(hCreatedComptBMP, sizeof( BITMAP), &BMP);
    YScroll= BMP.bmHeight * ScrollInfo.nPos;
    ScrollDC(hdc, 0, YScroll, NULL, NULL, NULL, &UpdateRect);
    InvalidateRect(hDlg, &UpdateRect, FALSE);
    UpdateWindow(hDlg);
    look at SCROLLINFO struct and "Types of Coordinate Systems" as there may be issues between world and device units.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 02-13-2008, 01:59 PM
  2. Edit controls of a dialog from another dialog...
    By Snake in forum Windows Programming
    Replies: 9
    Last Post: 07-01-2005, 02:18 PM
  3. make Child Dialog not Popup?
    By Zeusbwr in forum Windows Programming
    Replies: 5
    Last Post: 04-08-2005, 02:42 PM
  4. Getting the position of a dialog without parent on the screen
    By stormbringer in forum Windows Programming
    Replies: 1
    Last Post: 08-27-2003, 02:59 AM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM

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