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.

276 lines
7.9 KiB

  1. // AutomaticSessDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "emshell.h"
  5. #include "AutomaticSessDlg.h"
  6. #include "Emshellview.h"
  7. #include "comdef.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CAutomaticSessDlg dialog
  15. extern PEmObject GetEmObj(BSTR bstrEmObj);
  16. CAutomaticSessDlg::CAutomaticSessDlg(PSessionSettings pSettings, VARIANT *pVar, EmObjectType type, CWnd* pParent /*=NULL*/)
  17. : CDialog(CAutomaticSessDlg::IDD, pParent)
  18. {
  19. //{{AFX_DATA_INIT(CAutomaticSessDlg)
  20. m_bNotifyAdmin = FALSE;
  21. m_bMiniDump = FALSE;
  22. m_bUserDump = FALSE;
  23. m_bRecursiveMode = FALSE;
  24. m_strNotifyAdmin = _T("");
  25. m_strAltSymbolPath = _T("");
  26. m_bRememberSettings = FALSE;
  27. //}}AFX_DATA_INIT
  28. m_pSettings = pSettings;
  29. m_pECXVariantList = pVar;
  30. m_emSessionType = type;
  31. }
  32. void CAutomaticSessDlg::DoDataExchange(CDataExchange* pDX)
  33. {
  34. CDialog::DoDataExchange(pDX);
  35. //{{AFX_DATA_MAP(CAutomaticSessDlg)
  36. DDX_Control(pDX, IDC_CK_RECURSIVEMODE, m_btnRecursiveMode);
  37. DDX_Control(pDX, IDC_CK_NOTIFYADMIN, m_btnNotifyAdmin);
  38. DDX_Control(pDX, IDOK, m_btnOK);
  39. DDX_Control(pDX, IDC_EDIT_NOTIFYADMIN, m_NotifyAdminEditControl);
  40. DDX_Control(pDX, IDC_CK_COMMANDSET, m_btnCommandSet);
  41. DDX_Control(pDX, IDC_LIST_COMMANDSET, m_mainListControl);
  42. DDX_Check(pDX, IDC_CK_NOTIFYADMIN, m_bNotifyAdmin);
  43. DDX_Check(pDX, IDC_CK_MINIDUMP, m_bMiniDump);
  44. DDX_Check(pDX, IDC_CK_USERDUMP, m_bUserDump);
  45. DDX_Check(pDX, IDC_CK_RECURSIVEMODE, m_bRecursiveMode);
  46. DDX_Text(pDX, IDC_EDIT_NOTIFYADMIN, m_strNotifyAdmin);
  47. DDX_Text(pDX, IDC_EDIT_ALTSYMBOLPATH, m_strAltSymbolPath);
  48. DDX_Check(pDX, IDC_CK_REMEMBERSETTINGS, m_bRememberSettings);
  49. //}}AFX_DATA_MAP
  50. }
  51. BEGIN_MESSAGE_MAP(CAutomaticSessDlg, CDialog)
  52. //{{AFX_MSG_MAP(CAutomaticSessDlg)
  53. ON_NOTIFY(NM_CLICK, IDC_LIST_COMMANDSET, OnClickListCommandset)
  54. ON_BN_CLICKED(IDC_CK_NOTIFYADMIN, OnCkNotifyadmin)
  55. //}}AFX_MSG_MAP
  56. END_MESSAGE_MAP()
  57. /////////////////////////////////////////////////////////////////////////////
  58. // CAutomaticSessDlg message handlers
  59. void CAutomaticSessDlg::UpdateSessionDlgData(bool bUpdate)
  60. {
  61. LVFINDINFO findInfo;
  62. int nIndex = 0;
  63. //if bUpdate is TRUE, we are loading the dialog settings from m_pSettings
  64. if ( bUpdate ) {
  65. if ( m_pSettings != NULL ) {
  66. m_bNotifyAdmin = m_pSettings->dwNotifyAdmin;
  67. m_bMiniDump = m_pSettings->dwProduceMiniDump;
  68. m_bUserDump = m_pSettings->dwProduceUserDump;
  69. m_strNotifyAdmin = m_pSettings->strAdminName;
  70. m_strAltSymbolPath = m_pSettings->strAltSymbolPath;
  71. m_strSelectedCommandSet = m_pSettings->strCommandSet;
  72. m_NotifyAdminEditControl.EnableWindow( m_bNotifyAdmin );
  73. if (m_emSessionType == EMOBJ_SERVICE) {
  74. m_bRecursiveMode = m_pSettings->dwRecursiveMode;
  75. m_btnRecursiveMode.EnableWindow(TRUE);
  76. } else {
  77. m_btnRecursiveMode.SetCheck(FALSE);
  78. m_btnRecursiveMode.EnableWindow(FALSE);
  79. }
  80. //Create and initialize a findInfo object to retrieve the index for the item were looking for
  81. findInfo.flags = LVFI_STRING;
  82. findInfo.psz = m_strSelectedCommandSet;
  83. if ( m_mainListControl.GetItemCount() > 0) {
  84. //Search for m_strSelectedCommandSet in the list control and select it.
  85. nIndex = m_mainListControl.FindItem(&findInfo);
  86. if ( nIndex != -1 ) {
  87. //We have found it, now hilight it
  88. m_mainListControl.SetItemState( nIndex,LVIS_SELECTED | LVIS_FOCUSED , LVIS_SELECTED | LVIS_FOCUSED);
  89. m_strSelectedCommandSet = m_mainListControl.GetItemText(nIndex, 0);
  90. } else {
  91. //Select the only item in the list
  92. m_mainListControl.SetItemState( 0,LVIS_SELECTED | LVIS_FOCUSED , LVIS_SELECTED | LVIS_FOCUSED);
  93. m_strSelectedCommandSet = m_mainListControl.GetItemText(0, 0);
  94. }
  95. }
  96. else {
  97. //We have no items in the list, disable the okay button
  98. m_btnOK.EnableWindow(FALSE);
  99. }
  100. }
  101. }
  102. //if bUpdate is FALSE, we are saving the dialog settings to m_pSettings
  103. else {
  104. m_pSettings->dwNotifyAdmin = m_bNotifyAdmin;
  105. m_pSettings->dwProduceMiniDump = m_bMiniDump;
  106. m_pSettings->dwProduceUserDump = m_bUserDump;
  107. m_pSettings->dwRecursiveMode = m_bRecursiveMode;
  108. m_pSettings->strAdminName = m_strNotifyAdmin;
  109. m_pSettings->strAltSymbolPath = m_strAltSymbolPath;
  110. m_pSettings->strCommandSet = m_strSelectedCommandSet;
  111. }
  112. }
  113. BOOL CAutomaticSessDlg::OnInitDialog()
  114. {
  115. CDialog::OnInitDialog();
  116. // TODO: Add extra initialization here
  117. //Populate the list control with the ECX files.
  118. HRESULT hr = E_FAIL;
  119. LONG lLBound = 0;
  120. LONG lUBound = 0;
  121. BSTR bstrEmObj = NULL;
  122. EmObject CurrentObj;
  123. CString strDescription;
  124. CString strName;
  125. do {
  126. //Check mark the command set button, but disable it
  127. m_btnCommandSet.SetCheck(1);
  128. m_btnCommandSet.EnableWindow(FALSE);
  129. //Add the columns to the list control
  130. m_mainListControl.BeginSetColumn(2);
  131. strName.LoadString(IDS_AUTOSESSDLG_NAME);
  132. strDescription.LoadString(IDS_AUTOSESSDLG_DESCRIPTION);
  133. m_mainListControl.AddColumn(strName);
  134. m_mainListControl.AddColumn(strDescription);
  135. m_mainListControl.EndSetColumn();
  136. m_mainListControl.ResizeColumnsFitScreen();
  137. m_mainListControl.SetExtendedStyle(LVS_EX_FULLROWSELECT);
  138. //Get the lower and upper bounds of the variant array
  139. hr = SafeArrayGetLBound(m_pECXVariantList->parray, 1, &lLBound);
  140. if(FAILED(hr)) break;
  141. hr = SafeArrayGetUBound(m_pECXVariantList->parray, 1, &lUBound);
  142. if(FAILED(hr)) break;
  143. //There are elements at both the lower bound and upper bound, so include them
  144. for(; lLBound <= lUBound; lLBound++)
  145. {
  146. //Get a BSTR object from the safe array
  147. hr = SafeArrayGetElement(m_pECXVariantList->parray, &lLBound, &bstrEmObj);
  148. if (FAILED(hr)) break;
  149. //Create a local copy of the EmObject (there aren't any pointers in
  150. //EmObject structure, so don't worry about doing a deep copy
  151. CurrentObj = *GetEmObj(bstrEmObj);
  152. if (bstrEmObj != NULL ) {
  153. SysFreeString( bstrEmObj );
  154. }
  155. //Convert the BSTR object to an EmObject and pass it to DisplayData
  156. DisplayData(&CurrentObj);
  157. }
  158. //Synchronize the dialog with the view data
  159. UpdateSessionDlgData();
  160. UpdateData(FALSE);
  161. } while (FALSE);
  162. SysFreeString( bstrEmObj );
  163. if (FAILED(hr)) {
  164. ((CEmshellApp*)AfxGetApp())->DisplayErrMsgFromHR(hr);
  165. }
  166. return TRUE; // return TRUE unless you set the focus to a control
  167. // EXCEPTION: OCX Property Pages should return FALSE
  168. }
  169. HRESULT CAutomaticSessDlg::DisplayData(PEmObject pEmObject)
  170. {
  171. _ASSERTE(pEmObject != NULL);
  172. HRESULT hr = E_FAIL;
  173. TCHAR szPid[20] = {0};
  174. LONG lRow = 0L;
  175. int nImage = 0;
  176. CString csPROCStatus;
  177. do
  178. {
  179. if( pEmObject == NULL ){
  180. hr = E_INVALIDARG;
  181. break;
  182. }
  183. _ltot(pEmObject->nId, szPid, 10);
  184. lRow = m_mainListControl.SetItemText(-1, 0, pEmObject->szName);
  185. if(lRow == -1L){
  186. hr = E_FAIL;
  187. break;
  188. }
  189. if ( pEmObject->dwBucket1 )
  190. lRow = m_mainListControl.SetItemText(lRow, 1, pEmObject->szBucket1);
  191. hr = S_OK;
  192. }
  193. while( false );
  194. return hr;
  195. }
  196. void CAutomaticSessDlg::OnClickListCommandset(NMHDR* pNMHDR, LRESULT* pResult)
  197. {
  198. // TODO: Add your control notification handler code here
  199. //Set the m_strSelectedCommandSet to the value of the currently selected item
  200. //in the list
  201. //Get the currently selected item
  202. POSITION pos = NULL;
  203. int nIndex = 0;
  204. do {
  205. pos = m_mainListControl.GetFirstSelectedItemPosition();
  206. if ( pos != NULL ) {
  207. nIndex = m_mainListControl.GetNextSelectedItem(pos);
  208. m_strSelectedCommandSet = m_mainListControl.GetItemText(nIndex, 0);
  209. }
  210. //Enable the Okay button
  211. //m
  212. } while ( FALSE );
  213. *pResult = 0;
  214. }
  215. void CAutomaticSessDlg::OnCkNotifyadmin()
  216. {
  217. // TODO: Add your control notification handler code here
  218. // The user has checked the box, enable the edit box
  219. UpdateData(TRUE);
  220. m_NotifyAdminEditControl.EnableWindow( m_bNotifyAdmin );
  221. }
  222. void CAutomaticSessDlg::OnOK()
  223. {
  224. // TODO: Add extra validation here
  225. CDialog::OnOK();
  226. //Store off the current settings
  227. UpdateSessionDlgData(FALSE);
  228. }