
// GraphOperationDlg.cpp : implementation file
//

#include "stdafx.h"
#include "GraphOperation.h"
#include "GraphOperationDlg.h"
#include "afxdialogex.h"
#include "clogger_api.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CGraphOperationDlg dialog



CGraphOperationDlg::CGraphOperationDlg(CWnd* pParent /*=NULL*/)
	: CDialogEx(IDD_GRAPHOPERATION_DIALOG, pParent)
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CGraphOperationDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_COMBO_ACTIVATE, m_combo_activate);
	DDX_Control(pDX, IDC_COMBO_AREA2ENABLE, m_combo_area2_enable);
	DDX_Control(pDX, IDC_COMBO_AUTOSCROLLENABLE, m_combo_auto_scrol_enable);
	DDX_Control(pDX, IDC_COMBO_CHANNELDISPENABLE, m_combo_channel_disp_enable);
	DDX_Control(pDX, IDC_COMBO_CHANNELENABLE, m_combo_channel_enable);
	DDX_Control(pDX, IDC_COMBO_CHANNELNO, m_combo_channel_no);
	DDX_Control(pDX, IDC_COMBO_DIGIT, m_combo_digit);
	DDX_Control(pDX, IDC_COMBO_DISPLAYDOT, m_combo_display_dot);
	DDX_Control(pDX, IDC_COMBO_IMAGEAREA, m_combo_image_area);
	DDX_Control(pDX, IDC_COMBO_MOVEAXIS, m_combo_move_axis);
	DDX_Control(pDX, IDC_COMBO_MOVEDIRECTION, m_combo_move_direction);
	DDX_Control(pDX, IDC_COMBO_OPENMODE, m_combo_open_mode);
	DDX_Control(pDX, IDC_COMBO_TARGET, m_combo_target);
	DDX_Control(pDX, IDC_COMBO_TARGETITEM, m_combo_target_item);
	DDX_Control(pDX, IDC_COMBO_TIMEUNIT, m_combo_time_unit);
	DDX_Control(pDX, IDC_COMBO_TITLEENABLE, m_combo_title_enable);
	DDX_Control(pDX, IDC_COMBO_WINDOWOPERATION, m_combo_window_operation);
	DDX_Control(pDX, IDC_COMBO_YAXISMAGNIFICATIONENABLE, m_combo_y_axis_magnification_enable);
	DDX_Control(pDX, IDC_COMBO_ZOOM, m_combo_zoom);
	DDX_Control(pDX, IDC_COMBO_ZOOMAXIS, m_combo_zoom_axis);
	DDX_Control(pDX, IDC_EDIT_RETURNNUM, m_edit_returnnum);
	DDX_Control(pDX, IDC_EDIT_TITLETEXT, m_edit_title_text);
	DDX_Control(pDX, IDC_MFCEDITBROWSE_CAPTUREFILEPATH, m_edit_capture_filepath);
	DDX_Control(pDX, IDC_MFCEDITBROWSE_LOADFILEPATH, m_edit_load_filepath);
	DDX_Control(pDX, IDC_EDIT_MOVEDISTANCE, m_edit_move_distance);
}

BEGIN_MESSAGE_MAP(CGraphOperationDlg, CDialogEx)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON_LOGGEROPENAPPLICATION, &CGraphOperationDlg::OnBnClickedButtonLoggeropenapplication)
	ON_BN_CLICKED(IDC_BUTTON_LOGGERLOADDATAFILE, &CGraphOperationDlg::OnBnClickedButtonLoggerloaddatafile)
	ON_BN_CLICKED(IDC_BUTTON_LOGGERGRAPHWINDOWOPERATION, &CGraphOperationDlg::OnBnClickedButtonLoggergraphwindowoperation)
	ON_BN_CLICKED(IDC_BUTTON_LOGGERCAPTURESCREEN, &CGraphOperationDlg::OnBnClickedButtonLoggercapturescreen)
	ON_BN_CLICKED(IDC_BUTTON_LOGGERSETGRAPHZOOM, &CGraphOperationDlg::OnBnClickedButtonLoggersetgraphzoom)
	ON_BN_CLICKED(IDC_BUTTON_LOGGERMOVEGRAPHPOS, &CGraphOperationDlg::OnBnClickedButtonLoggermovegraphpos)
	ON_BN_CLICKED(IDC_BUTTON_LOGGERSETGRAPHCHANNEL, &CGraphOperationDlg::OnBnClickedButtonLoggersetgraphchannel)
	ON_BN_CLICKED(IDC_BUTTON_LOGGERSETGRAPH, &CGraphOperationDlg::OnBnClickedButtonLoggersetgraph)
	ON_BN_CLICKED(IDC_BUTTON_LOGGERSETGRAPHLABELTEXT, &CGraphOperationDlg::OnBnClickedButtonLoggersetgraphlabeltext)
	ON_BN_CLICKED(IDC_BUTTON_LOGGERCLOSEAPPLICATION, &CGraphOperationDlg::OnBnClickedButtonLoggercloseapplication)
	ON_BN_CLICKED(IDC_BUTTON_CLOSE, &CGraphOperationDlg::OnBnClickedButtonClose)
END_MESSAGE_MAP()

//----------------------------------------
// Global variable declaration
//----------------------------------------
short	g_appid;									// App access ID

// CGraphOperationDlg message handlers
//================================================================================
// Initial settings
//================================================================================
BOOL CGraphOperationDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	CString		text_temp;			// For temporary text storage

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	//----------------------------------------
	// Create the combobox for window size
	//----------------------------------------
	m_combo_open_mode.AddString(_T("Minimize"));
	m_combo_open_mode.AddString(_T("Normal"));
	m_combo_open_mode.AddString(_T("Maximize"));
	//----------------------------------------
	// Window size combobox selection
	//----------------------------------------
	m_combo_open_mode.SetCurSel(LOGGER_PARAM_WINDOW_OFF);
	//----------------------------------------
	// Create the combobox for window operation
	//----------------------------------------
	m_combo_window_operation.AddString(_T("New"));
	m_combo_window_operation.AddString(_T("Close"));
	//----------------------------------------
	// Window operation combobox selection
	//----------------------------------------
	m_combo_window_operation.SetCurSel(LOGGER_PARAM_GRAPH_OPEN);
	//----------------------------------------
	// Create the combobox for window operation target
	//----------------------------------------
	m_combo_target.AddString(_T("File and Graph"));
	m_combo_target.AddString(_T("Graph"));
	//----------------------------------------
	// Window operation target combobox selection
	//----------------------------------------
	m_combo_target.SetCurSel(LOGGER_PARAM_FILE);
	//----------------------------------------
	// Screen Capture - Create the combobox for save range
	//----------------------------------------
	m_combo_image_area.AddString(_T("Entire"));
	m_combo_image_area.AddString(_T("YT Graph"));
	//----------------------------------------
	// Screen Capture - Save range combobox selection
	//----------------------------------------
	m_combo_image_area.SetCurSel(LOGGER_PARAM_AREA_ENTIRE);
	//----------------------------------------
	// Graph Resize - Create the combobox for axis
	//----------------------------------------
	m_combo_zoom_axis.AddString(_T("X-axis"));
	m_combo_zoom_axis.AddString(_T("Y-axis"));
	//----------------------------------------
	// Graph Resize - Axis combobox selection
	//----------------------------------------
	m_combo_zoom_axis.SetCurSel(LOGGER_PARAM_AXIS_X);
	//----------------------------------------
	// Graph Resize - Create the combobox for zoom
	//----------------------------------------
	m_combo_zoom.AddString(_T("Zoom in(2x)"));
	m_combo_zoom.AddString(_T("Zoom out(x/2)"));
	//----------------------------------------
	// Graph Resize - Zoom combobox selection
	//----------------------------------------
	m_combo_zoom.SetCurSel(LOGGER_PARAM_ZOOM_IN);
	//----------------------------------------
	// Graph Movement - Create the combobox for axis
	//----------------------------------------
	m_combo_move_axis.AddString(_T("X-axis"));
	m_combo_move_axis.AddString(_T("Y-axis"));
	//----------------------------------------
	// Graph Movement - Axis combobox selection
	//----------------------------------------
	m_combo_move_axis.SetCurSel(LOGGER_PARAM_AXIS_X);
	//----------------------------------------
	// Graph Movement - Updated movement amount display
	//----------------------------------------
	m_edit_move_distance.SetWindowTextW(_T("1"));
	//----------------------------------------
	// Graph Movement - Create the combobox for movement direction
	//----------------------------------------
	m_combo_move_direction.AddString(_T("-"));
	m_combo_move_direction.AddString(_T("+"));
	//----------------------------------------
	// Graph Movement - Movement direction combobox selection
	//----------------------------------------
	m_combo_move_direction.SetCurSel(0);
	//----------------------------------------
	// Channel Information - Create the combobox for sequence number
	//----------------------------------------
	m_combo_channel_no.AddString(_T("0"));
	m_combo_channel_no.AddString(_T("1"));
	m_combo_channel_no.AddString(_T("2"));
	m_combo_channel_no.AddString(_T("3"));
	//----------------------------------------
	// Channel Information - Sequence number combobox selection
	//----------------------------------------
	m_combo_channel_no.SetCurSel(0);
	//----------------------------------------
	// Channel Information - Create the combobox for display
	//----------------------------------------
	m_combo_channel_enable.AddString(_T("Disable"));
	m_combo_channel_enable.AddString(_T("Enable"));
	//----------------------------------------
	// Channel Information - Display combobox selection
	//----------------------------------------
	m_combo_channel_enable.SetCurSel(LOGGER_PARAM_DISABLE);
	//----------------------------------------
	// Channel Information - Create the combobox for Activation
	//----------------------------------------
	m_combo_activate.AddString(_T("Disable"));
	m_combo_activate.AddString(_T("Enable"));
	//----------------------------------------
	// Channel Information - Activation combobox selection
	//----------------------------------------
	m_combo_activate.SetCurSel(LOGGER_PARAM_DISABLE);
	//----------------------------------------
	// Channel Information - Create the combobox for dotted
	//----------------------------------------
	m_combo_display_dot.AddString(_T("Disable"));
	m_combo_display_dot.AddString(_T("Enable"));
	//----------------------------------------
	// Channel Information - Dotted combobox selection
	//----------------------------------------
	m_combo_display_dot.SetCurSel(LOGGER_PARAM_DISABLE);
	//----------------------------------------
	// Channel Information - Create the combobox for time axis type
	//----------------------------------------
	m_combo_time_unit.AddString(_T("Absolute time"));
	m_combo_time_unit.AddString(_T("Relative time"));
	//----------------------------------------
	// Channel Information - Time axis type combobox selection
	//----------------------------------------
	m_combo_time_unit.SetCurSel(LOGGER_PARAM_AXISTYPE_ABSOLUTE);
	//----------------------------------------
	// Channel Information - Create the combobox for decimal places
	//----------------------------------------
	m_combo_digit.AddString(_T("0"));
	m_combo_digit.AddString(_T("1"));
	m_combo_digit.AddString(_T("2"));
	m_combo_digit.AddString(_T("3"));
	m_combo_digit.AddString(_T("4"));
	m_combo_digit.AddString(_T("5"));
	//----------------------------------------
	// Channel Information - Decimal places combobox selection
	//----------------------------------------
	m_combo_digit.SetCurSel(0);
	//----------------------------------------
	// Channel Information - Create the combobox for 2-split window
	//----------------------------------------
	m_combo_area2_enable.AddString(_T("Disable"));
	m_combo_area2_enable.AddString(_T("Enable"));
	//----------------------------------------
	// Channel Information - 2-split window combobox selection
	//----------------------------------------
	m_combo_area2_enable.SetCurSel(LOGGER_PARAM_DISABLE);
	//----------------------------------------
	// Channel Information - Create the combobox for Y-axis magnification display
	//----------------------------------------
	m_combo_y_axis_magnification_enable.AddString(_T("Disable"));
	m_combo_y_axis_magnification_enable.AddString(_T("Enable"));
	//----------------------------------------
	// Channel Information - Y-axis magnification display combobox selection
	//----------------------------------------
	m_combo_y_axis_magnification_enable.SetCurSel(LOGGER_PARAM_DISABLE);
	//----------------------------------------
	// Channel Information - Create the combobox for channel name library display
	//----------------------------------------
	m_combo_channel_disp_enable.AddString(_T("Disable"));
	m_combo_channel_disp_enable.AddString(_T("Enable"));
	//----------------------------------------
	// Channel Information - Channel name library display combobox selection
	//----------------------------------------
	m_combo_channel_disp_enable.SetCurSel(LOGGER_PARAM_DISABLE);
	//----------------------------------------
	// Channel Information - Create the combobox for graph auto-scroll
	//----------------------------------------
	m_combo_auto_scrol_enable.AddString(_T("Disable"));
	m_combo_auto_scrol_enable.AddString(_T("Enable"));
	//----------------------------------------
	// Channel Information - Graph auto-scroll combobox selection
	//----------------------------------------
	m_combo_auto_scrol_enable.SetCurSel(LOGGER_PARAM_DISABLE);
	//----------------------------------------
	// Channel Information - Create the combobox for graph title
	//----------------------------------------
	m_combo_target_item.AddString(_T("X-axis"));
	m_combo_target_item.AddString(_T("Y-axis"));
	m_combo_target_item.AddString(_T("Graph title"));
	//----------------------------------------
	// Channel Information - Graph title combobox selection
	//----------------------------------------
	m_combo_target_item.SetCurSel(LOGGER_PARAM_AXIS_X);
	//----------------------------------------
	// Channel Information - Create the combobox for display
	//----------------------------------------
	m_combo_title_enable.AddString(_T("Disable"));
	m_combo_title_enable.AddString(_T("Enable"));
	//----------------------------------------
	// Channel Information - Display combobox selection
	//----------------------------------------
	m_combo_title_enable.SetCurSel(LOGGER_PARAM_DISABLE);
	//----------------------------------------
	// Channel Information - Update graph title
	//----------------------------------------
	m_edit_title_text.SetWindowTextW(_T("Graph title"));
	return TRUE;  // return TRUE  unless you set the focus to a control
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CGraphOperationDlg::OnPaint()
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialogEx::OnPaint();
	}
}

// The system calls this function to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CGraphOperationDlg::OnQueryDragIcon()
{
	return static_cast<HCURSOR>(m_hIcon);
}

//================================================================================
// This is the process that occurs when you click the LoggerOpenApplication button
// Launch the app and enable access
//================================================================================
void CGraphOperationDlg::OnBnClickedButtonLoggeropenapplication()
{
	TCHAR			text_temp[256];				// For temporary text storage
	char			error_string[256];			// Error code string
	unsigned short	openmode;					// Screen size
	long			ret;						// For return code
	CString			text_string;				// For error code display

	//----------------------------------------
	// Get screen size from combobox
	//----------------------------------------
	openmode = m_combo_open_mode.GetCurSel();
	//----------------------------------------
	// Initialize the app
	//----------------------------------------
	ret = LoggerOpenApplication("", &g_appid, openmode);
	//----------------------------------------
	// Get error string
	//----------------------------------------
	LoggerGetErrorString(ret, error_string);
	//----------------------------------------
	// Display error code and message
	//----------------------------------------
	wsprintf(text_temp, _T("%S"), error_string);
	text_string.Format(_T("LoggerOpenApplication = %ld : %s"), ret, text_temp);
	m_edit_returnnum.SetWindowText(text_string);
	return;
}

//================================================================================
// This is the process that occurs when you click the LoggerLoadDataFile button
// Read the collected data
//================================================================================
void CGraphOperationDlg::OnBnClickedButtonLoggerloaddatafile()
{
	TCHAR	text_temp[256];				// For temporary text storage
	char	filepath[256];				// File path
	char	error_string[256];			// Error code string
	long	ret;						// For return code
	CString	text_string;				// For error code display

	//----------------------------------------
	// Get file path from text box
	//----------------------------------------
	m_edit_load_filepath.GetWindowText(text_temp, _countof(text_temp));
	WideCharToMultiByte(CP_ACP, 0, &text_temp[0], -1, &filepath[0], 256, NULL, NULL);
	//----------------------------------------
	// Loading the collected data
	//----------------------------------------
	ret = LoggerLoadDataFile(g_appid, filepath);
	//----------------------------------------
	// Get error string
	//----------------------------------------
	LoggerGetErrorString(ret, error_string);
	//----------------------------------------
	// Display error code and message
	//----------------------------------------
	wsprintf(text_temp, _T("%S"), error_string);
	text_string.Format(_T("LoggerLoadDataFile = %ld : %s"), ret, text_temp);
	m_edit_returnnum.SetWindowText(text_string);
	return;
}

//================================================================================
// This is the process when the LoggerGraphWindowOperation button is clicked
// Operate the window
//================================================================================
void CGraphOperationDlg::OnBnClickedButtonLoggergraphwindowoperation()
{
	TCHAR			text_temp[256];									// For temporary text storage
	char			error_string[256];								// Error code string
	long			ret;											// For return code
	CString			text_string;									// For error code display
	unsigned short	target				= LOGGER_PARAM_FILE;		// For storing the target
	unsigned short	window_operation	= LOGGER_PARAM_GRAPH_OPEN;	// For storing window operations

	//----------------------------------------
	// Get target from combobox
	//----------------------------------------
	target = m_combo_target.GetCurSel();
	//----------------------------------------
	// Get window operation from combobox
	//----------------------------------------
	window_operation = m_combo_window_operation.GetCurSel();
	//----------------------------------------
	// Window operations
	//----------------------------------------
	ret = LoggerGraphWindowOperation(	g_appid,
										window_operation,
										target,
										0);					// Fixed to 0 (reserved)
	//----------------------------------------
	// Get error string
	//----------------------------------------
	LoggerGetErrorString(ret, error_string);
	//----------------------------------------
	// Display error code and message
	//----------------------------------------
	wsprintf(text_temp, _T("%S"), error_string);
	text_string.Format(_T("LoggerGraphWindowOperation = %ld : %s"), ret, text_temp);
	m_edit_returnnum.SetWindowText(text_string);
	return;
}

//================================================================================
// This is the process that occurs when you click the LoggerCaptureScreen button
// Save the image
//================================================================================
void CGraphOperationDlg::OnBnClickedButtonLoggercapturescreen()
{
	TCHAR			text_temp[256];									// For temporary text storage
	char			error_string[256];								// Error code string
	long			ret;											// For return code
	CString			text_string;									// For error code display
	char			filepath[256];									// File path
	unsigned short	image_area			= LOGGER_PARAM_AREA_ENTIRE;	// For storing the storage range

	//----------------------------------------
	// Get file path from textbox
	//----------------------------------------
	m_edit_capture_filepath.GetWindowText(text_temp, _countof(text_temp));
	WideCharToMultiByte(CP_ACP, 0, &text_temp[0], -1, &filepath[0], 256, NULL, NULL);
	//----------------------------------------
	// Get the saved range from the combobox
	//----------------------------------------
	image_area = m_combo_image_area.GetCurSel();
	//----------------------------------------
	// Save image
	//----------------------------------------
	ret = LoggerCaptureScreen(	g_appid,
								0,				// Fixed to 0 (reserved)
								image_area,
								filepath);
	//----------------------------------------
	// Get error string
	//----------------------------------------
	LoggerGetErrorString(ret, error_string);
	//----------------------------------------
	// Display error code and message
	//----------------------------------------
	wsprintf(text_temp, _T("%S"), error_string);
	text_string.Format(_T("LoggerCaptureScreen = %ld : %s"), ret, text_temp);
	m_edit_returnnum.SetWindowText(text_string);
	return;
}

//================================================================================
// This is the process that occurs when the LoggerSetGraphZoom button is clicked
// Zoom the graph
//================================================================================
void CGraphOperationDlg::OnBnClickedButtonLoggersetgraphzoom()
{
	TCHAR			text_temp[256];								// For temporary text storage
	char			error_string[256];							// Error code string
	long			ret;										// For return code
	CString			text_string;								// For error code display
	unsigned short	axis				= LOGGER_PARAM_AXIS_X;	// For storing the axis
	unsigned short	zoom				= 0;					// For scaling storage

	//----------------------------------------
	// Get axis from combobox
	//----------------------------------------
	axis = m_combo_zoom_axis.GetCurSel();
	//----------------------------------------
	// Get scaling from combobox
	//----------------------------------------
	zoom = m_combo_zoom.GetCurSel();
	//----------------------------------------
	// Zoom the graph
	//----------------------------------------
	ret = LoggerSetGraphZoom(	g_appid,
								0,			// Fixed to 0 (reserved)
								axis,
								zoom);
	//----------------------------------------
	// Get error string
	//----------------------------------------
	LoggerGetErrorString(ret, error_string);
	//----------------------------------------
	// Display error code and message
	//----------------------------------------
	wsprintf(text_temp, _T("%S"), error_string);
	text_string.Format(_T("LoggerSetGraphZoom = %ld : %s"), ret, text_temp);
	m_edit_returnnum.SetWindowText(text_string);
	return;
}

//================================================================================
// This is the process that occurs when the LoggerMoveGraphPos button is clicked
// Move the graph
//================================================================================
void CGraphOperationDlg::OnBnClickedButtonLoggermovegraphpos()
{
	TCHAR			text_temp[256];									// For temporary text storage
	char			error_string[256];								// Error code string
	long			ret;											// For return code
	CString			text_string;									// For error code display
	unsigned short	axis				= LOGGER_PARAM_AXIS_X;		// For storing the axis
	long			distance			= 0;						// For storing movement amount
	long			direction			= 0;						// For storing movement direction
	unsigned long	status				= 0;						// For storing status

	//----------------------------------------
	// Get axis from combobox
	//----------------------------------------
	axis = m_combo_move_axis.GetCurSel();
	//----------------------------------------
	// Get the movement amount from the textbox
	//----------------------------------------
	m_edit_move_distance.GetWindowText(text_temp, _countof(text_temp));
	distance = (long)_ttol(text_temp);
	//----------------------------------------
	// Get the movement direction from the combobox
	//----------------------------------------
	direction = m_combo_move_direction.GetCurSel();
	//----------------------------------------
	// In the negative direction, the movement amount is converted to a negative value
	//----------------------------------------
	if(direction == 0){
		distance = distance * (-1);
	}
	//----------------------------------------
	// Move the graph
	//----------------------------------------
	ret = LoggerMoveGraphPos(	g_appid,
								0,			// Fixed to 0 (reserved)
								axis,
								distance,
								&status);
	//----------------------------------------
	// Get error string
	//----------------------------------------
	LoggerGetErrorString(ret, error_string);
	//----------------------------------------
	// Display error code and message
	//----------------------------------------
	wsprintf(text_temp, _T("%S"), error_string);
	text_string.Format(_T("LoggerMoveGraphPos = %ld : %s\r\nstatus=%ld"), ret, text_temp, status);
	m_edit_returnnum.SetWindowText(text_string);
	return;
}

//================================================================================
// This is the process that occurs when you click the LoggerSetGraphChannel button
// Switch channel display
//================================================================================
void CGraphOperationDlg::OnBnClickedButtonLoggersetgraphchannel()
{
	TCHAR			text_temp[256];							// For temporary text storage
	char			error_string[256];						// Error code string
	long			ret;									// For return code
	CString			text_string;							// For error code display
	unsigned short	channel_no		= 0;					// For storing sequence number
	unsigned short	channel_enable	= 0;					// For storing the display
	unsigned short	activate		= LOGGER_PARAM_DISABLE;	// For storing activation
	unsigned short	display_dot		= LOGGER_PARAM_DISABLE;	// For storing dot display

	//----------------------------------------
	// Get the sequence number from the combobox (index)
	//----------------------------------------
	channel_no = m_combo_channel_no.GetCurSel();
	//----------------------------------------
	// Get the display from the combobox
	//----------------------------------------
	channel_enable = m_combo_channel_enable.GetCurSel();
	//----------------------------------------
	// Get activation from combobox
	//----------------------------------------
	activate = m_combo_activate.GetCurSel();
	//----------------------------------------
	// Get dot display from combobox
	//----------------------------------------
	display_dot = m_combo_display_dot.GetCurSel();
	//----------------------------------------
	// Switch channel display
	//----------------------------------------
	ret = LoggerSetGraphChannel(	g_appid,
									0,					// Fixed to 0 (reserved)
									channel_no,
									channel_enable,
									activate,
									display_dot);
	//----------------------------------------
	// Get error string
	//----------------------------------------
	LoggerGetErrorString(ret, error_string);
	//----------------------------------------
	// Display error code and message
	//----------------------------------------
	wsprintf(text_temp, _T("%S"), error_string);
	text_string.Format(_T("LoggerSetGraphChannel = %ld : %s"), ret, text_temp);
	m_edit_returnnum.SetWindowText(text_string);
	return;
}

//================================================================================
// This is the process that occurs when you click the LoggerSetGraph button
// Set the graph window detail
//================================================================================
void CGraphOperationDlg::OnBnClickedButtonLoggersetgraph()
{
	TCHAR			text_temp[256];													// For temporary text storage
	char			error_string[256];												// Error code string
	long			ret;															// For return code
	CString			text_string;													// For error code display
	unsigned short	time_unit					= LOGGER_PARAM_AXISTYPE_ABSOLUTE;	// For storing time axis types
	unsigned short	digit						= 0;								// For storing the number of decimal places
	unsigned short	area2_enable				= LOGGER_PARAM_DISABLE;				// For storing 2-split graph displays
	unsigned short	y_axis_magnification_enable	= LOGGER_PARAM_DISABLE;				// For storing the Y-axis magnification display
	unsigned short	channel_disp_enable			= LOGGER_PARAM_DISABLE;				// For storing channel name library displays
	unsigned short	auto_scroll_enable			= LOGGER_PARAM_DISABLE;				// For storing automatic graph scrolling

	//----------------------------------------
	// Get the time axis type from the combobox
	//----------------------------------------
	time_unit = m_combo_time_unit.GetCurSel();
	//----------------------------------------
	// Get decimal places from combobox
	//----------------------------------------
	digit = m_combo_digit.GetCurSel();
	//----------------------------------------
	// Get 2-split graph display from combobox
	//----------------------------------------
	area2_enable = m_combo_area2_enable.GetCurSel();
	//----------------------------------------
	// Get Y-axis zoom from combobox
	//----------------------------------------
	y_axis_magnification_enable = m_combo_y_axis_magnification_enable.GetCurSel();
	//----------------------------------------
	// Get channel name library display from combobox
	//----------------------------------------
	channel_disp_enable = m_combo_channel_disp_enable.GetCurSel();
	//----------------------------------------
	// Get graph autoscroll from combobox
	//----------------------------------------
	auto_scroll_enable = m_combo_auto_scrol_enable.GetCurSel();
	//----------------------------------------
	// Set graph window detail
	//----------------------------------------
	ret = LoggerSetGraph(	g_appid,
							0,								// Fixed to 0 (reserved)
							time_unit,
							digit,
							area2_enable,
							y_axis_magnification_enable,
							channel_disp_enable,
							auto_scroll_enable);
	//----------------------------------------
	// Get error string
	//----------------------------------------
	LoggerGetErrorString(ret, error_string);
	//----------------------------------------
	// Display error code and message
	//----------------------------------------
	wsprintf(text_temp, _T("%S"), error_string);
	text_string.Format(_T("LoggerSetGraph = %ld : %s"), ret, text_temp);
	m_edit_returnnum.SetWindowText(text_string);
	return;
}

//================================================================================
// This is the process that occurs when you click the LoggerSetGraphLabelText button
// 
//================================================================================
void CGraphOperationDlg::OnBnClickedButtonLoggersetgraphlabeltext()
{
	TCHAR			text_temp[256];								// For temporary text storage
	char			title[256];									// Title
	char			error_string[256];							// Error code string
	long			ret;										// For return code
	CString			text_string;								// For error code display
	unsigned short	target_item			= LOGGER_PARAM_AXIS_X;	// For storing the title axis
	unsigned short	title_enable		= LOGGER_PARAM_DISABLE;	// For storing the display

	//----------------------------------------
	// Get title axis from combobox
	//----------------------------------------
	target_item = m_combo_target_item.GetCurSel();
	//----------------------------------------
	// Get the display from the combobox
	//----------------------------------------
	title_enable = m_combo_title_enable.GetCurSel();
	//----------------------------------------
	// Get title from textbox
	//----------------------------------------
	m_edit_title_text.GetWindowText(text_temp, _countof(text_temp));
	WideCharToMultiByte(CP_ACP, 0, &text_temp[0], -1, &title[0], 256, NULL, NULL);
	//----------------------------------------
	// Set graph window detail
	//----------------------------------------
	ret = LoggerSetGraphLabelText(	g_appid,
									0,					// Fixed to 0 (reserved)
									target_item,
									title_enable,
									title);
	//----------------------------------------
	// Get error string
	//----------------------------------------
	LoggerGetErrorString(ret, error_string);
	//----------------------------------------
	// Display error code and message
	//----------------------------------------
	wsprintf(text_temp, _T("%S"), error_string);
	text_string.Format(_T("LoggerSetGraphLabelText = %ld : %s"), ret, text_temp);
	m_edit_returnnum.SetWindowText(text_string);
	return;
}

//================================================================================
// This is the process that occurs when the LoggerCloseApplication button is clicked
// Stop the app and disable access
//================================================================================
void CGraphOperationDlg::OnBnClickedButtonLoggercloseapplication()
{
	TCHAR			text_temp[256];										// For temporary text storage
	TCHAR			status_string[256];									// Status display string
	char			error_string[256];									// Error code string
	long			ret;												// For return code
	CString			text_string;										// For error code display
	unsigned long	status				= LOGGER_STATUS_SUCCESS;		// For storing status

	//----------------------------------------
	// The app is stopped and cannot be accessed
	//----------------------------------------
	ret = LoggerCloseApplication(g_appid, &status);
	//----------------------------------------
	// Get error string
	//----------------------------------------
	LoggerGetErrorString(ret, error_string);
	if (ret != 0) {
		//----------------------------------------
		// Display error code and message
		//----------------------------------------
		wsprintf(text_temp, _T("%S"), error_string);
		text_string.Format(_T("LoggerCloseApplication = %ld : %s"), ret, text_temp);
		m_edit_returnnum.SetWindowText(text_string);
		return;
	}
	//----------------------------------------
	// Get status string
	//----------------------------------------
	switch(status){
	case LOGGER_STATUS_SUCCESS:
		wsprintf(status_string, _T("Successful completion"));
		break;
	case LOGGER_STATUS_FAILURE:
		wsprintf(status_string, _T("C-LOGGER exit error"));
		break;
	default:
		wsprintf(status_string, _T("Unknown status"));
		break;
	}
	//----------------------------------------
	// Display error code and message
	//----------------------------------------
	wsprintf(text_temp, _T("%S"), error_string);
	text_string.Format(_T("LoggerCloseApplication = %ld : %s\r\nstatus=%ld : %s"), ret, text_temp, status, status_string);
	m_edit_returnnum.SetWindowText(text_string);
	return;
}

//================================================================================
// This is the process that occurs when the Close button is clicked
// 
//================================================================================
void CGraphOperationDlg::OnBnClickedButtonClose()
{
	unsigned long	status				= LOGGER_STATUS_SUCCESS;		// For status storage

	//----------------------------------------
	// Close the file(Considering that C-LOGGER may have exited, do not check the result)
	//----------------------------------------
	LoggerGraphWindowOperation(	g_appid,
										LOGGER_PARAM_GRAPH_CLOSE,
										LOGGER_PARAM_FILE,
										0);							// Reserved
	//----------------------------------------
	// Stop the application and disable access
	//----------------------------------------
	LoggerCloseApplication(g_appid, &status);
	//----------------------------------------
	// Exit the dialog
	//----------------------------------------
	CDialog::OnOK();
	return;
}

