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.

209 lines
4.5 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. // Copyright (c) 2002 Microsoft Corporation. All rights reserved.
  3. // Copyright (c) 2002 OSR Open Systems Resources, Inc.
  4. //
  5. // PathDlg.cpp : implementation file
  6. //////////////////////////////////////////////////////////////////////////////
  7. #include "stdafx.h"
  8. #include <direct.h>
  9. #include <dlgs.h>
  10. #include <tchar.h>
  11. #include <wmistr.h>
  12. #include <initguid.h>
  13. extern "C" {
  14. #include <evntrace.h>
  15. }
  16. #include <traceprt.h>
  17. #include "TraceView.h"
  18. #include "PathDlg.h"
  19. #ifdef _DEBUG
  20. #define new DEBUG_NEW
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CPathDlg
  26. IMPLEMENT_DYNAMIC(CPathDlg, CFileDialog)
  27. CPathDlg::CPathDlg(BOOL bOpenFileDialog,
  28. LPCTSTR lpszDefExt,
  29. LPCTSTR lpszFileName,
  30. DWORD dwFlags,
  31. LPCTSTR lpszFilter,
  32. CWnd *pParentWnd) :
  33. CFileDialog(bOpenFileDialog,
  34. lpszDefExt,
  35. lpszFileName,
  36. dwFlags |= OFN_ENABLETEMPLATE,
  37. lpszFilter,
  38. pParentWnd)
  39. {
  40. m_ofn.hInstance = AfxGetResourceHandle();
  41. m_ofn.lpTemplateName = MAKEINTRESOURCE(CPathDlg::IDD);
  42. m_ofn.Flags &= ~OFN_EXPLORER;
  43. //{{AFX_DATA_INIT(CPathDlg)
  44. //}}AFX_DATA_INIT
  45. }
  46. void CPathDlg::DoDataExchange(CDataExchange* pDX)
  47. {
  48. CDialog::DoDataExchange(pDX);
  49. //{{AFX_DATA_MAP(CPathDlg)
  50. DDX_Control(pDX, IDC_PATH_NAME_EDIT, m_PathName);
  51. //}}AFX_DATA_MAP
  52. }
  53. BEGIN_MESSAGE_MAP(CPathDlg, CFileDialog)
  54. //{{AFX_MSG_MAP(CPathDlg)
  55. ON_WM_PAINT()
  56. //}}AFX_MSG_MAP
  57. END_MESSAGE_MAP()
  58. BOOL CPathDlg::OnInitDialog()
  59. {
  60. CString str;
  61. CenterWindow();
  62. GetDlgItem(stc2)->ShowWindow(SW_HIDE);
  63. GetDlgItem(stc3)->ShowWindow(SW_HIDE);
  64. GetDlgItem(edt1)->ShowWindow(SW_HIDE);
  65. GetDlgItem(lst1)->ShowWindow(SW_HIDE);
  66. GetDlgItem(cmb1)->ShowWindow(SW_HIDE);
  67. GetDlgItem(stc1)->ShowWindow(SW_HIDE);
  68. GetDlgItem(chx1)->ShowWindow(SW_HIDE);
  69. GetDlgItem(psh15)->EnableWindow(FALSE);
  70. SetDlgItemText(edt1,_T("Junk"));
  71. //
  72. // Need to fill in edit control(IDC_PATH_NAME_EDIT)
  73. //
  74. CListBox* pList = (CListBox*)GetDlgItem(lst2);
  75. int iIndex = pList->GetCurSel();
  76. m_pathName.Empty();
  77. if(iIndex != LB_ERR) {
  78. pList->GetText(iIndex, str);
  79. for(int i = 0; i <= iIndex; i++) {
  80. pList->GetText(i, str);
  81. if(i > 1) {
  82. m_pathName += "\\";
  83. m_pathName += str;
  84. } else {
  85. m_pathName += str;
  86. }
  87. }
  88. m_pathName.MakeUpper();
  89. ((CEdit *)GetDlgItem(IDC_PATH_NAME_EDIT))->SetWindowText(m_pathName);
  90. }
  91. GetDlgItem(lst2)->SetFocus();
  92. m_bFirstTime = TRUE;
  93. CFileDialog::OnInitDialog();
  94. //
  95. // return FALSE to set the focus to a control
  96. //
  97. return FALSE;
  98. }
  99. void CPathDlg::OnPaint()
  100. {
  101. //
  102. // device context for painting
  103. //
  104. CPaintDC dc(this);
  105. if (m_bFirstTime) {
  106. m_bFirstTime = FALSE;
  107. SendDlgItemMessage(lst2, LB_SETCURSEL, 0, 0L);
  108. }
  109. //
  110. // Do not call CFileDialog::OnPaint() for painting messages
  111. //
  112. }
  113. void CPathDlg::OnLBSelChangedNotify(UINT nIDBox, UINT iCurSel, UINT nCode)
  114. {
  115. CString str;
  116. int i;
  117. CListBox* pList = (CListBox*)GetDlgItem(lst2);
  118. int iIndex = pList->GetCurSel();
  119. m_pathName.Empty();
  120. if (iIndex != LB_ERR) {
  121. pList->GetText(iIndex, str);
  122. for (i = 0; i <= iIndex; i++) {
  123. pList->GetText(i, str);
  124. if (i > 1) {
  125. m_pathName += "\\";
  126. m_pathName += str;
  127. } else {
  128. m_pathName += str;
  129. }
  130. }
  131. ((CEdit*)GetDlgItem(IDC_PATH_NAME_EDIT))->SetWindowText(m_pathName);
  132. }
  133. }
  134. BOOL CPathDlg::OnFileNameOK(void)
  135. {
  136. CString drive;
  137. CString str;
  138. int retVal;
  139. m_PathName.GetWindowText(m_pathName);
  140. drive = m_pathName.Left(3);
  141. retVal = m_pathName.FindOneOf(_T("*?|/<>\""));
  142. if (retVal >= 0) {
  143. str.Format(_T("%s is not a valid pathname."), m_pathName);
  144. AfxMessageBox(str);
  145. return TRUE;
  146. }
  147. if (_tchdir(m_pathName)) {
  148. str.Format(_T("Directory %s does not exist."), m_pathName);
  149. AfxMessageBox(str);
  150. return TRUE;
  151. }
  152. TCHAR buffer[MAX_PATH];
  153. str = m_pathName + "\\" + m_ofn.lpstrFileTitle;
  154. _tcscpy(buffer, str);
  155. _tcscpy(m_ofn.lpstrFile, buffer);
  156. m_pofnTemp->nFileOffset = m_pathName.GetLength() + 1;
  157. m_pofnTemp->nFileExtension = (WORD)str.GetLength();
  158. return FALSE;
  159. }