Solved

How can I change button shape at run time ?

Posted on 2008-06-18
3
424 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
wait notify demo infinite loop 3 148
Changing the installation path of this MSI 5 119
WPF - External data binding to controls inside a UserControl 2 93
Example code 13 42
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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…

732 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