Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Writing on the screen and scroll a number of pixel?

Posted on 2003-03-25
Medium Priority
Last Modified: 2013-11-20
Is it possible to change the color and size of the font when one is writing on an MDI? If so, can anyone tell me how to do it?

Secondly, When I click on a (vertical) scroll bar I want the application to move 300 pixel down ( still with my MDI application), how can I do this?

Please help.

Question by:NeoMind
  • 2
LVL 31

Expert Comment

ID: 8210175
Hi NeoMind,

both depend on the type of view which you use in your MDI app:

I.e. in a CScrollView-derived view you can set the logical
size of the document-view with CScrollView::SetScrollSizes().
In the overridden OnDraw of the view you can draw to logical
coordinates Text of any font-type/size/color ...
for every font-type/size you need to create a new font with
i.e. CFont::CreateFont, CFont::CreatePointFont a.o. and
select this new font into the current DC via CDC::SelectObject.
You can use CDC::SetTextColor() to change the color of the font,
further you can set the text's backgroundcolor using CDC::SetBkColor().
And you can set the text-drawing mode with CDC::SetBkMode()

Take care that you need to select the formerly selected objects
back into the dc before you return from OnDraw, i.e.:

CMyView::OnDraw( CDC* pDC )
 CFont myFont;
 myFont.CreatePointFont( 120, "Times New Roman", pDC );
 CFont* pOldFont = pDC->SelectObject( &myFont );
 // draw text here with CDC::TextOut or CDC::DrawText(Ex)
 pDC->SelectObject( pOldFont ); // never forget this

hope that helps,


Author Comment

ID: 8216288
Thank u ZOPPO,

The view class that I am using is:

CprogView  and it is derived from CScrollView.

But how do I set the number of pixel such that when I click on the scroll bar it moves down by, say, 300 pixel.

LVL 31

Accepted Solution

Zoppo earned 200 total points
ID: 8216968
With CScrollView::SetScrollSizes you can pass a page-size and
a line-size. The page-size defines the step to scroll when
the scrollbar is clicked between the thumb and arrows. The
line-size defines the step to scroll when clicking on
the arrows.


 CSize sizeTotal( 1000, 1000 ); // the size of the logical view in logical coordinates
 CSize sizePage( 300, 300 ); // the logical size of one page-scroll
 CSize sizeLine( 15, 15 ); // the logical size of one line-scroll

 SetScrollSizes( MM_TEXT, sizeTotal, sizePage, sizeLine );

I use MM_TEXT here because it's the simpliest: logical coordinates
are pixels so you don't need to calculate lengths between
logical and device coordinate (you still need to convert
points because of the different origin depending on the


Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question