//*********************************************************
// Labwindows/cvi8.5
// szlihongtao
// 2010-09-06
// 参照 王建新的<Labwindows/cvi测试技术及工程应用> page257
// 稍有改写
//*********************************************************
#include "windows.h"
#include <utility.h>
#include "winreg.h"
#include "toolbox.h"
#include <cvirte.h>
#include <userint.h>
#include "regoperation.h"
//-----------------------------------------------------------------------------
static int panelHandle;
//-----------------------------------------------------------------------------
int main (int argc, char *argv[])
{
if (InitCVIRTE (0, argv, 0) == 0)
return -1; /* out of memory */
if ((panelHandle = LoadPanel (0, "regoperation.uir", PANEL)) < 0)
return -1;
DisplayPanel (panelHandle);
RunUserInterface ();
DiscardPanel (panelHandle);
return 0;
}
//-----------------------------------------------------------------------------
int CVICALLBACK add (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
char prj[MAX_PATHNAME_LEN];
char hoticon[MAX_PATHNAME_LEN];
char icon[MAX_PATHNAME_LEN];
unsigned int realstringsize;
unsigned int buffersize = 300;
unsigned char stringbuffer[300];
switch (event)
{
case EVENT_COMMIT:
{
prj[0] = '\0';
hoticon[0] = '\0';
icon[0] = '\0';
stringbuffer[0] = '\0';
GetProjectDir (prj);
strcat (hoticon, prj);
strcat (hoticon, "\\hoticon.ico"); //将hoticon.ico图标放入字符串数组hoticon中
strcat (icon, prj);
strcat (icon, "\\icon.ico"); //将icon.ico图标放入字符串数组icon中
//读取LabWindows/CVI的存储路径
RegReadString (REGKEY_HKLM, "SOFTWARE\\National Instruments\\CVI\\8.5\\User Info", "Directory", stringbuffer, buffersize, &realstringsize);
strcat (stringbuffer, "\\cvi.exe");
//修改注册表键值
RegWriteString (REGKEY_HKLM, "Software\\Microsoft\\Internet Explorer\\Extensions\\{06DD38D3-D187-11CF-A80D-00C04FD74AD8}", "CLSID", "{1FBA04EE-3024-11D2-8F1F-0000F87ABD16}");
RegWriteString (REGKEY_HKLM, "Software\\Microsoft\\Internet Explorer\\Extensions\\{06DD38D3-D187-11CF-A80D-00C04FD74AD8}", "ButtonText", "提示----我的工具栏");
RegWriteString (REGKEY_HKLM, "Software\\Microsoft\\Internet Explorer\\Extensions\\{06DD38D3-D187-11CF-A80D-00C04FD74AD8}", "Default Visible", "yes");
RegWriteString (REGKEY_HKLM, "Software\\Microsoft\\Internet Explorer\\Extensions\\{06DD38D3-D187-11CF-A80D-00C04FD74AD8}", "Icon", icon);
RegWriteString (REGKEY_HKLM, "Software\\Microsoft\\Internet Explorer\\Extensions\\{06DD38D3-D187-11CF-A80D-00C04FD74AD8}", "HotIcon", hoticon);
RegWriteString (REGKEY_HKLM, "Software\\Microsoft\\Internet Explorer\\Extensions\\{06DD38D3-D187-11CF-A80D-00C04FD74AD8}", "Exec", stringbuffer);
RegWriteString (REGKEY_HKLM, "Software\\Microsoft\\Internet Explorer\\Extensions\\{06DD38D3-D187-11CF-A80D-00C04FD74AD8}", "MenuText", "NI LabWindows/CVI");
RegWriteString (REGKEY_HKLM, "Software\\Microsoft\\Internet Explorer\\Extensions\\{06DD38D3-D187-11CF-A80D-00C04FD74AD8}", "MenuStatusBar", "打开 CVI");
break;
}
}
return 0;
}
//-----------------------------------------------------------------------------
int CVICALLBACK QuitCallback (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
{
QuitUserInterface (0);
break;
}
}
return 0;
}
//-----------------------------------------------------------------------------
int CVICALLBACK del (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
//清空注册表键值,不删除键值
RegWriteString (REGKEY_HKLM, "Software\\Microsoft\\Internet Explorer\\Extensions\\{06DD38D3-D187-11CF-A80D-00C04FD74AD8}", "CLSID", "");
RegWriteString (REGKEY_HKLM, "Software\\Microsoft\\Internet Explorer\\Extensions\\{06DD38D3-D187-11CF-A80D-00C04FD74AD8}", "ButtonText", "");
RegWriteString (REGKEY_HKLM, "Software\\Microsoft\\Internet Explorer\\Extensions\\{06DD38D3-D187-11CF-A80D-00C04FD74AD8}", "Default Visible", "");
RegWriteString (REGKEY_HKLM, "Software\\Microsoft\\Internet Explorer\\Extensions\\{06DD38D3-D187-11CF-A80D-00C04FD74AD8}", "Icon", "");
RegWriteString (REGKEY_HKLM, "Software\\Microsoft\\Internet Explorer\\Extensions\\{06DD38D3-D187-11CF-A80D-00C04FD74AD8}", "HotIcon", "");
RegWriteString (REGKEY_HKLM, "Software\\Microsoft\\Internet Explorer\\Extensions\\{06DD38D3-D187-11CF-A80D-00C04FD74AD8}", "Exec", "");
RegWriteString (REGKEY_HKLM, "Software\\Microsoft\\Internet Explorer\\Extensions\\{06DD38D3-D187-11CF-A80D-00C04FD74AD8}", "MenuText", "");
RegWriteString (REGKEY_HKLM, "Software\\Microsoft\\Internet Explorer\\Extensions\\{06DD38D3-D187-11CF-A80D-00C04FD74AD8}", "MenuStatusBar", "");
break;
}
return 0;
}
//-----------------------------------------------------------------------------
int CVICALLBACK readreg (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
unsigned int realstringsize;
unsigned int buffersize = 300;
unsigned char stringbuffer[300];
switch (event)
{
case EVENT_COMMIT:
//读取注册表键值,并显示在文本框中
ResetTextBox (panelHandle, PANEL_TEXTBOX, "");
RegReadString (REGKEY_HKLM, "Software\\Microsoft\\Internet Explorer\\Extensions\\{06DD38D3-D187-11CF-A80D-00C04FD74AD8}", "CLSID", stringbuffer, buffersize, &realstringsize);
strcat (stringbuffer, " --CLSID");
InsertTextBoxLine (panelHandle, PANEL_TEXTBOX, -1, stringbuffer);
RegReadString (REGKEY_HKLM, "Software\\Microsoft\\Internet Explorer\\Extensions\\{06DD38D3-D187-11CF-A80D-00C04FD74AD8}", "ButtonText", stringbuffer, buffersize, &realstringsize);
strcat (stringbuffer, " --ButtonText");
InsertTextBoxLine (panelHandle, PANEL_TEXTBOX, -1, stringbuffer);
RegReadString (REGKEY_HKLM, "Software\\Microsoft\\Internet Explorer\\Extensions\\{06DD38D3-D187-11CF-A80D-00C04FD74AD8}", "Default Visible", stringbuffer, buffersize, &realstringsize);
strcat (stringbuffer, " --Default Visible");
InsertTextBoxLine (panelHandle, PANEL_TEXTBOX, -1, stringbuffer);
RegReadString (REGKEY_HKLM, "Software\\Microsoft\\Internet Explorer\\Extensions\\{06DD38D3-D187-11CF-A80D-00C04FD74AD8}", "Icon", stringbuffer, buffersize, &realstringsize);
strcat (stringbuffer, " --Icon");
InsertTextBoxLine (panelHandle, PANEL_TEXTBOX, -1, stringbuffer);
RegReadString (REGKEY_HKLM, "Software\\Microsoft\\Internet Explorer\\Extensions\\{06DD38D3-D187-11CF-A80D-00C04FD74AD8}", "HotIcon", stringbuffer, buffersize, &realstringsize);
strcat (stringbuffer, " --HotIcon");
InsertTextBoxLine (panelHandle, PANEL_TEXTBOX, -1, stringbuffer);
RegReadString (REGKEY_HKLM, "Software\\Microsoft\\Internet Explorer\\Extensions\\{06DD38D3-D187-11CF-A80D-00C04FD74AD8}", "Exec", stringbuffer, buffersize, &realstringsize);
strcat (stringbuffer, " --Exec");
InsertTextBoxLine (panelHandle, PANEL_TEXTBOX, -1, stringbuffer);
RegReadString (REGKEY_HKLM, "Software\\Microsoft\\Internet Explorer\\Extensions\\{06DD38D3-D187-11CF-A80D-00C04FD74AD8}", "MenuText", stringbuffer, buffersize, &realstringsize);
strcat (stringbuffer, " --MenuText");
InsertTextBoxLine (panelHandle, PANEL_TEXTBOX, -1, stringbuffer);
RegReadString (REGKEY_HKLM, "Software\\Microsoft\\Internet Explorer\\Extensions\\{06DD38D3-D187-11CF-A80D-00C04FD74AD8}", "MenuStatusBar", stringbuffer, buffersize, &realstringsize);
strcat (stringbuffer, " --MenuStatusBar");
InsertTextBoxLine (panelHandle, PANEL_TEXTBOX, -1, stringbuffer);
break;
}
return 0;
}
//-----------------------------------------------------------------------------
int CVICALLBACK delkey (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
HKEY hKey;
switch (event)
{
case EVENT_COMMIT:
{
//打开注册表,获得操作句柄
RegOpenKeyEx (HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Internet Explorer\\Extensions\\{06DD38D3-D187-11CF-A80D-00C04FD74AD8}",
0, KEY_ALL_ACCESS, &hKey);
RegDeleteValue (hKey, "CLSID"); //删除注册表中的子键值
RegDeleteValue (hKey, "ButtonText");
RegDeleteValue (hKey, "Default Visible");
RegDeleteValue (hKey, "Icon");
RegDeleteValue (hKey, "HotIcon");
RegDeleteValue (hKey, "Exec");
RegDeleteValue (hKey, "MenuText");
RegDeleteValue (hKey, "MenuStatusBar");
RegCloseKey (hKey); //关闭注册表
//-----------------------------------------------------------------------------
RegOpenKeyEx (HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Internet Explorer\\Extensions",
0, KEY_ALL_ACCESS, &hKey);
RegDeleteKey (hKey,"{06DD38D3-D187-11CF-A80D-00C04FD74AD8}"); //删除注册表中的键值
RegCloseKey (hKey);
break;
}
}
return 0;
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
文章评论(0条评论)
登录后参与讨论