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.

215 lines
6.0 KiB

  1. #include "pch.h"
  2. #pragma hdrstop
  3. /*-----------------------------------------------------------------------------
  4. / Local functions / data
  5. /----------------------------------------------------------------------------*/
  6. static TCHAR szMachineRole[] = TEXT("MachineRole");
  7. static LPWSTR c_szClassList[] =
  8. {
  9. L"computer",
  10. };
  11. static struct
  12. {
  13. INT idString;
  14. LPWSTR c_szPropertyValue;
  15. }
  16. machineRoleValues[] =
  17. {
  18. IDS_ANY, L"(sAMAccountType=805306369)",
  19. IDS_WKSSERVER, L"(&(samAccountType=805306369)(!(primaryGroupId=516)))",
  20. IDS_DC, L"(primaryGroupID=516)",
  21. };
  22. static PAGECTRL ctrls[] =
  23. {
  24. IDC_COMPNAME, c_szName, FILTER_CONTAINS,
  25. IDC_COMPOWNER, L"managedBy", FILTER_CONTAINS,
  26. };
  27. static COLUMNINFO columns[] =
  28. {
  29. 0, 0, IDS_CN, 0, c_szName,
  30. 0, 0, IDS_MACHINEROLE, 0, L"userAccountControl,{C40FBD00-88B9-11d2-84AD-00C04FA31A86}",
  31. 0, 0, IDS_OWNER, 0, L"managedBy,{DDE5783A-88B9-11d2-84AD-00C04FA31A86}",
  32. 0, DEFAULT_WIDTH_DESCRIPTION, IDS_DESCRIPTION, 0, c_szDescription,
  33. };
  34. //
  35. // Control help meppings
  36. //
  37. static DWORD const aFormHelpIDs[] =
  38. {
  39. IDC_COMPNAME, IDH_COMPUTER_NAME,
  40. IDC_COMPOWNER, IDH_OWNER,
  41. IDC_COMPROLE, IDH_ROLE,
  42. 0, 0,
  43. };
  44. /*-----------------------------------------------------------------------------
  45. / PageProc_Computer
  46. / -----------------
  47. / PageProc for finding computers.
  48. /
  49. / In:
  50. / pForm -> instance data for this form
  51. / hwnd = window handle for the form dialog
  52. / uMsg, wParam, lParam = message parameters
  53. /
  54. / Out:
  55. / HRESULT (E_NOTIMPL) if not handled
  56. /----------------------------------------------------------------------------*/
  57. HRESULT CALLBACK PageProc_Computer(LPCQPAGE pPage, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  58. {
  59. HRESULT hr = S_OK;
  60. LPWSTR pQuery = NULL;
  61. TraceEnter(TRACE_FORMS, "PageProc_Computer");
  62. switch ( uMsg )
  63. {
  64. case CQPM_INITIALIZE:
  65. case CQPM_RELEASE:
  66. break;
  67. case CQPM_ENABLE:
  68. EnablePageControls(hwnd, ctrls, ARRAYSIZE(ctrls), (BOOL)wParam);
  69. EnableWindow(GetDlgItem(hwnd, IDC_COMPROLE), (BOOL)wParam);
  70. break;
  71. case CQPM_GETPARAMETERS:
  72. {
  73. INT iCurSel;
  74. iCurSel = ComboBox_GetCurSel(GetDlgItem(hwnd, IDC_COMPROLE));
  75. if ( (iCurSel < 0) || (iCurSel >= ARRAYSIZE(machineRoleValues)) )
  76. ExitGracefully(hr, E_FAIL, "Bad selection of computer role");
  77. hr = GetQueryString(&pQuery, machineRoleValues[iCurSel].c_szPropertyValue, hwnd, ctrls, ARRAYSIZE(ctrls));
  78. if ( SUCCEEDED(hr) )
  79. {
  80. hr = QueryParamsAlloc((LPDSQUERYPARAMS*)lParam, pQuery, GLOBAL_HINSTANCE, ARRAYSIZE(columns), columns);
  81. LocalFreeStringW(&pQuery);
  82. }
  83. FailGracefully(hr, "Failed to build DS argument block");
  84. break;
  85. }
  86. case CQPM_CLEARFORM:
  87. ResetPageControls(hwnd, ctrls, ARRAYSIZE(ctrls));
  88. break;
  89. case CQPM_PERSIST:
  90. {
  91. BOOL fRead = (BOOL)wParam;
  92. IPersistQuery* pPersistQuery = (IPersistQuery*)lParam;
  93. INT i;
  94. hr = PersistQuery(pPersistQuery, fRead, c_szMsComputer, hwnd, ctrls, ARRAYSIZE(ctrls));
  95. FailGracefully(hr, "Failed to persist page");
  96. if ( fRead )
  97. {
  98. if ( SUCCEEDED(pPersistQuery->ReadInt(c_szMsComputer, szMachineRole, &i)) )
  99. ComboBox_SetCurSel(GetDlgItem(hwnd, IDC_COMPROLE), i);
  100. }
  101. else
  102. {
  103. hr = pPersistQuery->WriteInt(c_szMsComputer, szMachineRole,
  104. ComboBox_GetCurSel(GetDlgItem(hwnd, IDC_COMPROLE)));
  105. FailGracefully(hr, "Failed when writing out computer type");
  106. }
  107. break;
  108. }
  109. case CQPM_HELP:
  110. {
  111. LPHELPINFO pHelpInfo = (LPHELPINFO)lParam;
  112. WinHelp((HWND)pHelpInfo->hItemHandle,
  113. DSQUERY_HELPFILE,
  114. HELP_WM_HELP,
  115. (DWORD_PTR)aFormHelpIDs);
  116. break;
  117. }
  118. case DSQPM_GETCLASSLIST:
  119. {
  120. hr = ClassListAlloc((LPDSQUERYCLASSLIST*)lParam, c_szClassList, ARRAYSIZE(c_szClassList));
  121. FailGracefully(hr, "Failed to allocate class list");
  122. break;
  123. }
  124. case DSQPM_HELPTOPICS:
  125. {
  126. HWND hwndFrame = (HWND)lParam;
  127. HtmlHelp(hwndFrame, TEXT("omc.chm"), HH_HELP_FINDER, 0);
  128. break;
  129. }
  130. default:
  131. hr = E_NOTIMPL;
  132. break;
  133. }
  134. exit_gracefully:
  135. TraceLeaveResult(hr);
  136. }
  137. /*-----------------------------------------------------------------------------
  138. / DlgProc_Computer
  139. / ----------------
  140. / Standard dialog proc for the page, handle any special buttons and other
  141. / such nastyness we must here.
  142. /
  143. / In:
  144. / hwnd, uMsg, wParam, lParam = standard parameters
  145. /
  146. / Out:
  147. / INT_PTR
  148. /----------------------------------------------------------------------------*/
  149. INT_PTR CALLBACK DlgProc_Computer(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  150. {
  151. INT_PTR fResult = 0;
  152. LPCQPAGE pQueryPage;
  153. HWND hwndCtrl;
  154. if ( uMsg == WM_INITDIALOG )
  155. {
  156. TCHAR szBuffer[MAX_PATH];
  157. INT i;
  158. pQueryPage = (LPCQPAGE)lParam;
  159. SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR)pQueryPage);
  160. Edit_LimitText(GetDlgItem(hwnd, IDC_COMPNAME), MAX_PATH);
  161. Edit_LimitText(GetDlgItem(hwnd, IDC_COMPOWNER), MAX_PATH);
  162. for ( i = 0 ; i < ARRAYSIZE(machineRoleValues) ; i++ )
  163. {
  164. LoadString(GLOBAL_HINSTANCE, machineRoleValues[i].idString, szBuffer, ARRAYSIZE(szBuffer));
  165. ComboBox_AddString(GetDlgItem(hwnd, IDC_COMPROLE), szBuffer);
  166. }
  167. ComboBox_SetCurSel(GetDlgItem(hwnd, IDC_COMPROLE), 0);
  168. }
  169. else if ( uMsg == WM_CONTEXTMENU )
  170. {
  171. WinHelp((HWND)wParam, DSQUERY_HELPFILE, HELP_CONTEXTMENU, (DWORD_PTR)aFormHelpIDs);
  172. fResult = TRUE;
  173. }
  174. return fResult;
  175. }