Chapter 12: Dialog-Based Windows Visual C++ and MFC Fundamentals
WndCls.hbrBackground, WndCls.hIcon);
Create(StrClass, StrWndName, WS_OVERLAPPEDWINDOW, rectDefault);
}
At any time you can find out the location and size of a rectangle by calling the
CWnd::GetWindowRect() method. Its syntax is:
void GetWindowRect(LPRECT lpRect) const;
To use this method, pass it a RECT or a CRect variable as lpRect. The method returns
the rectangle properties of the window. Here is an example:
void CMainFrame::OnViewLocationandsize()
{
// TODO: Add your command handler code here
CRect Recto;
GetWindowRect(&Recto);
char Str[80];
sprintf(Str, "The window rectangle is:\nLeft: %d\nTop:
%d\nWidth: %d\nHeight: %d",
Recto.left, Recto.top, Recto.Width(), Recto.Height());
MessageBox(Str);
}
If you created your application using AppWizard, it sets a default rectangle for the frame
(actually the left and top values are randomly selected). Whether you created the frame
using the CFrameWnd::Create() method or AppWizard, you can redefine its location
and size from the PreCreateWindow() event. Because this event is called after
CFrameWnd::Create but before the window is displayed, its values are applied to the
window. The syntax of the CWnd::PreCreateWindow() event is (this event is inherited
from CWnd but CFrameWnd, like any other class that needs it, overrides it and provides
its own functionality as it relates to a window frame):
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
This event takes as argument a CREATESTRUCT object. This structure is defined as
follows:
typedef struct tagCREATESTRUCT {
LPVOID lpCreateParams;
HANDLE hInstance;
HMENU hMenu;
HWND hwndParent;