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.

153 lines
4.7 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999 - 1999
  6. //
  7. // File: svfildlg.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. // svfildlg.cpp : implSELECTEDementation file
  11. //
  12. #include "stdafx.h"
  13. #ifdef IMPLEMENT_LIST_SAVE // See nodemgr.idl (t-dmarm)
  14. #include "svfildlg.h"
  15. #include <shlobj.h>
  16. #include "AMC.h"
  17. #include "AMCDoc.h"
  18. #include "Shlwapi.h"
  19. #include <windows.h>
  20. #include "macros.h"
  21. // The following constant is defined in Windows.hlp
  22. // So we need to use windows.hlp for help on this topic.
  23. #define IDH_SAVE_SELECTED_ROWS 29520
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CSaveFileDialog dialog
  26. const TCHAR CSaveFileDialog::strSection[] = _T("Settings");
  27. const TCHAR CSaveFileDialog::strStringItem[] = _T("List Save Location");
  28. CSaveFileDialog::CSaveFileDialog(BOOL bOpenFileDialog,
  29. LPCTSTR lpszDefExt, LPCTSTR lpszFileName, DWORD dwFlags,
  30. LPCTSTR lpszFilter, bool bSomeRowSelected, CWnd* pParentWnd)
  31. : CFileDialogEx(bOpenFileDialog, lpszDefExt, lpszFileName,
  32. dwFlags, lpszFilter, pParentWnd), m_bSomeRowSelected(bSomeRowSelected)
  33. {
  34. //{{AFX_DATA_INIT(CSaveFileDialog)
  35. // NOTE: the ClassWizard will add member initialization here
  36. //}}AFX_DATA_INIT
  37. m_ofn.lpstrInitialDir = NULL;
  38. // Set the initial path
  39. // 1st choice
  40. // Try to access the default directory in the registry
  41. CWinApp* pApp = AfxGetApp();
  42. m_strRegPath = pApp->GetProfileString (strSection, strStringItem);
  43. // Check if the directory is valid, if so then it is now the starting directory
  44. DWORD validdir = GetFileAttributes(m_strRegPath);
  45. if ((validdir != 0xFFFFFFFF) && (validdir | FILE_ATTRIBUTE_DIRECTORY))
  46. m_ofn.lpstrInitialDir = m_strRegPath;
  47. // 2nd choice:
  48. // Set the initial save directory to the personal directory
  49. // Get the user's personal directory
  50. // We'll get it now since we'll ust it in the destructor as well
  51. LPITEMIDLIST pidl;
  52. HRESULT hres = SHGetSpecialFolderLocation(NULL, CSIDL_PERSONAL, &pidl) ;
  53. if (SUCCEEDED(hres))
  54. {
  55. SHGetPathFromIDList(pidl, szPath);
  56. // Free the pidl
  57. IMallocPtr spMalloc;
  58. SHGetMalloc(&spMalloc);
  59. spMalloc->Free(pidl);
  60. if ((m_ofn.lpstrInitialDir == NULL) && (SUCCEEDED(hres)))
  61. m_ofn.lpstrInitialDir = szPath;
  62. }
  63. // 3rd choice: The current directory (m_ofn.lpstrInitialDir = NULL; was set above)
  64. // Set additional items about the dialog box
  65. ZeroMemory(szFileName, sizeof(szFileName));
  66. m_ofn.lpstrFile = szFileName;
  67. m_ofn.nMaxFile = countof(szFileName);
  68. m_ofn.Flags |= (OFN_ENABLETEMPLATE|OFN_EXPLORER|OFN_PATHMUSTEXIST);
  69. m_ofn.lpTemplateName = MAKEINTRESOURCE(HasModernFileDialog() ? IDD_LIST_SAVE_NEW : IDD_LIST_SAVE);
  70. m_flags = 0;
  71. // Set the title of the dialog.
  72. if (LoadString(m_strTitle, IDS_EXPORT_LIST))
  73. m_ofn.lpstrTitle = (LPCTSTR)m_strTitle;
  74. }
  75. CSaveFileDialog::~CSaveFileDialog()
  76. {
  77. // Get the path of the file that was just saved
  78. if (*m_ofn.lpstrFile == '\0' || m_ofn.nFileOffset < 1)
  79. return;
  80. CString strRecentPath(m_ofn.lpstrFile, m_ofn.nFileOffset - 1);
  81. // If the personal path exists and it is different from the old path, then change or add
  82. // the registry entry
  83. if ((szPath != NULL) && (strRecentPath != m_strRegPath))
  84. AfxGetApp()->WriteProfileString (strSection, strStringItem, strRecentPath);
  85. }
  86. void CSaveFileDialog::DoDataExchange(CDataExchange* pDX)
  87. {
  88. CDialog::DoDataExchange(pDX);
  89. //{{AFX_DATA_MAP(CConsolePropPage)
  90. //{{AFX_DATA_MAP(CSaveFileDialog)
  91. // NOTE: the ClassWizard will add DDX and DDV calls here
  92. //}}AFX_DATA_MAP
  93. }
  94. BEGIN_MESSAGE_MAP(CSaveFileDialog, CDialog)
  95. //{{AFX_MSG_MAP(CSaveFileDialog)
  96. ON_BN_CLICKED(IDC_SEL, OnSel)
  97. //}}AFX_MSG_MAP
  98. ON_MESSAGE(WM_INITDIALOG, OnInitDialog)
  99. ON_MMC_CONTEXT_HELP()
  100. END_MESSAGE_MAP()
  101. /////////////////////////////////////////////////////////////////////////////
  102. // CSaveFileDialog message handlers
  103. void CSaveFileDialog::OnSel()
  104. {
  105. m_flags ^= SELECTED; // Toggle the Selected flag
  106. }
  107. LRESULT CSaveFileDialog::OnInitDialog(WPARAM, LPARAM)
  108. {
  109. DECLARE_SC (sc, _T("CSaveFileDialog::OnInitDialog"));
  110. CDialog::OnInitDialog();
  111. HWND hwndSelRowsOnly = ::GetDlgItem(*this, IDC_SEL);
  112. if (hwndSelRowsOnly)
  113. ::EnableWindow(hwndSelRowsOnly, m_bSomeRowSelected );
  114. return TRUE;
  115. }
  116. #endif // IMPLEMENT_LIST_SAVE See nodemgr.idl (t-dmarm)