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.

425 lines
13 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: filetransferpage.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. // FileTransferPage.cpp : implementation file
  11. //
  12. #include "precomp.hxx"
  13. #include "filetransferpage.h"
  14. #include "debug.h"
  15. #ifdef _DEBUG
  16. #define new DEBUG_NEW
  17. #undef THIS_FILE
  18. static char THIS_FILE[] = __FILE__;
  19. #endif
  20. const DWORD g_FileTransferHelp[] = {
  21. IDC_DISPLAYTRAY, IDH_DISPLAYTRAY,
  22. IDC_SENDFILESGROUP, IDH_DISABLEHELP,
  23. IDC_ALLOWSEND, IDH_ALLOWSEND,
  24. IDC_DISPLAYRECV, IDH_DISPLAYRECV,
  25. IDC_LOCATIONTITLE, IDH_LOCATIONTITLE,
  26. IDC_RECEIVEDFILESLOCATION, IDH_RECEIVEDFILESLOCATION,
  27. IDC_CHOOSEFILELOCATION, IDH_CHOOSEFILELOCATION,
  28. IDC_SOUND, IDH_PLAYSOUND,
  29. 0, 0
  30. };
  31. /////////////////////////////////////////////////////////////////////////////
  32. // FileTransferPage property page
  33. void FileTransferPage::OnCommand(UINT ctrlId, HWND hwndCtrl, UINT cNotify)
  34. {
  35. IRINFO((_T("FileTransferPage::OnCommand")));
  36. switch (ctrlId) {
  37. case IDC_ALLOWSEND:
  38. OnAllowsend();
  39. break;
  40. case IDC_DISPLAYRECV:
  41. OnDisplayrecv();
  42. break;
  43. case IDC_DISPLAYTRAY:
  44. OnDisplaytray();
  45. break;
  46. case IDC_CHOOSEFILELOCATION:
  47. OnChoosefilelocation();
  48. break;
  49. case IDC_SOUND:
  50. OnPlaySound();
  51. break;
  52. }
  53. }
  54. INT_PTR FileTransferPage::OnNotify(NMHDR * nmhdr)
  55. {
  56. switch (nmhdr->code)
  57. {
  58. case NM_CLICK:
  59. switch (nmhdr->idFrom)
  60. {
  61. case IDC_NETWORKCONNECTIONS_LINK:
  62. return OnNetworkConnectionsLink();
  63. }
  64. break;
  65. }
  66. return PropertyPage::OnNotify(nmhdr);
  67. }
  68. /////////////////////////////////////////////////////////////////////////////
  69. // Opens the Network Connections Folder
  70. BOOL FileTransferPage::OnNetworkConnectionsLink()
  71. {
  72. // This is: ::{CLSID_MyComputer}\::{CLSID_ControlPanel}\::{CLSID_NetworkConnections}
  73. if (ShellExecute(NULL, NULL, L"::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{7007ACC7-3202-11D1-AAD2-00805FC1270E}", L"", NULL, SW_SHOWNORMAL) > reinterpret_cast<HINSTANCE>(32))
  74. {
  75. return TRUE;
  76. }
  77. else
  78. {
  79. return FALSE;
  80. }
  81. }
  82. /////////////////////////////////////////////////////////////////////////////
  83. // FileTransferPage message handlers
  84. void FileTransferPage::OnAllowsend()
  85. {
  86. int AllowSend = m_cbAllowSend.GetCheck();
  87. if (AllowSend != m_fAllowSend)
  88. m_ChangeMask |= CHANGE_ALLOW_FILE_XFER;
  89. else
  90. m_ChangeMask &= ~(CHANGE_ALLOW_FILE_XFER);
  91. SetModified(m_ChangeMask);
  92. }
  93. void FileTransferPage::OnDisplayrecv()
  94. {
  95. int DisplayRecv = m_cbDisplayRecv.GetCheck();
  96. if (DisplayRecv != m_fDisplayRecv)
  97. m_ChangeMask |= CHANGE_NOTIFY_ON_FILE_XFER;
  98. else
  99. m_ChangeMask &= ~(CHANGE_NOTIFY_ON_FILE_XFER);
  100. SetModified(m_ChangeMask);
  101. }
  102. void FileTransferPage::OnDisplaytray()
  103. {
  104. int DisplayIcon = m_cbDisplayTray.GetCheck();
  105. if (DisplayIcon != m_fDisplayTray)
  106. m_ChangeMask |= CHANGE_DISPLAY_ICON;
  107. else
  108. m_ChangeMask &= ~(CHANGE_DISPLAY_ICON);
  109. SetModified(m_ChangeMask);
  110. }
  111. void FileTransferPage::OnPlaySound()
  112. {
  113. int NewState = m_cbPlaySound.GetCheck();
  114. if (NewState != m_fPlaySound)
  115. m_ChangeMask |= CHANGE_PLAY_SOUND;
  116. else
  117. m_ChangeMask &= ~(CHANGE_PLAY_SOUND);
  118. SetModified(m_ChangeMask);
  119. }
  120. INT_PTR FileTransferPage::OnInitDialog(HWND hwndDlg)
  121. {
  122. PropertyPage::OnInitDialog(hwndDlg);
  123. m_recvdFilesLocation.SetParent(hwndDlg);
  124. m_cbDisplayTray.SetParent(hwndDlg);
  125. m_cbDisplayRecv.SetParent(hwndDlg);
  126. m_cbAllowSend.SetParent(hwndDlg);
  127. m_cbPlaySound.SetParent(hwndDlg);
  128. IRINFO((_T("FileTransferPage::OnInitDialog")));
  129. LoadRegistrySettings();
  130. m_cbAllowSend.SetCheck(m_fAllowSend);
  131. m_cbDisplayRecv.SetCheck(m_fDisplayRecv);
  132. m_cbDisplayTray.SetCheck(m_fDisplayTray);
  133. m_recvdFilesLocation.SetWindowText(m_FinalDestLocation);
  134. m_cbPlaySound.SetCheck(m_fPlaySound);
  135. return TRUE; // return TRUE unless you set the focus to a control
  136. // EXCEPTION: OCX Property Pages should return FALSE
  137. }
  138. void FileTransferPage::LoadRegistrySettings(void)
  139. {
  140. HKEY hIrKey = NULL;
  141. HKEY hftKey = NULL;
  142. DWORD iSize = sizeof(DWORD);
  143. DWORD data = 0;
  144. TCHAR szReceivedFilesLocation[MAX_PATH];
  145. IRINFO((_T("FileTransferPage::LoadRegistrySettings")));
  146. RegOpenKeyEx (HKEY_CURRENT_USER, TEXT("Control Panel\\Infrared\\File Transfer"),
  147. 0, KEY_READ, &hftKey);
  148. RegOpenKeyEx (HKEY_CURRENT_USER, TEXT("Control Panel\\Infrared\\Global"),
  149. 0, KEY_READ, &hIrKey);
  150. if (!hIrKey && !hftKey)
  151. return;
  152. if (hIrKey) {
  153. if (ERROR_SUCCESS ==
  154. RegQueryValueEx (hIrKey, TEXT("ShowTrayIcon"), NULL, NULL,
  155. (LPBYTE)&data, &iSize))
  156. m_fDisplayTray = data?TRUE:FALSE;
  157. iSize=sizeof(data);
  158. if (ERROR_SUCCESS ==
  159. RegQueryValueEx (hIrKey, TEXT("PlaySound"), NULL, NULL,
  160. (LPBYTE)&data, &iSize))
  161. m_fPlaySound = data?TRUE:FALSE;
  162. }
  163. iSize=sizeof(data);
  164. if (hftKey && ERROR_SUCCESS ==
  165. RegQueryValueEx (hftKey, TEXT("AllowSend"), NULL, NULL,
  166. (LPBYTE)&data, &iSize))
  167. m_fAllowSend = data?TRUE:FALSE;
  168. iSize=sizeof(data);
  169. if (hftKey && ERROR_SUCCESS ==
  170. RegQueryValueEx (hftKey, TEXT("ShowRecvStatus"), NULL, NULL,
  171. (LPBYTE)&data, &iSize))
  172. m_fDisplayRecv = data?TRUE:FALSE;
  173. // If the destionation location is not specified,
  174. // use the default(Desktop subfolder).
  175. // Create it if necessary.
  176. SHGetSpecialFolderPath (hDlg, m_FinalDestLocation,
  177. CSIDL_DESKTOPDIRECTORY, 0);
  178. iSize = MAX_PATH * sizeof (TCHAR);
  179. if (hftKey != NULL) {
  180. DWORD Result;
  181. Result=RegQueryValueEx (hftKey, TEXT("RecvdFilesLocation"), NULL,
  182. NULL, (LPBYTE)&szReceivedFilesLocation[0], &iSize);
  183. if (Result == ERROR_SUCCESS) {
  184. DWORD Attributes;
  185. Attributes=GetFileAttributes(szReceivedFilesLocation);
  186. if ((Attributes != INVALID_FILE_ATTRIBUTES) && (Attributes & FILE_ATTRIBUTE_DIRECTORY)) {
  187. StringCbCopy(m_FinalDestLocation,sizeof(m_FinalDestLocation),szReceivedFilesLocation);
  188. }
  189. }
  190. }
  191. //
  192. // m_TempDestLocation will be used as the intial
  193. // folder of choice for SHBrowseForFolder call.
  194. //
  195. StringCbCopy(m_TempDestLocation,sizeof(m_TempDestLocation), m_FinalDestLocation);
  196. if (hIrKey)
  197. RegCloseKey(hIrKey);
  198. if (hftKey)
  199. RegCloseKey(hftKey);
  200. }
  201. void FileTransferPage::SaveSettingsToRegistry(void)
  202. {
  203. HKEY hIrKey = NULL;
  204. HKEY hftKey = NULL;
  205. DWORD dwDisposition;
  206. IRINFO((_T("FileTransferPage::SaveSettingsToRegistry")));
  207. RegCreateKeyEx (HKEY_CURRENT_USER, TEXT("Control Panel\\Infrared\\File Transfer"),
  208. 0, TEXT(""), REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS,
  209. NULL, &hftKey, &dwDisposition);
  210. RegCreateKeyEx (HKEY_CURRENT_USER, TEXT("Control Panel\\Infrared\\Global"),
  211. 0, TEXT(""), REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS,
  212. NULL, &hIrKey, &dwDisposition);
  213. if (hIrKey)
  214. {
  215. RegSetValueEx(hIrKey, TEXT("ShowTrayIcon"), 0, REG_BINARY,
  216. (CONST BYTE*)&m_fDisplayTray, 1);
  217. RegSetValueEx(hIrKey, TEXT("PlaySound"), 0, REG_BINARY,
  218. (CONST BYTE*)&m_fPlaySound, 1);
  219. RegCloseKey(hIrKey);
  220. }
  221. if (hftKey)
  222. {
  223. RegSetValueEx(hftKey, TEXT("AllowSend"), 0, REG_BINARY,
  224. (CONST BYTE*)&m_fAllowSend, 1);
  225. RegSetValueEx(hftKey, TEXT("ShowRecvStatus"), 0, REG_BINARY,
  226. (CONST BYTE*)&m_fDisplayRecv, 1);
  227. RegSetValueEx(hftKey, TEXT("RecvdFilesLocation"), 0, REG_SZ,
  228. (CONST BYTE*)&m_FinalDestLocation, sizeof(TCHAR)*lstrlen(m_FinalDestLocation));
  229. RegCloseKey(hftKey);
  230. }
  231. }
  232. int CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData)
  233. {
  234. WPARAM sendWParam;
  235. LPARAM sendLParam;
  236. LPCTSTR lpszFilesLocation;
  237. TCHAR szErrorMsg[MAX_PATH];
  238. TCHAR szErrorTitle[MAX_PATH];
  239. HINSTANCE hInstanceRes;
  240. IRINFO((_T("FileTransferPage::BrowseCallbackProc")));
  241. switch (uMsg)
  242. {
  243. case BFFM_INITIALIZED:
  244. lpszFilesLocation = (LPCTSTR)lpData;
  245. sendWParam = TRUE;
  246. sendLParam = (LPARAM)lpszFilesLocation;
  247. SendMessage(hwnd, BFFM_SETSELECTION, sendWParam, sendLParam);
  248. break;
  249. case BFFM_VALIDATEFAILED:
  250. hInstanceRes = gHInst;
  251. ::LoadString (hInstanceRes, IDS_INVALID_MSG, szErrorMsg, MAX_PATH);
  252. ::LoadString (hInstanceRes, IDS_INVALID_TITLE, szErrorTitle, MAX_PATH);
  253. ::MessageBox (hwnd, szErrorMsg, szErrorTitle, MB_OK | MB_ICONSTOP);
  254. return 1;
  255. default:
  256. break;
  257. }
  258. return 0;
  259. }
  260. void FileTransferPage::OnChoosefilelocation()
  261. {
  262. BROWSEINFO browseInfo;
  263. TCHAR pszSelectedFolder[MAX_PATH];
  264. LPITEMIDLIST lpItemIDList;
  265. LPMALLOC pMalloc;
  266. TCHAR szBrowseTitle [MAX_PATH];
  267. IRINFO((_T("FileTransferPage::OnChoosefileLocation")));
  268. //load the title
  269. ::LoadString (hInstance, IDS_FILEFOLDER_PROMPT,
  270. szBrowseTitle, MAX_PATH);
  271. browseInfo.hwndOwner = hDlg;
  272. browseInfo.pidlRoot = NULL; //this will get the desktop folder
  273. browseInfo.pszDisplayName = pszSelectedFolder;
  274. browseInfo.lpszTitle = szBrowseTitle;
  275. browseInfo.ulFlags = BIF_RETURNONLYFSDIRS | BIF_RETURNFSANCESTORS |
  276. BIF_VALIDATE | BIF_EDITBOX;
  277. browseInfo.lpfn = BrowseCallback;
  278. browseInfo.lParam = (LPARAM)m_TempDestLocation;
  279. if (NULL != (lpItemIDList = SHBrowseForFolder (&browseInfo)))
  280. {
  281. //
  282. // the user chose the OK button in the browse dialog box
  283. //
  284. HRESULT hr;
  285. SHGetPathFromIDList(lpItemIDList, pszSelectedFolder);
  286. StringCbCopy(m_TempDestLocation, sizeof(m_TempDestLocation),pszSelectedFolder);
  287. m_recvdFilesLocation.SetWindowText(m_TempDestLocation);
  288. if (lstrcmpi(m_TempDestLocation, m_FinalDestLocation))
  289. m_ChangeMask |= CHANGE_FILE_LOCATION;
  290. else
  291. m_ChangeMask &= ~(CHANGE_FILE_LOCATION);
  292. SetModified(m_ChangeMask);
  293. hr=SHGetMalloc(&pMalloc);
  294. if (SUCCEEDED(hr)) {
  295. pMalloc->Free (lpItemIDList); //free the item id list as we do not need it any more
  296. pMalloc->Release();
  297. }
  298. }
  299. }
  300. void FileTransferPage::OnApply(LPPSHNOTIFY lppsn)
  301. {
  302. IRINFO((_T("FileTransferPage::OnApply")));
  303. if (m_ChangeMask)
  304. {
  305. if (m_ChangeMask & CHANGE_FILE_LOCATION)
  306. StringCbCopy(m_FinalDestLocation,sizeof(m_FinalDestLocation), m_TempDestLocation);
  307. if (m_ChangeMask & CHANGE_ALLOW_FILE_XFER)
  308. m_fAllowSend = m_cbAllowSend.GetCheck();
  309. if (m_ChangeMask & CHANGE_NOTIFY_ON_FILE_XFER)
  310. m_fDisplayRecv = m_cbDisplayRecv.GetCheck();
  311. if (m_ChangeMask & CHANGE_DISPLAY_ICON)
  312. m_fDisplayTray = m_cbDisplayTray.GetCheck();
  313. if (m_ChangeMask & CHANGE_PLAY_SOUND)
  314. m_fPlaySound = m_cbPlaySound.GetCheck();
  315. SaveSettingsToRegistry();
  316. m_ChangeMask = 0;
  317. }
  318. PropertyPage::OnApply(lppsn);
  319. }
  320. BOOL FileTransferPage::OnHelp (LPHELPINFO pHelpInfo)
  321. {
  322. TCHAR szHelpFile[MAX_PATH];
  323. IRINFO((_T("FileTransferPage::OnHelp")));
  324. ::LoadString(hInstance, IDS_HELP_FILE, szHelpFile, MAX_PATH);
  325. ::WinHelp((HWND)(pHelpInfo->hItemHandle),
  326. (LPCTSTR) szHelpFile,
  327. HELP_WM_HELP,
  328. (ULONG_PTR)(LPTSTR)g_FileTransferHelp);
  329. return FALSE;
  330. }
  331. BOOL FileTransferPage::OnContextMenu (WPARAM wParam, LPARAM lParam)
  332. {
  333. TCHAR szHelpFile[MAX_PATH];
  334. IRINFO((_T("FileTransferPage::OnContextMenu")));
  335. ::LoadString(hInstance, IDS_HELP_FILE, szHelpFile, MAX_PATH);
  336. ::WinHelp((HWND) wParam,
  337. (LPCTSTR) szHelpFile,
  338. HELP_CONTEXTMENU,
  339. (ULONG_PTR)(LPVOID)g_FileTransferHelp);
  340. return FALSE;
  341. }