修改设置界面为独立弹窗
This commit is contained in:
107
OfficeAssistant_msvc/mysettingsdialog.cpp
Normal file
107
OfficeAssistant_msvc/mysettingsdialog.cpp
Normal file
@ -0,0 +1,107 @@
|
||||
#include "mysettingsdialog.h"
|
||||
#include <Windows.h>
|
||||
#include <QClipBoard>
|
||||
#include "netio.h"
|
||||
#include "globalvariables.h"
|
||||
MySettingsDialog::MySettingsDialog(QWidget *parent)
|
||||
: QDialog(parent)
|
||||
{
|
||||
ui.setupUi(this);
|
||||
this->setFixedSize(width(), height());
|
||||
HKEY hRoot = HKEY_CURRENT_USER;
|
||||
wchar_t *szSubKey = L"Software\\Microsoft\\Windows\\CurrentVersion\\Run";
|
||||
HKEY hKey;
|
||||
DWORD dwDisposition = REG_OPENED_EXISTING_KEY; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD>
|
||||
LONG lRet = RegCreateKeyEx(hRoot, szSubKey, 0, NULL,
|
||||
REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition);
|
||||
if (lRet != ERROR_SUCCESS) {
|
||||
ui.autostart->setDisabled(true);
|
||||
}
|
||||
QString app = QApplication::applicationFilePath();
|
||||
app.replace("/", "\\");
|
||||
DWORD size=128;
|
||||
wchar_t reg[128];
|
||||
lRet = RegGetValue(hRoot, szSubKey, L"OfficeAssistant", RRF_RT_ANY, nullptr, reg, &size);
|
||||
if (wcscmp(reg,app.toStdWString().c_str())==0) {
|
||||
ui.autostart->setChecked(true);
|
||||
}
|
||||
copyButton = ui.copy;
|
||||
connect(copyButton, &QPushButton::clicked, this, &MySettingsDialog::copyToCLipboard);
|
||||
connect(ui.autostart, &QCheckBox::stateChanged, this, &MySettingsDialog::autoStart);
|
||||
connect(ui.addshortcut, &QPushButton::clicked, this, &MySettingsDialog::createShortcut);
|
||||
connect(ui.law_button, &QPushButton::clicked, this, &MySettingsDialog::law);
|
||||
ui.code->setText(QString(QCryptographicHash::hash(getMachineGUID().toUtf8(), QCryptographicHash::Md5).toHex()));
|
||||
}
|
||||
|
||||
MySettingsDialog::~MySettingsDialog()
|
||||
{
|
||||
}
|
||||
|
||||
void MySettingsDialog::autoStart(int state)
|
||||
{
|
||||
if (state == Qt::Checked) {
|
||||
HKEY hRoot = HKEY_CURRENT_USER;
|
||||
wchar_t *szSubKey = L"Software\\Microsoft\\Windows\\CurrentVersion\\Run";
|
||||
HKEY hKey;
|
||||
DWORD dwDisposition = REG_OPENED_EXISTING_KEY; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD>
|
||||
LONG lRet = RegCreateKeyEx(hRoot, szSubKey, 0, NULL,
|
||||
REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition);
|
||||
if (lRet != ERROR_SUCCESS) {
|
||||
QMessageBox::critical(this, QString::fromLocal8Bit("<EFBFBD><EFBFBD>ʾ"), QString::fromLocal8Bit("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>"));
|
||||
return;
|
||||
}
|
||||
QString app = QApplication::applicationFilePath();
|
||||
app.replace("/", "\\");
|
||||
qDebug() << app.toStdWString().c_str();
|
||||
lRet = RegSetValueEx(hKey, L"OfficeAssistant", 0, REG_SZ, (BYTE*)app.toStdWString().c_str(), app.length()*sizeof(wchar_t));
|
||||
if (lRet == ERROR_SUCCESS)
|
||||
{
|
||||
QMessageBox::information(this, QString::fromLocal8Bit("<EFBFBD><EFBFBD>ʾ"), QString::fromLocal8Bit("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>"));
|
||||
}
|
||||
RegCloseKey(hKey);
|
||||
}
|
||||
else if (state == Qt::Unchecked) {
|
||||
HKEY hRoot = HKEY_CURRENT_USER;
|
||||
wchar_t *szSubKey = L"Software\\Microsoft\\Windows\\CurrentVersion\\Run";
|
||||
HKEY hKey;
|
||||
DWORD dwDisposition = REG_OPENED_EXISTING_KEY;
|
||||
LONG lRet = RegCreateKeyEx(hRoot, szSubKey, 0, NULL,
|
||||
REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition);
|
||||
if (lRet != ERROR_SUCCESS) {
|
||||
QMessageBox::critical(this, QString::fromLocal8Bit("<EFBFBD><EFBFBD>ʾ"), QString::fromLocal8Bit("<EFBFBD>Ƴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܡ<EFBFBD>"));
|
||||
return;
|
||||
}
|
||||
QString app = QApplication::applicationFilePath();
|
||||
lRet = RegDeleteValue(hKey, L"OfficeAssistant");
|
||||
if (lRet == ERROR_SUCCESS)
|
||||
{
|
||||
QMessageBox::information(this, QString::fromLocal8Bit("<EFBFBD><EFBFBD>ʾ"), QString::fromLocal8Bit("<EFBFBD>Ƴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD>"));
|
||||
}
|
||||
RegCloseKey(hKey);
|
||||
}
|
||||
}
|
||||
|
||||
void MySettingsDialog::law()
|
||||
{
|
||||
QString path = QApplication::applicationDirPath();
|
||||
QString license = path + "/license.txt";
|
||||
license.replace("/", "\\");
|
||||
ShellExecute(GetDesktopWindow(), L"open", L"notepad.exe" , license.toStdWString().c_str(), nullptr, SW_SHOW);
|
||||
}
|
||||
|
||||
void MySettingsDialog::copyToCLipboard() {
|
||||
QClipboard *clip = QApplication::clipboard();
|
||||
clip->setText(QString(QCryptographicHash::hash(getMachineGUID().toUtf8(), QCryptographicHash::Md5).toHex()));
|
||||
}
|
||||
void MySettingsDialog::createShortcut() {
|
||||
QString deskTopPath = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
|
||||
deskTopPath = deskTopPath + QString::fromLocal8Bit("/<2F>칫<EFBFBD><ECB9AB><EFBFBD><EFBFBD>.lnk");
|
||||
QString srcFile = QApplication::applicationFilePath();
|
||||
bool succeed=QFile::link(srcFile, deskTopPath);
|
||||
if (succeed) {
|
||||
QMessageBox::information(this, QString::fromLocal8Bit("<EFBFBD><EFBFBD>ʾ"), QString::fromLocal8Bit("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݷ<EFBFBD>ʽ<EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD>"));
|
||||
}
|
||||
else {
|
||||
QMessageBox::information(this, QString::fromLocal8Bit("<EFBFBD><EFBFBD>ʾ"), QString::fromLocal8Bit("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݷ<EFBFBD>ʽʧ<EFBFBD>ܡ<EFBFBD>"));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user