how to move button when the dialog is resized?
-
antonio343 wrote:
But not run
Crash or not moving the controls in the good position ? When doing something like that, moving controls around, I play dumb and use the dialog client area rectangle (
GetClientRect
). Play around with the values to move to the bottom of the rect returned by GetClientRect; Note: be careful with the coordinate being in either relative to the client or window .Watched code never compiles.
Not moving the controls in the good position. I dont know how to use this function. Maybe on this way:
void CEjemplo::OnSize(UINT nType, int cx, int cy)
{
CDialogEx::OnSize(nType, cx, cy);
CRect myRect;
GetClientRect(&myRect);if (GetDlgItem(IDC\_EDIT1)) { m\_Edit.MoveWindow(5,5,cx-55,cy-55); //puedes jugar con estos valores m\_Button1.MoveWindow(myRect.right, myRect.bottom, myRect.Width(), myRect.Height()); }
}
But I dont want to change the size, only the position. I'd like to move at the right botton corner.
-
Not moving the controls in the good position. I dont know how to use this function. Maybe on this way:
void CEjemplo::OnSize(UINT nType, int cx, int cy)
{
CDialogEx::OnSize(nType, cx, cy);
CRect myRect;
GetClientRect(&myRect);if (GetDlgItem(IDC\_EDIT1)) { m\_Edit.MoveWindow(5,5,cx-55,cy-55); //puedes jugar con estos valores m\_Button1.MoveWindow(myRect.right, myRect.bottom, myRect.Width(), myRect.Height()); }
}
But I dont want to change the size, only the position. I'd like to move at the right botton corner.
use
SetWindowPos
(with the SWP_NOSIZE option, check the documentation ) function instead of MoveWindow. M.Watched code never compiles.
-
use
SetWindowPos
(with the SWP_NOSIZE option, check the documentation ) function instead of MoveWindow. M.Watched code never compiles.
I've tried with this:
void CEjemplo::OnSize(UINT nType, int cx, int cy)
{
CDialogEx::OnSize(nType, cx, cy);
CRect myRect;
const CWnd &p=wndBottom;
GetClientRect(&myRect);if (GetDlgItem(IDC\_EDIT1)) { GetDlgItem(IDC\_EDIT1)->MoveWindow(5,5,cx-50,cy-80); //puedes jugar con estos valores m\_Button1.SetWindowPos(&p,5,5,cx-50,cy-75,SWP\_NOSIZE); }
}
But when I run the application it crash X|
-
I've tried with this:
void CEjemplo::OnSize(UINT nType, int cx, int cy)
{
CDialogEx::OnSize(nType, cx, cy);
CRect myRect;
const CWnd &p=wndBottom;
GetClientRect(&myRect);if (GetDlgItem(IDC\_EDIT1)) { GetDlgItem(IDC\_EDIT1)->MoveWindow(5,5,cx-50,cy-80); //puedes jugar con estos valores m\_Button1.SetWindowPos(&p,5,5,cx-50,cy-75,SWP\_NOSIZE); }
}
But when I run the application it crash X|
antonio343 wrote:
But when I run the application it crash
Exception thrown? Assertion fired? Have you stepped into the code to see what is actually going on?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
-
I've tried with this:
void CEjemplo::OnSize(UINT nType, int cx, int cy)
{
CDialogEx::OnSize(nType, cx, cy);
CRect myRect;
const CWnd &p=wndBottom;
GetClientRect(&myRect);if (GetDlgItem(IDC\_EDIT1)) { GetDlgItem(IDC\_EDIT1)->MoveWindow(5,5,cx-50,cy-80); //puedes jugar con estos valores m\_Button1.SetWindowPos(&p,5,5,cx-50,cy-75,SWP\_NOSIZE); }
}
But when I run the application it crash X|
antonio343 wrote:
m_Button1.SetWindowPos(&p,5,5,cx-50,cy-75,SWP_NOSIZE)
change this to read:
m_Button1.SetWindowPos(&wndTop, cx - m_Button1.Width - 5, cy - m_Button1.Height - 5, 0, 0, SWP_NOSIZE);
If your actions inspire others to dream more, learn more, do more and become more, you are a leader." - John Quincy Adams
You must accept one of two basic premises: Either we are alone in the universe, or we are not alone in the universe. And either way, the implications are staggering” - Wernher von Braun -
Hi, I have a modeless dialog with a edit control, and two button. I show the dialog maximized, I got maximized the edit control with
void CEjemplo::OnSize(UINT nType, int cx, int cy)
{
CDialogEx::OnSize(nType, cx, cy);if (GetDlgItem(IDC\_EDIT1)) { GetDlgItem(IDC\_EDIT1)->MoveWindow(5,5,cx-1,cy-1); }
}
But I dont know how to move the button at the botton of the dialog. Now, when I maximized the dialog the button dont move itself and it is at back of edit control I tried to do
if (GetDlgItem(IDC_EDIT1))
{
GetDlgItem(IDC_EDIT1)->MoveWindow(5,5,cx-1,cy-1);
GetDlgItem(IDC_button1)->MoveWindow(5,5,cx-1,cy-1);}
But not run.
antonio343 wrote:
Now, when I maximized the dialog the button dont move itself...
See if the Extras section of this article is of any help. I've updated the code in a newer project but the premise is the same.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
-
antonio343 wrote:
But when I run the application it crash
Exception thrown? Assertion fired? Have you stepped into the code to see what is actually going on?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
I'm sorry , the error wasn't due to the setwindowspos. I solved the error. It run well, but I need know the coordinates of the right bottom corner.
-
I'm sorry , the error wasn't due to the setwindowspos. I solved the error. It run well, but I need know the coordinates of the right bottom corner.
antonio343 wrote:
It run well, but I need know the coordinates of the right bottom corner.
Relative to what?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
-
antonio343 wrote:
Now, when I maximized the dialog the button dont move itself...
See if the Extras section of this article is of any help. I've updated the code in a newer project but the premise is the same.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
+5. Good bit of code.
If your actions inspire others to dream more, learn more, do more and become more, you are a leader." - John Quincy Adams
You must accept one of two basic premises: Either we are alone in the universe, or we are not alone in the universe. And either way, the implications are staggering” - Wernher von Braun -
antonio343 wrote:
m_Button1.SetWindowPos(&p,5,5,cx-50,cy-75,SWP_NOSIZE)
change this to read:
m_Button1.SetWindowPos(&wndTop, cx - m_Button1.Width - 5, cy - m_Button1.Height - 5, 0, 0, SWP_NOSIZE);
If your actions inspire others to dream more, learn more, do more and become more, you are a leader." - John Quincy Adams
You must accept one of two basic premises: Either we are alone in the universe, or we are not alone in the universe. And either way, the implications are staggering” - Wernher von BraunI cant change this, becouse CButton don't have some member "width" and "Height"
-
Hi, I have a modeless dialog with a edit control, and two button. I show the dialog maximized, I got maximized the edit control with
void CEjemplo::OnSize(UINT nType, int cx, int cy)
{
CDialogEx::OnSize(nType, cx, cy);if (GetDlgItem(IDC\_EDIT1)) { GetDlgItem(IDC\_EDIT1)->MoveWindow(5,5,cx-1,cy-1); }
}
But I dont know how to move the button at the botton of the dialog. Now, when I maximized the dialog the button dont move itself and it is at back of edit control I tried to do
if (GetDlgItem(IDC_EDIT1))
{
GetDlgItem(IDC_EDIT1)->MoveWindow(5,5,cx-1,cy-1);
GetDlgItem(IDC_button1)->MoveWindow(5,5,cx-1,cy-1);}
But not run.
The first two arguments to MoveWindow are the new X and Y coordinates of the upper left of the window. You are putting all your things at [5,5], on top of one another. No wonder it doesn't seem to work.
-
I cant change this, becouse CButton don't have some member "width" and "Height"
A CButton is a Window, WIndows have Rect (GetWindowRect() function). Rect gives you height and width. So it's not a straightforward as posted but easily obtainable.
-
I cant change this, becouse CButton don't have some member "width" and "Height"
Sorry, the other poster is right. Use
CRect rect;
m_Button1.GetWindowRect(&rect)
rect.Width()
rect.Height()If your actions inspire others to dream more, learn more, do more and become more, you are a leader." - John Quincy Adams
You must accept one of two basic premises: Either we are alone in the universe, or we are not alone in the universe. And either way, the implications are staggering” - Wernher von Braun -
Not moving the controls in the good position. I dont know how to use this function. Maybe on this way:
void CEjemplo::OnSize(UINT nType, int cx, int cy)
{
CDialogEx::OnSize(nType, cx, cy);
CRect myRect;
GetClientRect(&myRect);if (GetDlgItem(IDC\_EDIT1)) { m\_Edit.MoveWindow(5,5,cx-55,cy-55); //puedes jugar con estos valores m\_Button1.MoveWindow(myRect.right, myRect.bottom, myRect.Width(), myRect.Height()); }
}
But I dont want to change the size, only the position. I'd like to move at the right botton corner.
Assuming the coordinate system is correct (Client View, Control View, Screen View), which is a big assumption at this point, the line
m_Button1.MoveWindow(myRect.right, myRect.bottom,
seems to want to put the left edge of the button at the right edge of the main window, therefore, it's not visible since it's off the right side of the main window. Similarly for the y coordinate, you're putting the top of the button starting at the bottom of the window, therefore it's outside the viewing area
-
Hi, I have a modeless dialog with a edit control, and two button. I show the dialog maximized, I got maximized the edit control with
void CEjemplo::OnSize(UINT nType, int cx, int cy)
{
CDialogEx::OnSize(nType, cx, cy);if (GetDlgItem(IDC\_EDIT1)) { GetDlgItem(IDC\_EDIT1)->MoveWindow(5,5,cx-1,cy-1); }
}
But I dont know how to move the button at the botton of the dialog. Now, when I maximized the dialog the button dont move itself and it is at back of edit control I tried to do
if (GetDlgItem(IDC_EDIT1))
{
GetDlgItem(IDC_EDIT1)->MoveWindow(5,5,cx-1,cy-1);
GetDlgItem(IDC_button1)->MoveWindow(5,5,cx-1,cy-1);}
But not run.