SetWindowPos & GetWindowRect
-
Hi, I am trying to resize 2 CButtons at runtime, but am having a really hard time getting them to appear in the correct place. GetWindowRect gives me values that are offset to the dialog. To demonstrate, the code i am using is something like the following;
CRect btnRect; btn1.GetWindowRect(btnRect); ::SetWindowPos(btn1.m_hwnd, btnRect.left, btnRect.top, btnRect.Width(), btnRect.Height(), SWP_SHOWWINDOW);
This results in the button moving diagonally across the screen, it doesnt stay still, which is what I would have expected. I find that if i take away (rectDialog.left + 3) and (rectDialog.top + 29) from btnRect.left and .top it will work (stay still). I assume the '3' is the width of the boarder, and '29' the height of the title bar. Is this correct? If so, how can I find it programatically? Thank you very much for your help. -
Hi, I am trying to resize 2 CButtons at runtime, but am having a really hard time getting them to appear in the correct place. GetWindowRect gives me values that are offset to the dialog. To demonstrate, the code i am using is something like the following;
CRect btnRect; btn1.GetWindowRect(btnRect); ::SetWindowPos(btn1.m_hwnd, btnRect.left, btnRect.top, btnRect.Width(), btnRect.Height(), SWP_SHOWWINDOW);
This results in the button moving diagonally across the screen, it doesnt stay still, which is what I would have expected. I find that if i take away (rectDialog.left + 3) and (rectDialog.top + 29) from btnRect.left and .top it will work (stay still). I assume the '3' is the width of the boarder, and '29' the height of the title bar. Is this correct? If so, how can I find it programatically? Thank you very much for your help.SetWindowPos coordinates for child windows are relative to the client area of the parent window. You are using window coordinates relative to the screen. Try GetClientRect instead of GetWindowRect. What Roger said :) Also, MoveWindow is simpler and more appropriate for this than SetWindowPos. Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
Hi, I am trying to resize 2 CButtons at runtime, but am having a really hard time getting them to appear in the correct place. GetWindowRect gives me values that are offset to the dialog. To demonstrate, the code i am using is something like the following;
CRect btnRect; btn1.GetWindowRect(btnRect); ::SetWindowPos(btn1.m_hwnd, btnRect.left, btnRect.top, btnRect.Width(), btnRect.Height(), SWP_SHOWWINDOW);
This results in the button moving diagonally across the screen, it doesnt stay still, which is what I would have expected. I find that if i take away (rectDialog.left + 3) and (rectDialog.top + 29) from btnRect.left and .top it will work (stay still). I assume the '3' is the width of the boarder, and '29' the height of the title bar. Is this correct? If so, how can I find it programatically? Thank you very much for your help.MapWindowPoints() or ScreenToClient() CRect btnRect; btn1.GetWindowRect(btnRect); ScreenToClient(&btnRect); //assumes that this is the parent of btn1 btn1.SetWindowPos(wndTop, btnRect.left, btnRect.top, btnRect.Width(), btnRect.Height(), SWP_SHOWWINDOW);