⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dlgsetup.cpp

📁 天文望远镜电动调焦距驱动程序
💻 CPP
字号:
// DlgSetup.cpp : implementation file
//

#include "stdafx.h"
#include "resource.h"
#include "DlgSetup.h"

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



static char RBuf[256];
char *reg_r(char *str, HKEY &Key)
{
	long lStat; // TODO do someting with the status code!
	strnset ( RBuf, 0, sizeof ( RBuf ) );
	DWORD Len = sizeof ( RBuf );
	lStat = RegQueryValueEx ( Key, str, 0, 0, (unsigned char *) RBuf, &Len);
	return(RBuf);
}



long reg_w(char *str,CString St, HKEY &Key)
{
	long lStat;
	lStat = RegSetValueEx( Key, str, 0, REG_SZ, (unsigned char *) (LPCSTR) St, St.GetLength());
	return(lStat);
}

const char * ROOT_KEY = "Software\\ASCOM\\Focuser Drivers\\DualFocus.Focuser";

/////////////////////////////////////////////////////////////////////////////
// CDlgSetup dialog


CDlgSetup::CDlgSetup(CWnd* pParent /*=NULL*/)
	: CDialog(CDlgSetup::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDlgSetup)
	m_ComPort = -1;
	m_MaxPos = 0;
	m_FocusNum = 0;
	m_MaxPos1 = 0;
	m_Scale = _T("");
	m_Scale1 = _T("");
	//}}AFX_DATA_INIT


	// Defaults
	m_FocusNum = 0;
	m_ComPort = 0;
	m_MaxPos = 1000000;
	m_MaxPos1 = 1000000;
	
	HKEY Key;
	DWORD lRes;
    LONG lStat = RegCreateKeyEx(HKEY_LOCAL_MACHINE, ROOT_KEY, 0, 0, 0, KEY_READ | KEY_WRITE | KEY_CREATE_SUB_KEY, 0, &Key, &lRes);
	if (lStat == ERROR_SUCCESS) 
	{
		
		m_ComPort = atoi(reg_r("COM",Key));
		m_FocusNum = atoi(reg_r("FocusNum",Key));

		// Focuser 0
		m_Scale = reg_r("Scale",Key);
		m_MaxPos = atoi(reg_r("MaxPos",Key));

		// Focuser 1
		m_Scale1 = reg_r("Scale1",Key);
		m_MaxPos1 = atoi(reg_r("MaxPos1",Key));

		RegCloseKey ( Key );

	}
	
	if (m_ComPort < 0) m_ComPort = 0;
	if (m_ComPort > 7) m_ComPort = 7;
	
	if (m_MaxPos == 0) m_MaxPos = 1000000;  // Default
	if (m_MaxPos < 10) m_MaxPos = 10;
	if (m_MaxPos > 1000000) m_MaxPos = 1000000;

	if (m_MaxPos1 == 0) m_MaxPos1 = 1000000;  // Default
	if (m_MaxPos1 < 10) m_MaxPos1 = 10;
	if (m_MaxPos1 > 1000000) m_MaxPos1 = 1000000;

	if (m_FocusNum < 0) m_FocusNum = 0;
	if (m_FocusNum > 1) m_FocusNum = 1;
}


void CDlgSetup::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlgSetup)
	DDX_CBIndex(pDX, IDC_COMPORT, m_ComPort);
	DDX_Text(pDX, IDC_MAX_POS, m_MaxPos);
	DDV_MinMaxInt(pDX, m_MaxPos, 0, 1000000);
	DDX_Text(pDX, IDC_FOCUSNUM, m_FocusNum);
	DDV_MinMaxInt(pDX, m_FocusNum, 0, 1);
	DDX_Text(pDX, IDC_MAX_POS1, m_MaxPos1);
	DDV_MinMaxInt(pDX, m_MaxPos1, 0, 1000000);
	DDX_Text(pDX, IDC_SCALE, m_Scale);
	DDV_MaxChars(pDX, m_Scale, 8);
	DDX_Text(pDX, IDC_SCALE1, m_Scale1);
	DDV_MaxChars(pDX, m_Scale1, 8);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDlgSetup, CDialog)
	//{{AFX_MSG_MAP(CDlgSetup)
	ON_EN_HSCROLL(IDC_MAX_POS, OnHscrollMaxPos)
	ON_EN_HSCROLL(IDC_FOCUSNUM, OnHscrollFocusNum)
	ON_EN_HSCROLL(IDC_MAX_POS1, OnHscrollMaxPos1)
	ON_EN_CHANGE(IDC_SCALE, OnChangeScale)
	ON_EN_CHANGE(IDC_SCALE1, OnChangeScale1)
	ON_CBN_EDITCHANGE(IDC_COMPORT, OnEditchangeComport)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlgSetup message handlers
// Write registry Values
void CDlgSetup::OnOK() 
{
	// Save default
	if (!UpdateData()) return;

	HKEY Key;
	DWORD lRes;
    LONG lStat = RegCreateKeyEx(HKEY_LOCAL_MACHINE, ROOT_KEY, 0, 0, 0, KEY_READ | KEY_WRITE | KEY_CREATE_SUB_KEY, 0, &Key, &lRes);
	if (lStat != ERROR_SUCCESS) return;

	CString St;

	St.Format ( "%i", m_ComPort );
	lStat = reg_w("COM",St,Key);

	St.Format ( "%i", m_FocusNum );
	lStat = reg_w("FocusNum",St,Key);

	// Focuser 0
	St.Format ( "%i", m_MaxPos );
	lStat = reg_w("MaxPos"
		,St,Key);
	St = m_Scale;
	lStat = reg_w("Scale",St,Key);

	// Focuser 1
	St.Format ( "%i", m_MaxPos1 );
	lStat = reg_w("MaxPos1",St,Key);
	St = m_Scale1;
	lStat = reg_w("Scale1",St,Key);

	RegCloseKey ( Key );

	CDialog::OnOK();
}

void CDlgSetup::OnHscrollFocusNum() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function to send the EM_SETEVENTMASK message to the control
	// with the ENM_SCROLL flag ORed into the lParam mask.
	
	// TODO: Add your control notification handler code here
	
}
void CDlgSetup::OnHscrollMaxPos() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function to send the EM_SETEVENTMASK message to the control
	// with the ENM_SCROLL flag ORed into the lParam mask.
	
	// TODO: Add your control notification handler code here
	
}

void CDlgSetup::OnHscrollMaxPos1() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function to send the EM_SETEVENTMASK message to the control
	// with the ENM_SCROLL flag ORed into the lParam mask.
	
	// TODO: Add your control notification handler code here
	
}

void CDlgSetup::OnChangeScale() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	
}

void CDlgSetup::OnChangeScale1() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	
}
#


void CDlgSetup::OnEditchangeComport() 
{
	// TODO: Add your control notification handler code here
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -