Solved

Round style command buttons in Window captionr

Posted on 1998-08-19
7
312 Views
Last Modified: 2013-11-20
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
Comment
Question by:leehdo
  • 4
  • 3
7 Comments
 
LVL 7

Accepted Solution

by:
psdavis earned 50 total points
Comment Utility
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
 
LVL 7

Expert Comment

by:psdavis
Comment Utility
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
 

Author Comment

by:leehdo
Comment Utility
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 7

Expert Comment

by:psdavis
Comment Utility
> 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
 

Author Comment

by:leehdo
Comment Utility
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
 

Author Comment

by:leehdo
Comment Utility
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
 
LVL 7

Expert Comment

by:psdavis
Comment Utility
That's the most wonderful thank you I've yet to receive from this site.  You're truly welcome.

Phillip Davis

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now