Click here to Skip to main content
15,900,461 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i want to save window state in file like VMware and resume window

What I have tried:

i am trying in c++ but i have only done to get process list .
Posted
Updated 28-May-19 4:59am

I wrote this article[^] about it.
Basically, you periodically store in a .config file or in the Registry any such information (such as the window state). Then when your application starts, you read this information.
 
Share this answer
 
Take a look at Save and restore your form size and location[^] by the great @OriginalGriff. It is for .NET but should give you a reasonable idea of the process you need to follow.
 
Share this answer
 
You must save the needed values in a file or registry and restore it on launch. It is firstly the windows size and position and I guess its data which is displayed.

Maybe my article about Repositioning of Windows shows you some insights.
 
Share this answer
 
v2
Quote:
i want to save window state in file like VMware and resume window
If you meant 'I want to save Windows (the operating system) state' then I fear it would be a very (very) difficult task. Probably you'd better find a tool for the purpose.
 
Share this answer
 
If you have MFC app this snippet saves window position:

C++
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
		return -1;
    //.....
        LoadPlacement();
	return 0;
}

void CMainFrame::OnClose() 
{
	SavePlacement();	
	CMDIFrameWnd::OnClose();
}

void CMainFrame::LoadPlacement()
{
	LPBYTE pbtData = 0;
	UINT nSize = 0;
	WINDOWPLACEMENT wp;
	if(!AfxGetApp()->GetProfileBinary(_T("MainWindow"), _T("Position"), &pbtData, &nSize))
		return;
	
	memcpy(&wp, pbtData, sizeof(WINDOWPLACEMENT));
	
	if(wp.flags & WPF_RESTORETOMAXIMIZED)
		wp.showCmd = SW_SHOWMAXIMIZED;
	else
		wp.showCmd = AfxGetApp ()->m_nCmdShow;
	
	SetWindowPlacement(&wp);
	
    delete [] pbtData;
}

void CMainFrame::SavePlacement()
{
	WINDOWPLACEMENT wp;
	if(!GetWindowPlacement(&wp))
		return;
	
	AfxGetApp()->WriteProfileBinary(_T("MainWindow"), _T("Position"), 
		reinterpret_cast<LPBYTE>((LPWINDOWPLACEMENT)&wp), 
         sizeof(WINDOWPLACEMENT));
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900