Raspuns: Implementarea unei astfel de comportament este extrem de simpla si implica utilizarea
functiilor virtuale OnDestroy() si ActivateFrame().
In functie de implementarea dorita, datele se pot salva intr-un fisier config sau in registry,
ca in cazul de fata.
Pentru salvarea pozitiei ferestrei se supraincarca functia OnDestroy():
- Cod: Selectaţi tot
#define KEY "Main"
#define SECTION "Setari\\Position"
void CMainFrame::OnDestroy()
{
// get current position:
WINDOWPLACEMENT wp;
::ZeroMemory(&wp, sizeof(wp));
GetWindowPlacement(&wp);
// save data to registry
theApp.WriteProfileBinary(SECTION, KEY, (LPBYTE)&wp, sizeof(WINDOWPLACEMENT));
// destroy the window
CFrameWnd::OnDestroy();
}
Pentru restaurarea ferestrei in pozitia initiala se supraincarca functia ActivateFrame (int nCmdShow):
- Cod: Selectaţi tot
void CMainFrame::ActivateFrame(int nCmdShow)
{
// do default:
CFrameWnd::ActivateFrame(nCmdShow);
// read position from the registry:
UINT n = 0;
WINDOWPLACEMENT* pWp = NULL;
theApp.GetProfileBinary(SECTION, KEY, (LPBYTE*)&pWp, &n);
// restore the window position:
if(n == sizeof(WINDOWPLACEMENT))
SetWindowPlacement(pWp);
// clean up our mess:
delete [] pWp;
}


