// WndRegPosition.cpp : _xZkqqHx_iDeDiDjDiDhGiDiKiDiBiDjDiDgFiBfLiDfGiDiHiDjD_xHqqkZx_ _xZkqqHx_iDhEiDeAiDeDiDiL_xHqqkZx_
//

#include "stdafx.h"
#include "DynamicDraw.h"	// For FFGetApp().
#include "RegData.h"		// For GetLocalAppName().
#include "UtilWin.h"		// For FFJustifyToMonitor.
#include "UtilErr.h"		// For FFThrowMiscUnknown.
#include "WndRegPosition.h"		// This header.

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CFCWndRegPosition

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	CFCWndRegPosition::CFCWndRegPosition
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iDgGiDhEiDeIiDiLiDgHiDfCiDjDiDfIiDgHiDiJiDeOiDfOiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	05.11.13 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
CFCWndRegPosition::CFCWndRegPosition (DWORD dwId)
			:m_dwId(dwId)	// _xZkqqHx_iDfPiDeDiDeBiDiNiDePiCmM_xHqqkZx_ID_xZkqqHx_iBeCiDiMiDfHiDfIiDgHiDiKiCnGiCmMjFnLjBlGiCmJiOgHiCkEiBeC_xHqqkZx_
{
} // CFCWndRegPosition::CFCWndRegPosition.

BEGIN_MESSAGE_MAP(CFCWndRegPosition, BASE_CLASS)
	//{{AFX_MSG_MAP(CFCWndRegPosition)
	ON_WM_CREATE()
	ON_WM_DESTROY()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFCWndRegPosition _xZkqqHx_iDiGiBfLiDfFiKnGjAjEiBeC_xHqqkZx_

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	CFCWndRegPosition::SetWindowVisible
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iDiMiDfHiDfIiDgHiDiKiCmMjCgMiCmJiPfNiCmBiCmEiDeFiDeCiDjDiDgIiDeFiCmMjFfMiOkGiBeFjEpBjFfMiOkGiCpAjAnIiCoIjBnGiCkGiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_iJpAjAoA_xHqqkZx_>	SetWindowVisible(BOOL)_xZkqqHx_iCmNiMmEiCnBiPgPiClFiOjOiCmJjFfMiOkGiPpDjBnEiCpAjAnNjCoIiCmFiCkLiCoJiCkKiBeB_xHqqkZx_
 *			_xZkqqHx_iClBiCmMiKnGjAjEiCmNiDiMiDfHiDfIiDgHiDiKiCmMjCgMiCmFjFfMiOkGiBeFjEpBjFfMiOkGiCpAjAnNjCoIiClHiCoJiClOiCkPiBeC_xHqqkZx_
 *			_xZkqqHx_jCmKiPoNiCmN_xHqqkZx_Create_xZkqqHx_iKnGjAjEiCmMiMoDiCmJiCfAiJpBiClOiCkPiOmAiNhDiClHiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	05.11.13 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
void CFCWndRegPosition::SetWindowVisible ()
{
	ASSERT(m_dwId != DWORD(-1));
	// _xZkqqHx_iDeMiBfLjGlMiCpAiNoMjAkMiBeC_xHqqkZx_
	WString wstrKey;
	wstrKey.Format(L"%s\\CFCDlgModelessBase-%x", ::GetLocalAppName(), m_dwId);
	// _xZkqqHx_iDeFiDeCiDjDiDgIiDeFiCmMjFfMiOkGiBeFjEpBjFfMiOkGiCpAiDiMiDfHiDfIiDgHiDiKiCkJiCoHjDmHiCnNiPgPiClHiBeC_xHqqkZx_
	BOOL bIsVisible = (BOOL)FFGetApp()->GetProfileIntW(wstrKey, L"Visible", int(FALSE));
	ShowWindow(bIsVisible ? SW_SHOW : SW_HIDE);
} // CFCWndRegPosition::SetWindowVisible.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	CFCWndRegPosition::SetWindowVisible
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iDeFiDeCiDjDiDgIiDeFiCmMjFfMiOkGiBeFjEpBjFfMiOkGiCpAjAnIiCoIjBnGiCkGiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_iIpIjAjE_xHqqkZx_>	bIsVisible	:_xZkqqHx_jFfMiOkGiPpDjBnEiCmJiClHiCoJiPoKiNiHiCmN_xHqqkZx_TRUE_xZkqqHx_iBeBjEpBjFfMiOkGiPpDjBnEiCmJiClHiCoJiPoKiNiHiCmN_xHqqkZx_
 *						 FALSE _xZkqqHx_iCpAiOhHjCoIiBeC_xHqqkZx_
 *
 * <_xZkqqHx_iJpAjAoA_xHqqkZx_>	_xZkqqHx_jFfMiOkGiPpDjBnEiCpAjFmPiNfIiClFiClNiMoDiBeBiDiMiDfHiDfIiDgHiDiKiCmJjFfMiOkGiBeFjEpBjFfMiOkGiPpDjBnEiCpAiLeMjIfOiClHiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	05.11.13 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
void CFCWndRegPosition::SetWindowVisible (BOOL bIsVisible)
{
	ASSERT(m_dwId != DWORD(-1));
	if (::IsWindow(m_hWnd))
		ShowWindow(bIsVisible ? SW_SHOW : SW_HIDE);
	//----- _xZkqqHx_iDiMiDfHiDfIiDgHiDiKiCmJjCgMiCpAjAnNjCoI_xHqqkZx_ -----
	// _xZkqqHx_iDeMiBfLjGlMiCpAiNoMjAkMiBeC_xHqqkZx_
	WString wstrKey;
	wstrKey.Format(L"%s\\CFCDlgModelessBase-%x", ::GetLocalAppName(), m_dwId);
	// _xZkqqHx_iDeFiDeCiDjDiDgIiDeFiCmMjFfMiOkGiBeFjEpBjFfMiOkGiCpAiDiMiDfHiDfIiDgHiDiKiCmJiLeMjIfOiBeC_xHqqkZx_
	FFGetApp()->WriteProfileIntW(wstrKey, L"Visible", int(bIsVisible));
} // CFCWndRegPosition::SetWindowVisible.

/////////////////////////////////////////////////////////////////////////////
// CFCWndRegPosition _xZkqqHx_iDiBiDgCiDfKiBfLiDfH_xHqqkZx_ _xZkqqHx_iDgOiDjDiDgIiDiJ_xHqqkZx_

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	CFCWndRegPosition::OnCreate
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iDeFiDeCiDjDiDgIiDeFiNoMjAkMiOjOiCmJiOmAiNhDiClDiCoKiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	05.11.13 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
int CFCWndRegPosition::OnCreate (LPCREATESTRUCT lpCreateStruct)
{
	ASSERT(m_dwId != DWORD(-1));
	// Superclass_xZkqqHx_iKnGjAjEiOmAiNhDiBeC_xHqqkZx_
	if (BASE_CLASS::OnCreate(lpCreateStruct) == -1)
		return -1;
	//----- _xZkqqHx_iDiMiDfHiDfIiDgHiDiKiCkJiCoHjCgMiCpAiOoGjDlO_xHqqkZx_ -----
	// _xZkqqHx_iDeMiBfLjGlMiCpAiNoMjAkMiBeC_xHqqkZx_
	WString wstrKey;
	wstrKey.Format(L"%s\\CFCDlgModelessBase-%x", ::GetLocalAppName(), m_dwId);
	// _xZkqqHx_iDeFiDeCiDjDiDgIiDeFiCmMiImKjChFiCpAiDiMiDfHiDfIiDgHiDiKiCkJiCoHjDmHiCnNiPgPiClHiBeC_xHqqkZx_
	CRect* rtWindow;
	UINT uiDataSz;
	if (FFGetApp()->GetProfileBinaryW(wstrKey, L"Rect", (LPBYTE*)&rtWindow, &uiDataSz))
	//----- _xZkqqHx_iDiMiDfHiDfIiDgHiDiKiCkJiCoHiDeFiDeCiDjDiDgIiDeFiNmAjFfHiCkKjDmHiCnNiPgPiClJiClNiPoKiNiH_xHqqkZx_ -----
	{
		// _xZkqqHx_iDeFiDeCiDjDiDgIiDeFiNmAjFfHiCpAiDiCiDgKiDfOiBfLiImKjChFiCmJjFoCjAlDiBeC_xHqqkZx_
		// _xZkqqHx_iDhNiDiLiDgAiDiCiDgKiDfOiBfLiKmCiLkLiCpAiNgMjHlGiBeC_xHqqkZx_
		*rtWindow += FFJustifyToMonitor(*rtWindow);
		// _xZkqqHx_iDeFiDeCiDjDiDgIiDeFiCpAiInKjDkOiBeC_xHqqkZx_
		MoveWindow(*rtWindow);
		delete[] rtWindow;
	}
	return 0;
} // CFCWndRegPosition::OnCreate.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	CFCWndRegPosition::OnDestroy
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iDeFiDeCiDjDiDgIiDeFjEgKiKpMiOjOiCmJiOmAiNhDiClDiCoKiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	05.11.13 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
void CFCWndRegPosition::OnDestroy ()
{
	ASSERT(m_dwId != DWORD(-1));
	//----- _xZkqqHx_iDiMiDfHiDfIiDgHiDiKiCmJjCgMiCpAjAnNjCoI_xHqqkZx_ -----
	// _xZkqqHx_iDeMiBfLjGlMiCpAiNoMjAkMiBeC_xHqqkZx_
	WString wstrKey;
	wstrKey.Format(L"%s\\CFCDlgModelessBase-%x", ::GetLocalAppName(), m_dwId);
	// _xZkqqHx_iDeFiDeCiDjDiDgIiDeFiCmMiImKjChFiCpAiDiMiDfHiDfIiDgHiDiKiCmJiLeMjIfOiBeC_xHqqkZx_
	CRect rtWindow;
	GetWindowRect(rtWindow);
	FFGetApp()->WriteProfileBinaryW(wstrKey, L"Rect", (LPBYTE)&rtWindow, sizeof(rtWindow));
	// Superclass_xZkqqHx_iKnGjAjEiBeC_xHqqkZx_
	BASE_CLASS::OnDestroy();
} // CFCWndRegPosition::OnDestroy.

