static INT_PTR CALLBACK EspRestartServiceDlgProc( _In_ HWND hwndDlg, _In_ UINT uMsg, _In_ WPARAM wParam, _In_ LPARAM lParam ) { PRESTART_SERVICE_CONTEXT context; if (uMsg == WM_INITDIALOG) { context = (PRESTART_SERVICE_CONTEXT)lParam; SetProp(hwndDlg, L"Context", (HANDLE)context); } else { context = (PRESTART_SERVICE_CONTEXT)GetProp(hwndDlg, L"Context"); if (uMsg == WM_DESTROY) RemoveProp(hwndDlg, L"Context"); } if (!context) return FALSE; switch (uMsg) { case WM_INITDIALOG: { PhCenterWindow(hwndDlg, GetParent(hwndDlg)); // TODO: Use the progress information. PhSetWindowStyle(GetDlgItem(hwndDlg, IDC_PROGRESS), PBS_MARQUEE, PBS_MARQUEE); SendMessage(GetDlgItem(hwndDlg, IDC_PROGRESS), PBM_SETMARQUEE, TRUE, 75); SetDlgItemText(hwndDlg, IDC_MESSAGE, PhaFormatString(L"Attempting to stop %s...", context->ServiceItem->Name->Buffer)->Buffer); if (PhUiStopService(hwndDlg, context->ServiceItem)) { SetTimer(hwndDlg, 1, 250, NULL); } else { EndDialog(hwndDlg, IDCANCEL); } } break; case WM_COMMAND: { switch (LOWORD(wParam)) { case IDCANCEL: { EndDialog(hwndDlg, IDCANCEL); } break; } } break; case WM_TIMER: { if (wParam == 1 && !context->DisableTimer) { SERVICE_STATUS serviceStatus; if (QueryServiceStatus(context->ServiceHandle, &serviceStatus)) { if (!context->Starting && serviceStatus.dwCurrentState == SERVICE_STOPPED) { // The service is stopped, so start the service now. SetDlgItemText(hwndDlg, IDC_MESSAGE, PhaFormatString(L"Attempting to start %s...", context->ServiceItem->Name->Buffer)->Buffer); context->DisableTimer = TRUE; if (PhUiStartService(hwndDlg, context->ServiceItem)) { context->DisableTimer = FALSE; context->Starting = TRUE; } else { EndDialog(hwndDlg, IDCANCEL); } } else if (context->Starting && serviceStatus.dwCurrentState == SERVICE_RUNNING) { EndDialog(hwndDlg, IDOK); } } } } break; } return FALSE; }
INT_PTR CALLBACK PhpServicesPageProc( _In_ HWND hwndDlg, _In_ UINT uMsg, _In_ WPARAM wParam, _In_ LPARAM lParam ) { PPH_SERVICES_CONTEXT servicesContext; HWND lvHandle; if (uMsg == WM_INITDIALOG) { servicesContext = (PPH_SERVICES_CONTEXT)lParam; SetProp(hwndDlg, PhMakeContextAtom(), (HANDLE)servicesContext); } else { servicesContext = (PPH_SERVICES_CONTEXT)GetProp(hwndDlg, PhMakeContextAtom()); if (uMsg == WM_DESTROY) { RemoveProp(hwndDlg, PhMakeContextAtom()); } } if (!servicesContext) return FALSE; lvHandle = GetDlgItem(hwndDlg, IDC_LIST); switch (uMsg) { case WM_INITDIALOG: { ULONG i; PhRegisterCallback( &PhServiceModifiedEvent, ServiceModifiedHandler, servicesContext, &servicesContext->ModifiedEventRegistration ); servicesContext->WindowHandle = hwndDlg; // Initialize the list. PhSetListViewStyle(lvHandle, TRUE, TRUE); PhSetControlTheme(lvHandle, L"explorer"); PhAddListViewColumn(lvHandle, 0, 0, 0, LVCFMT_LEFT, 120, L"Name"); PhAddListViewColumn(lvHandle, 1, 1, 1, LVCFMT_LEFT, 220, L"Display name"); PhSetExtendedListView(lvHandle); for (i = 0; i < servicesContext->NumberOfServices; i++) { PPH_SERVICE_ITEM serviceItem; INT lvItemIndex; serviceItem = servicesContext->Services[i]; lvItemIndex = PhAddListViewItem(lvHandle, MAXINT, serviceItem->Name->Buffer, serviceItem); PhSetListViewSubItem(lvHandle, lvItemIndex, 1, serviceItem->DisplayName->Buffer); } ExtendedListView_SortItems(lvHandle); PhpFixProcessServicesControls(hwndDlg, NULL); PhInitializeLayoutManager(&servicesContext->LayoutManager, hwndDlg); PhAddLayoutItem(&servicesContext->LayoutManager, GetDlgItem(hwndDlg, IDC_LIST), NULL, PH_ANCHOR_ALL); PhAddLayoutItem(&servicesContext->LayoutManager, GetDlgItem(hwndDlg, IDC_DESCRIPTION), NULL, PH_ANCHOR_LEFT | PH_ANCHOR_RIGHT | PH_ANCHOR_BOTTOM); PhAddLayoutItem(&servicesContext->LayoutManager, GetDlgItem(hwndDlg, IDC_START), NULL, PH_ANCHOR_RIGHT | PH_ANCHOR_BOTTOM); PhAddLayoutItem(&servicesContext->LayoutManager, GetDlgItem(hwndDlg, IDC_PAUSE), NULL, PH_ANCHOR_RIGHT | PH_ANCHOR_BOTTOM); } break; case WM_DESTROY: { ULONG i; for (i = 0; i < servicesContext->NumberOfServices; i++) PhDereferenceObject(servicesContext->Services[i]); PhFree(servicesContext->Services); PhUnregisterCallback( &PhServiceModifiedEvent, &servicesContext->ModifiedEventRegistration ); if (servicesContext->ListViewSettingName) PhSaveListViewColumnsToSetting(servicesContext->ListViewSettingName, lvHandle); PhDeleteLayoutManager(&servicesContext->LayoutManager); PhFree(servicesContext); } break; case WM_COMMAND: { INT id = LOWORD(wParam); switch (id) { case IDC_START: { PPH_SERVICE_ITEM serviceItem = PhGetSelectedListViewItemParam(lvHandle); if (serviceItem) { switch (serviceItem->State) { case SERVICE_RUNNING: PhUiStopService(hwndDlg, serviceItem); break; case SERVICE_PAUSED: PhUiStopService(hwndDlg, serviceItem); break; case SERVICE_STOPPED: PhUiStartService(hwndDlg, serviceItem); break; } } } break; case IDC_PAUSE: { PPH_SERVICE_ITEM serviceItem = PhGetSelectedListViewItemParam(lvHandle); if (serviceItem) { switch (serviceItem->State) { case SERVICE_RUNNING: PhUiPauseService(hwndDlg, serviceItem); break; case SERVICE_PAUSED: PhUiContinueService(hwndDlg, serviceItem); break; } } } break; } } break; case WM_NOTIFY: { LPNMHDR header = (LPNMHDR)lParam; PhHandleListViewNotifyBehaviors(lParam, lvHandle, PH_LIST_VIEW_DEFAULT_1_BEHAVIORS); switch (header->code) { case NM_DBLCLK: { if (header->hwndFrom == lvHandle) { PPH_SERVICE_ITEM serviceItem = PhGetSelectedListViewItemParam(lvHandle); if (serviceItem) { PhShowServiceProperties(hwndDlg, serviceItem); } } } break; case LVN_ITEMCHANGED: { if (header->hwndFrom == lvHandle) { //LPNMITEMACTIVATE itemActivate = (LPNMITEMACTIVATE)header; PPH_SERVICE_ITEM serviceItem = NULL; if (ListView_GetSelectedCount(lvHandle) == 1) serviceItem = PhGetSelectedListViewItemParam(lvHandle); PhpFixProcessServicesControls(hwndDlg, serviceItem); } } break; } } break; case WM_SIZE: { PhLayoutManagerLayout(&servicesContext->LayoutManager); } break; case WM_PH_SERVICE_MODIFIED: { PPH_SERVICE_MODIFIED_DATA serviceModifiedData = (PPH_SERVICE_MODIFIED_DATA)lParam; PPH_SERVICE_ITEM serviceItem = NULL; if (ListView_GetSelectedCount(lvHandle) == 1) serviceItem = PhGetSelectedListViewItemParam(lvHandle); if (serviceModifiedData->Service == serviceItem) { PhpFixProcessServicesControls(hwndDlg, serviceItem); } PhFree(serviceModifiedData); } break; case WM_PH_SET_LIST_VIEW_SETTINGS: { PWSTR settingName = (PWSTR)lParam; servicesContext->ListViewSettingName = settingName; PhLoadListViewColumnsFromSetting(settingName, lvHandle); } break; } return FALSE; }