Moving Windows
-
I'm trying to align static text windows on a CFormView dialog. I used the visual editor, but sometimes there's a larger gap between text windows than others, so I want to make this even. I've tried to adjust the window positions in the OnInitialUpdate function. The confusing part to me is that the following 4 lines end up putting my static text window in random places within my application. Between the 3rd and 4th lines of code I would obviously adjust the CRect borders, but I was hoping somebody could give me a reason as to how and why these lines of code cause my window to appear (if it shows at all) in random locations within my dialog. How can I fix this? Thanks a ton!!! :-D CWnd * MyWindow = GetDlgItem( NUMBER_STATIC ); ASSERT( NUMBER_STATIC ); MyWindow->GetWindowRect( &WindowRect ); MyWindow->MoveWindow( &WindowRect ); Douglas A. Wright dawrigh3@kent.edu
-
I'm trying to align static text windows on a CFormView dialog. I used the visual editor, but sometimes there's a larger gap between text windows than others, so I want to make this even. I've tried to adjust the window positions in the OnInitialUpdate function. The confusing part to me is that the following 4 lines end up putting my static text window in random places within my application. Between the 3rd and 4th lines of code I would obviously adjust the CRect borders, but I was hoping somebody could give me a reason as to how and why these lines of code cause my window to appear (if it shows at all) in random locations within my dialog. How can I fix this? Thanks a ton!!! :-D CWnd * MyWindow = GetDlgItem( NUMBER_STATIC ); ASSERT( NUMBER_STATIC ); MyWindow->GetWindowRect( &WindowRect ); MyWindow->MoveWindow( &WindowRect ); Douglas A. Wright dawrigh3@kent.edu
you're using GetWindowRect, which is the rect of the window on the screen. GetClientRect would return the control rect on the client x,y BUT, grabbing a rect, then moving the window right back to the same position will do absolutely nothing, even if you do it right.
-
I'm trying to align static text windows on a CFormView dialog. I used the visual editor, but sometimes there's a larger gap between text windows than others, so I want to make this even. I've tried to adjust the window positions in the OnInitialUpdate function. The confusing part to me is that the following 4 lines end up putting my static text window in random places within my application. Between the 3rd and 4th lines of code I would obviously adjust the CRect borders, but I was hoping somebody could give me a reason as to how and why these lines of code cause my window to appear (if it shows at all) in random locations within my dialog. How can I fix this? Thanks a ton!!! :-D CWnd * MyWindow = GetDlgItem( NUMBER_STATIC ); ASSERT( NUMBER_STATIC ); MyWindow->GetWindowRect( &WindowRect ); MyWindow->MoveWindow( &WindowRect ); Douglas A. Wright dawrigh3@kent.edu
GetWindowRect() retrieves the window position in screen co-ordinates (i.e. 0,0 is the top-left corner of the screen. MoveWindow() moves the window to the specified client co-ordinates of its parent window (i.e. 0,0 is the top-left corner of the parent window). You need to peform a conversion between the screen and client co-ordinates before moving the window as follows: MyWindow->GetWindowRect( &WindowRect ); ScreenToClient( &WindowRect ); // Adjust the position here... MyWindow->MoveWindow( &WindowRect ); Dave http://www.cloudsofheaven.org