.NET
  Home arrow .NET arrow Page 3 - Color, Link and Image Editor Controls for...
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

Color, Link and Image Editor Controls for MFC
By: Gabor Bernat
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2009-10-21

    Table of Contents:
  • Color, Link and Image Editor Controls for MFC
  • Colors
  • More Colors
  • The color picker control
  • Image Editor

  • 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


    Color, Link and Image Editor Controls for MFC - More Colors


    (Page 3 of 5 )

    The color bar is a large frame that hosts multiple colors and maybe two buttons (automatic and other) that will choose a default color or bring up the color dialog.

    Method

    What it does

    ContextToSize

    Calculates the size needed for the buttons and the colors, and then adjusts to this. A sort of size to content.

    CreateControl

    Handles the create process and resize of the control to contain the colors.

    Create

    The same as CreateControl, but does not resize.

    EnableAutomaticButton

    Show/hide this.

    EnableOtherButton

    Show/hide this.

    GetColor

    Currently selected color.

    GetCommandID

    Returns the command ID of the current color bar control.

    GetHighlightedColor

    Tells what color is used to signal the selected state of a color.

    GetHorzMargin

    Space between the client area boundary and left/right color cell.

    GetVertMargin

    Space between the client area boundary and top/bottom color cell.

    IsTearOff

    Is the color bar dockable?

    SetColor

    Sets the currently selected color.

    SetColorName

    Sets the name for a specified color.

    SetCommandID

    Sets a new command ID for a color bar.

    SetDocumentColors

    Sets a list of controls to display inside the color bar.

    SetHorzMargin

    Set the horizontal margin.

    SetVertMargin

    Sets the vertical margin.

    CStatic m_wndColorBarFrame;

    CMFCColorBar m_wndColorBar;

    ...

    // Create regular color bar:

    CRect rectColorBar;

    m_wndColorBarFrame.GetClientRect(&rectColorBar);

     

    //transform this point to the context of the window

    m_wndColorBarFrame.MapWindowPoints(this, &rectColorBar);

     

    m_wndColorBar.SetHorzMargin(0);

    m_wndColorBar.SetVertMargin(0);

    m_wndColorBar.EnableOtherButton(_T("Other..."));

     

    m_wndColorBar.CreateControl(this, rectColorBar, IDC_COLORBAR, 5 /* columns */);

    m_wndColorBar.SetColor(RGB(0, 0, 0));

     

     

    Finally, call the same GetColor method to find out the chosen color:

    COLORREF color = m_wndColorBar.GetColor();

     

    Using a custom palette is a little more complicated. You need to create a logical palette and fill it one by one with the elements that you want to put inside it. To do this we will use a cycle and some shift operations.

    // define a structure where to define the colors

    #define NUM_COLOURS 64

    struct

    {

    LOGPALETTE LogPalette;

    PALETTEENTRY PalEntry[NUM_COLOURS];

    }pal;

     

    //create a logical palette -> and set version +color numbers

    LOGPALETTE* pLogPalette = (LOGPALETTE*) &pal;

    pLogPalette->palVersion = 0x300;

    pLogPalette->palNumEntries = (WORD) NUM_COLOURS;

     

    // Go from color to color

    COLORREF colorStart = RGB(0, 0, 255);

    COLORREF colorFinish = RGB(255, 255, 255);

    int nShift = 6;

     

    // Generate the colors

    for (int i = 0; i < NUM_COLOURS; i++)

    { BYTE bR = (BYTE)((GetRValue(colorStart) *(NUM_COLOURS - i) + GetRValue(colorFinish) * i) >> nShift);

    BYTE bG = (BYTE)((GetGValue(colorStart) *(NUM_COLOURS - i) + GetGValue(colorFinish) * i) >> nShift);

    BYTE bB = (BYTE)((GetBValue(colorStart) *(NUM_COLOURS - i)

    + GetBValue(colorFinish) * i) >> nShift);

     

    //set the new color combination

    pLogPalette->palPalEntry[i].peRed = bR;

    pLogPalette->palPalEntry[i].peGreen = bG;

    pLogPalette->palPalEntry[i].peBlue = bB;

    pLogPalette->palPalEntry[i].peFlags = 0; }

     

    //Create the palette

    m_palColorPicker.CreatePalette(pLogPalette);

     

    //Set the margins and create the control with our palette

    m_wndColorBar2.SetHorzMargin(0);

    m_wndColorBar2.SetVertMargin(0);

    m_wndColorBar2.CreateControl(this, rectColorBar, IDC_COLORBAR2, -1 /* columns */, &m_palColorPicker);

     

    //set the selected control

    m_wndColorBar2.SetColor(colorStart);

     

    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 9 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek