bool checked=false; HKEY pKey; unsigned char str[1024]; DWORD strSize=sizeof(str); if(RegOpenKeyEx(HKEY_CLASSES_ROOT, TEXT("TestCrafter.tdb\\shell\\open\\command"), 0, KEY_ALL_ACCESS, &pKey) ==ERROR_SUCCESS){ if(RegQueryValueEx(pKey, TEXT(""), NULL, NULL, str, &strSize)==ERROR_SUCCESS){ QMessageBox::information(this, "", QString((const char*)str)); if(QString((const char*)str).contains("tester.exe")) checked=true; } } associate->setChecked(checked); RegCloseKey(pKey);
#ifdef Q_WS_WIN QSettings reg("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run", QSettings::NativeFormat); if(value) reg.setValue(QCoreApplication::applicationName(), '"' + QDir::toNativeSeparators(QCoreApplication::applicationFilePath()) + '"'); else reg.remove(QCoreApplication::applicationName());#endif
bool checked=false; QSettings reg("HKEY_CLASSES_ROOT", QSettings::NativeFormat); if(reg.value("/TestCrafter.tdb/shell/open/command/.").toString().contains("tester.exe")) checked=true; associate->setChecked(checked);
associate=new QCheckBox;#ifdef Q_WS_WIN{ bool checked=false; QSettings reg("HKEY_CLASSES_ROOT", QSettings::NativeFormat); if(reg.value("/MyProg.mpf/shell/open/command/.").toString().contains("myprog.exe")) checked=true; associate->setChecked(checked); connect(associate, SIGNAL(stateChanged(int)),SLOT(slotAssociate(int)));}#else associate->setDisabled(true);#endif
void MyProg::slotAssociate(int state){#ifdef Q_WS_WIN QSettings reg("HKEY_CLASSES_ROOT", QSettings::NativeFormat); if(state==Qt::Checked){ reg.setValue("/.mpf/.", "MyProg.mpf"); reg.setValue("/MyProg.mpf/DefaultIcon/.", QDir::toNativeSeparators(QCoreApplication::applicationDirPath())+"\\mpf.ico"); reg.setValue("/MyProg.mpf/shell/open/command/.", '"'+QDir::toNativeSeparators(QCoreApplication::applicationFilePath())+"\" \"%1\""); }else if(state==Qt::Unchecked){ reg.setValue("/MyProg.mpf/shell/open/command/.", ""); }#endif}