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.

339 lines
7.7 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. ginfo.cpp : implementation file
  5. CPropertyPage support for User mgmt wizard
  6. File History:
  7. JonY Apr-96 created
  8. --*/
  9. #include "stdafx.h"
  10. #include "Speckle.h"
  11. #include "userlist.h"
  12. #include "wizbased.h"
  13. #include "ginfo.h"
  14. #include <lmcons.h>
  15. #include <lmapibuf.h>
  16. #include <lmaccess.h>
  17. #ifdef _DEBUG
  18. //#define new DEBUG_NEW
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22. /////////////////////////////////////////////////////////////////////////////
  23. // CGroupInfo property page
  24. IMPLEMENT_DYNCREATE(CGroupInfo, CWizBaseDlg)
  25. CGroupInfo::CGroupInfo() : CWizBaseDlg(CGroupInfo::IDD)
  26. {
  27. //{{AFX_DATA_INIT(CGroupInfo)
  28. m_csCaption = _T("");
  29. //}}AFX_DATA_INIT
  30. }
  31. CGroupInfo::~CGroupInfo()
  32. {
  33. }
  34. void CGroupInfo::DoDataExchange(CDataExchange* pDX)
  35. {
  36. CPropertyPage::DoDataExchange(pDX);
  37. //{{AFX_DATA_MAP(CGroupInfo)
  38. DDX_Control(pDX, IDC_GROUP_MEMBER_LIST, m_lbSelectedGroups);
  39. DDX_Control(pDX, IDC_GROUP_AVAILABLE_LIST, m_lbAvailableGroups);
  40. DDX_Text(pDX, IDC_STATIC1, m_csCaption);
  41. //}}AFX_DATA_MAP
  42. }
  43. BEGIN_MESSAGE_MAP(CGroupInfo, CWizBaseDlg)
  44. //{{AFX_MSG_MAP(CGroupInfo)
  45. ON_BN_CLICKED(IDC_ADD_BUTTON, OnAddButton)
  46. ON_BN_CLICKED(IDC_REMOVE_BUTTON, OnRemoveButton)
  47. ON_LBN_SETFOCUS(IDC_GROUP_AVAILABLE_LIST, OnSetfocusGroupAvailableList)
  48. ON_LBN_SETFOCUS(IDC_GROUP_MEMBER_LIST, OnSetfocusGroupMemberList)
  49. ON_LBN_SELCHANGE(IDC_GROUP_MEMBER_LIST, OnSelchangeGroupMemberList)
  50. ON_WM_SHOWWINDOW()
  51. ON_LBN_DBLCLK(IDC_GROUP_AVAILABLE_LIST, OnDblclkGroupAvailableList)
  52. ON_LBN_DBLCLK(IDC_GROUP_MEMBER_LIST, OnDblclkGroupMemberList)
  53. //}}AFX_MSG_MAP
  54. END_MESSAGE_MAP()
  55. /////////////////////////////////////////////////////////////////////////////
  56. // CGroupInfo message handlers
  57. BOOL CGroupInfo::OnInitDialog()
  58. {
  59. CWizBaseDlg::OnInitDialog();
  60. return TRUE; // return TRUE unless you set the focus to a control
  61. // EXCEPTION: OCX Property Pages should return FALSE
  62. }
  63. void CGroupInfo::OnAddButton()
  64. {
  65. UpdateData(TRUE);
  66. USHORT usSel = m_lbAvailableGroups.GetCurSel();
  67. if (usSel == LB_ERR)
  68. {
  69. GetDlgItem(IDC_ADD_BUTTON)->EnableWindow(FALSE);
  70. GetDlgItem(IDC_REMOVE_BUTTON)->EnableWindow(TRUE);
  71. m_lbSelectedGroups.SetCurSel(0);
  72. return;
  73. }
  74. CString csSel;
  75. m_lbAvailableGroups.GetText(usSel, csSel);
  76. USHORT usBmp = m_lbAvailableGroups.GetBitmapID(usSel);
  77. m_lbSelectedGroups.AddString(csSel, usBmp);
  78. m_lbAvailableGroups.DeleteString(usSel);
  79. // anybody left?
  80. if (m_lbAvailableGroups.GetCount() != 0)
  81. m_lbAvailableGroups.SetCurSel(0);
  82. else
  83. {
  84. m_lbSelectedGroups.SetCurSel(0);
  85. GetDlgItem(IDC_REMOVE_BUTTON)->EnableWindow(TRUE);
  86. GetDlgItem(IDC_ADD_BUTTON)->EnableWindow(FALSE);
  87. m_lbAvailableGroups.SetHorizontalExtent(0);
  88. }
  89. }
  90. void CGroupInfo::OnRemoveButton()
  91. {
  92. UpdateData(TRUE);
  93. USHORT usSel = m_lbSelectedGroups.GetCurSel();
  94. if (usSel == 65535)
  95. {
  96. GetDlgItem(IDC_REMOVE_BUTTON)->EnableWindow(FALSE);
  97. GetDlgItem(IDC_ADD_BUTTON)->EnableWindow(TRUE);
  98. m_lbAvailableGroups.SetCurSel(0);
  99. return;
  100. }
  101. CString csSel;
  102. m_lbSelectedGroups.GetText(usSel, csSel);
  103. USHORT usBmp = m_lbSelectedGroups.GetBitmapID(usSel);
  104. m_lbAvailableGroups.AddString(csSel, usBmp);
  105. m_lbSelectedGroups.DeleteString(usSel);
  106. // anybody left?
  107. if (m_lbSelectedGroups.GetCount() != 0)
  108. m_lbSelectedGroups.SetCurSel(0);
  109. else
  110. {
  111. m_lbAvailableGroups.SetCurSel(0);
  112. GetDlgItem(IDC_ADD_BUTTON)->EnableWindow(TRUE);
  113. GetDlgItem(IDC_REMOVE_BUTTON)->EnableWindow(FALSE);
  114. m_lbSelectedGroups.SetHorizontalExtent(0);
  115. }
  116. }
  117. LRESULT CGroupInfo::OnWizardBack()
  118. {
  119. return CPropertyPage::OnWizardBack();
  120. }
  121. LRESULT CGroupInfo::OnWizardNext()
  122. {
  123. UpdateData(TRUE);
  124. CSpeckleApp* pApp = (CSpeckleApp*)AfxGetApp();
  125. // add selected groups to list
  126. pApp->m_csaSelectedLocalGroups.RemoveAll();
  127. pApp->m_csaSelectedGlobalGroups.RemoveAll();
  128. short sGroupCount = m_lbSelectedGroups.GetCount();
  129. short sCount;
  130. CString csVal;
  131. for (sCount = 0; sCount < sGroupCount; sCount++)
  132. {
  133. USHORT usBmp = m_lbSelectedGroups.GetBitmapID(sCount);
  134. m_lbSelectedGroups.GetText(sCount, csVal);
  135. if (usBmp == 3) pApp->m_csaSelectedLocalGroups.Add(csVal);
  136. else if (usBmp == 1) pApp->m_csaSelectedGlobalGroups.Add(csVal);
  137. }
  138. pApp->m_cps1.SetWizardButtons(PSWIZB_NEXT | PSWIZB_BACK);
  139. return CPropertyPage::OnWizardNext();
  140. }
  141. void CGroupInfo::OnSetfocusGroupAvailableList()
  142. {
  143. m_lbSelectedGroups.SetCurSel(-1);
  144. GetDlgItem(IDC_ADD_BUTTON)->EnableWindow(TRUE);
  145. GetDlgItem(IDC_REMOVE_BUTTON)->EnableWindow(FALSE);
  146. }
  147. void CGroupInfo::OnSetfocusGroupMemberList()
  148. {
  149. UpdateData(TRUE);
  150. m_lbAvailableGroups.SetCurSel(-1);
  151. GetDlgItem(IDC_ADD_BUTTON)->EnableWindow(FALSE);
  152. GetDlgItem(IDC_REMOVE_BUTTON)->EnableWindow(TRUE);
  153. }
  154. void CGroupInfo::OnSelchangeGroupMemberList()
  155. {
  156. UpdateData(TRUE);
  157. }
  158. void CGroupInfo::OnShowWindow(BOOL bShow, UINT nStatus)
  159. {
  160. CWizBaseDlg::OnShowWindow(bShow, nStatus);
  161. if (!bShow) return;
  162. CSpeckleApp* pApp = (CSpeckleApp*)AfxGetApp();
  163. if (!pApp->m_bGReset) return;
  164. pApp->m_bGReset = FALSE;
  165. m_lbAvailableGroups.ResetContent();
  166. m_lbSelectedGroups.ResetContent();
  167. CWaitCursor wait;
  168. DWORD dwEntriesRead = 0;
  169. DWORD dwTotalEntries = 0;
  170. DWORD dwResumeHandle = 0;
  171. NET_API_STATUS nApi;
  172. unsigned long sIndex;
  173. TCHAR* pServer = pApp->m_csServer.GetBuffer(pApp->m_csServer.GetLength());
  174. pApp->m_csServer.ReleaseBuffer();
  175. // if this is on a domain, check for global groups
  176. if (pApp->m_bDomain)
  177. {
  178. PGROUP_INFO_1 pInfo;
  179. do
  180. {
  181. nApi = NetGroupEnum(pServer,
  182. (DWORD)1,
  183. (PBYTE*)&pInfo,
  184. (DWORD)5000,
  185. &dwEntriesRead,
  186. &dwTotalEntries,
  187. &dwResumeHandle);
  188. for (sIndex = 0; sIndex < dwEntriesRead; sIndex++)
  189. {
  190. TCHAR sTemp[50];
  191. swprintf(sTemp, TEXT("%s"), pInfo[sIndex].grpi1_name);
  192. m_lbAvailableGroups.AddString(1, sTemp);
  193. }
  194. NetApiBufferFree(pInfo);
  195. } while (dwResumeHandle != 0);
  196. // m_lbSelectedGroups.AddString(1, TEXT("Domain Users"));
  197. UpdateData(FALSE);
  198. }
  199. PLOCALGROUP_INFO_1 pLocalInfo;
  200. dwResumeHandle = 0;
  201. do
  202. {
  203. nApi = NetLocalGroupEnum(pServer,
  204. (DWORD)1,
  205. (PBYTE*)&pLocalInfo,
  206. (DWORD)5000,
  207. &dwEntriesRead,
  208. &dwTotalEntries,
  209. &dwResumeHandle);
  210. for (sIndex = 0; sIndex < dwEntriesRead; sIndex++)
  211. {
  212. TCHAR sTemp[50];
  213. swprintf(sTemp, TEXT("%s"), pLocalInfo[sIndex].lgrpi1_name);
  214. m_lbAvailableGroups.AddString(3, sTemp);
  215. }
  216. NetApiBufferFree(pLocalInfo);
  217. } while (dwResumeHandle != 0);
  218. m_lbAvailableGroups.SetCurSel(0);
  219. // set caption text
  220. CString csTemp;
  221. csTemp.LoadString(IDS_GROUP_CAPTION);
  222. CString csTemp2;
  223. csTemp2.Format(csTemp, pApp->m_csUserName);
  224. m_csCaption = csTemp2;
  225. UpdateData(FALSE);
  226. }
  227. void CGroupInfo::OnDblclkGroupAvailableList()
  228. {
  229. UpdateData(TRUE);
  230. USHORT usSel = m_lbAvailableGroups.GetCurSel();
  231. CString csSel;
  232. m_lbAvailableGroups.GetText(usSel, csSel);
  233. USHORT usBmp = m_lbAvailableGroups.GetBitmapID(usSel);
  234. m_lbSelectedGroups.AddString(csSel, usBmp);
  235. m_lbAvailableGroups.DeleteString(usSel);
  236. // anybody left?
  237. if (m_lbAvailableGroups.GetCount() != 0)
  238. m_lbAvailableGroups.SetCurSel(0);
  239. else
  240. {
  241. m_lbSelectedGroups.SetCurSel(0);
  242. GetDlgItem(IDC_REMOVE_BUTTON)->EnableWindow(TRUE);
  243. GetDlgItem(IDC_ADD_BUTTON)->EnableWindow(FALSE);
  244. m_lbAvailableGroups.SetHorizontalExtent(0);
  245. }
  246. }
  247. void CGroupInfo::OnDblclkGroupMemberList()
  248. {
  249. UpdateData(TRUE);
  250. USHORT usSel = m_lbSelectedGroups.GetCurSel();
  251. CString csSel;
  252. m_lbSelectedGroups.GetText(usSel, csSel);
  253. USHORT usBmp = m_lbSelectedGroups.GetBitmapID(usSel);
  254. m_lbAvailableGroups.AddString(csSel, usBmp);
  255. m_lbSelectedGroups.DeleteString(usSel);
  256. // anybody left?
  257. if (m_lbSelectedGroups.GetCount() != 0)
  258. m_lbSelectedGroups.SetCurSel(0);
  259. else
  260. {
  261. m_lbAvailableGroups.SetCurSel(0);
  262. GetDlgItem(IDC_ADD_BUTTON)->EnableWindow(TRUE);
  263. GetDlgItem(IDC_REMOVE_BUTTON)->EnableWindow(FALSE);
  264. m_lbSelectedGroups.SetHorizontalExtent(0);
  265. }
  266. }