BrainDump
  Home arrow BrainDump arrow Page 3 - The Graphic Device Interface for the MFC
Iron Speed
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Download TestComplete 
Windows Web Hosting
 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
IBM Developerworks
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
BRAINDUMP

The Graphic Device Interface for the MFC
By: Gabor Bernat
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2008-03-12

    Table of Contents:
  • The Graphic Device Interface for the MFC
  • Practice and Text
  • Practice and Text continued
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    Iron Speed
     
    ADVERTISEMENT

    Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    The Graphic Device Interface for the MFC - Practice and Text continued
    (Page 3 of 4 )

    MFC has a few classes that are very useful. For example, look at the CString class. It is just like STL’s string. It replaces the char arrays, but this allocates its memory dynamically. It has some additional advantages also. But going into the depths of it is, unfortunately, beyond the purpose of this article.

    Notwithstanding, let’s start from the beginning. At first, we create the necessary DC to allow us to draw to the client area. This is followed by declaring a 24-bit color to be the current text color. Now, if that is black — the default — then we will change it to red. The RGB color is made out of the three basic colors, using the following scheme: RedGreenBlue (Red amount, Green amount, Blue amount).

    The amount can be a value between 0 and 255. Now the RGB (0, 0, 0) stands for the black color, while the RGB (255, 255, 255) represents the white. For a text, the background can be either TRANSPARENT or OPAQUE. The transparent attribute ignores the background color and only the text itself will be drawn.

    There are many other really advanced text functions and as a foretaste, I’m presenting you the Spacing one. Basically, it adds extra spaces between the characters. As for the text part, we’ll only need to call the TextOutW (only TextOut for Visual Studios prior to the .Net platform). The first two parameters are the starting coordinates from where the code will be drawn, while the third parameter holds the content. The text is in a CString type variable.

    I’ve added some other dedicates. The CPen class is for the line style along with what the DC is drawing to the client area. The CBrush holds the pattern, which helps fill in the contour. The constructors each have a style and a color parameter, then there's the CPen and extra width parameter. Here I showed you how you can replace the customized settings.

    The SelectObject function replaces the assigned object and returns a pointer to the old object. Now if we choose to save this, we can later make a switch back to the old settings so that when we are writing a program, we always have the default settings. This way we might prevent those irritating situations where we are expecting one thing, but thanks to some of our changes at a different place in the code, we are dealing with a different situation.

    Just another remark: since we have written this code on the OnLButtonDown section and not in the OnDraw function, when the window requires a redraw (e.g.; minimizing the application), the previous image in its entirety will disappear. To solve this problem we should implement a saving/serializing algorithm and make the drawing part in the OnDraw function.

    We can force a redraw of the client area by calling the Invalidate() function first. This will result in the repainting of the client area at the next WM_PAINT message. Now we will also send a message, specifically a WM_PAINT one. We can individually send any message, but think about the results before you do. The combo will look like this:


    Invalidate ();

    const char *Msg = "The sent message";

    SendMessage(WM_PAINT, 0, (LPARAM)(LPCTSTR)Msg);

    More BrainDump Articles
    More By Gabor Bernat


       · Welcome my friend and thanks for reading my article. As previously mentioned I...
     

    BRAINDUMP ARTICLES

    - Multiple Service Contracts and Indigo
    - Cleaning Out Your Programs in XP
    - Handling Metadata with Indigo
    - Building Blocks for a WCF Service Web Site
    - Help! I Need Some Remote Assistance
    - Using Service Templates with Indigo
    - Windows XP Tips for Task Manager
    - Generating Clients and Services with Indigo
    - Vista SP1, A Review
    - Services and the WCF
    - VBScript: Final Date Functions
    - Creating Services with the WCF
    - The Resource View of the MFC
    - VBScript: More Fun with the Date Functions
    - Vista Price Cuts Dissected




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway