//
//  app_settings.cpp - application wide settings container class implementation file
//
//  $Id: app_settings.cpp 54 2014-04-11 01:06:56Z brian $ 
//
//  Copyright (c) 2014 by Precision Micro Control Corp. All rights reserved.
//
#include "stdafx.h"

void AppSettings::Restore(HWND hWnd)
{
	int xpos   = GetPrivateProfileInt("Main Window", "XPos",     0, m_ini_file);
	int ypos   = GetPrivateProfileInt("Main Window", "YPos",     0, m_ini_file);
	int width  = GetPrivateProfileInt("Main Window", "Width",  800, m_ini_file);
	int height = GetPrivateProfileInt("Main Window", "Height", 600, m_ini_file);
	SetWindowPos(hWnd, 0, xpos, ypos, width, height, SWP_NOZORDER);

	m_id = GetPrivateProfileInt("Controller", "ControllerID", 0, m_ini_file);
}

void AppSettings::Save(HWND hWnd)
{
	char buffer[32];

	if (hWnd && !IsIconic(hWnd))
	{
		RECT rc;
		GetWindowRect(hWnd, &rc);

		_snprintf(buffer, sizeof(buffer), "%d", rc.left);
		WritePrivateProfileString("Main Window", "XPos", buffer, m_ini_file);
		_snprintf(buffer, sizeof(buffer), "%d", rc.top);
		WritePrivateProfileString("Main Window", "YPos", buffer, m_ini_file);
		_snprintf(buffer, sizeof(buffer), "%d", rc.right - rc.left);
		WritePrivateProfileString("Main Window", "Width", buffer, m_ini_file);
		_snprintf(buffer, sizeof(buffer), "%d", rc.bottom - rc.top);
		WritePrivateProfileString("Main Window", "Height", buffer, m_ini_file);
	}

	_snprintf(buffer, sizeof(buffer), "%d", m_id);
	WritePrivateProfileString("Controller", "ControllerID", buffer, m_ini_file);
}
