?
Solved

Move at CButton at Runtime

Posted on 2003-03-27
1
Medium Priority
?
775 Views
Last Modified: 2008-02-01
How could I move a CButton on my dialog window at run time?

  CButton*
    state = static_cast<CEdit*>(GetDlgItem(IDC_BUTTON_STATE));

Is this right so far?  If so, how do I move the button 'state'?

Thanks

Ernie
0
Comment
Question by:fastawdtsi
1 Comment
 

Accepted Solution

by:
fuzzbury earned 400 total points
ID: 8221045
The functions to move a control on a dialog box are in the baseclass CWnd that all controls are derived from.

For a CButton control, the following code will move the button to the top left corner of your dialog box if the code is excuted in the dialog class containing the button.

CButton* pButton=static_cast<CButton*>(this->GetDlgItem(IDC_BUTTON1));
     CRect rc;
     pButton->GetWindowRect(rc);
     int x=0; //x coord
     int y=0; //y coord
     pButton->MoveWindow(x,y,rc.Width(),rc.Height(),TRUE);


If you want to depress the button, assuming you are using a push button

     //to depress the button set TRUE (if push button)
     pButton->SetState(TRUE);

Note: the cast to CButton is not necessary to move the button, it could be left as
CWnd* pButton=this->GetDlgItem(IDC_BUTTON1));

The cast is necessary to set the state though
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

588 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