Solved

Round style command buttons in Window captionr

Posted on 1998-08-19
7
315 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Show shut-down message as Windows 8 shuts down. 9 90
fix34  challenge 9 117
Unix Command -- Challenging  question 7 90
Sed question 2 85
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

770 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