Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Round style command buttons in Window captionr

Posted on 1998-08-19
7
316 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
ID: 1320994
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
ID: 1320995
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
ID: 1320996
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
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.

 
LVL 7

Expert Comment

by:psdavis
ID: 1320997
> 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
ID: 1320998
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
ID: 1320999
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
ID: 1321000
That's the most wonderful thank you I've yet to receive from this site.  You're truly welcome.

Phillip Davis

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Prevent this page from creating additional dialogs. 3 622
sum28 challenge 31 115
Execute multiple curl cmds with sleep and send output to file 10 104
Problem to App 4 97
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: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

828 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