Solved

Problem with CButton (shape, size, appearance)

Posted on 1998-12-19
6
498 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
Comment Utility
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
Comment Utility
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
Comment Utility
Further explaination desired... (no second contact from expert)
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 8

Expert Comment

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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: 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.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

771 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

12 Experts available now in Live!

Get 1:1 Help Now