Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

789 lines
23 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORP., 1996
  4. *
  5. * TITLE: GETSET.C
  6. *
  7. * VERSION: 2.0
  8. *
  9. * AUTHOR: ReedB
  10. *
  11. * DATE: 17 Oct, 1996
  12. *
  13. * DESCRIPTION:
  14. * Power management UI. Control panel applet. Support for set/get to/from
  15. * dialog controls.
  16. *
  17. *******************************************************************************/
  18. #include <nt.h>
  19. #include <ntrtl.h>
  20. #include <nturtl.h>
  21. #include <windows.h>
  22. #include <commctrl.h>
  23. #include "powercfg.h"
  24. // Private functions implemented in GETSET.C
  25. LPTSTR IDtoStr(UINT, PUINT);
  26. VOID DoSetSlider(HWND, UINT, DWORD, DWORD);
  27. VOID DoSetText(HWND, UINT, LPTSTR, DWORD);
  28. BOOLEAN DoComboSet(HWND, UINT, PUINT, UINT);
  29. BOOLEAN DoComboGet(HWND, UINT, PUINT, PUINT);
  30. BOOLEAN DoGetCheckBox(HWND, UINT, PUINT, LPDWORD);
  31. BOOLEAN DoGetCheckBoxEnable(HWND, UINT, PUINT, LPDWORD, LPDWORD);
  32. BOOLEAN ValidateCopyData(LPDWORD, LPDWORD, DWORD);
  33. /*******************************************************************************
  34. *
  35. * G L O B A L D A T A
  36. *
  37. *******************************************************************************/
  38. /*******************************************************************************
  39. *
  40. * P U B L I C E N T R Y P O I N T S
  41. *
  42. *******************************************************************************/
  43. /*******************************************************************************
  44. *
  45. * DisableControls
  46. *
  47. * DESCRIPTION:
  48. * Disable all specified controls. Only modify those which are visable.
  49. *
  50. * PARAMETERS:
  51. *
  52. *******************************************************************************/
  53. VOID DisableControls(
  54. HWND hWnd,
  55. UINT uiNumControls,
  56. POWER_CONTROLS pc[]
  57. )
  58. {
  59. UINT i;
  60. HWND hWndControl;
  61. for (i = 0; i < uiNumControls; i++) {
  62. switch (pc[i].uiType) {
  63. case CHECK_BOX:
  64. case CHECK_BOX_ENABLE:
  65. case SLIDER:
  66. case EDIT_UINT:
  67. case EDIT_TEXT:
  68. case EDIT_TEXT_RO:
  69. case PUSHBUTTON:
  70. case STATIC_TEXT:
  71. case COMBO_BOX:
  72. if (hWndControl = GetDlgItem(hWnd, pc[i].uiID)) {
  73. if (GetWindowLong(hWndControl, GWL_STYLE) & WS_VISIBLE) {
  74. EnableWindow(hWndControl, FALSE);
  75. // Force state to disable.
  76. if (pc[i].lpdwState) {
  77. *pc[i].lpdwState = CONTROL_DISABLE;
  78. }
  79. }
  80. }
  81. else {
  82. DebugPrint( "DisableControls, GetDlgItem failed, hWnd: 0x%X, ID: 0x%X, Index: %d", hWnd, pc[i].uiID, i);
  83. }
  84. break;
  85. default:
  86. DebugPrint( "DisableControls, unknown control type");
  87. } // switch (ppc[i].uType)
  88. }
  89. }
  90. /*******************************************************************************
  91. *
  92. * HideControls
  93. *
  94. * DESCRIPTION:
  95. * Hide all specified controls. Used to handle error cases.
  96. *
  97. * PARAMETERS:
  98. *
  99. *******************************************************************************/
  100. VOID HideControls(
  101. HWND hWnd,
  102. UINT uiNumControls,
  103. POWER_CONTROLS pc[]
  104. )
  105. {
  106. UINT i;
  107. HWND hWndControl;
  108. for (i = 0; i < uiNumControls; i++) {
  109. switch (pc[i].uiType) {
  110. case CHECK_BOX:
  111. case CHECK_BOX_ENABLE:
  112. case SLIDER:
  113. case EDIT_UINT:
  114. case EDIT_TEXT:
  115. case EDIT_TEXT_RO:
  116. case PUSHBUTTON:
  117. case STATIC_TEXT:
  118. case COMBO_BOX:
  119. // Force state to hide.
  120. if (pc[i].lpdwState) {
  121. *pc[i].lpdwState = CONTROL_HIDE;
  122. }
  123. if (hWndControl = GetDlgItem(hWnd, pc[i].uiID)) {
  124. ShowWindow(hWndControl, SW_HIDE);
  125. }
  126. else {
  127. DebugPrint( "HideControls, GetDlgItem failed, hWnd: 0x%X, ID: 0x%X, Index: %d", hWnd, pc[i].uiID, i);
  128. }
  129. break;
  130. default:
  131. DebugPrint( "HideControls, unknown control type");
  132. } // switch (ppc[i].uType)
  133. }
  134. }
  135. /*******************************************************************************
  136. *
  137. * SetControls
  138. *
  139. * DESCRIPTION:
  140. * Set dialogbox controls using control description array. Walks an array of
  141. * POWER_CONTROLS dialog controls specifiers and sets the state of the controls
  142. * (specified by the uiID member) to match the data value pointed to by
  143. * the lpdwParam member. This function is typically called during
  144. * WM_INITDIALOG or after a data value has changed and the UI needs to be
  145. * updated. The optional lpdwState member points to a state variable which
  146. * controls the visible/hidden status of the control.
  147. *
  148. * PARAMETERS:
  149. * hWnd - Dialog window handle.
  150. * uiNumControls - Number of controls to set.
  151. * pc[] - Aarray of POWER_CONTROLS dialog controls specifiers.
  152. *
  153. *******************************************************************************/
  154. BOOL SetControls(
  155. HWND hWnd,
  156. UINT uiNumControls,
  157. POWER_CONTROLS pc[]
  158. )
  159. {
  160. UINT i, uiMaxMin, uiData, uiMsg;
  161. PUINT pui;
  162. LPTSTR lpsz;
  163. UINT uiIndex;
  164. HWND hWndControl;
  165. for (i = 0; i < uiNumControls; i++) {
  166. // Validate/Copy input data.
  167. switch (pc[i].uiType) {
  168. case CHECK_BOX:
  169. case CHECK_BOX_ENABLE:
  170. case SLIDER:
  171. case EDIT_UINT:
  172. if (!pc[i].lpvData) {
  173. DebugPrint( "SetControls, NULL lpvData, index: %d", i);
  174. return FALSE;
  175. }
  176. if (!ValidateCopyData(&uiData, pc[i].lpvData, pc[i].dwSize)) {
  177. DebugPrint( "SetControls, validate/copy failed, index: %d", i);
  178. return FALSE;
  179. }
  180. break;
  181. case EDIT_TEXT:
  182. case EDIT_TEXT_RO:
  183. if (!pc[i].lpvData) {
  184. DebugPrint( "SetControls, edit text, NULL lpvData, index: %d", i);
  185. return FALSE;
  186. }
  187. break;
  188. case COMBO_BOX:
  189. if (!pc[i].lpvData) {
  190. DebugPrint( "SetControls, combo box, NULL lpvData, index: %d", i);
  191. return FALSE;
  192. }
  193. if (!pc[i].lpdwParam) {
  194. DebugPrint( "SetControls, combo box, NULL lpdwParam, index: %d", i);
  195. return FALSE;
  196. }
  197. if (!ValidateCopyData(&uiData, pc[i].lpdwParam, pc[i].dwSize)) {
  198. DebugPrint( "SetControls, combo box, validate/copy failed, index: %d", i);
  199. return FALSE;
  200. }
  201. break;
  202. }
  203. switch (pc[i].uiType) {
  204. case CHECK_BOX:
  205. // lpdwParam points to an optional flag mask.
  206. if (pc[i].lpdwParam) {
  207. uiData &= *pc[i].lpdwParam;
  208. }
  209. CheckDlgButton(hWnd, pc[i].uiID, uiData);
  210. break;
  211. case CHECK_BOX_ENABLE:
  212. // lpdwParam points to an optional flag mask.
  213. if (pc[i].lpdwParam) {
  214. uiData &= *pc[i].lpdwParam;
  215. }
  216. if (pc[i].lpdwState) {
  217. if (uiData) {
  218. *pc[i].lpdwState |= CONTROL_ENABLE;
  219. }
  220. else {
  221. *pc[i].lpdwState &= ~CONTROL_ENABLE;
  222. }
  223. }
  224. CheckDlgButton(hWnd, pc[i].uiID, uiData);
  225. break;
  226. case SLIDER:
  227. // lpdwParam points to scale MaxMin initialization.
  228. if (!pc[i].lpdwParam) {
  229. DebugPrint( "SetControls, NULL slider scale pointer, index: %d", i);
  230. return FALSE;
  231. }
  232. DoSetSlider(hWnd, pc[i].uiID, uiData, *pc[i].lpdwParam);
  233. break;
  234. case EDIT_UINT:
  235. if (pc[i].lpdwParam) {
  236. PSPIN_DATA psd = (PSPIN_DATA)pc[i].lpdwParam;
  237. SendDlgItemMessage(hWnd, psd->uiSpinId, UDM_SETRANGE, 0,
  238. (LPARAM) *(psd->puiRange));
  239. }
  240. SetDlgItemInt(hWnd, pc[i].uiID, uiData, FALSE);
  241. break;
  242. case EDIT_TEXT:
  243. case EDIT_TEXT_RO:
  244. DoSetText(hWnd, pc[i].uiID, pc[i].lpvData, pc[i].dwSize);
  245. break;
  246. case COMBO_BOX:
  247. if (!DoComboSet(hWnd, pc[i].uiID, pc[i].lpvData, uiData)) {
  248. DebugPrint( "SetControls, DoComboSet failed, control: %d", i);
  249. }
  250. break;
  251. case PUSHBUTTON:
  252. case STATIC_TEXT:
  253. // Just set visable/enable for this one.
  254. break;
  255. default:
  256. DebugPrint( "SetControls, unknown control type");
  257. return FALSE;
  258. } // switch (ppc[i].uType)
  259. // Control type CHECK_BOX_ENABLE is always visible and enabled.
  260. if ((pc[i].uiType != CHECK_BOX_ENABLE) && pc[i].lpdwState) {
  261. if (hWndControl = GetDlgItem(hWnd, pc[i].uiID)) {
  262. ShowWindow(hWndControl, (*pc[i].lpdwState & CONTROL_HIDE) ? SW_HIDE:SW_SHOW);
  263. EnableWindow(hWndControl, (*pc[i].lpdwState & CONTROL_ENABLE) ? TRUE:FALSE);
  264. }
  265. else {
  266. DebugPrint( "SetControls, GetDlgItem failed, hWnd: 0x%X, ID: 0x%X, Index: %d", hWnd, pc[i].uiID, i);
  267. }
  268. }
  269. }
  270. return TRUE;
  271. }
  272. /*******************************************************************************
  273. *
  274. * GetControls
  275. *
  276. * DESCRIPTION:
  277. * Get dialogbox controls values using control description array. Walks an
  278. * array of POWER_CONTROLS dialog controls specifiers and gets the state of the
  279. * controls (specified by the uiID member). The control states are placed in
  280. * the data values pointed to by the lpdwParam members of the description array.
  281. * This function is typically called during WM_COMMAND processing when the
  282. * state of a control has changed and the cooresponding data value needs to be
  283. * updated. The optional lpdwState member points to a state variable which
  284. * controls the visible/hidden status of the control. These state values will
  285. * be updated by CHECK_BOX_ENABLE controls.
  286. *
  287. * PARAMETERS:
  288. * hWnd - Dialog window handle.
  289. * uiNumControls - Number of controls to set.
  290. * pc[] - Aarray of POWER_CONTROLS dialog controls specifiers.
  291. *
  292. *******************************************************************************/
  293. BOOL GetControls(
  294. HWND hWnd,
  295. UINT uiNumControls,
  296. POWER_CONTROLS pc[]
  297. )
  298. {
  299. UINT i, uiIndex, uiDataOut, uiMsg, uiDataIn = 0;
  300. BOOL bSuccess;
  301. for (i = 0; i < uiNumControls; i++) {
  302. // Validate output data pointers.
  303. switch (pc[i].uiType) {
  304. case CHECK_BOX:
  305. case CHECK_BOX_ENABLE:
  306. case SLIDER:
  307. case EDIT_UINT:
  308. if (!pc[i].lpvData) {
  309. DebugPrint( "GetControls, NULL lpvData, index: %d", i);
  310. return FALSE;
  311. }
  312. if (!ValidateCopyData(&uiDataIn, pc[i].lpvData, pc[i].dwSize)) {
  313. DebugPrint( "GetControls, validate/copy input data failed, index: %d", i);
  314. return FALSE;
  315. }
  316. uiDataOut = uiDataIn;
  317. break;
  318. case COMBO_BOX:
  319. if (!pc[i].lpvData) {
  320. DebugPrint( "GetControls, combo box, NULL lpvData, index: %d", i);
  321. return FALSE;
  322. }
  323. if (!pc[i].lpdwParam) {
  324. DebugPrint( "SetControls, COMBO_BOX, NULL lpdwParam, index: %d", i);
  325. return FALSE;
  326. }
  327. if (!ValidateCopyData(&uiDataIn, pc[i].lpdwParam, pc[i].dwSize)) {
  328. DebugPrint( "GetControls, combo box, validate/copy input data failed, index: %d", i);
  329. return FALSE;
  330. }
  331. uiDataOut = uiDataIn;
  332. break;
  333. case EDIT_TEXT:
  334. if (!pc[i].lpvData) {
  335. DebugPrint( "GetControls, edit text, NULL lpvData, index: %d", i);
  336. return FALSE;
  337. }
  338. break;
  339. }
  340. switch (pc[i].uiType) {
  341. case CHECK_BOX:
  342. // lpdwParam points to a flag mask.
  343. DoGetCheckBox(hWnd, pc[i].uiID, &uiDataOut, pc[i].lpdwParam);
  344. break;
  345. case CHECK_BOX_ENABLE:
  346. // lpdwParam points to a flag mask.
  347. DoGetCheckBoxEnable(hWnd, pc[i].uiID, &uiDataOut,
  348. pc[i].lpdwParam, pc[i].lpdwState);
  349. break;
  350. case EDIT_UINT:
  351. uiDataOut = GetDlgItemInt(hWnd, pc[i].uiID, &bSuccess, FALSE);
  352. if (!bSuccess) {
  353. DebugPrint( "GetControls, GetDlgItemInt failed, index: %d", i);
  354. return FALSE;
  355. }
  356. break;
  357. case EDIT_TEXT:
  358. GetDlgItemText(hWnd, pc[i].uiID, pc[i].lpvData,
  359. (pc[i].dwSize / sizeof(TCHAR)) - 1);
  360. break;
  361. case SLIDER:
  362. uiDataOut = (UINT) SendDlgItemMessage(hWnd, pc[i].uiID, TBM_GETPOS, 0, 0);
  363. break;
  364. case COMBO_BOX:
  365. if (!DoComboGet(hWnd, pc[i].uiID, pc[i].lpvData, &uiDataOut)) {
  366. DebugPrint( "GetControls, DoComboGet failed, control: %d", i);
  367. }
  368. break;
  369. case EDIT_TEXT_RO:
  370. case PUSHBUTTON:
  371. case STATIC_TEXT:
  372. // Do nothing, these control types can only be set.
  373. break;
  374. default:
  375. DebugPrint( "GetControls, unknown control type");
  376. return FALSE;
  377. } // switch (pc[i].uType)
  378. // Copy output data.
  379. switch (pc[i].uiType) {
  380. case CHECK_BOX:
  381. case CHECK_BOX_ENABLE:
  382. case SLIDER:
  383. case EDIT_UINT:
  384. if (!ValidateCopyData(pc[i].lpvData, &uiDataOut, pc[i].dwSize)) {
  385. DebugPrint( "GetControls, validate/copy output data failed, index: %d", i);
  386. return FALSE;
  387. }
  388. break;
  389. case COMBO_BOX:
  390. if (!ValidateCopyData(pc[i].lpdwParam, &uiDataOut, pc[i].dwSize)) {
  391. DebugPrint( "GetControls, combo box, validate/copy output data failed, index: %d", i);
  392. return FALSE;
  393. }
  394. }
  395. }
  396. return TRUE;
  397. }
  398. /*******************************************************************************
  399. *
  400. * RangeLimitIDarray
  401. *
  402. * DESCRIPTION:
  403. * Limit the range of values in a ID array based on the passed in Min and Max
  404. * values.
  405. *
  406. * PARAMETERS:
  407. *
  408. *******************************************************************************/
  409. VOID RangeLimitIDarray(UINT uiID[], UINT uiMin, UINT uiMax)
  410. {
  411. UINT i, j;
  412. // Find the min value and slide the other entries down so that
  413. // it is the first entry in the array.
  414. if (uiMin != (UINT) -1) {
  415. i = 0;
  416. while (uiID[i++]) {
  417. if (uiID[i++] >= uiMin) {
  418. break;
  419. }
  420. }
  421. if (i > 1) {
  422. i -= 2;
  423. j = 0;
  424. while (uiID[i]) {
  425. uiID[j++] = uiID[i++];
  426. uiID[j++] = uiID[i++];
  427. }
  428. }
  429. uiID[j++] = 0; uiID[j] = 0;
  430. }
  431. // Find the max value and terminate the array so that it's the last entry.
  432. if (uiMax != (UINT) -1) {
  433. i = 0;
  434. while (uiID[i++]) {
  435. // Don't mess with timeouts of value zero ("Never").
  436. if (uiID[i] == 0) {
  437. break;
  438. }
  439. if (uiID[i++] > uiMax) {
  440. uiID[--i] = 0; uiID[--i] = 0;
  441. break;
  442. }
  443. }
  444. }
  445. }
  446. /*******************************************************************************
  447. *
  448. * P R I V A T E F U N C T I O N S
  449. *
  450. *******************************************************************************/
  451. /*******************************************************************************
  452. *
  453. * IDtoStr
  454. *
  455. * DESCRIPTION:
  456. * Builds a string from an array of string resource ID's.
  457. *
  458. * PARAMETERS:
  459. *
  460. *******************************************************************************/
  461. LPTSTR IDtoStr(
  462. UINT uiCount,
  463. UINT uiStrID[]
  464. )
  465. {
  466. TCHAR szTmp[MAX_UI_STR_LEN];
  467. LPTSTR lpsz = NULL;
  468. szTmp[0] = '\0';
  469. while (uiCount) {
  470. lpsz = LoadDynamicString(uiStrID[--uiCount]);
  471. if (lpsz) {
  472. if ((lstrlen(lpsz) + lstrlen(szTmp)) < (MAX_UI_STR_LEN - 3)) {
  473. if (szTmp[0]) {
  474. lstrcat(szTmp, TEXT(", "));
  475. }
  476. lstrcat(szTmp, lpsz);
  477. }
  478. LocalFree(lpsz);
  479. lpsz = LocalAlloc(0, STRSIZE(szTmp));
  480. if (lpsz) {
  481. lstrcpy(lpsz, szTmp);
  482. }
  483. }
  484. }
  485. return lpsz;
  486. }
  487. /*******************************************************************************
  488. *
  489. * DoSetSlider
  490. *
  491. * DESCRIPTION:
  492. *
  493. * PARAMETERS:
  494. *
  495. *******************************************************************************/
  496. VOID DoSetSlider(HWND hWnd, UINT uiID, DWORD dwData, DWORD dwMaxMin)
  497. {
  498. if (dwMaxMin) {
  499. SendDlgItemMessage(hWnd, uiID, TBM_SETRANGE, FALSE, (LPARAM) dwMaxMin);
  500. }
  501. SendDlgItemMessage(hWnd, uiID, TBM_SETPOS, TRUE, (LPARAM) dwData);
  502. }
  503. /*******************************************************************************
  504. *
  505. * DoSetText
  506. *
  507. * DESCRIPTION:
  508. *
  509. * PARAMETERS:
  510. *
  511. *******************************************************************************/
  512. VOID DoSetText(HWND hWnd, UINT uiID, LPTSTR lpsz, DWORD dwSize)
  513. {
  514. if (dwSize) {
  515. SendDlgItemMessage(hWnd, uiID, EM_SETLIMITTEXT,
  516. dwSize - sizeof(TCHAR), 0);
  517. }
  518. SetDlgItemText(hWnd, uiID, lpsz);
  519. }
  520. /*******************************************************************************
  521. *
  522. * DoComboSet
  523. *
  524. * DESCRIPTION:
  525. * Reset and populate a combo box with the data pointed to by uiId. Select the
  526. * item pointed to by uiData.
  527. *
  528. * PARAMETERS:
  529. *
  530. *******************************************************************************/
  531. BOOLEAN DoComboSet(
  532. HWND hWnd,
  533. UINT uiID,
  534. UINT uiId[],
  535. UINT uiData
  536. )
  537. {
  538. UINT uiSelIndex, uiIndex = 0, i = 0;
  539. BOOL bFoundSel = FALSE;
  540. LPTSTR lpsz;
  541. SendDlgItemMessage(hWnd, uiID, CB_RESETCONTENT, 0, 0);
  542. // Populate the combo list box.
  543. while (uiId[i]) {
  544. lpsz = LoadDynamicString(uiId[i++]);
  545. if (lpsz) {
  546. if (uiIndex != (UINT) SendDlgItemMessage(hWnd, uiID, CB_ADDSTRING,
  547. 0, (LPARAM)lpsz)) {
  548. DebugPrint( "DoComboSet, CB_ADDSTRING failed: %s", lpsz);
  549. LocalFree(lpsz);
  550. return FALSE;
  551. }
  552. LocalFree(lpsz);
  553. if (uiId[i] == uiData) {
  554. bFoundSel = TRUE;
  555. uiSelIndex = uiIndex;
  556. }
  557. if (SendDlgItemMessage(hWnd, uiID, CB_SETITEMDATA,
  558. uiIndex++, (LPARAM)uiId[i++]) == CB_ERR) {
  559. DebugPrint( "DoComboSet, CB_SETITEMDATA failed, index: %d", --uiIndex);
  560. return FALSE;
  561. }
  562. }
  563. else {
  564. DebugPrint( "DoComboSet, unable to load string, index: %d", --i);
  565. return FALSE;
  566. }
  567. }
  568. if (bFoundSel) {
  569. if ((UINT)SendDlgItemMessage(hWnd, uiID, CB_SETCURSEL,
  570. (WPARAM)uiSelIndex, 0) != uiSelIndex) {
  571. DebugPrint( "DoComboSet, CB_SETCURSEL failed, index: %d", uiSelIndex);
  572. return FALSE;
  573. }
  574. }
  575. else {
  576. DebugPrint( "DoComboSet unable to find data: 0x%X", uiData);
  577. return FALSE;
  578. }
  579. return TRUE;
  580. }
  581. /*******************************************************************************
  582. *
  583. * DoComboGet
  584. *
  585. * DESCRIPTION:
  586. * Get data for currently selected combo box item.
  587. *
  588. * PARAMETERS:
  589. *
  590. *******************************************************************************/
  591. BOOLEAN DoComboGet(
  592. HWND hWnd,
  593. UINT uiID,
  594. UINT uiId[],
  595. PUINT puiData
  596. )
  597. {
  598. UINT uiIndex, uiData;
  599. uiIndex = (UINT) SendDlgItemMessage(hWnd, uiID, CB_GETCURSEL,0, 0);
  600. if (uiIndex == CB_ERR) {
  601. DebugPrint( "DoComboGet, CB_GETCURSEL failed");
  602. return FALSE;
  603. }
  604. uiData = (UINT) SendDlgItemMessage(hWnd, uiID, CB_GETITEMDATA, uiIndex, 0);
  605. if (uiData == CB_ERR) {
  606. DebugPrint( "DoComboGet, CB_GETITEMDATA failed, index: %d", uiIndex);
  607. return FALSE;
  608. }
  609. *puiData = uiData;
  610. return TRUE;
  611. }
  612. /*******************************************************************************
  613. *
  614. * DoGetCheckBox
  615. *
  616. * DESCRIPTION:
  617. *
  618. * PARAMETERS:
  619. *
  620. *******************************************************************************/
  621. BOOLEAN DoGetCheckBox(
  622. HWND hWnd,
  623. UINT uiID,
  624. PUINT puiData,
  625. LPDWORD lpdwMask
  626. )
  627. {
  628. UINT uiButtonState;
  629. BOOLEAN bRet;
  630. uiButtonState = IsDlgButtonChecked(hWnd, uiID);
  631. if (lpdwMask) {
  632. if (uiButtonState == BST_CHECKED) {
  633. bRet = TRUE;
  634. *puiData |= *lpdwMask;
  635. }
  636. else {
  637. bRet = FALSE;
  638. *puiData &= ~(*lpdwMask);
  639. }
  640. }
  641. else {
  642. if (uiButtonState == BST_CHECKED) {
  643. bRet = *puiData = TRUE;
  644. }
  645. else {
  646. bRet = *puiData = FALSE;
  647. }
  648. }
  649. return bRet;
  650. }
  651. /*******************************************************************************
  652. *
  653. * DoGetCheckBoxEnable
  654. *
  655. * DESCRIPTION:
  656. *
  657. * PARAMETERS:
  658. *
  659. *******************************************************************************/
  660. BOOLEAN DoGetCheckBoxEnable(
  661. HWND hWnd,
  662. UINT uiID,
  663. PUINT puiData,
  664. LPDWORD lpdwMask,
  665. LPDWORD lpdwEnableState
  666. )
  667. {
  668. UINT uiData;
  669. if (DoGetCheckBox(hWnd, uiID, puiData, lpdwMask)) {
  670. if (lpdwEnableState) {
  671. *lpdwEnableState |= CONTROL_ENABLE;
  672. }
  673. return TRUE;
  674. }
  675. else {
  676. if (lpdwEnableState) {
  677. *lpdwEnableState &= ~CONTROL_ENABLE;
  678. }
  679. return FALSE;
  680. }
  681. }
  682. /*******************************************************************************
  683. *
  684. * ValidateCopyData
  685. *
  686. * DESCRIPTION:
  687. * Data size must be BYTE, SHORT or DWORD.
  688. *
  689. * PARAMETERS:
  690. *
  691. *******************************************************************************/
  692. BOOLEAN ValidateCopyData(LPDWORD lpDst, LPDWORD lpSrc, DWORD dwSize)
  693. {
  694. switch (dwSize) {
  695. case sizeof(BYTE):
  696. case sizeof(SHORT):
  697. case sizeof(DWORD):
  698. *lpDst = 0;
  699. memcpy(lpDst, lpSrc, dwSize);
  700. return TRUE;
  701. default:
  702. DebugPrint( "ValidateCopyData, invalid variable size: %d", dwSize);
  703. }
  704. return FALSE;
  705. }