| | | | The bRepaint flag should be set to True to have Windows repaint the window after it is moved or resized. | | | | | | Unfortunately, all of the parameters to this function must be filled in, so even if we want to change only the window's size, we must compute the window's current position to use in the position parameters. This can be done using the GetWindowRect function discussed below. | | | | | | We discussed the SetWindowPos function earlier in the chapter. This function can be used to change the size, position, and Z order of a window: | | BOOL SetWindowPos( HWND hWnd, // handle to window HWND hWndInsertAfter, // placement-order handle int X, // horizontal position int Y, // vertical position int cx, // width int cy, // height UINT uFlags // window-positioning flags ); | | | | Note that there is no corresponding GetWindowPos. | | | | | | GetWindowRect and GetClientRect | | | | | | The GetWindowRect function retrieves the window's rectangle (or bounding rectangle), which is a rectangle that would precisely circumscribe the entire window (client and nonclient areas). The dimensions of this rectangle are screen coordinates, that is, coordinates (in pixels) relative to the upper-left corner of the screen. Here is the declaration: | | | | | | BOOL GetWindowRect( HWND hWnd, // handle to window LPRECT lpRect // address of RECT structure that will be filled by function ); | | | | | | The GetClientRect function does the same thing for the client area of the window: | | | | | | BOOL GetClientRect( HWND hWnd, // handle to window LPRECT lpRect // address of structure for client coordinates ); | | | | | | You might expect that the coordinates returned in the RECT structure would be window coordinates, that is, coordinates relative to the upper-left corner of the window, but this is not the case. Indeed, the main purpose of this function is to retrieve the size of the client area, so it simplifies matters for the function to return client coordinates, that is, coordinates that are relative to the client area itself. Hence, the upper-left corner will always be (0,0). | | |