Solved

How can I change button shape at run time ?

Posted on 2008-06-18
3
425 Views
Last Modified: 2013-11-25
how can u change button shape at run time in VC ++ ?
0
Comment
Question by:ajaygoel
[X]
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
3 Comments
 
LVL 3

Accepted Solution

by:
Norbert earned 50 total points
ID: 21814198
Create new class, Inherit from CButton
class CMyButton:public CButton)
{
public:
    virtual void DrawItem(  LPDRAWITEMSTRUCT lpDrawItemStruct );

    virtual BOOL Create(  LPCTSTR lpszCaption,  DWORD dwStyle,  const RECT& rect,  CWnd* pParentWnd,   UINT nID );

};
BOOL CMyButton::Create(  LPCTSTR lpszCaption,  DWORD dwStyle,  const RECT& rect,  CWnd* pParentWnd,   UINT nID )
{
    DWStyle|=BS_OWNERDRAW;
    CButton::CreatelpszCaption,dwStyle,Rect,ParentWnd,nID);
}
void CMyButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
// Do your Drawing.
//have a look to online help Function DrawItem for more details
}
0
 
LVL 5

Expert Comment

by:isprabu
ID: 22313319
ajaygoel,
You can easily change the size and/or position of a Button (for that matter any window control) at runtime.
This is true in case of  Window components that inherit from CWnd. CButton is one of them. You can just call MoveWindow() method. An that's it!
See my example code below: (in the parent window/dialog)

Try this and see for yourself!
	CRect rect(10,180,130,210); // left, top, right, bottom
         // m_Button1 is of type CButton
	m_Button1.MoveWindow((LPCRECT) &rect, TRUE);

Open in new window

0

Featured Post

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

690 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