Scrollbars in dialog
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.
You can use a simple resource editor - I recommend ResEd. You just put the scrollbar on a dialog an that's it ;)
Thanks for your info but I use Visual C++ 6!
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.
I'm a beginner. So, could you illustrate the use of ScrollDC() with an example ?.
>>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
//find area to create DC I use a Frame control and then
//create our DC and bitmap
//these are global or members, we need them while the dlg runs
//put our BMP in the DC and catch return for later
hOrgBmp = SelectObject( hCompDC, hCompBMP);
//wipe DC ie paint white ( GetStockObject(WHITE_BRUSH) )
//clean up GDIs
//delete any brush font ect
//only after removing it from DC by replacing original GDI object
When the dlg closes;
//return original bmp
SelectObject( hCompDC, hOrgBMP);
//clean up GDI
when dlg gets a paint msg;
//draw our compDC to the screen
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
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.
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.....
look at SCROLLINFO struct and "Types of Coordinate Systems" as there may be issues between world and device units.
GetObject(hCreatedComptBMP, sizeof( BITMAP), &BMP);
YScroll= BMP.bmHeight * ScrollInfo.nPos;
ScrollDC(hdc, 0, YScroll, NULL, NULL, NULL, &UpdateRect);
InvalidateRect(hDlg, &UpdateRect, FALSE);