CodeGuru
Earthweb Search
Forums Wireless Jars Gamelan Developer.com
CodeGuru Navigation
Member Sign In
User ID:
Password:
Remember Me:
Forgot Password?
Not a member?
Click here for more information and to register.

Become a Marketplace Partner

jobs.internet.com

internet.commerce
Partners & Affiliates
















RSS Feeds

RSSAll

RSSVC++/C++

RSS.NET/C#

RSSVB

See more EarthWeb Network feeds

Home >> Visual C++ / C++ >> Windows & Dialogs >> Dialog >> Title Bar


Adding Buttons to Dialog Caption
Rating: none

Fabi Pantera (view profile)
January 26, 2000

(Fabi Pantera)


(continued)



Environment: Windows NT 4 SP5, Visual C++ 6 SP2

This source code demonstrates how you can add buttons to dialog caption bar and also how you can paint the caption.

A lot of peoples asked me to show how they can add buttons to the caption. Of course, first the question is:
Is it possible to add buttons to the non-client area?
The answer is NO.
So what is this article about? Well, this demo shows how to add buttons to the non-client area.

As you probably now you can add controls only in the client area. To add something similar in the non-client area, you have to draw everything by yourself and handle the mouse message for the non-client area. For this you have just to implement WM_NCPAINT message and draw whatever you want. I drawed a gradient caption and some buttons:

void CTemplateDlg::OnNcPaint()
{
 Default();//call default to let windows handle first

 CRect rc, rcwin;
 CalculateCaptionTextRect(this, &rc);

 CDC* pDC = GetWindowDC();
 CDC dcMem;
 dcMem.CreateCompatibleDC(pDC);
 CBitmap bitmap;
 bitmap.CreateCompatibleBitmap(pDC, rc.Width(), rc.Height());
 CBitmap* pOldBitmap = dcMem.SelectObject(&bitmap);

 CSize sizeButton(GetSystemMetrics(SM_CXSIZE),
  GetSystemMetrics(SM_CYSIZE));
 DoGradientFill(this, acLeft, m_startColor, m_endColor);
 rc.right -= 5;
 rc.top += 1;
 rc.bottom -= 3;
 CRect rcBitBlt = rc;
 for (int i = 0; i < 6; i++)
 {
  rc.right -= sizeButton.cx;
  rc.left = rc.right - sizeButton.cx;
  switch (i)
  {
   case 0:
    {
     if (mPushedButton[i] == TRUE)
     //this draw button
      dcMem.DrawFrameControl(rc, DFC_BUTTON ,
       DFCS_BUTTONPUSH | DFCS_CHECKED);
     else
      dcMem.DrawFrameControl(rc, DFC_BUTTON ,
       DFCS_BUTTONPUSH);//same
     break;
    }
   case 1:
 .
 .
 .
}
After this, you should treat the WM_NCHITTEST, WM_NCLBUTTONDOWN, WM_LBUTTONUP messages and force a redraw in the non-client area by sending a WM_NCPAINT message:
PostMessage(WM_NCPAINT,NULL, NULL);
For now, that's all for the custom drawing in the non-client area. Anyway, this demo can be reused. The class that implements the previous behaviour is called CTemplateDlg. This class is an abstract class which provide in its interface, 6 virtual functions: Button0, BUtt1,...,Button5. This are the "callback" functions which handle the left button up click message on every button. So, to use this class just derive your CDialog class from CTemplateDlg and simply implement this functions. Of course you also have to modify the construction, but you can take a look in the code.

If everyone need to modify this code or to create a smart control don't hesitate to e-mail me.

Downloads

Download demo project - 24 Kb

Tools:
Add www.codeguru.com to your favorites
Add www.codeguru.com to your browser search box
IE 7 | Firefox 2.0 | Firefox 1.5.x
Receive news via our XML/RSS feed







RATE THIS ARTICLE:   Excellent  Very Good  Average  Below Average  Poor  

(You must be signed in to rank an article. Not a member? Click here to register)

Latest Comments:
put CButton on caption - is it possible??? - Legacy CodeGuru (08/10/2002)
dialog - Legacy CodeGuru (06/13/2002)
Can i add the buttons with my own GUI - Legacy CodeGuru (11/13/2001)
Thank you! - Legacy CodeGuru (05/21/2001)
Logical Syntax Error - Legacy CodeGuru (01/27/2000)

View All Comments
Add a Comment:
Title:
Comment:
Pre-Formatted: Check this if you want the text to display with the formatting as typed (good for source code)



(You must be signed in to comment on an article. Not a member? Click here to register)


JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
IBM Whitepaper: Innovative Collaboration to Advance Your Business
Internet.com eBook: Real Life Rails
Avaya Article: Call Control XML - Powerful, Standards-Based Call Control
Tripwire Whitepaper: Seven Practical Steps to Mitigate Virtualization Security Risks
Internet.com eBook: The Pros and Cons of Outsourcing
Go Parallel Article: Scalable Parallelism with Intel(R) Threading Building Blocks
Internet.com eBook: Best Practices for Developing a Web Site
IBM CXO Whitepaper: The 2008 Global CEO Study "The Enterprise of the Future"
Avaya Article: Call Control XML in Action - A CCXML Auto Attendant
Go Parallel Article: James Reinders on the Intel Parallel Studio Beta Program
IBM CXO Whitepaper: Unlocking the DNA of the Adaptable Workforce--The Global Human Capital Study 2008
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
Go Parallel Article: Getting Started with TBB on Windows
HP eBook: Storage Networking , Part 1
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Go Parallel Video: Intel(R) Threading Building Blocks: A New Method for Threading in C++
HP Video: Is Your Data Center Ready for a Real World Disaster?
Microsoft Partner Portal Video: Microsoft Gold Certified Partners Build Successful Practices
HP On Demand Webcast: Virtualization in Action
Go Parallel Video: Performance and Threading Tools for Game Developers
Rackspace Hosting Center: Customer Videos
Intel vPro Developer Virtual Bootcamp
HP Disaster-Proof Solutions eSeminar
HP On Demand Webcast: Discover the Benefits of Virtualization
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Microsoft Download: Silverlight 2 Software Development Kit Beta 2
30-Day Trial: SPAMfighter Exchange Module
Red Gate Download: SQL Toolbelt
Iron Speed Designer Application Generator
Microsoft Download: Silverlight 2 Beta 2 Runtime
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
IBM IT Innovation Article: Green Servers Provide a Competitive Advantage
Microsoft Article: Expression Web 2 for PHP Developers--Simplify Your PHP Applications
Featured Algorithm: Intel Threading Building Blocks - parallel_reduce
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES