#define	STRICT
#include	<windows.h>
#include	<commctrl.h>
#include	<tchar.h>
#include	"kctrl.h"
#include	"appmain.h"

DWORD	g_dwAppVersion = 35 ;
DWORD	g_dwDllVersion = 0 ;

int WINAPI
#ifdef	_WIN32_WCE
WinMain( HINSTANCE hThisInst, HINSTANCE hPrevInst,
		 LPTSTR lpszArgs, int nWinMode )
#else	/* _WIN32_WCE */
WinMain( HINSTANCE hThisInst, HINSTANCE hPrevInst,
		 LPSTR lpszArgs, int nWinMode )
#endif	/* _WIN32_WCE */
{
	HWND	hWnd ;

	/* 既に起動されているかどうかチェックする */
	hWnd = FindWindow( szClassName, NULL ) ;
	if ( hWnd != NULL ) {
		/* 起動済みの方をアクティブにする */
		SendMessage( hWnd, WM_COMMAND, IDM_ACTIVATE, 0 ) ;
		return TRUE ;
	}

#ifdef	_WIN32_WCE
	InitCommonControls() ;
#endif	/* _WIN32_WCE */

	/* KCTRL.DLLの初期化を行う */
	if ( !InitKanjiControls() ) {
		wsprintf( MessageBuf, TEXT("KCTRL.DLL Initialize error\r\nError=%x"),
				  GetLastError() ) ;
		MessageBeep( MB_ICONEXCLAMATION ) ;
		MessageBox( NULL, MessageBuf, TEXT("KCTRL Error"), MB_OK ) ;
		return -1 ;
	}
	g_dwDllVersion = GetKVersion() ;

	BOOL		exitVal = FALSE ;
	MainApp		*pApp = new MainApp() ;
	if ( !pApp ) {
		goto exit ;
	}
	if ( pApp->Create( hThisInst ) ) {
		exitVal = pApp->Run() ;
	}
	delete pApp ;

exit:
	ReleaseKanjiControls() ;
	return exitVal ;
}

HWND
GetCenterWindow()
{
	POINT	point ;

	point.x = GetSystemMetrics( SM_CXSCREEN ) / 2 ;
	point.y = GetSystemMetrics( SM_CYSCREEN ) / 2 ;
	return WindowFromPoint( point ) ;
}
