Control for drawing a bevelline

.

This is one of my first extensions to the MFC ... since I just have been asked to publish it, here is what I expected to come from Microsoft:
A static control that displays a bevel line (i.e. a 3d-shaded-Line).

draw_bevel.gif (1273 Byte)

How to put a bevelline in my dialog:
  1. In the dialog resource editor, put a CStatic (Text) in the position of the bevelline. Give the control an ID other than IDC_STATIC.
    I recommend to give it a minimal height if you want a horzontal line, a minimal width if you want a vertical line (see further notes below).
  2. Using ClassWizard, add a member variable (type control) for the control (i.e. m_wndBevel).
  3. Open the dialog's implementation file, #include the header file "cdxCBevelLine.h" and replace the word "CStatic" of your newly created control by "cdxCBevelLine".
  4. Don't forget to add both cdxCBevelLine.h and cdxCBevelLine.cpp to your project's file list.

Further notes:

  1. Using the constructor, you can alternatively change the public member m_bSunken to false which indicates that the bevelline should appear high, not lowered.
    During run-time, you can manually set m_bSunken and call CWnd::Invalidate() and CWnd::UpdateWindow().
  2. The control will determine its orientation from the size of the area it occupies; i.e. if the window's height is bigger than its width, the bevelline will be drawn vertically, otherwise horizontally.

Future plannings:

  1. Add the possibility to add a text to a horizontal line :)

Source code follows....

cdxCBevelLine.h:

#if !defined(AFX_CDXCBEVELLINE_H__0609E262_670A_11D1_A589_444553540000__INCLUDED_)

#define AFX_CDXCBEVELLINE_H__0609E262_670A_11D1_A589_444553540000__INCLUDED_

#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
// cdxCBevelLine.h : header file

/*
 * cdxCBevelLine
 * =============
 * Display a bevelline.
 *
 * To put a bevelline into your dialog, create a static control that acts as a placeholder,
 * create a member variable of type control ("CStatic") for it, open the dialog's
 * include file, include this file and replace the "CStatic" by a "cdxCBevelLine".
 *
 * (w)1997 Hans B|hler, hans.buehler@student.hu-berlin.de
 * freeware.
 */

class cdxCBevelLine : public CStatic
{
public:
   enum
   {
      LineWid = 1,
      LineHi  = 1
   };

// Construction
public:
   cdxCBevelLine(bool bSunken = true) : m_bSunken(bSunken) {}
   virtual ~cdxCBevelLine() {}
   BOOL Create(const RECT& rect, CWnd* pParentWnd)   
         { return CStatic::Create(NULL,WS_CHILD|WS_VISIBLE,rect,pParentWnd); }

// Attributes
public:

// Operations
public:

// Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(cdxCBevelLine)
    //}}AFX_VIRTUAL

// Implementation
public:
   bool m_bSunken;   // call Invalidate() and UpdateWindow() to redraw control

// Generated message map functions
protected:
   //{{AFX_MSG(cdxCBevelLine)
   afx_msg void OnPaint();
   //}}AFX_MSG

   DECLARE_MESSAGE_MAP()
};

/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_CDXCBEVELLINE_H__0609E262_670A_11D1_A589_444553540000__INCLUDED_)

cdxCBevelLine.cpp:

// cdxCBevelLine.cpp : implementation file

#include "stdafx.h"
#include "cdxCBevelLine.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////

// cdxCBevelLine

BEGIN_MESSAGE_MAP(cdxCBevelLine, CStatic)
    //{{AFX_MSG_MAP(cdxCBevelLine)
    ON_WM_PAINT()
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////

// cdxCBevelLine message handlers

void cdxCBevelLine::OnPaint() 
{
   CPaintDC dc(this); // device context for painting
   CRect r;
   GetClientRect(&r);

   DWORD hiCol = ::GetSysColor(!m_bSunken ? COLOR_3DHIGHLIGHT : COLOR_3DSHADOW);
   DWORD loCol = ::GetSysColor(m_bSunken ? COLOR_3DHIGHLIGHT : COLOR_3DSHADOW);

   if(r.bottom > r.right)
   {
      // vertical
      r.right /= 2;
      r.left = r.right - LineWid;
      r.right += LineWid;
   }
   else
   {
      // horizonzal
      r.bottom /= 2;
      r.top = r.bottom - LineHi;
      r.bottom += LineHi;
   }
   dc.Draw3dRect(&r,hiCol,loCol);
}



Comments

  • Jordan shoes mentioned Gene to pay off the discredit, a division of Nike

    Posted by TaddyGaffic on 04/20/2013 10:29am

    The sole of shoes are made from high quality rubber material and come with the lining. One can easily search for Vans footwear in the various online stores where they are easily available at great discount prices. These come in almost an infinite amount of [url=http://northernroofing.co.uk/roofins.cfm]nike free uk[/url] color and are usually on the cheap side. Experts as well as the rights of employees in regards to the apple can annihilate the Nike Air Max For travel arrangements in developing abjection can be a acceptable accord added in comparison to they're prevention, nonetheless they do accommodate sports sports athletes while using high duke inside their profession. Bargain Nike Air Max 2009 aswell provides countless jobs inside the nations absolutely area it's hardly accessible to acquire a job. In Indonesia, for archetype nike air max 90, even acknowledging baby assets [url=http://markwarren.org.uk/goodbuy.cfm]nike free run[/url] in barter for plan Air Max, however, Nike bargain shoes inside a aught bulk adaptation and utilisation of the circadian needs.. Nike Zoom Vapor VI Tour Men`s tennis shoe is a great shoe popular in the tennis courts. It has Fly wire upper for ultra support and light weight ability, it sits on a frame that gives extra heel support and contains a full-length durable rubber support and herring bone pattern. It also has extra traction for all surfaces of play.. Write a Shakespeare Sonnet without any effort! Express loving [url=http://northernroofing.co.uk/roofins.cfm]nike free run 3[/url] feelings in a sonnet in Shakespeare's own words in 15 minutes. The rhyme scheme of a Sonnet is a,b,a,b,c,d,c,d,e,f,e,f,g,g. Think of a theme like "love" "death" or "deceit", then choose your lines in the rhyme pattern and put a Sonnet together using the programme

    Reply
  • No code needed!!!

    Posted by Legacy on 10/16/2000 12:00am

    Originally posted by: Stefan Amourette

    Hello,

    just put a picture control as one line at your dialog-recource and turn on two items at "extented format". client-edge and static-edge! That's all.

    I use this nearly inside every project without any code added!

    Greetings
    Stefan

    http://www.amourette.de

    Reply
  • Beveled CStatics

    Posted by Legacy on 11/04/1998 12:00am

    Originally posted by: David Little

    You can do this with the resource edit by adding a picture control (the one with the cactus on the button) and give it either no heighth (horizontal) or width (vertical).

    Reply
  • Etched control.

    Posted by Legacy on 10/28/1998 12:00am

    Originally posted by: Cole

    You can do this by using the picture control and having the type as etched. If you have the control with no width/height you get the same effect.

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • Some of the statistics about the growth of enterprise mobility are surprising, not the least of which is the 4X increase in mobile malware from 2013 to 2014. Many employees today not only expect to be able to use their own personal devices at work, but will even contravene policies that restrict personal device use for work.  IT must find the right approach that balances the benefits of mobility with the risks involved.  This on-demand webcast offers steps toward developing a winning mobile strategy, and …

Most Popular Programming Stories

More for Developers

RSS Feeds