CodeGuru Forums -
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic Newsletters VB Forums Developer.com


Newest CodeGuru.com Articles:

  • Installing SQL Server 2008
  • Writing UDFs for Firebird Embedded SQL Server
  • [Updated] Shutdown Manager
  • Building Windows Azure Cloud Service Applications with Azure Storage and the Azure SDK

  • Search CodeGuru:
     



    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > Visual C++ Programming
    FAQ Members List Calendar Search Today's Posts Mark Forums Read

    Visual C++ Programming Ask questions about Windows programming with Visual C++ and help others by answering their questions.

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1    
    Old November 15th, 1999, 11:31 PM
    Chris Bradley Chris Bradley is offline
    Member
     
    Join Date: Oct 1999
    Posts: 79
    Chris Bradley is an unknown quantity at this point (<10)
    GetWindowPlacement/SetWindowPlacement

    Hi,

    I'm attempting to save certain things about my Mainframe window (SDI app), including Position, size, whether its maximized or not.

    I use GetWindowPlacement to obtain a WINDOWPLACEMENT structure, then write it off to the registery.

    Later when the program starts, in the mainframes OnCreate member, after calling CFrameWnd::OnCreate(), i then perform a SetWindowPlacement, using the previously saved off structure.

    This works totally fine in reguards to winow position and size, but if i maximize the window, close the app, re-run, the window opens at exactly the right size of the maximized state, but the window is not maximized - the maximize control on the system menu is enabled.

    How come this does not do the trick? and what do i need to do, to force the MainFrame to open in a maximized state?

    Chris

    Reply With Quote
      #2    
    Old November 15th, 1999, 11:48 PM
    Guest
     
    Posts: n/a
    Re: GetWindowPlacement/SetWindowPlacement

    try to do the following:
    1. Remove SetWindowPlacement from OnCreate.
    2. Override Create function:

    BOOL CMyFrame::Create(CWnd* pParentWnd)
    {
    ...
    // do not set WS_VISIBLE in style mask
    if ( !CFrameWnd::Create(...) )
    return FALSE;

    // m_wndpl.length is used to find out if the structure
    // has been initialized
    if ( m_wndpl.length &gt; 0 )
    {
    m_wndpl.flags &= ~WPF_RESTORETOMAXIMIZED;
    m_wndpl.ptMinPosition.x = m_wndpl.ptMinPosition.y = 0;
    m_wndpl.ptMaxPosition.x = m_wndpl.ptMaxPosition.y = -2;
    SetWindowPlacement(&m_wndpl);
    }
    else
    ShowWindow(SW_SHOW);
    ...
    return TRUE;
    }

    hope it helps

    Reply With Quote
      #3    
    Old November 16th, 1999, 01:54 AM
    Chris Bradley Chris Bradley is offline
    Member
     
    Join Date: Oct 1999
    Posts: 79
    Chris Bradley is an unknown quantity at this point (<10)
    Re: GetWindowPlacement/SetWindowPlacement

    Thanks for replying,


    I tried your suggestion, but my program was still stuborn. It still produces a non-maximized window, created at maximum size.

    Im beginning to think that somewhere else in the program its being restored or something. Any other ideas ?



    Chris

    Reply With Quote
      #4    
    Old November 16th, 1999, 04:06 AM
    Guest
     
    Posts: n/a
    Re: GetWindowPlacement/SetWindowPlacement

    Call SetWindowPlacement in ActivateFrame of the main window and pass the value for nCmdShow read from the registry to the CFrameWnd's ActivateFrame. This will do the needful.

    Example

    ... ActivateFrame(int nCmdShow)
    {
    // Write a function to set the window placement and size and return the
    // nCmdShow value read from the registry.

    // Let the function be SetWindowSizeAndPos()
    // Call it like this.
    CFrameWnd::ActivateFrame(SetWindowSizeAndPos());
    }
    This should solve your problem.


    Reply With Quote
      #5    
    Old November 16th, 1999, 12:49 PM
    Chris Bradley Chris Bradley is offline
    Member
     
    Join Date: Oct 1999
    Posts: 79
    Chris Bradley is an unknown quantity at this point (<10)
    Re: GetWindowPlacement/SetWindowPlacement

    Hi,


    Cheers for putting me onto the ActivateFrame(). That did the trick with starting the window in a maxed state... (hehe) however..., I must be doing something wrong, because if i make the window half the size of the screen, then maximize, then close. When i re-run the program, the window opens in a max state, but when i do a restore, to restores to the full size of the screen. Ill post all my code fragments so you guys can see what is going on..:


    void CMainFrame::ActivateFrame(int nCmdShow)
    {
    // TODO: Add your specialized code here and/or call the base class

    if (m_WndPrefs.Valid)
    nCmdShow = m_WndPrefs.WndPlacement.showCmd; //SW_SHOWMAXIMIZED;

    CFrameWnd::ActivateFrame(nCmdShow);
    }

    void CMainFrame::OnClose()
    {
    // Get window position
    CWnd::GetWindowPlacement(&m_WndPrefs.WndPlacement); // Copy frames placement, before closing
    // Get splitter position
    int Garbage;
    m_wndSplitter.GetColumnInfo(0,(int&)m_WndPrefs.SplitterX,(int&)Garbage);
    CFrameWnd::OnClose();
    }

    int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
    {
    if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
    return -1;

    if (m_WndPrefs.Valid) //WINDOWPLACEMENT
    SetWindowPlacement (&m_WndPrefs.WndPlacement);

    ....
    ....
    }




    The registry loading/saving takes place in the CMainFrame constructor/deconstructor. The structure m_WndPrefs (Which contains the WINDOWPLACEMENT structure) is updated in OnClose. So the registry should always save the correct values.

    Thanks for all your help

    Chris

    Reply With Quote
    Reply

    Bookmarks
    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > Visual C++ Programming


    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 08:39 PM.



    Acceptable Use Policy

    internet.comMediabistrojusttechjobs.comGraphics.com

    WebMediaBrands Corporate Info


    Advertise | Newsletters | Feedback | Submit News

    Legal Notices | Licensing | Permissions | Privacy Policy


    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
    Copyright WebMediaBrands Inc. 2002-2009