#ifndef __UtilWin_h
#define __UtilWin_h

class CFCCtlBrHRuler;
class CFCCtlBrVRuler;

//----------<NOT EXPORT TO VIEWER>-----------

////////////////////////////////////////////////////////////////////////
// _xZkqqHx_iDeOiDiJiDfIiBeBiNfMjBkCjBmMiBeC_xHqqkZx_

class WString;

struct FCWinTitleRec
{
	FCWinTitleRec ();
	FCWinTitleRec (HWND hwnd, const wchar_t* tcp);
	operator = (const FCWinTitleRec& rec);
	HWND		hwndApp;
	WCharAuto	atpTitle;
}; // struct FCWinTitleRec.

typedef vector<FCWinTitleRec> FCWinTitleRecVector;

struct FCWndAndId
{
	CWnd*	pWnd;
	DWORD	dwId;
}; // struct FCWndAndId.

////////////////////////////////////////////////////////////////////////
// _xZkqqHx_iDePiDiNiBfLiDgPiDiLiKnGjAjEiBeC_xHqqkZx_

//----- 03.09.15 Fukushiro M. _xZkqqHx_jFmPiNfIjBeP_xHqqkZx_ ()-----
//extern void EnumWinTitle (FCWinTitleRecVector& vWinTtl, const wchar_t* tcpAppTitle = NULL);
//extern HWND FFFindDdDocumentWindow (const wchar_t* tcpDocTitle, const wchar_t* tcpAppTitle = NULL,
//							HWND hwndFrom = NULL);
//----- 03.09.15 Fukushiro M. _xZkqqHx_jFmPiNfIiMoD_xHqqkZx_ ()-----
extern void EnumWinTitle (FCWinTitleRecVector& vWinTtl);
extern HWND FFFindDdDocumentWindow (const wchar_t* tcpDocTitle, HWND hwndFrom = NULL);
//----- 03.09.15 Fukushiro M. _xZkqqHx_jFmPiNfIiPeJ_xHqqkZx_ ()-----
extern HWND FFFindHidocumentWindow (const wchar_t* wcpProjectPath,
									long lDocId,
									HWND hwndFrom = NULL,
									const wchar_t* wcpAppName = NULL);
extern BOOL ExecMolipDraw (const wchar_t* szParam = NULL, HWND hWndMsg = NULL,
							DWORD dwQuitMsg = 0,
							DWORD* pdwThreadId = NULL, DWORD* pdwProcId = NULL);
extern BOOL ExecAndWaitApp (const wchar_t* szAppName, const wchar_t* szParam = NULL,
							DWORD dwMillisec = INFINITE);
extern HWND GetThreadTopWnd (DWORD pdwThreadId);
//----------</NOT EXPORT TO VIEWER>-----------

extern void CloseImeStatus (HWND hWnd);

//----------<NOT EXPORT TO VIEWER>-----------
extern const wchar_t* FFGetMolipExePath ();
extern WString FFGetTemplateDirPath ();
extern void FFHorznizeToolBar (CToolBar* pToolBar, FCWndAndId wid[], long lWidSz);
//----------</NOT EXPORT TO VIEWER>-----------

extern int FFGetWindowText (const CWnd* pWnd, wchar_t* wszStringBuf, int nMaxCount,
							WORD wCodePage = CP_ACP);
extern int FFGetWindowText (HWND hWnd, wchar_t* wszStringBuf, int nMaxCount,
							WORD wCodePage = CP_ACP);
extern void FFGetWindowText (const CWnd* pWnd, WString& rString, WORD wCodePage = CP_ACP);
extern void FFGetWindowText (HWND hWnd, WString& rString, WORD wCodePage = CP_ACP);
extern void FFSetWindowText (CWnd* pWnd, const wchar_t* lpszString, WORD wCodePage = CP_ACP);
extern void FFSetWindowText (HWND hWnd, const wchar_t* lpszString, WORD wCodePage = CP_ACP);

extern void FFGetLBText (const CComboBox* pCmb, int nIndex, WString& rString);

//----------<NOT EXPORT TO VIEWER>-----------
extern int FFGetMenuString (const CMenu* pMenu, UINT nIDItem, WString& rString, UINT nFlags);
//----------</NOT EXPORT TO VIEWER>-----------

extern BOOL FFSetItemText (CListCtrl* pCtrl, int nItem, int nSubItem, const wchar_t* lpszText);
extern BOOL FFSetItemText (CTreeCtrl* pCtrl, HTREEITEM hItem, const wchar_t* lpszItem);
extern int FFInsertColumn (CListCtrl* pCtrl, int nCol, const wchar_t* lpszColumnHeading,
							int nFormat = LVCFMT_LEFT, int nWidth = -1, int nSubItem = -1);

extern void FFGetMonitorRect (vector<CRect>& vMonitorRect);
extern CSize FFJustifyToMonitor (const CRect& rect);
extern CSize FFJustifyToMonitor (const CPoint& pt);
extern DWORD FFPointToMenuId (HWND hwnd, const CPoint& pt);
extern DWORD FFPointToMenuId (const CPoint& pt);
extern HWND FFWindowFromPoint (HWND hwndParent, const CPoint& pt, UINT uFlags);
// 06.03.03 Fukushiro M. 1_xZkqqHx_iNhDjCmHiJmB_xHqqkZx_ ()
extern HWND FFWindowFromPoint (HWND hwndParent, const set<HWND>& stHwnd, const CPoint& pt, UINT uFlags);

// 06.02.27 Fukushiro M. 1_xZkqqHx_iNhDjCmHiJmB_xHqqkZx_ ()
extern void FFSendDataMessage (HWND hWnd, DWORD dwMessage, DWORD dwDataSz, void* pData);

//----- 06.03.16 Fukushiro M. _xZkqqHx_jCmHiJmBiOgO_xHqqkZx_ ()-----
extern BOOL FFScreenToClient (HWND hwnd, LPRECT lpRect);
extern BOOL FFClientToScreen (HWND hwnd, LPRECT lpRect);
//----- 06.03.16 Fukushiro M. _xZkqqHx_jCmHiJmBiPeJ_xHqqkZx_ ()-----

//----- 06.12.05 Fukushiro M. _xZkqqHx_iNoNiPjMiOgO_xHqqkZx_ ()-----
//// 06.12.01 Fukushiro M. 1_xZkqqHx_iNhDjCmHiJmB_xHqqkZx_ ()
//extern void FFAddRgn (HWND hwnd);
//----- 06.12.05 Fukushiro M. _xZkqqHx_iNoNiPjMiPeJ_xHqqkZx_ ()-----

///////////////////////////////////////////////////////////////////////////
// PendingMessage_xZkqqHx_iKnGjIeBiBeC_xHqqkZx_

#define FD_PMSG_MASK_INSTANCE	0xff000000	// _xZkqqHx_iDeDiDjDiDfIiDfOiDjDiDfIiCmMiDhNiDfIiDeOiBeC_xHqqkZx_
#define FD_PMSG_MASK_STATUS		0x00ffffff	// _xZkqqHx_iDeDiDjDiDfIiDfOiDjDiDfIiPpDjBnEiCmMiDhNiDfIiDeOiBeC_xHqqkZx_

//----- FCPendingMessage_xZkqqHx_iCmMiDiBiDgCiDfKiBfLiDfHjBjHjFhEjAoGiDeFiDeCiDjDiDgIiDeFiBeFiPpAiMiPiDeFiDeCiDjDiDgIiDeF_xHqqkZx_ ------
#define FD_PMSG_NONE		(0L << 24)	// _xZkqqHx_jBjHjFhEjAoGiCmIiClFiBeC_xHqqkZx_
#define FD_PMSG_MAIN_WND	(1L << 24)	// FFGetMainWnd()->GetWnd()_xZkqqHx_iBeC_xHqqkZx_
#define FD_PMSG_FRAME		(2L << 24)	// g_pFrame_xZkqqHx_iBeC_xHqqkZx_
#define FD_PMSG_IN_PLACE	(3L << 24)	// g_pInPlace_xZkqqHx_iBeC_xHqqkZx_
#define FD_PMSG_VIEW		(4L << 24)	// g_pView.
#define FD_PMSG_DOCUMENT	(5L << 24)	// g_pDoc.
#define FD_PMSG_MAIN_HRULER	(6L << 24)	// FFGetMainWnd()->HRuler().
#define FD_PMSG_MAIN_VRULER	(7L << 24)	// FFGetMainWnd()->VRuler().
#define FD_PMSG_TEXT_EDITOR	(8L << 24)	// g_pView->GetRTFEditor().

//----- FCPendingMessage_xZkqqHx_iCmMiDiBiDgCiDfKiBfLiDfHjBjHjFhEiPpAiMiP_xHqqkZx_ ------
#define FD_PMSG_IF_ENABLE		(1L << 0)	// _xZkqqHx_iDeFiDeCiDjDiDgIiDeF_xHqqkZx_/_xZkqqHx_iDgIiDeMiDiFiDiBiDjDiDgHiCkKjHeMiMpIiBeC_xHqqkZx_
#define FD_PMSG_IF_DISABLE		(1L << 1)	// _xZkqqHx_iDeFiDeCiDjDiDgIiDeF_xHqqkZx_/_xZkqqHx_iDgIiDeMiDiFiDiBiDjDiDgHiCkKjGlDiMpIiBeC_xHqqkZx_
#define FD_PMSG_IF_VISIBLE		(1L << 2)	// _xZkqqHx_iDeFiDeCiDjDiDgIiDeFiCkKjFfMiOkGiPpDjBnEiBeC_xHqqkZx_
#define FD_PMSG_IF_INVISIBLE	(1L << 3)	// _xZkqqHx_iDeFiDeCiDjDiDgIiDeFiCkKjEpBjFfMiOkGiPpDjBnEiBeC_xHqqkZx_

/*************************************************************************
 * <_xZkqqHx_iNfMjBkCjBmM_xHqqkZx_>	FCPendingMessage
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_jBjHjFhEjFnLjHkPiDiBiDgCiDfKiBfLiDfHiCmMjDoAjHgFiCpAiLeMiNnKiClHiCoJiNfMjBkCjBmMiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	03.07.14 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
struct FCPendingMessage
{
	FCPendingMessage ();
	FCPendingMessage (	DWORD dwDestinationConditons,
						DWORD dwMessage,
						DWORD dwWParam = NULL,
						DWORD dwLParam = NULL,
						BOOL bImmediate = TRUE);
	FCPendingMessage (	DWORD dwDestination,
						DWORD dwMessage, DWORD dwWParam, DWORD dwLParam,
						BOOL bImmediate,
						DWORD dwCondition0);
	FCPendingMessage (	DWORD dwDestination,
						DWORD dwMessage, DWORD dwWParam, DWORD dwLParam,
						BOOL bImmediate,
						DWORD dwCondition0,
						DWORD dwCondition1);
	FCPendingMessage (	DWORD dwDestination,
						DWORD dwMessage, DWORD dwWParam, DWORD dwLParam,
						BOOL bImmediate,
						DWORD dwCondition0,
						DWORD dwCondition1,
						DWORD dwCondition2);

	DWORD		m_dwDestination;	// _xZkqqHx_iDiBiDgCiDfKiBfLiDfHjBjHjFhEjAoGiDeFiDeCiDjDiDgIiDeFiBeC_xHqqkZx_
	DWORD		m_dwMessage;		// _xZkqqHx_iDiBiDgCiDfKiBfLiDfHjDoAjHgFiBeC_xHqqkZx_
	DWORD		m_dwWParam;			// _xZkqqHx_iDiBiDgCiDfKiBfLiDfHiCmM_xHqqkZx_WPARAM_xZkqqHx_iBeC_xHqqkZx_
	DWORD		m_dwLParam;			// _xZkqqHx_iDiBiDgCiDfKiBfLiDfHiCmM_xHqqkZx_LPARAM_xZkqqHx_iBeC_xHqqkZx_
	BOOL		m_bImmediate;		// SendMessage_xZkqqHx_iCmFjBjHjFhEiClHiCoJiCkJiBeI_xHqqkZx_
	DWORDVector	m_vConditions;		// _xZkqqHx_iDiBiDgCiDfKiBfLiDfHjBjHjFhEiPpAiMiPiBeC_xHqqkZx_AND_xZkqqHx_iBeC_xHqqkZx_
}; // struct FCPendingMessage.

extern void FFPushPendingMessage (const FCPendingMessage& pmsg, BOOL bCheckNow = TRUE);
extern void FFNotifyPendingMessage (CWnd* pWnd, BOOL bWndShow);

extern void FFSendPendingMessage (	DWORD dwDestination,
									DWORD dwMessage,
									DWORD dwWParam = NULL,
									DWORD dwLParam = NULL);
extern void FFPostPendingMessage (	DWORD dwDestination,
									DWORD dwMessage,
									DWORD dwWParam = NULL,
									DWORD dwLParam = NULL);

extern void FFPostSendMessage (	DWORD dwDestination,
								DWORD dwMessage,
								DWORD dwWParam = NULL,
								DWORD dwLParam = NULL);

////////////////////////////////////////////////////////////////////////
// template_xZkqqHx_iKnGjAjEiBeC_xHqqkZx_

// UNICODE_xZkqqHx_iCmFjFlGiOjKjHpBiCpAjCmHiJmBiBeC_xHqqkZx_
template<class T> int FFAddString (T* pCtrl, const wchar_t* wstr)
{
	return pCtrl->AddString(WStrToTStr(wstr));
} // template<class T> int FFAddString.

// UNICODE_xZkqqHx_iCmFjFlGiOjKjHpBiCpAjCmHiJmBiBeC_xHqqkZx_
template<class T> void FFReplaceSel (T* pCtrl, const wchar_t* wstr, BOOL bCanUndo = FALSE)
{
	pCtrl->ReplaceSel(WStrToTStr(wstr), bCanUndo);
} // template<class T> void FFReplaceSel.

template<class T> long FFInsertItem (T* pCtrl, long lItem, const wchar_t* wstr)
{
	return pCtrl->InsertItem(lItem, WStrToTStr(wstr));
} // template<class T> void FFInsertItem.

//----- 06.10.24 Fukushiro M. _xZkqqHx_jCmHiJmBiOgO_xHqqkZx_ ()-----
template<class T> void FFGetText (T* pCtrl, int iIndex, WString& wstr)
{
#if defined(_MBCS)
	CString str;
	pCtrl->GetText(iIndex, str);
	wstr = TStrToWStr(str);
#elif defined(_UNICODE)
	pCtrl->GetText(iIndex, wstr);
#endif//_UNICODE
} // template<class T> void FFGetText.

template<class T> int FFInsertString (T* pCtrl, int iIndex, const wchar_t* wstr)
{
	return pCtrl->InsertString(iIndex, WStrToTStr(wstr));
} // template<class T> int FFInsertString.
//----- 06.10.24 Fukushiro M. _xZkqqHx_jCmHiJmBiPeJ_xHqqkZx_ ()-----

#endif//__UtilWin_h
