BrainDump
  Home arrow BrainDump arrow Page 4 - Using Controls in the Microsoft Foundation...
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 
eWeek
 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

Using Controls in the Microsoft Foundation Class Library
By: Gabor Bernat
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2008-03-19

    Table of Contents:
  • Using Controls in the Microsoft Foundation Class Library
  • Common Controls
  • Image Handling
  • Image Handling continued

  • 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!

    Using Controls in the Microsoft Foundation Class Library - Image Handling continued
    (Page 4 of 4 )

    Now we move on to the proper image displaying. It can be done with a few lines added in the OnDraw section:

    if(!_fileName.IsEmpty())

    {

    Graphics graphics(*pDC);

    Image image(_fileName);

    graphics.DrawImage(&image, 0, 40);

    }


    "If _fileName isn't empty" means that we had to choose an image from our HDD. So we have that to show on the screen. We can now move on.

    First we create a device that is assigned to the current client area. The image is created by referring to the fileName(Path Name). The pure draw part is resolved in the final line. The DrawImage function handles it, carrying three parameters. The first points toward the image itself. The remaining two are coordinates pointing to the place where the image should be drawn in the client area.

    Pretty simple, isn't it? Build the project and start up the application. If you made everything correctly, after opening a picture you should see something like this (obviously with the opened image):

    And here is the zipped source file I created just in case you have any issues creating it on your own. Be aware that I used Visual Studio 2005, so if you have an earlier version, you will need to create a new solution/workspace for it.



    Conclusion

    In this article, we concluded the GDI part of MFC. You learned about standard controls (edit box), common controls (the spinner), and also how to handle/display your pictures. Also you got a small introduction to the power of GDI+. We need at least 7-8 long lines to open an image in the traditional way, while we can accomplish the same task with three short lines using GDI+.

    Don't go far away because we are close to the end. One last part is waiting for you where we'll cover all that you should know about the resource editor, creating dialog boxes and filling them with standard/common controls, customizing your applications icon, acceleration keys, and modifying the menu so your toolbar won't be forgotten.

    Until next time, I wish you a pleasant day and don't forget, if there are any further questions or unresolved issues that are related to this article or to IT in general, visit the friendly, ever-growing community at DevHardware Forums.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · Wellcome 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 5 hosted by Hostway