.NET
  Home arrow .NET arrow Page 4 - New Controls for 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? 
.NET

New Controls for MFC
By: Gabor Bernat
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 2
    2009-10-20

    Table of Contents:
  • New Controls for MFC
  • Create a property sheet inside a dialog
  • Style and Radio Buttons
  • Push buttons
  • Menu buttons

  • 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


    New Controls for MFC - Push buttons


    (Page 4 of 5 )

    However, returning to the push button. As I just presented, you can add an image near the text image. Customize the position of these two so that they're related to each other, or disable some of it.

    Add a new button to the resource property page. Modify it to the new extended one: CMFCButton. Make sure to embed the control inside the dialog. During the initialization, you can make the button transparent with the m_bTransparent member:

    m_Button.m_bTransparent = TRUE;

     

    If you do not use the systems themes, you can set three types of border: flat, semi-flat or a 3D look:

     

    m_Button.m_nFlatStyle = CMFCButton::BUTTONSTYLE_3D;

     

    If you do not want to display the image, just set a null image pointer to the button:

     

    m_Button.SetImage((HBITMAP) NULL);

     

    Alternatively, if you want an image, you actually need to set two images: one for when the button is pushed (it is hot), and one for the other times. Just add/create the new bitmaps and use their resource ID.

    if (afxGlobalData.bIsOSAlphaBlendingSupport)

    {

    m_Button.SetImage(IDB_BTN1_32, IDB_BTN1_HOT_32);

    }

    else

    {

    m_Button.SetImage(IDB_BTN1, IDB_BTN1_HOT);

    }

     

    Use the SetWindowText call to set new text, or just set none by passing an empty string:

     

    m_Button.SetWindowText(_T(""));

     

    You can change the position of the image if you modify the values of the two public members: m_bRightImage (left/right alignment as compared with the text) and m_bTopImage (up-down alignment as compared with the text). These are bool values. For example, in our case, we delineated three scenarios:

     

    switch (m_nImageLocation)

    {

    case 0:

    m_Button.m_bRightImage = FALSE;

    m_Button.m_bTopImage = FALSE;

    break;

     

    case 1:

    m_Button.m_bRightImage = TRUE;

    m_Button.m_bTopImage = FALSE;

    break;

     

    case 2:

    m_Button.m_bRightImage = FALSE;

    m_Button.m_bTopImage = TRUE;

    break;

    }

     

    The m_nAlignStyle will accept three enum values: center, left and right. Use this to align the text inside the button.

     

    m_btnRadio1.m_nAlignStyle = CMFCButton::ALIGN_CENTER;

     

    Whenever you make a change, it is a good idea to resize the control and invalidate it. This will ensure that the application will draw the most up-to-date state.

     

    m_Button.SizeToContent();

    m_Button.Invalidate();

     

    You can set custom cursors. This is the shape of the mouse while it hovers over the corresponding button. You can use the system default, set a hand cursor or use one from a custom cursor file.

     

    switch (m_iCursor)

    {

    case 0:

    m_Button.SetMouseCursor(NULL); //system cursor

    break;

     

    case 1:

    m_Button.SetMouseCursorHand(); // Hand cursor

    break;

     

    case 2:

    m_Button.SetMouseCursor(AfxGetApp()-> LoadCursor(IDC_CURSOR)); // custom

    break;

    }

     

     

    You can set some custom tooltips with the SetTooltip method:

    m_Button.SetTooltip(m_strToolTip_text);

     

    Here it an image made from integrating all of this inside a group that you can modify on the fly:

    More .NET Articles
    More By Gabor Bernat


     

    .NET ARTICLES

    - Introducing .NET
    - Building Business Objects for an Application
    - Methods for an Application`s Business Logic ...
    - Properties of an Application`s Business Logi...
    - Classes and Properties in an Application`s B...
    - Organizing Code for the Business Logic Layer...
    - Building the Business Logic Layer
    - Completing a Business Layer with Windows Wor...
    - Building Applications with Windows Workflow ...
    - Building the Data and Business Layers Using ...
    - The Transformed XML Explorer in MFC
    - List Control and Property Grid with the MFC ...
    - Font, Shell and Masked Edit Controls for MFC
    - Color, Link and Image Editor Controls for M...
    - New Controls for MFC





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