Sample Code
Windows Driver Samples/ Microsoft slate system virtual audio device driver sample/ C++/ SwapAPO/ PropPageExtensions/ UIWidgets.cpp/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 | //**@@@*@@@**************************************************** // // Microsoft Windows // Copyright (C) Microsoft Corporation. All rights reserved. // //**@@@*@@@**************************************************** // // FileName: UIWidgets.cpp // // Abstract: Implementation of CUIWidget and derived classes // // ---------------------------------------------------------------------------- #include "stdafx.h" #include <DeviceTopology.h> #include "UIWidgets.h" _Analysis_mode_(_Analysis_code_type_user_driver_) // ---------------------------------------------------------------------- // CUIWidget base class // ---------------------------------------------------------------------------- // Function: // CUIWidget::CUIWidget // // Description: // CUIWidget constructor // ---------------------------------------------------------------------------- CUIWidget::CUIWidget ( IPart* pPart, REFIID iid ) : m_hwndParentDlg(NULL), m_iid(iid), m_wstrLabel(NULL), m_bRegisteredForCallbacks(NULL) { // This is done here rather than in the initializer list to avoid a prefix error if (pPart != NULL) { m_spPart = pPart; } m_dwProcessId = GetCurrentProcessId(); } // ---------------------------------------------------------------------------- // Function: // CUIWidget::~CUIWidget // // Description: // CUIWidget destructor // ---------------------------------------------------------------------------- CUIWidget::~CUIWidget() { SAFE_COTASKMEMFREE(m_wstrLabel); if (m_bRegisteredForCallbacks) { m_spPart->UnregisterControlChangeCallback( this ); } } // ---------------------------------------------------------------------------- // Function: // CUIWidget::Create // // Description: // -- Activates the control interface on the specified part // -- Registers for control change callbacks // // Parameters: // hwndDlg - [in] Parent dialog of the widget // rc - [in] Not used // ctrlIdBase - [in] Not used // // Return values: // S_OK if successful // ---------------------------------------------------------------------------- HRESULT CUIWidget::Create ( HWND hwndDlg, SRECT& /*rc*/, UINT & /*ctrlIdBase*/ ) { HRESULT hr; m_hwndParentDlg = hwndDlg; RPC_STATUS rpcs = UuidCreate(&m_guidEventContext); if (rpcs != RPC_S_OK) { hr = HRESULT_FROM_WIN32(rpcs); goto Exit; } hr = m_spPart->Activate(CLSCTX_INPROC_SERVER, m_iid, ( void **)&m_spControl); IF_FAILED_JUMP(hr, Exit); hr = m_spPart->RegisterControlChangeCallback(m_iid, this ); IF_FAILED_JUMP(hr, Exit); m_bRegisteredForCallbacks = TRUE; hr = m_spPart->GetName(&m_wstrLabel); Exit: return hr; }; // ---------------------------------------------------------------------- // Function: // CUIWidget::OnNotify // // Description: // Implementation of IControlChangeNotify::OnNotify // Called when someone calls a "Set" method on a control interface. // // Parameters: // dwProcessId - [in] Process ID // pguidEventContext - Event context guid // // Return: // S_OK always // ---------------------------------------------------------------------- _Use_decl_annotations_ HRESULT CUIWidget::OnNotify ( DWORD dwProcessId, LPCGUID pguidEventContext ) { UNREFERENCED_PARAMETER(dwProcessId); if ((pguidEventContext == NULL) || (*pguidEventContext != m_guidEventContext)) { // Delegate to derived class HandleControlChangeNotification(); } return S_OK; } // ---------------------------------------------------------------------- // ---------------------------------------------------------------------- // CBooleanWidget // ---------------------------------------------------------------------------- // Function: // CBooleanWidget::CBooleanWidget // // Description: // CBooleanWidget constructor // ---------------------------------------------------------------------------- CBooleanWidget::CBooleanWidget ( IPart* pPart, REFIID iid ) : CUIWidget(pPart, iid), m_hwndCheckbox(NULL), m_bCurrentValue(FALSE) { } // ---------------------------------------------------------------------------- // Function: // CBooleanWidget::Create // // Description: // Creates the widget which is a dialog // // Parameters: // hwndDlg - [in] Parent dialog of the widget // rc - [in] Position of the widget // nCtrlId - [in] Child-window identifier // // Return values: // S_OK if successful // ---------------------------------------------------------------------------- HRESULT CBooleanWidget::Create ( HWND hwndDlg, SRECT& rc, UINT & nCtrlId ) { HRESULT hr; HFONT hFont; DWORD dwStyle = WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_AUTOCHECKBOX; // Activate the control interface and register for callbacks hr = CUIWidget::Create(hwndDlg, rc, nCtrlId); IF_FAILED_JUMP(hr, Exit); // Create a check box rc.w = 300; rc.h = 20; m_hwndCheckbox = CreateWindowEx( 0, //WS_EX_STATICEDGE, WC_BUTTON, m_wstrLabel, dwStyle, rc.x, rc.y, // put at (x,y) rc.w, rc.h, m_hwndParentDlg, ( HMENU )( UINT_PTR )nCtrlId, NULL, 0); IF_TRUE_ACTION_JUMP((m_hwndCheckbox == NULL), hr = HRESULT_FROM_WIN32(GetLastError()), Exit); // Make the new control use the same font as the dialog hFont = Window_GetFont(hwndDlg); Window_SetFont(m_hwndCheckbox, hFont); // Get the current value hr = HandleControlChangeNotification(); IF_FAILED_JUMP(hr, Exit); Exit: return hr; } // ---------------------------------------------------------------------- // Function: // CBooleanWidget::HandleControlChangeNotification() // // Description: // Handles widget change notifications // // Return: // S_OK if successful // ---------------------------------------------------------------------- HRESULT CBooleanWidget::HandleControlChangeNotification() { HRESULT hr = S_OK; ATLASSERT(m_spControl); ATLASSERT(m_hwndCheckbox); // Set value on DeviceTopology control interface if (m_iid == __uuidof(IAudioLoudness)) { CComQIPtr<IAudioLoudness> spLoudness = m_spControl; hr = spLoudness->GetEnabled(&m_bCurrentValue); } else if (m_iid == __uuidof(IAudioAutoGainControl)) { CComQIPtr<IAudioAutoGainControl> spAGC = m_spControl; hr = spAGC->GetEnabled(&m_bCurrentValue); } else if (m_iid == __uuidof(IDeviceSpecificProperty)) { CComQIPtr<IDeviceSpecificProperty> spBoolCtrl = m_spControl; DWORD cbValue = sizeof (m_bCurrentValue); hr = spBoolCtrl->GetValue(&m_bCurrentValue, &cbValue); } // Set the check box to reflect the current value SendMessage(m_hwndCheckbox, BM_SETCHECK, ( WPARAM )( int )(m_bCurrentValue), 0L); return hr; } // ---------------------------------------------------------------------------- // Function: // CBooleanWidget::CommitValue // // Description: // Commit the value set on the control // // Return values: // S_OK if successful // ---------------------------------------------------------------------------- HRESULT CBooleanWidget::CommitValue() { HRESULT hr = S_OK; ATLASSERT(m_spControl); ATLASSERT(m_hwndCheckbox); // Get current value from check box m_bCurrentValue = (( int )( DWORD )SendMessage(m_hwndCheckbox, BM_GETCHECK, 0L, 0L)); // Set value on DeviceTopology control interface if (m_iid == __uuidof(IAudioLoudness)) { CComQIPtr<IAudioLoudness> spLoudness = m_spControl; hr = spLoudness->SetEnabled(m_bCurrentValue, GetEventContext()); } else if (m_iid == __uuidof(IAudioAutoGainControl)) { CComQIPtr<IAudioAutoGainControl> spAGC = m_spControl; hr = spAGC->SetEnabled(m_bCurrentValue, GetEventContext()); } else if (m_iid == __uuidof(IDeviceSpecificProperty)) { CComQIPtr<IDeviceSpecificProperty> spBoolCtrl = m_spControl; hr = spBoolCtrl->SetValue(&m_bCurrentValue, sizeof (m_bCurrentValue), GetEventContext()); } return hr; }; |
Our Services
-
What our customers say about us?
Read our customer testimonials to find out why our clients keep returning for their projects.
View Testimonials