?
Solved

Move at CButton at Runtime

Posted on 2003-03-27
1
Medium Priority
?
733 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
[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
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

800 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