• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 561
  • Last Modified:

Problem with CButton (shape, size, appearance)

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
iseverynametaken
Asked:
iseverynametaken
  • 3
  • 2
1 Solution
 
Answers2000Commented:
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
 
iseverynametakenAuthor Commented:
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
 
iseverynametakenAuthor Commented:
Further explaination desired... (no second contact from expert)
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Answers2000Commented:
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
 
dd_bCommented:
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
 
iseverynametakenAuthor Commented:
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

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!

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