| CodeGuru Home | VC++ / MFC / C++ | .NET / C# | Visual Basic | Newsletters | VB Forums | Developer.com |
|
|||||||
| Visual C++ Programming Ask questions about Windows programming with Visual C++ and help others by answering their questions. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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 > 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 |
|
#3
|
|||
|
|||
|
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 |
|
#4
|
|||
|
|||
|
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. |
|
#5
|
|||
|
|||
|
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 |
![]() |
| Bookmarks |
|
||||||
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|