Restoring View Size in Split Views :: MFC

kuphryn

Senior member
Jan 7, 2001
400
0
0
Hello.

I have having trouble getting a program to restore the the location of the splitter bar in a program with splitter views (two).

Here is the code in main.

-----
BOOL CMainFrame::eek:nCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
CString version = _T("1.0");

if (!m_wndSplitter.CreateStatic(this, 2, 1) ||
!m_wndSplitter.CreateView(1, 0, RUNTIME_CLASS(CView2),
CSize(0, 0), pContext) ||
!m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CView1),
CSize(0, MyApp.GetProfileInt(version, _T("Size"), 300)), pContext))
return FALSE;

return TRUE;
}

The progres saves the size of the window in the register. Everything looks okay and function well except for the splitter. Here is the program design.

- program first starts with default View1 at height 300 (Note: I created view2 first for UpdateAllViews() to work right similar what Prosise presents in his book).

- progres restores size of view1 via code above.

Again, I cannot see a flaw in the code unless there is a flaw somewhere in the design. I implement the same code Prosise presents in his book to return windows size and location. Here is the code that does that.

-----
if (!(reinterpret_cast(m_pMainWnd))->RestoreWindowState())
m_pMainWnd->ShowWindow(m_nCmdShow);
-----

Is it possible that this code and the one to restore size of view1 are conflicting?

Again, I am open to all interpretations and if you have a better technique please show.

Thanks,
Kuphryn
 

BuckleDownBen

Banned
Jun 11, 2001
519
0
0
Hi-

I am not a C++ programmer, but I see you posting here a lot, and I'm wondering if you wouldn't have more responses of you posted on the Microsoft newsgroups. Whenever I have VB or SQL Server questions, I post there, and I usually get some real good answers within an hour.

Just trying to be helpful.

 

kuphryn

Senior member
Jan 7, 2001
400
0
0
Here is the solution in RestoreWindowState() function.

A special thanks to members of CodeGuru and CodeProject for responding about function SetColumnInfo() and RecalcLayout().

-----
bool CMainFrame::RestoreWindowState()
{
m_bVeriReturn = false;
CString version = _T("1.0");

WINDOWPLACEMENT wp;
wp.length = sizeof(WINDOWPLACEMENT);
GetWindowPlacement(&wp);

if (((wp.flags = theApp.GetProfileInt(version, _T("flag"), -1)) != -1) &&
((wp.showCmd = theApp.GetProfileInt(version, _T("command"), -1)) != -1) &&
((wp.rcNormalPosition.bottom = theApp.GetProfileInt(version, _T("bottom"), -1)) != -1) &&
((wp.rcNormalPosition.left = theApp.GetProfileInt(version, _T("left"), -1)) != -1) &&
((wp.rcNormalPosition.right = theApp.GetProfileInt(version, _T("right"), -1)) != -1) &&
((wp.rcNormalPosition.top = theApp.GetProfileInt(version, _T("top"), -1)) != -1))
{
wp.rcNormalPosition.left = min(wp.rcNormalPosition.left,
::GetSystemMetrics(SM_CXSCREEN) - ::GetSystemMetrics(SM_CXICON));
wp.rcNormalPosition.top = min(wp.rcNormalPosition.top,
::GetSystemMetrics(SM_CYSCREEN) - ::GetSystemMetrics(SM_CYICON));
SetWindowPlacement(&wp);

m_nSplitSize = theApp.GetProfileInt(version, _T("topsplit"), 300);
m_wndSplitter.SetRowInfo(0, m_nSplitSize, 10);
m_wndSplitter.RecalcLayout();

m_bVeriReturn = true;
}

return m_bVeriReturn;
}
-----

Kuphryn