• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 324
  • 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.
0
leehdo
Asked:
leehdo
  • 4
  • 3
1 Solution
 
psdavisCommented:
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.

Phillip
0
 
psdavisCommented:
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.CreateCompatibleDC(pDC);
   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.

   dcBack.CreateCompatibleDC(pDC);
   dcObject.CreateCompatibleDC(pDC);
   dcMem.CreateCompatibleDC(pDC);
   dcSave.CreateCompatibleDC(pDC);
   
// 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.

   dcTemp.SetMapMode(pDC->GetMapMode());
   
// 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.

   dcTemp.SetBkColor(cColor);
   
// 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.
   dcBack.SelectObject(pbmBackOld);
   dcObject.SelectObject(pbmObjectOld);
   dcMem.SelectObject(pbmMemOld);
   dcSave.SelectObject(pbmSaveOld);
   
// Memory DCs and Bitmap objects will be deleted automatically
   }


Phillip
0
 
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.

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
psdavisCommented:
> 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:

DFC_BUTTON
DFCS_BUTTON3STATE   Three-state button
DFCS_BUTTONCHECK   Check box
DFCS_BUTTONPUSH   Push button
DFCS_BUTTONRADIO   Radio 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.

Phillip

p.s.

   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 ));

0
 
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)
0
 
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)
0
 
psdavisCommented:
That's the most wonderful thank you I've yet to receive from this site.  You're truly welcome.

Phillip Davis

0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

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