Thread: Restoring View Size in Split Views :: MFC

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348

    Restoring View Size in Split Views :: MFC

    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: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

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Here is the solution in RestoreWindowState() functon.

    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. MFC Assertion Failure
    By maxthecat in forum Windows Programming
    Replies: 5
    Last Post: 08-01-2002, 09:58 AM
  2. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM
  3. Getting Size & Location of ChildView :: MFC
    By kuphryn in forum C++ Programming
    Replies: 0
    Last Post: 04-03-2002, 07:26 PM
  4. Getting Latest Rectange & Window Size :: MFC
    By kuphryn in forum C++ Programming
    Replies: 4
    Last Post: 03-15-2002, 08:52 AM
  5. File Size and File Size on Disk
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 12-15-2001, 08:03 PM