• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 327
  • Last Modified:

Round style command buttons in Window captionr

How can I ave My own style command buttons in the Window caption.
Round style with 3D metal effect button may be perfect!
and I'll appreciate source code and sample project.
Thank you.
  • 4
  • 3
1 Solution
Definitely take a look at www.codeguru.com.  There's quite a few examples of creating buttons with various shapes and styles.  You will be looking at the SetWindowRgn function to modify the current size of the image.  

To give yourself the 3D effect on a round button, you will probably want to really take a good look at a CBitmapButton.  You will create images of an up/down/focused, etc, button and the CBitmapButton will simulate the full functionality of a button.  Put a transparent bitmap color in the areas that you want to make look round and I believe you'll have it.

If you want more info, comment back.

Here's the code for the transparent bitmaps.  This will give you the rounded effect.  The metallic look will have to come from some Paint program.

void DrawTransparentBitmap(CDC* pDC, CBitmap* pBitmap, int xStart, int yStart, COLORREF cTransparentColor)
   CBitmap    bmAndBack, bmAndObject, bmAndMem, bmSave;
   CDC        dcMem, dcBack, dcObject, dcTemp, dcSave;
   dcTemp.SelectObject(pBitmap);   // Select the bitmap
   BITMAP     bm;
   pBitmap->GetObject(sizeof(BITMAP), (LPSTR)&bm);
   CPoint     ptSize;
   ptSize.x = bm.bmWidth;            // Get width of bitmap
   ptSize.y = bm.bmHeight;           // Get height of bitmap
   dcTemp.DPtoLP(&ptSize, 1);      // Convert from device to logical points
// Create some DCs to hold temporary data.

// Create a bitmap for each DC. DCs are required for a number of GDI functions.

// Monochrome DC

   bmAndBack.CreateBitmap(ptSize.x, ptSize.y, 1, 1, NULL);
// Monochrome DC

   bmAndObject.CreateBitmap(ptSize.x, ptSize.y, 1, 1, NULL);
   bmAndMem.CreateCompatibleBitmap(pDC, ptSize.x, ptSize.y);
   bmSave.CreateCompatibleBitmap(pDC, ptSize.x, ptSize.y);
// Each DC must select a bitmap object to store pixel data.

   CBitmap* pbmBackOld   = dcBack.SelectObject(&bmAndBack);
   CBitmap* pbmObjectOld = dcObject.SelectObject(&bmAndObject);
   CBitmap* pbmMemOld    = dcMem.SelectObject(&bmAndMem);
   CBitmap* pbmSaveOld   = dcSave.SelectObject(&bmSave);
// Set proper mapping mode.

// Save the bitmap sent here, because it will be overwritten.

   dcSave.BitBlt(0, 0, ptSize.x, ptSize.y, &dcTemp, 0, 0, SRCCOPY);
// Set the background color of the source DC to the color.
// contained in the parts of the bitmap that should be transparent

   COLORREF cColor = dcTemp.SetBkColor(cTransparentColor);
// Create the object mask for the bitmap by performing a BitBlt
// from the source bitmap to a monochrome bitmap.

   dcObject.BitBlt(0, 0, ptSize.x, ptSize.y, &dcTemp, 0, 0, SRCCOPY);
// Set the background color of the source DC back to the original color.

// Create the inverse of the object mask.

   dcBack.BitBlt(0, 0, ptSize.x, ptSize.y, &dcObject, 0, 0, NOTSRCCOPY);
// Copy the background of the main DC to the destination.

   dcMem.BitBlt(0, 0, ptSize.x, ptSize.y, pDC, xStart, yStart, SRCCOPY);
// Mask out the places where the bitmap will be placed.

   dcMem.BitBlt(0, 0, ptSize.x, ptSize.y, &dcObject, 0, 0, SRCAND);
// Mask out the transparent colored pixels on the bitmap.

   dcTemp.BitBlt(0, 0, ptSize.x, ptSize.y, &dcBack, 0, 0, SRCAND);
// XOR the bitmap with the background on the destination DC.

   dcMem.BitBlt(0, 0, ptSize.x, ptSize.y, &dcTemp, 0, 0, SRCPAINT);
// Copy the destination to the screen.

   pDC->BitBlt(xStart, yStart, ptSize.x, ptSize.y, &dcMem, 0, 0,SRCCOPY);
// Place the original bitmap back into the bitmap sent here.

   dcTemp.BitBlt(0, 0, ptSize.x, ptSize.y, &dcSave, 0, 0, SRCCOPY);
// Reset the memory bitmaps.
// Memory DCs and Bitmap objects will be deleted automatically

leehdoAuthor Commented:
Dear psdavis

First of all, thank you for your answer.

But I want to have command buttons(minimize, maximize and close button) in window caption area.

I have no idea about implementing owner draw buttton in non-client area  and handling system command button.

As your advice, I took a look at Codeguru but I can't find any examples of command buttons in window caption area.

And I encountered new question about solving this problem.
What is different between using transparent bitmap as you commented me and owner drawn button image.

P.S : Please give me brief example using DrwaTransparentBitmap() function.

Best regards.

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

> But I want to have command buttons(minimize, maximize and close button) in window caption area

You're right! I missed the command button question.  To add buttons to the window caption area you have to use DrawFrameControl to add a button.

BOOL DrawFrameControl( LPRECT lpRect, UINT nType, UINT nState );

Use the nState value DFCS_ADJUSTRECT to adjust the bounding rectangle to exclude the surrounding edge of the push button. One or more of the following values can be used to set the state of the control to be drawn:

DFCS_CHECKED   Button is checked.
DFCS_FLAT   Button has a flat border.
DFCS_INACTIVE   Button is inactive (grayed).
DFCS_MONO   Button has a monochrome border.
DFCS_PUSHED   Button is pushed.
In several cases, nState depends on the nType parameter. The following list shows the relationship between the four nType values and nState:

DFCS_BUTTON3STATE   Three-state button
DFCS_BUTTONRADIOIMAGE   Image for radio button (nonsquare needs image)
DFCS_BUTTONRADIOMASK   Mask for radio button (nonsquare needs mask)

// The DFCS_BUTTONRADIOIMAGE looks more like what you want.

To handle messages in the non-client area, look at the OnNcLMouseDown message.  There is a code example at the codeguru site involving CControlBar implementation by some guy named 'Oliver' you can look at for an example.

The difference between using a transparent bitmap and a ownder drawn button is that the transparent owner drawn bitmap can simulate a non-rectangular image.

// I hope this answer was a little better.



   BITMAP bmLogo;
   m_bmLogo.GetObject( sizeof( BITMAP ), &bmLogo );

   CPoint ptLogo(( rcClientRect.Width( ) - bmLogo.bmWidth ) / 2, ( rcClientRect.Height( ) - bmLogo.bmHeight )/* / 2 */ );
   DrawTransparentBitmap( &dc, &m_bmLogo, ptLogo.x, ptLogo.y, RGB( 255, 255, 255 ));

leehdoAuthor Commented:
Thank you is too small a word.

Your answer is very helpful to me.
I think you are genuine expert.

Thanks again..

 - leehdo (Actual name : Hyundo Lee)
leehdoAuthor Commented:
Thank you is too small a word.

Your answer is very helpful to me.
I think you are genuine expert.

Thanks again..

 - leehdo (Actual name : Hyundo Lee)
That's the most wonderful thank you I've yet to receive from this site.  You're truly welcome.

Phillip Davis

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now