Solved

How can I change button shape at run time ?

Posted on 2008-06-18
3
415 Views
Last Modified: 2013-11-25
how can u change button shape at run time in VC ++ ?
0
Comment
Question by:ajaygoel
3 Comments
 
LVL 3

Accepted Solution

by:
Norbert earned 50 total points
Comment Utility
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
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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…

763 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