Take a look at
this example, you can use it as it is:
Saving the window's position:
void CMainFrame::OnClose() {
CWinApp* app = AfxGetApp();
WINDOWPLACEMENT wp;
GetWindowPlacement(&wp);
app->WriteProfileInt("Frame", "Status", wp.showCmd);
app->WriteProfileInt("Frame", "Top", wp.rcNormalPosition.top);
app->WriteProfileInt("Frame", "Left", wp.rcNormalPosition.left);
app->WriteProfileInt("Frame", "Bottom", wp.rcNormalPosition.bottom);
app->WriteProfileInt("Frame", "Right", wp.rcNormalPosition.right);
CFrameWnd::OnClose();
}
Restoring it:
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
CWinApp* app = AfxGetApp();
int s, t, b, r, l;
if ( -1 != (s = app->GetProfileInt("Frame", "Status", -1)) &&
-1 != (t = app->GetProfileInt("Frame", "Top", -1)) &&
-1 != (l = app->GetProfileInt("Frame", "Left", -1)) &&
-1 != (b = app->GetProfileInt("Frame", "Bottom", -1)) &&
-1 != (r = app->GetProfileInt("Frame", "Right", -1))
) {
app->m_nCmdShow = s;
cs.cx = r - l;
cs.cy = b - t;
RECT workArea;
SystemParametersInfo(SPI_GETWORKAREA, 0, &workArea, 0);
l += workArea.left;
t += workArea.top;
int max_x = GetSystemMetrics(SM_CXSCREEN) -
GetSystemMetrics(SM_CXICON);
int max_y = GetSystemMetrics(SM_CYSCREEN) -
GetSystemMetrics(SM_CYICON);
cs.x = min(l, max_x);
cs.y = min(t, max_y);
}
return CFrameWnd::PreCreateWindow(cs);
}