Solved

How can I change button shape at run time ?

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Hibernate methods 2 71
Problem to adjust sheet 1 90
Window placement 17 82
Access 2013: API code to put hidden database icon in taskbar? 8 74
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…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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…

773 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