BrainDump
  Home arrow BrainDump arrow Page 3 - The Graphic Device Interface for the MFC
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  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 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
     
     
    ADVERTISEMENT


    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

    - Introduction to Office Live Workspace
    - Using MS Excel for One-way Analysis of Varia...
    - Comparing Data Sets Using Statistical Analys...
    - Import Blogger Posts into WordPress Using Wi...
    - Download WordPress from an FTP Server and Ru...
    - Install and Run WordPress in XAMPP Local Host
    - What Windows 7 Brings to the Table
    - Virtualization and Sandbox Detection
    - Advanced Firebug Techniques in Windows XP Ho...
    - Editing CSS with Firebug in Windows XP Home
    - Using Firebug in Windows XP Home
    - Migrating to Exchange Server 2007
    - Using System Restore on a Non-Bootable PC
    - Finding Logged on Users and More Scripting S...
    - Developing Macro Commands in MS Excel





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek