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.

400 lines
12 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 lpszReceivedFilesLocation[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 && ERROR_SUCCESS ==
  180. RegQueryValueEx (hftKey, TEXT("RecvdFilesLocation"), NULL,
  181. NULL, (LPBYTE)lpszReceivedFilesLocation, &iSize))
  182. lstrcpy(m_FinalDestLocation, lpszReceivedFilesLocation);
  183. //
  184. // m_TempDestLocation will be used as the intial
  185. // folder of choice for SHBrowseForFolder call.
  186. //
  187. lstrcpy(m_TempDestLocation, m_FinalDestLocation);
  188. if (hIrKey)
  189. RegCloseKey(hIrKey);
  190. if (hftKey)
  191. RegCloseKey(hftKey);
  192. }
  193. void FileTransferPage::SaveSettingsToRegistry(void)
  194. {
  195. HKEY hIrKey = NULL;
  196. HKEY hftKey = NULL;
  197. DWORD dwDisposition;
  198. IRINFO((_T("FileTransferPage::SaveSettingsToRegistry")));
  199. RegCreateKeyEx (HKEY_CURRENT_USER, TEXT("Control Panel\\Infrared\\File Transfer"),
  200. 0, TEXT(""), REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS,
  201. NULL, &hftKey, &dwDisposition);
  202. RegCreateKeyEx (HKEY_CURRENT_USER, TEXT("Control Panel\\Infrared\\Global"),
  203. 0, TEXT(""), REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS,
  204. NULL, &hIrKey, &dwDisposition);
  205. if (hIrKey)
  206. {
  207. RegSetValueEx(hIrKey, TEXT("ShowTrayIcon"), 0, REG_BINARY,
  208. (CONST BYTE*)&m_fDisplayTray, 1);
  209. RegSetValueEx(hIrKey, TEXT("PlaySound"), 0, REG_BINARY,
  210. (CONST BYTE*)&m_fPlaySound, 1);
  211. RegCloseKey(hIrKey);
  212. }
  213. if (hftKey)
  214. {
  215. RegSetValueEx(hftKey, TEXT("AllowSend"), 0, REG_BINARY,
  216. (CONST BYTE*)&m_fAllowSend, 1);
  217. RegSetValueEx(hftKey, TEXT("ShowRecvStatus"), 0, REG_BINARY,
  218. (CONST BYTE*)&m_fDisplayRecv, 1);
  219. RegSetValueEx(hftKey, TEXT("RecvdFilesLocation"), 0, REG_SZ,
  220. (CONST BYTE*)&m_FinalDestLocation, sizeof(TCHAR)*lstrlen(m_FinalDestLocation));
  221. RegCloseKey(hftKey);
  222. }
  223. }
  224. int CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData)
  225. {
  226. WPARAM sendWParam;
  227. LPARAM sendLParam;
  228. LPCTSTR lpszFilesLocation;
  229. TCHAR szErrorMsg[MAX_PATH];
  230. TCHAR szErrorTitle[MAX_PATH];
  231. HINSTANCE hInstanceRes;
  232. IRINFO((_T("FileTransferPage::BrowseCallbackProc")));
  233. switch (uMsg)
  234. {
  235. case BFFM_INITIALIZED:
  236. lpszFilesLocation = (LPCTSTR)lpData;
  237. sendWParam = TRUE;
  238. sendLParam = (LPARAM)lpszFilesLocation;
  239. SendMessage(hwnd, BFFM_SETSELECTION, sendWParam, sendLParam);
  240. break;
  241. case BFFM_VALIDATEFAILED:
  242. hInstanceRes = gHInst;
  243. ::LoadString (hInstanceRes, IDS_INVALID_MSG, szErrorMsg, MAX_PATH);
  244. ::LoadString (hInstanceRes, IDS_INVALID_TITLE, szErrorTitle, MAX_PATH);
  245. ::MessageBox (hwnd, szErrorMsg, szErrorTitle, MB_OK | MB_ICONSTOP);
  246. return 1;
  247. default:
  248. break;
  249. }
  250. return 0;
  251. }
  252. void FileTransferPage::OnChoosefilelocation()
  253. {
  254. BROWSEINFO browseInfo;
  255. TCHAR pszSelectedFolder[MAX_PATH];
  256. LPITEMIDLIST lpItemIDList;
  257. LPMALLOC pMalloc;
  258. TCHAR szBrowseTitle [MAX_PATH];
  259. IRINFO((_T("FileTransferPage::OnChoosefileLocation")));
  260. //load the title
  261. ::LoadString (hInstance, IDS_FILEFOLDER_PROMPT,
  262. szBrowseTitle, MAX_PATH);
  263. browseInfo.hwndOwner = hDlg;
  264. browseInfo.pidlRoot = NULL; //this will get the desktop folder
  265. browseInfo.pszDisplayName = pszSelectedFolder;
  266. browseInfo.lpszTitle = szBrowseTitle;
  267. browseInfo.ulFlags = BIF_RETURNONLYFSDIRS | BIF_RETURNFSANCESTORS |
  268. BIF_VALIDATE | BIF_EDITBOX;
  269. browseInfo.lpfn = BrowseCallback;
  270. browseInfo.lParam = (LPARAM)m_TempDestLocation;
  271. if (NULL != (lpItemIDList = SHBrowseForFolder (&browseInfo)))
  272. {
  273. //the user chose the OK button in the browse dialog box
  274. SHGetPathFromIDList(lpItemIDList, pszSelectedFolder);
  275. lstrcpy (m_TempDestLocation, pszSelectedFolder);
  276. m_recvdFilesLocation.SetWindowText(m_TempDestLocation);
  277. if (lstrcmpi(m_TempDestLocation, m_FinalDestLocation))
  278. m_ChangeMask |= CHANGE_FILE_LOCATION;
  279. else
  280. m_ChangeMask &= ~(CHANGE_FILE_LOCATION);
  281. SetModified(m_ChangeMask);
  282. SHGetMalloc(&pMalloc);
  283. pMalloc->Free (lpItemIDList); //free the item id list as we do not need it any more
  284. pMalloc->Release();
  285. }
  286. }
  287. void FileTransferPage::OnApply(LPPSHNOTIFY lppsn)
  288. {
  289. IRINFO((_T("FileTransferPage::OnApply")));
  290. if (m_ChangeMask)
  291. {
  292. if (m_ChangeMask & CHANGE_FILE_LOCATION)
  293. lstrcpy(m_FinalDestLocation, m_TempDestLocation);
  294. if (m_ChangeMask & CHANGE_ALLOW_FILE_XFER)
  295. m_fAllowSend = m_cbAllowSend.GetCheck();
  296. if (m_ChangeMask & CHANGE_NOTIFY_ON_FILE_XFER)
  297. m_fDisplayRecv = m_cbDisplayRecv.GetCheck();
  298. if (m_ChangeMask & CHANGE_DISPLAY_ICON)
  299. m_fDisplayTray = m_cbDisplayTray.GetCheck();
  300. if (m_ChangeMask & CHANGE_PLAY_SOUND)
  301. m_fPlaySound = m_cbPlaySound.GetCheck();
  302. SaveSettingsToRegistry();
  303. m_ChangeMask = 0;
  304. }
  305. PropertyPage::OnApply(lppsn);
  306. }
  307. BOOL FileTransferPage::OnHelp (LPHELPINFO pHelpInfo)
  308. {
  309. TCHAR szHelpFile[MAX_PATH];
  310. IRINFO((_T("FileTransferPage::OnHelp")));
  311. ::LoadString(hInstance, IDS_HELP_FILE, szHelpFile, MAX_PATH);
  312. ::WinHelp((HWND)(pHelpInfo->hItemHandle),
  313. (LPCTSTR) szHelpFile,
  314. HELP_WM_HELP,
  315. (ULONG_PTR)(LPTSTR)g_FileTransferHelp);
  316. return FALSE;
  317. }
  318. BOOL FileTransferPage::OnContextMenu (WPARAM wParam, LPARAM lParam)
  319. {
  320. TCHAR szHelpFile[MAX_PATH];
  321. IRINFO((_T("FileTransferPage::OnContextMenu")));
  322. ::LoadString(hInstance, IDS_HELP_FILE, szHelpFile, MAX_PATH);
  323. ::WinHelp((HWND) wParam,
  324. (LPCTSTR) szHelpFile,
  325. HELP_CONTEXTMENU,
  326. (ULONG_PTR)(LPVOID)g_FileTransferHelp);
  327. return FALSE;
  328. }