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.

297 lines
6.9 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: rasui.cpp
  7. //
  8. // Contents: helper functions for showing Ras UI
  9. //
  10. // Classes:
  11. //
  12. // Notes:
  13. //
  14. // History: 08-Dec-97 rogerg Created.
  15. //
  16. //--------------------------------------------------------------------------
  17. #include "precomp.h"
  18. extern TCHAR szSyncMgrHelp[];
  19. extern ULONG g_aContextHelpIds[];
  20. extern HINSTANCE g_hmodThisDll;
  21. //+---------------------------------------------------------------------------
  22. //
  23. // Member: CRasUI::CRasUI, public
  24. //
  25. // Synopsis:
  26. //
  27. // Arguments:
  28. //
  29. // Returns:
  30. //
  31. // Modifies:
  32. //
  33. // History: 08-Nov-97 rogerg Created.
  34. //
  35. //----------------------------------------------------------------------------
  36. CRasUI::CRasUI()
  37. {
  38. m_pNetApi = NULL;
  39. m_cEntries = 0;
  40. m_lprasentry = 0;
  41. }
  42. //+---------------------------------------------------------------------------
  43. //
  44. // Member: CRasUI::~CRasUI, public
  45. //
  46. // Synopsis:
  47. //
  48. // Arguments:
  49. //
  50. // Returns:
  51. //
  52. // Modifies:
  53. //
  54. // History: 08-Nov-97 rogerg Created.
  55. //
  56. //----------------------------------------------------------------------------
  57. CRasUI::~CRasUI()
  58. {
  59. // clear out any cached enum
  60. m_cEntries = 0; // make sure on error our enum cash is reset.
  61. if (m_lprasentry)
  62. {
  63. FREE(m_lprasentry);
  64. m_lprasentry = NULL;
  65. }
  66. m_pNetApi->Release();
  67. }
  68. //+---------------------------------------------------------------------------
  69. //
  70. // Member: CRasUI::Initialize, public
  71. //
  72. // Synopsis:
  73. //
  74. // Arguments:
  75. //
  76. // Returns:
  77. //
  78. // Modifies:
  79. //
  80. // History: 08-Nov-97 rogerg Created.
  81. //
  82. //----------------------------------------------------------------------------
  83. BOOL CRasUI::Initialize()
  84. {
  85. if (NOERROR != MobsyncGetClassObject(MOBSYNC_CLASSOBJECTID_NETAPI,
  86. (void **) &m_pNetApi))
  87. {
  88. m_pNetApi = NULL;
  89. }
  90. return TRUE; // always return true, let other ras calls fail since need
  91. // to handle LAN.
  92. }
  93. //+---------------------------------------------------------------------------
  94. //
  95. // Member: CRasUI::IsConnectionLan, public
  96. //
  97. // Synopsis:
  98. //
  99. // Arguments:
  100. //
  101. // Returns:
  102. //
  103. // Modifies:
  104. //
  105. // History: 08-Nov-97 rogerg Created.
  106. //
  107. //----------------------------------------------------------------------------
  108. BOOL CRasUI::IsConnectionLan(int iConnectionNum)
  109. {
  110. // ui always puts the LAN connection as the first item
  111. // Need to add logic to get if truly lan if add support
  112. // for multiple LAN cards and/or not show if no LAN
  113. // card.
  114. if (iConnectionNum ==0)
  115. {
  116. return TRUE;
  117. }
  118. else
  119. {
  120. return FALSE;
  121. }
  122. }
  123. //+---------------------------------------------------------------------------
  124. //
  125. // Member: CRasUI::FillRasCombo, public
  126. //
  127. // Synopsis:
  128. //
  129. // Arguments: hwndCtrl - Combo Ctrl to fill items with
  130. // fForceEnum - reenum rasphonebook instead of using cache
  131. // fShowRasEntries - true if should include ras entries
  132. // in combo, if false, only LAN Connection is shown.
  133. //
  134. // Returns:
  135. //
  136. // Modifies:
  137. //
  138. // History: 08-Nov-97 rogerg Created.
  139. //
  140. //----------------------------------------------------------------------------
  141. void CRasUI::FillRasCombo(HWND hwndCtl,BOOL fForceEnum,BOOL fShowRasEntries)
  142. {
  143. DWORD dwSize;
  144. DWORD dwError;
  145. COMBOBOXEXITEM comboItem;
  146. DWORD cEntryIndex;
  147. int iItem = 0;
  148. HIMAGELIST himage;
  149. HICON hIcon;
  150. TCHAR szBuf[MAX_PATH + 1];
  151. UINT ImageListflags;
  152. ImageListflags = ILC_COLOR | ILC_MASK;
  153. if (IsHwndRightToLeft(hwndCtl))
  154. {
  155. ImageListflags |= ILC_MIRROR;
  156. }
  157. himage = ImageList_Create(16,16,ImageListflags ,5,20);
  158. if (himage)
  159. {
  160. SendMessage(hwndCtl,CBEM_SETIMAGELIST,0,(LPARAM) himage);
  161. }
  162. if (LoadString(g_hmodThisDll, IDS_LAN_CONNECTION, szBuf, MAX_PATH))
  163. {
  164. hIcon = LoadIcon(g_hmodThisDll,MAKEINTRESOURCE(IDI_LANCONNECTION));
  165. comboItem.iImage = ImageList_AddIcon(himage,hIcon);
  166. comboItem.mask = CBEIF_TEXT | CBEIF_IMAGE | CBEIF_LPARAM | CBEIF_INDENT
  167. | CBEIF_SELECTEDIMAGE;
  168. comboItem.iItem = iItem;
  169. comboItem.pszText = szBuf;
  170. comboItem.cchTextMax = lstrlen(szBuf) + 1;
  171. comboItem.iIndent = 0;
  172. comboItem.iSelectedImage = comboItem.iImage;
  173. comboItem.lParam = SYNCSCHEDINFO_FLAGS_CONNECTION_LAN;
  174. iItem = ComboEx_InsertItem(hwndCtl,&comboItem);
  175. ++iItem;
  176. }
  177. dwError = 0; // if dont' show ras there are now errors
  178. if (fShowRasEntries)
  179. {
  180. // if we are forced to reenum the Rasconnections then free any existing cache
  181. if (fForceEnum)
  182. {
  183. m_cEntries = 0;
  184. if (m_lprasentry)
  185. {
  186. FREE(m_lprasentry);
  187. m_lprasentry = NULL;
  188. }
  189. }
  190. // if RAS couldn't be loaded, just have LAN connection.
  191. if (NULL == m_lprasentry) // if don't already have an enum cached then enum now.
  192. {
  193. dwSize = sizeof(RASENTRYNAME);
  194. m_lprasentry = (LPRASENTRYNAME) ALLOC(dwSize);
  195. if(!m_lprasentry)
  196. goto error;
  197. m_lprasentry->dwSize = sizeof(RASENTRYNAME);
  198. m_cEntries = 0;
  199. dwError = m_pNetApi->RasEnumEntries(NULL, NULL,
  200. m_lprasentry, &dwSize, &m_cEntries);
  201. if (dwError == ERROR_BUFFER_TOO_SMALL)
  202. {
  203. FREE(m_lprasentry);
  204. m_lprasentry = (LPRASENTRYNAME) ALLOC(dwSize);
  205. if(!m_lprasentry)
  206. goto error;
  207. m_lprasentry->dwSize = sizeof(RASENTRYNAME);
  208. m_cEntries = 0;
  209. dwError = m_pNetApi->RasEnumEntries(NULL, NULL,
  210. m_lprasentry, &dwSize, &m_cEntries);
  211. Assert(0 == dwError);
  212. }
  213. if (dwError)
  214. goto error;
  215. }
  216. cEntryIndex = m_cEntries;
  217. comboItem.mask = CBEIF_DI_SETITEM | CBEIF_TEXT | CBEIF_IMAGE | CBEIF_LPARAM | CBEIF_INDENT
  218. | CBEIF_SELECTEDIMAGE ;
  219. hIcon = LoadIcon(g_hmodThisDll,MAKEINTRESOURCE(IDI_RASCONNECTION));
  220. comboItem.iImage = ImageList_AddIcon(himage,hIcon);
  221. comboItem.iItem = iItem;
  222. comboItem.iIndent = 0;
  223. comboItem.iSelectedImage = comboItem.iImage;
  224. comboItem.lParam = SYNCSCHEDINFO_FLAGS_CONNECTION_WAN;
  225. while(cEntryIndex)
  226. {
  227. comboItem.pszText = m_lprasentry[cEntryIndex-1].szEntryName;
  228. iItem = ComboEx_InsertItem(hwndCtl,&comboItem);
  229. cEntryIndex--;
  230. }
  231. }
  232. error:
  233. SendMessage(hwndCtl, CB_SETCURSEL,0, 0);
  234. if (dwError)
  235. {
  236. m_cEntries = 0; // make sure on error our enum cash is reset.
  237. if (m_lprasentry)
  238. {
  239. FREE(m_lprasentry);
  240. m_lprasentry = NULL;
  241. }
  242. }
  243. }