Solved

Problem with CButton (shape, size, appearance)

Posted on 1998-12-19
6
514 Views
Last Modified: 2013-11-20
Hi,

I'm using a derived class for the CButton object which allows me to change the shape of the push button.  Although I can get the shape to change (an ellipse for example), the grey corners still show on the button. This isn't a problem when in a dialog, because the background is also grey and it blends, but my app uses a green background.

  When creating a CButton derived object inside my application (not CForm view or CRecordView or in a dialog ), the derived class calculates the lighting, etc. and draws the button as the regular CButton class would, except that it draws the button face as any shape desired.  The problem here is that the actual space taken up by the button is still rectangular, which means that ugly grey corners still show on the button (when using ellipse for example).

  I don't want to cover it with rectangular bitmaps, because that will defeat the whole purpose and I would have to match the bitmap corners with my app's background colors, etc...  That would be a pain.  

  When I actually create the CButton derived button, I'm forced to pass a RECT or CRect object, so it appears that this is my road-block, but I don't know how to tackle this problem.  If I could change the actual size that the button itself occupies, I think everything would be fine, but for now, I'm stuck.

 I've tried this with & w/out BS_OWNERDRAW.
 I think dealRect is the real problem here.

m_dealButton.Create("Deal", BS_OWNERDRAW | VISIBLE,
                     dealRect, this, 7);

   Call to derived CButton class with predefined shape.
   Not particularly important, but shown so that it's
   known that it's called after button is created.

m_dealButton.SetVtx(VTX_STRETCHEDCIRCLE);

Does anybody know of a way to get around this problem?  Please let me know if any further explaination, source, link to derived class source on web, picture of problem button, etc.... is needed.

Totally frustrated,

Jon Phillips
0
Comment
Question by:iseverynametaken
  • 3
  • 2
6 Comments
 
LVL 8

Expert Comment

by:Answers2000
ID: 1326418
Create a region.  After the button is created,  use SetWindowRgn.  This will cause the button to clip to the region.

Use SetWindowRgn with a NULL region to restore the rectangular shape before setting another region (e.g. changing shape from circle to diamond)

Also be aware that most region creaton functions work in screen coords
0
 

Author Comment

by:iseverynametaken
ID: 1326419
Sorry to keep you waiting,

Thank you for showing me how to go about it.  
It makes sense, but could you be a little more
precise?  I haven't quite got it working yet.
Here's what I've got so far...

[snip]

/* How to go about using screen coordinates? */
CDC* pDC = GetDC();
CRgn bRegion;

m_dealButton.Create("Deal", BS_OWNERDRAW | WS_VISIBLE,
                     dealRect, this, 7);

bRegion.CreateEllipticRgn( dealRect.TopLeft().x,
                           dealRect.TopLeft().y,
                           dealRect.BottomRight().x,
                           dealRect.BottomRight().y );

m_dealButton.SetWindowRgn(bRegion, true);
m_dealButton.SetVtx(VTX_STRETCHEDCIRCLE);
ReleaseDC(pDC);


Again, sorry for the tardiness...

Jon Phillips

0
 

Author Comment

by:iseverynametaken
ID: 1326420
Further explaination desired... (no second contact from expert)
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 8

Expert Comment

by:Answers2000
ID: 1326421
Sorry I didn't see your follow up till now.

I don't have time to debug your program at the moment.  Maybe another expert can add a comment/answer, otherwise I'll be back soon.
0
 
LVL 1

Accepted Solution

by:
dd_b earned 200 total points
ID: 1326422
Form the problem statement it seems that u r trying for irregular shape button. for this instead of using OWNER DRAWN property try extend style.

WS_EX_TRANSPERANT : this style will create transparent window & shows only portion drawn under PAINT ( OnDraw )

for this u have to create your button using CreateEx (...)


Try this

All the Best

dd_b
0
 

Author Comment

by:iseverynametaken
ID: 1326423
Thanks for your post dd_b,

This question was hard to answer, only because I was
using a CButton derived class.  No one has asked to
even take a peek at the source, but this is why I
offered a large number of pts.  I did solve my prob.
already.  I had to modify the source that I used.  I
just added a parameter to the Create function to specify
a background color to blend with the main window's bg
color and made a few other minor adjustments (fully
documenting the changes of course...).  I do thank you
for your time though.  The original expert gave up, I
guess, so the points are yours.
   
    Thanks again for your time,

    Jon Phillips
    jonboy108@hotmail.com


0

Featured Post

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.

772 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