//********************************************************************************************
/**
 * @file		dialog.cpp
 * @brief		ダイアログ
 *
 *	このファイルの詳細説明
 *
 * @author		N.Takeda
 * @date		2010/03/24(水) 19:42:04
 */
//********************************************************************************************
#include "main.h"

#include "resource.h"

extern WINDOW_INFO		s_cWin;
extern STRUCT_GLOBAL	s_stGl;


void	List_show();

static BOOL CALLBACK DlgProc1( HWND _hDlg, unsigned _uMessage, WPARAM _wParam, LPARAM _lParam );
static BOOL CALLBACK DlgProc6( HWND _hDlg, unsigned _uMessage, WPARAM _wParam, LPARAM _lParam );


//======================================================
//		ダイアログを呼び出すルーチン					
//======================================================
BOOL 	Dlg_msgbox1()
{
	/// ダイアログ開く.
	if( DialogBox( s_stGl.hInst, (LPTSTR)IDD_DIALOG1, s_cWin.m_hWnd, (DLGPROC)DlgProc1 ) == -1 )
	{
		MessageBox( s_cWin.m_hWnd, TEXT("ダイアログが作成できません"), TEXT("プロパティ"), MB_OK );
		return FALSE;
	}
	return TRUE;
}


//======================================================
//		これは、ダイアログ関数です						
//======================================================
static BOOL CALLBACK DlgProc1( HWND _hDlg, unsigned _uMessage, WPARAM _wParam, LPARAM _lParam )
{
	BOOL	bChk;
	
	switch( _uMessage )
	{
		/// ダイアログの作成時に送られてくるメッセージです.
		case WM_INITDIALOG:
			SendDlgItemMessage( _hDlg, ID_AUTOEXEC,			BM_SETCHECK,	s_stGl.m_cSysOption.m_bAuto,			0 );
			SendDlgItemMessage( _hDlg, ID_AUEXIT,			BM_SETCHECK,	s_stGl.m_cSysOption.m_bAtExit,			0 );
			SendDlgItemMessage( _hDlg, ID_OUTINFO,			BM_SETCHECK,	s_stGl.m_cSysOption.m_bOutInfo,			0 );
			SendDlgItemMessage( _hDlg, IDC_BACKUP,			BM_SETCHECK,	s_stGl.m_cSysOption.m_bBackup,			0 );
			SendDlgItemMessage( _hDlg, IDC_RETEXEC,			BM_SETCHECK,	s_stGl.m_cSysOption.m_bRetexec,			0 );
			SendDlgItemMessage( _hDlg, IDC_SEARCHSUB,		BM_SETCHECK,	s_stGl.m_cSysOption.m_bSearchSubDir,	0 );
			SendDlgItemMessage( _hDlg, IDC_DEFAULTCURRENT,	BM_SETCHECK,	s_stGl.m_cSysOption.m_bDefaultCurrent,	0 );
			
			bChk = SendDlgItemMessage( _hDlg, ID_AUTOEXEC, BM_GETCHECK, 0, 0 );
			EnableWindow( GetDlgItem( _hDlg, ID_AUEXIT ), bChk );
			
			SetDlgItemText( _hDlg, ID_EDIT, s_stGl.m_cSysOption.m_sOutInfoName );
			
			SetDlgItemText( _hDlg, ID_EDIT2, s_stGl.m_cSysOption.m_sBackupPath );
			bChk = SendDlgItemMessage( _hDlg, IDC_BACKUP, BM_GETCHECK, 0, 0 );
			EnableWindow( GetDlgItem( _hDlg, ID_EDIT2 ), bChk );
			
			
			SendDlgItemMessage( _hDlg,IDC_COMBO1,CB_ADDSTRING, 0, (long)TEXT("範囲限定なし") );
			SendDlgItemMessage( _hDlg,IDC_COMBO1,CB_ADDSTRING, 0, (long)TEXT("範囲限定") );
			SendDlgItemMessage( _hDlg,IDC_COMBO1,CB_ADDSTRING, 0, (long)TEXT("記号含み限定") );
			SendDlgItemMessage( _hDlg,IDC_COMBO1,CB_SETCURSEL, s_stGl.m_cSysOption.m_iRange, 0 );
			
			break;
			
		//右上のＸボタン
		case WM_CLOSE:
			EndDialog( _hDlg,_wParam );
			break;
			
		//ボタンが押さたときに送られてくるメッセージです
		case WM_COMMAND:
			switch( LOWORD(_wParam) )
			{
				case ID_OK:
					
					List_show();
					
					s_stGl.m_cSysOption.m_bAuto				= SendDlgItemMessage( _hDlg, ID_AUTOEXEC,		BM_GETCHECK, 0, 0 );
					s_stGl.m_cSysOption.m_bAtExit			= SendDlgItemMessage( _hDlg, ID_AUEXIT,			BM_GETCHECK, 0, 0 );
					s_stGl.m_cSysOption.m_bOutInfo			= SendDlgItemMessage( _hDlg, ID_OUTINFO,		BM_GETCHECK, 0, 0 );
					s_stGl.m_cSysOption.m_bBackup			= SendDlgItemMessage( _hDlg, IDC_BACKUP,		BM_GETCHECK, 0, 0 );
					s_stGl.m_cSysOption.m_bRetexec			= SendDlgItemMessage( _hDlg, IDC_RETEXEC,		BM_GETCHECK, 0, 0 );
					s_stGl.m_cSysOption.m_iRange			= SendDlgItemMessage( _hDlg, IDC_COMBO1,		CB_GETCURSEL, 0, 0 );
					s_stGl.m_cSysOption.m_bSearchSubDir		= SendDlgItemMessage( _hDlg, IDC_SEARCHSUB,		BM_GETCHECK, 0, 0 );
					s_stGl.m_cSysOption.m_bDefaultCurrent	= SendDlgItemMessage( _hDlg, IDC_DEFAULTCURRENT,BM_GETCHECK, 0, 0 );
					
					GetDlgItemText( _hDlg, ID_EDIT, s_stGl.m_cSysOption.m_sOutInfoName, _MAX_PATH);
					GetDlgItemText( _hDlg, ID_EDIT2, s_stGl.m_cSysOption.m_sBackupPath, _MAX_PATH);
					
					/// プロパティを操作したならシステム設定に戻す.
					s_stGl.m_pOption = &s_stGl.m_cSysOption;
					
					EndDialog( _hDlg,_wParam );
					break;
				
				case ID_AUTOEXEC:
					bChk = SendDlgItemMessage( _hDlg, ID_AUTOEXEC, BM_GETCHECK, 0, 0 );
					EnableWindow( GetDlgItem( _hDlg,ID_AUEXIT ),bChk );
					break;
				
			//	case ID_OUTINFO:
			//		bChk = SendDlgItemMessage( _hDlg, ID_OUTINFO, BM_GETCHECK, 0, 0 );
			//		EnableWindow( GetDlgItem( _hDlg,ID_EDIT ),bChk );
			//		break;
				
				case IDC_BACKUP:
					bChk = SendDlgItemMessage( _hDlg, IDC_BACKUP, BM_GETCHECK, 0, 0 );
					EnableWindow( GetDlgItem( _hDlg, ID_EDIT2 ), bChk );
					break;
			}
			break;
			
		default:
			return FALSE;
	}
	
	return TRUE;
}


//======================================================
//		ダイアログを呼び出すルーチン					
//======================================================
BOOL 	Dlg_msgbox6()
{
	// ダイアログ開く
	if( DialogBox( s_stGl.hInst, (TCHAR*)IDD_DIALOG6, s_cWin.m_hWnd, (DLGPROC)DlgProc6 ) == -1 )
	{
		MessageBox( s_cWin.m_hWnd, TEXT("ダイアログが作成できません"),TEXT("プロパティ"), MB_OK );
		return FALSE;
	}
	return TRUE;
}


//======================================================
//		これは、ダイアログ関数です						
//======================================================
static BOOL CALLBACK DlgProc6( HWND _hDlg, unsigned _uMessage, WPARAM _wParam, LPARAM _lParam )
{
	switch( _uMessage )
	{
		//ダイアログの作成時に送られてくるメッセージです
		case WM_INITDIALOG:
			break;
		
		//右上のＸボタン
		case WM_CLOSE:
			EndDialog( _hDlg,_wParam );
			break;
		
		//ボタンが押さたときに送られてくるメッセージです
		case WM_COMMAND:
			switch( LOWORD(_wParam) )
			{
				case ID_OK:
					EndDialog( _hDlg,_wParam );
					break;
			}
			break;
		
		default:
			return FALSE;
	}
	
	return TRUE;
}
