// assumes UnregisterHotKeys was called before static int RegisterHotKeys() { hMessageWindow = CreateWindowEx(0, _T("STATIC"), NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL); SetWindowLongPtr(hMessageWindow, GWLP_WNDPROC, (LONG_PTR)MessageWndProc); int count = GetProfileCount(0, 0); for ( int i=0; i < count; i++ ) { if (!db_get_b(NULL, MODULENAME, OptName(i, SETTING_REGHOTKEY), 0)) continue; WORD wHotKey = db_get_w(NULL, MODULENAME, OptName(i, SETTING_HOTKEY), 0); hkInfo = ( HKINFO* )realloc(hkInfo, (hkiCount+1)*sizeof(HKINFO)); if (hkInfo == NULL) return -1; char atomname[255]; mir_snprintf(atomname, _countof(atomname), "StatusProfile_%d", i); hkInfo[hkiCount].id = GlobalAddAtomA(atomname); if (hkInfo[hkiCount].id == 0) continue; hkInfo[hkiCount].profile = i; hkiCount ++; RegisterHotKey(hMessageWindow, (int)hkInfo[hkiCount-1].id, GetFsModifiers(wHotKey), LOBYTE(wHotKey)); } if (hkiCount == 0) UnregisterHotKeys(); return 0; }
static int CreateMainMenuItems(WPARAM, LPARAM) { char servicename[128]; int i, count; CMenuItem mi; mi.position = 2000100000; mi.flags = CMIF_TCHAR; mcount = 0; count = GetProfileCount(0, 0); for (i = 0; i < count; i++) { TCHAR profilename[128]; if (!db_get_b(NULL, MODULENAME, OptName(i, SETTING_CREATEMMITEM), 0) || GetProfileName(i, (LPARAM)profilename)) continue; if (db_get_b(NULL, MODULENAME, OptName(i, SETTING_INSUBMENU), 1)) mi.root = Menu_CreateRoot(MO_STATUS, LPGENT("Status profiles"), 2000100000); mi.name.t = profilename; mi.position = 2000100000 + mcount; mir_snprintf(servicename, _countof(servicename), "%s%d", MS_SS_MENUSETPROFILEPREFIX, mcount); switch(mcount) { case 0: hProfileServices[mcount] = CreateServiceFunction(servicename, profileService0); break; case 1: hProfileServices[mcount] = CreateServiceFunction(servicename, profileService1); break; case 2: hProfileServices[mcount] = CreateServiceFunction(servicename, profileService2); break; case 3: hProfileServices[mcount] = CreateServiceFunction(servicename, profileService3); break; case 4: hProfileServices[mcount] = CreateServiceFunction(servicename, profileService4); break; case 5: hProfileServices[mcount] = CreateServiceFunction(servicename, profileService5); break; default: MessageBox(NULL, TranslateT("There is a maximum of 6 menu items"), TranslateT("StartupStatus"), MB_OK); return 0; } mi.pszService = servicename; if (Menu_AddStatusMenuItem(&mi)) { menuprofiles[mcount] = i; mcount += 1; } } return 0; }
INT_PTR LoadAndSetProfile(WPARAM wParam, LPARAM lParam) { // wParam == profile no. int profileCount = GetProfileCount(0, 0); int profile = (int)wParam; TSettingsList profileSettings( 10, CompareSettings ); if ( !GetProfile( profile, profileSettings)) { profile = (profile >= 0)?profile:db_get_w(NULL, MODULENAME, SETTING_DEFAULTPROFILE, 0); char setting[64]; mir_snprintf(setting, "%d_%s", profile, SETTING_SHOWCONFIRMDIALOG); if (!db_get_b(NULL, MODULENAME, setting, 0)) CallService(MS_CS_SETSTATUSEX,(WPARAM)&profileSettings, 0); else CallService(MS_CS_SHOWCONFIRMDLGEX, (WPARAM)&profileSettings, (LPARAM)db_get_dw(NULL, MODULENAME, SETTING_DLGTIMEOUT, 5)); } // add timer here if (hTTBModuleLoadedHook) releaseTtbTimerId = SetTimer(NULL, 0, 100, releaseTtbTimerFunction); return 0; }
// Write CPACS fuselage profiles void CCPACSFuselageProfiles::WriteCPACS(TixiDocumentHandle tixiHandle) { const char* elementPath = "/cpacs/vehicles/profiles/fuselageProfiles"; std::string path; ReturnCode tixiRet; int fuselageProfileCount, test; TixiSaveExt::TixiSaveElement(tixiHandle, "/cpacs/vehicles", "profiles"); TixiSaveExt::TixiSaveElement(tixiHandle, "/cpacs/vehicles/profiles", "fuselageProfiles"); if (tixiGetNamedChildrenCount(tixiHandle, elementPath, "fuselageProfile", &test) != SUCCESS) { throw CTiglError("XML error: tixiGetNamedChildrenCount failed in CCPACSFuselageProfiles::WriteCPACS", TIGL_XML_ERROR); } fuselageProfileCount = GetProfileCount(); for (int i = 1; i <= fuselageProfileCount; i++) { std::stringstream ss; ss << elementPath << "/fuselageProfile[" << i << "]"; path = ss.str(); CCPACSFuselageProfile& fuselageProfile = GetProfile(i); if ((tixiRet = tixiCheckElement(tixiHandle, path.c_str())) == ELEMENT_NOT_FOUND) { if ((tixiRet = tixiCreateElement(tixiHandle, elementPath, "fuselageProfile")) != SUCCESS) { throw CTiglError("XML error: tixiCreateElement failed in CCPACSFuselageProfiles::WriteCPACS", TIGL_XML_ERROR); } } fuselageProfile.WriteCPACS(tixiHandle, path); } for (int i = fuselageProfileCount + 1; i <= test; i++) { std::stringstream ss; ss << elementPath << "/fuselageProfile[" << fuselageProfileCount + 1 << "]"; path = ss.str(); tixiRet = tixiRemoveElement(tixiHandle, path.c_str()); } }
static BOOL GetProfiles(HWND hwndDlg) { PPROFILEDATA pProfileData; WCHAR szName[8]; DWORD dwNameLength; DWORD dwProfileNumber; DWORD dwIndex = 0; HKEY hKey; LONG lError; pProfileData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(PROFILEDATA)); if (pProfileData == NULL) return FALSE; pProfileData->dwLastProfile = (DWORD)-1; pProfileData->dwSelectedProfileIndex = (DWORD)-1; if (!GetProfileCount(&pProfileData->dwProfileCount)) { HeapFree(GetProcessHeap(), 0, pProfileData); return FALSE; } pProfileData->pProfiles = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, pProfileData->dwProfileCount * sizeof(PROFILE)); if (pProfileData->pProfiles == NULL) { HeapFree(GetProcessHeap(), 0, pProfileData); return FALSE; } SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pProfileData); if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"System\\CurrentControlSet\\Control\\IDConfigDB\\Hardware Profiles", 0, KEY_READ, &hKey) != ERROR_SUCCESS) return FALSE; for (dwIndex = 0; dwIndex < pProfileData->dwProfileCount; dwIndex++) { dwNameLength = 8; lError = RegEnumKeyExW(hKey, dwIndex, szName, &dwNameLength, NULL, NULL, NULL, NULL); if (lError != ERROR_SUCCESS) break; dwProfileNumber = wcstoul(szName, NULL, 10); DPRINT("Profile name: %S\n", szName); DPRINT("Profile number: %lu\n", dwProfileNumber); if ((pProfileData->dwLastProfile == (DWORD)-1) || (pProfileData->dwLastProfile < dwProfileNumber)) pProfileData->dwLastProfile = dwProfileNumber; DPRINT("Last Profile number: %lu\n", pProfileData->dwLastProfile); GetProfile(hwndDlg, hKey, szName, dwProfileNumber, &pProfileData->pProfiles[dwIndex]); } RegCloseKey(hKey); return TRUE; }
// Invalidates internal state void CCPACSFuselageProfiles::Invalidate(void) { for (int i = 1; i < GetProfileCount(); i++) { GetProfile(i).Invalidate(); } }