static void setWindowText(HWND dialog, UINT field, IPropertyBagPtr statistics, const _bstr_t& key) { VARIANT var; ::VariantInit(&var); V_VT(&var) = VT_UI8; if (FAILED(statistics->Read(key, &var, 0))) { ::VariantClear(&var); return; } unsigned long long value = V_UI8(&var); String valueStr = WTF::String::number(value); setWindowText(dialog, field, _bstr_t(valueStr.utf8().data())); ::VariantClear(&var); }
void WebCam::EnumerateVideoDevicesForComboBox(HWND hwndComboBox) { HRESULT hr; // Create the system device enumerator. ICreateDevEnumPtr pDevEnum; hr = pDevEnum.CreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC); if (S_OK != hr) { return; } // Create an enumerator for video capture devices. IEnumMonikerPtr pClassEnum; pDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &pClassEnum, 0); if (FAILED(hr) || (pClassEnum == NULL)) { return; } ULONG cFetched; IMonikerPtr pMoniker; videoDevices.clear(); while (pClassEnum->Next(1, &pMoniker, &cFetched) == S_OK) { VideoDevice device; // Get the property bag of the moniker { IPropertyBagPtr propBag; hr = pMoniker->BindToStorage(NULL, NULL, IID_IPropertyBag, reinterpret_cast<void**>(&propBag)); if (FAILED(hr)) { pMoniker.Release(); continue; } _variant_t v; hr = propBag->Read(L"Description", &v, 0); if (FAILED(hr)) { hr = propBag->Read(L"FriendlyName", &v, 0); } if (S_OK == hr) { device.friendlyName = v.bstrVal; } hr = propBag->Read(L"DevicePath", &v, 0); if (S_OK == hr) { device.devicePath = v.bstrVal; } videoDevices.push_back(device); LRESULT index = SendMessage( hwndComboBox, CB_ADDSTRING, (WPARAM)0, (LPARAM)device.friendlyName.c_str()); if (index < 0) { pMoniker.Release(); continue; } SendMessage( hwndComboBox, CB_SETITEMDATA, (WPARAM)index, (LPARAM)(DWORD)videoDevices.size() - 1); if ((index == 0) || ((uDeviceType == deviceType_camera) && (device.devicePath == this->sDevicePath))) { SendMessage( hwndComboBox, CB_SETCURSEL, (WPARAM)index, (LPARAM)0); } } pMoniker.Release(); } }