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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

765 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