|
最近比较忙,教程更新会比较慢,而且后面的教程也会需要一定的理解能力了,讲解要通俗易懂又要不烦锁还是有不少难度。针对这点,我们将会按功能分解来一步步实现,而不是一位的灌输,希望大家理解这一技巧,后面的时序编程也会采用这一模式,好处就是有一套比较完整的操作流程。
上位机是主要实现的,所以代码相对比较多,需要自己有一定的代码理解能力,讲解不会太深入,不会具体到每个功能怎么实现,希望大家理解。
言归正传,这次讲的是编程器软件的设置功能,这个也是必须的,方便使用,人性化设计。
为了便于管理,没有使用ini配置文件,而是直接写到注册表中。
使用到的注册表项uuprog,这里的位置会以系统自动定位的,图上是64位系统的存放位置,xp、2003有所不同。
通过看注册项名就能理解该项的用途了,要是你不懂,请翻一下英语字典。这个就不做多解释。勾选的含义:勾选为1,不勾选为0.
程序启动时自动加载注册表参数的函数loadconfig()来初始化软件环境
- void CUUProgDlg::LoadConfig()
- {
- HKEY myKey;
- DWORD dwtype=REG_DWORD;
- DWORD dwVal;
- DWORD dwsize=sizeof(DWORD);
- LPCTSTR myData="Software\\UUProg\\";
- long ret0 = RegOpenKeyEx(HKEY_LOCAL_MACHINE,myData,0,KEY_READ,&myKey);
- if(ret0 != ERROR_SUCCESS)
- {
- // char *sclass=""; //ÀàÃûÖ¸¶¨Îª¿Õ
- RegCreateKeyEx(HKEY_LOCAL_MACHINE,myData,0,NULL,REG_OPTION_NON_VOLATILE,KEY_READ|KEY_WRITE,NULL,&myKey,NULL);
- //ProgAuto
- m_iProgAuto = 0;
- RegSetValueEx(myKey, "ProgAuto",NULL,REG_DWORD,(LPBYTE)&m_iProgAuto,sizeof(DWORD));
- //m_iFiletype
- m_iFiletype = 0;
- RegSetValueEx(myKey, "Filetype",NULL,REG_DWORD,(LPBYTE)&m_iFiletype,sizeof(DWORD));
- //m_bReadID
- m_bReadID = true;
- RegSetValueEx(myKey, "ReadID",NULL,REG_DWORD,(LPBYTE)&m_bReadID,sizeof(DWORD));
- //m_bCheckBlank
- m_bCheckBlank = true;
- RegSetValueEx(myKey, "CheckBlank",NULL,REG_DWORD,(LPBYTE)&m_bCheckBlank,sizeof(DWORD));
- //m_bErase
- m_bErase = true;
- RegSetValueEx(myKey, "Erase",NULL,REG_DWORD,(LPBYTE)&m_bErase,sizeof(DWORD));
- //m_bPrograme
- m_bPrograme = true;
- RegSetValueEx(myKey, "Programe",NULL,REG_DWORD,(LPBYTE)&m_bPrograme,sizeof(DWORD));
- //m_bVerify
- m_bVerify = true;
- RegSetValueEx(myKey, "Verify",NULL,REG_DWORD,(LPBYTE)&m_bVerify,sizeof(DWORD));
- //m_bLockbit
- m_bLockbit = true;
- RegSetValueEx(myKey, "Lockbit",NULL,REG_DWORD,(LPBYTE)&m_bLockbit,sizeof(DWORD));
- //m_bBeepon
- m_bBeepon = true;
- RegSetValueEx(myKey, "Beepon",NULL,REG_DWORD,(LPBYTE)&m_bBeepon,sizeof(DWORD));
- //m_bSavelog
- m_bSavelog = true;
- RegSetValueEx(myKey, "Savelog",NULL,REG_DWORD,(LPBYTE)&m_bSavelog,sizeof(DWORD));
- //m_bCounton
- m_bCounton = true;
- RegSetValueEx(myKey, "Counton",NULL,REG_DWORD,(LPBYTE)&m_bCounton,sizeof(DWORD));
- //m_bCurNum
- m_iCurNum = 0;
- RegSetValueEx(myKey, "CurNum",NULL,REG_DWORD,(LPBYTE)&m_iCurNum,sizeof(DWORD));
- //m_bMaxNum
- m_iMaxNum = 100;
- RegSetValueEx(myKey, "MaxNum",NULL,REG_DWORD,(LPBYTE)&m_iMaxNum,sizeof(DWORD));
- //m_bFailureNum
- m_iFailureNum = 0;
- RegSetValueEx(myKey, "FailureNum",NULL,REG_DWORD,(LPBYTE)&m_iFailureNum,sizeof(DWORD));
- //m_bSuccessNum
- m_iSuccessNum = 0;
- RegSetValueEx(myKey, "SuccessNum",NULL,REG_DWORD,(LPBYTE)&m_iSuccessNum,sizeof(DWORD));
- //last device
- RegSetValueEx(myKey, "LastDevice",NULL,REG_SZ,(CONST BYTE *)(LPCTSTR)m_sDeviceName,m_sDeviceName.GetLength()+1);
- //last file
- RegSetValueEx(myKey, "LastFile",NULL,REG_SZ,(CONST BYTE *)(LPCTSTR)m_sLoadFileName,m_sLoadFileName.GetLength()+1);
- }
- else
- {
- // RegQueryValueEx(myKey,"RegisteredOwner",NULL,REG_DWORD,owner_Get,sizeof(DWORD));
- //ProgAuto
- RegQueryValueEx(myKey, "ProgAuto",NULL,&dwtype,(LPBYTE)&dwVal,&dwsize);
- m_iProgAuto = dwVal;
- //m_iFiletype
- RegQueryValueEx(myKey, "Filetype",NULL,&dwtype,(LPBYTE)&dwVal,&dwsize);
- m_iFiletype = dwVal;
- //m_bReadID
- RegQueryValueEx(myKey, "ReadID",NULL,&dwtype,(LPBYTE)&dwVal,&dwsize);
- m_bReadID = dwVal;
- //m_bCheckBlank
- RegQueryValueEx(myKey, "CheckBlank",NULL,&dwtype,(LPBYTE)&dwVal,&dwsize);
- m_bCheckBlank = dwVal;
- //m_bErase
- RegQueryValueEx(myKey, "Erase",NULL,&dwtype,(LPBYTE)&dwVal,&dwsize);
- m_bErase = dwVal;
- //m_bPrograme
- RegQueryValueEx(myKey, "Programe",NULL,&dwtype,(LPBYTE)&dwVal,&dwsize);
- m_bPrograme = dwVal;
- //m_bVerify
- RegQueryValueEx(myKey, "Verify",NULL,&dwtype,(LPBYTE)&dwVal,&dwsize);
- m_bVerify = dwVal;
- //m_bLockbit
- RegQueryValueEx(myKey, "Lockbit",NULL,&dwtype,(LPBYTE)&dwVal,&dwsize);
- m_bLockbit = dwVal;
- //m_bBeepon
- RegQueryValueEx(myKey, "Beepon",NULL,&dwtype,(LPBYTE)&dwVal,&dwsize);
- m_bBeepon = dwVal;
- //m_bSavelog
- RegQueryValueEx(myKey, "Savelog",NULL,&dwtype,(LPBYTE)&dwVal,&dwsize);
- m_bSavelog = dwVal;
- //m_bCounton
- RegQueryValueEx(myKey, "Counton",NULL,&dwtype,(LPBYTE)&dwVal,&dwsize);
- m_bCounton = dwVal;
- //m_bCurNum
- RegQueryValueEx(myKey, "CurNum",NULL,&dwtype,(LPBYTE)&dwVal,&dwsize);
- m_iCurNum = dwVal;
- //m_bMaxNum
- RegQueryValueEx(myKey, "MaxNum",NULL,&dwtype,(LPBYTE)&dwVal,&dwsize);
- m_iMaxNum = dwVal;
- //m_bFailureNum
- RegQueryValueEx(myKey, "FailureNum",NULL,&dwtype,(LPBYTE)&dwVal,&dwsize);
- m_iFailureNum = dwVal;
- //m_bSuccessNum
- RegQueryValueEx(myKey, "SuccessNum",NULL,&dwtype,(LPBYTE)&dwVal,&dwsize);
- m_iSuccessNum = dwVal;
- //last device
- dwtype = REG_SZ;
- LPBYTE getValue = new BYTE[50];
- dwsize = 20;
- RegQueryValueEx(myKey, "LastDevice",NULL,&dwtype,getValue,&dwsize);
- m_sDeviceName = getValue;
- //last file
- dwsize = 100;
- RegQueryValueEx(myKey, "LastFile",NULL,&dwtype,getValue,&dwsize);
- m_sLoadFileName = getValue;
- }
- RegCloseKey(myKey);
- }
复制代码 程序退出时又调用writeconfig()函数将参数保存。
- void CUUProgDlg::WriteConfig()
- {
- HKEY myKey;
- // DWORD dwtype=REG_DWORD;
- // DWORD dwVal;
- // DWORD dwsize=sizeof(DWORD);
- LPCTSTR myData="Software\\UUProg\\";
- long ret0 = RegOpenKeyEx(HKEY_LOCAL_MACHINE,myData,0,KEY_WRITE,&myKey);
- if(ret0 == ERROR_SUCCESS)
- {
- //ProgAuto
- RegSetValueEx(myKey, "ProgAuto",NULL,REG_DWORD,(LPBYTE)&m_iProgAuto,sizeof(DWORD));
- //m_iFiletype
- RegSetValueEx(myKey, "Filetype",NULL,REG_DWORD,(LPBYTE)&m_iFiletype,sizeof(DWORD));
- //m_bReadID
- RegSetValueEx(myKey, "ReadID",NULL,REG_DWORD,(LPBYTE)&m_bReadID,sizeof(DWORD));
- //m_bCheckBlank
- RegSetValueEx(myKey, "CheckBlank",NULL,REG_DWORD,(LPBYTE)&m_bCheckBlank,sizeof(DWORD));
- //m_bErase
- RegSetValueEx(myKey, "Erase",NULL,REG_DWORD,(LPBYTE)&m_bErase,sizeof(DWORD));
- //m_bPrograme
- RegSetValueEx(myKey, "Programe",NULL,REG_DWORD,(LPBYTE)&m_bPrograme,sizeof(DWORD));
- //m_bVerify
- RegSetValueEx(myKey, "Verify",NULL,REG_DWORD,(LPBYTE)&m_bVerify,sizeof(DWORD));
- //m_bLockbit
- RegSetValueEx(myKey, "Lockbit",NULL,REG_DWORD,(LPBYTE)&m_bLockbit,sizeof(DWORD));
- //m_bBeepon
- RegSetValueEx(myKey, "Beepon",NULL,REG_DWORD,(LPBYTE)&m_bBeepon,sizeof(DWORD));
- //m_bSavelog
- RegSetValueEx(myKey, "Savelog",NULL,REG_DWORD,(LPBYTE)&m_bSavelog,sizeof(DWORD));
- //m_bCounton
- RegSetValueEx(myKey, "Counton",NULL,REG_DWORD,(LPBYTE)&m_bCounton,sizeof(DWORD));
- //m_bCurNum
- RegSetValueEx(myKey, "CurNum",NULL,REG_DWORD,(LPBYTE)&m_iCurNum,sizeof(DWORD));
- //m_bMaxNum
- RegSetValueEx(myKey, "MaxNum",NULL,REG_DWORD,(LPBYTE)&m_iMaxNum,sizeof(DWORD));
- //m_bFailureNum
- RegSetValueEx(myKey, "FailureNum",NULL,REG_DWORD,(LPBYTE)&m_iFailureNum,sizeof(DWORD));
- //m_bSuccessNum
- RegSetValueEx(myKey, "SuccessNum",NULL,REG_DWORD,(LPBYTE)&m_iSuccessNum,sizeof(DWORD));
- //last device
- RegSetValueEx(myKey, "LastDevice",NULL,REG_SZ,(CONST BYTE *)(LPCTSTR)m_sDeviceName,m_sDeviceName.GetLength()+1);
- //last file
- RegSetValueEx(myKey, "LastFile",NULL,REG_SZ,(CONST BYTE *)(LPCTSTR)m_sLoadFileName,m_sLoadFileName.GetLength()+1);
- }
- else
- {
- return;
- }
- RegCloseKey(myKey);
- }
复制代码 其他每个点选操作都有相应的函数处理,最好自己看代码。代码比较简单,只是个值的切换处理。
配置窗口主要处理函数就是确定按钮的功能了。
- void CProgOption::OnOK()
- {
- // TODO: Add extra validation here
- UpdateData(true);
- parent->m_bBeepon = m_bBeepon;
- parent->m_bCheckBlank = m_bCheckBlank;
- parent->m_bCounton = m_bCounton;
- parent->m_bErase = m_bErase;
- parent->m_bLockbit = m_bLockbit;
- parent->m_bPrograme = m_bPrograme;
- parent->m_bReadID = m_bReadID;
- parent->m_bSavelog = m_bSavelog;
- parent->m_bVerify = m_bVerify;
- parent->m_iCurNum = atoi(m_sCurNum);
- parent->m_iFailureNum = atoi(m_sFailureNum);
- parent->m_iMaxNum = atoi(m_sMaxNum);
- parent->m_iSuccessNum = atoi(m_sSuccessNum);
- parent->m_iFiletype = m_iFiletype;
- parent->m_iProgAuto = m_iProgAuto;
- parent->SetCount();
- parent->SetAppLog("配置已修改");
- CDialog::OnOK();
- }
复制代码 这里主要的操作就是对注册表的操作,这个也算是个难点了,需要大家多练习,熟悉操作值的赋值读取等。
|
|