#include "stdafx.h"
#include "UtilGraph.h"		// This header.

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

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	GetWChar
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	pStr_xZkqqHx_iCmMjAoGjDkKiCkJiCoHiCfAjFlGiOjKiCpAiOoGjDlOiClFiBeBiOjPiCmMjFlGiOjKiCmMiDhMiDeDiDjDiDfOiCpA_xHqqkZx_pStrNext_xZkqqHx_iCmJ_xHqqkZx_
 *			_xZkqqHx_jAnNjCoIiClFiBeBjFlGiOjKiDfCiBfLiDgIiCpAjFnEiClHiBeCiBgJiCfBiDgPiDeDiDgHiDfCiBfLiDgIiCmJjBmOiJjOiBgK_xHqqkZx_
 *
 * <_xZkqqHx_iIpIjAjE_xHqqkZx_>	pStrNext	: _xZkqqHx_iOjPiCmMjFlGiOjKiCmMiDhMiDeDiDjDiDfO_xHqqkZx_
 *			pStr		: _xZkqqHx_iCfAjFlGiOjKiCpAiOoGjDlOiClHiCoJiClNiCnPiCmMiDhMiDeDiDjDiDfO_xHqqkZx_
 *
 * <_xZkqqHx_jFnEjCgM_xHqqkZx_>	_xZkqqHx_jFlGiOjKiDfCiBfLiDgIiBeC_xHqqkZx_UNICODE_xZkqqHx_iBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	99.04.07 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
wchar_t GetWChar (const _TCHAR*& pStrNext, const _TCHAR* pStr)
{
	pStrNext = ::CharNext(pStr);
	// _xZkqqHx_jFlGiOjKjHpBiCmMiNmFiMoDiBeC_xHqqkZx_
	if (pStrNext == pStr) return 0;
	wchar_t wChar = 0;
	do {
		wChar <<= 8;
		wChar |= _TUCHAR(*pStr);
		pStr++;
	} while (pStr != pStrNext);
	return wChar;
} // GetWChar.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	CalcStrWidth
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iOhHjCoIiClDiCoKiClNjFlGiOjKjHpBiCmMjFjNiCpAjFnEiClHiBeC_xHqqkZx_
 *
 * <_xZkqqHx_iIpIjAjE_xHqqkZx_>	hDC		:_xZkqqHx_jFlGiOjKjFjNiCpAiMhGiOfKiClHiCoJiInHiCmMiDgGiDgPiDeDiDfIiDfCiDjDiDgFiDeMiDfIiDgHiBeCjHfMiCnPiMhGiOfKjHhAiCmM_xHqqkZx_
 *					 _xZkqqHx_iDhEiDeIiDjDiDgHiCpAjAnNjCoIiClFiCmEiCkIiCkNiBeC_xHqqkZx_
 *			tcpStr	:_xZkqqHx_iMhGiOfKiClHiCoJiInHiCmMjFlGiOjKjHpBiCpAiOhHjCoIiBeCiJpMiNhDiBeBiLpDjFlGiOjKiCmMiImKjChFiCmFiDfIiDgHiDgCiDhG_xHqqkZx_
 *					 _xZkqqHx_iClFiCmEiBeBiDhMiDeDiDjDiDfOiCpAjFnEiClHiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jFnEjCgM_xHqqkZx_>	_xZkqqHx_jFfMiOkGjFjNiBgJiDhDiDeOiDfKiDiLiBgKiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	01.06.21 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
int CalcStrWidth (HDC hDC, const _TCHAR*& tcpStr)
{
	int iSize = 0;
	for (;;)
	{
		// 1_xZkqqHx_jFlGiOjKiCpAiOoGjDlOiBeC_xHqqkZx_
		wchar_t wChar = ::GetWChar(tcpStr, tcpStr);
		// _xZkqqHx_jFlGiOjKjHpBiPeJjCfLiCmMiPoKiNiHiBeBiJpMiNhDiDfCiBfLiDgIiCmMiPoKiNiHiCmNiPeJjHlJiBeC_xHqqkZx_
		if (wChar == 0 || wChar == _T('\r') || wChar == _T('\n')) break;
		// 1_xZkqqHx_jFlGiOjKiCmMjFjNiCpAiOoGjDlOiBeC_xHqqkZx_
		int iCharW;
// 01.07.22 Fukushiro M. 1_xZkqqHx_iNhDjFmPiNfI_xHqqkZx_ ()
//		GetCharWidth32(hDC, wChar, wChar, &iCharW);
		GetCharWidth(hDC, wChar, wChar, &iCharW);
		// _xZkqqHx_iClBiClBiCnMiCmFiCmMjFlGiOjKjFjNiCpAiMhGiOfKiBeC_xHqqkZx_
		iSize += iCharW;
	}
	return iSize;
} // CalcStrWidth.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	myETWProc
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	EnumThreadWindows_xZkqqHx_iKnGjAjEiCmMiDfCiBfLiDiLiDgPiDgCiDeOiBeCjGhLiKnGjAjEiCmNiBeBiCkAiCoJiDfIiDiMiDgCiDgIiCmJ_xHqqkZx_
 *			_xZkqqHx_iKnGiClHiCoJiDeFiDeCiDjDiDgIiDeFiCkK_xHqqkZx_hwnd_xZkqqHx_iCmJjAnNjCoIiClDiCoKiCmEiOjPiBfIiCmJiOmAiNhDiClDiCoKiCoJiBeC_xHqqkZx_
 *			hwnd_xZkqqHx_iCkKiDiBiDeDiDjDiDhEiDiMiBfLiDiAiCmFiCkAiCoJiCkJiCmHiCkEiCkJiCpAjClCiCnHiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_iIpIjAjE_xHqqkZx_>	hwnd	:_xZkqqHx_jClCiCnHiCoJjBmOiPnLiCmMiDeFiDeCiDjDiDgIiDeFiDgOiDjDiDgIiDiLiBeC_xHqqkZx_
 *			lParam	:hwnd_xZkqqHx_iCkKiDiBiDeDiDjDiDhEiDiMiBfLiDiAiCmMiOjOiCmJiBeB_xHqqkZx_hwnd_xZkqqHx_iCpAjFnEiClHjFmPjAjEiCmMiDhMiDeDiDjDiDfOiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jFnEjCgM_xHqqkZx_>	_xZkqqHx_jHpBiLjDiCpAjBlBiCkPiCoJiPoKiNiHiCmN_xHqqkZx_ TRUE_xZkqqHx_iBeBiPeJjHlJiClHiCoJiPoKiNiHiCmN_xHqqkZx_ FALSE_xZkqqHx_iBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	99.01.09 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *			99.03.29 Fukushiro M. FoundDoc_xZkqqHx_iCkJiCoHiInKjDkOiBeC_xHqqkZx_
 *			99.12.21 Fukushiro M. MolipDrawDoc_xZkqqHx_iCkJiCoHiInKjDkOiBeC_xHqqkZx_
 *			00.04.27 Fukushiro M. CommonDrawDoc_xZkqqHx_iCkJiCoHiInKjDkOiBeC_xHqqkZx_
 *			00.04.27 Fukushiro M. _xZkqqHx_jAgFiDeFiDeCiDjDiDgIiDeFiCkK_xHqqkZx_NULL_xZkqqHx_iCmMiPoKiNiHiCpAjElLjCgGiKoOiPiAiCmJiBeC_xHqqkZx_
 *************************************************************************/
static BOOL CALLBACK myETWProc (HWND hwnd, LPARAM lParam)
{
	HWND* hwdp = (HWND*)lParam;
	if (GetParent(hwnd) == NULL)
	{
		*hwdp = (HWND)hwnd;
		return FALSE;	// _xZkqqHx_iClBiClBiCmFjHpBiLjDiPiIjHjNiCmNiPeJiCoNiCoIiBeC_xHqqkZx_
	}
	return TRUE;
} // myETWProc.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	GetThreadTopWnd
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iOhHjCoIiClDiCoKiClNiDfIiDiMiDgCiDgIiCkKiPiKjBkOiClHiCoJiDeFiDeCiDjDiDgIiDeFiCmMiDgHiDgCiDhGiDeFiDeCiDjDiDgIiDeFiCpAjFnEiClHiBeC_xHqqkZx_
 *
 * <_xZkqqHx_iIpIjAjE_xHqqkZx_>	dwThreadId	:_xZkqqHx_iDfIiDiMiDgCiDgI_xHqqkZx_ID_xZkqqHx_iCpAiOhHjCoIiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jFnEjCgM_xHqqkZx_>	_xZkqqHx_iDeFiDeCiDjDiDgIiDeFiDgOiDjDiDgIiDiLiCpAjFnEiClHiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	00.04.27 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
HWND GetThreadTopWnd (DWORD dwThreadId)
{
	HWND hwnd;
	// _xZkqqHx_iDiBiDeDiDjDiDhEiDiMiBfLiDiAiDeFiDeCiDjDiDgIiDeFiDgOiDjDiDgIiDiLiCpAiOoGjDlOiBeC_xHqqkZx_
	::EnumThreadWindows(dwThreadId, myETWProc, (LPARAM)&hwnd);
	return hwnd;
} // GetThreadTopWnd.
