Leaked source code of windows server 2003
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.

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