LRESULT CDetailDlg::OnExport(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) { // This method is called when user clicks the "Export" button. // We should export crash report contents as a ZIP archive to // user-specified folder. CErrorReportSender* pSender = CErrorReportSender::GetInstance(); CCrashInfoReader* pCrashInfo = pSender->GetCrashInfo(); // Format file name for the output ZIP archive. CString sFileName = pCrashInfo->GetReport(m_nCurReport)->GetCrashGUID() + _T(".zip"); // Display "Save File" dialog. CFileDialog dlg(FALSE, _T("*.zip"), sFileName, OFN_PATHMUSTEXIST|OFN_OVERWRITEPROMPT, _T("ZIP Files (*.zip)\0*.zip\0All Files (*.*)\0*.*\0\0"), m_hWnd); INT_PTR result = dlg.DoModal(); if(result==IDOK) { // Determine what destination user chosen CString sExportFileName = dlg.m_szFileName; // Export crash report assynchronously pSender->ExportReport(sExportFileName); } return 0; }
LRESULT CDetailDlg::OnItemDblClicked(int /*idCtrl*/, LPNMHDR pnmh, BOOL& /*bHandled*/) { // This method is called when user double-clicks an item in the list control. // We need to open the file with an appropriate program. LPNMLISTVIEW lpItem = (LPNMLISTVIEW)pnmh; int iItem = lpItem->iItem; DWORD_PTR dwRet = 0; CErrorReportSender* pSender = CErrorReportSender::GetInstance(); CCrashInfoReader* pCrashInfo = pSender->GetCrashInfo(); // Check if double-clicked on empty space. if (iItem < 0) { // Do nothing return 0; } // Look for n-th item ERIFileItem* pFileItem = pCrashInfo->GetReport(m_nCurReport)->GetFileItemByIndex(iItem); if(pFileItem==NULL) return 0; // Get file name CString sFileName = pFileItem->m_sSrcFile; // Open the file with shell-provided functionality dwRet = (DWORD_PTR)::ShellExecute(0, _T("open"), sFileName, 0, 0, SW_SHOWNORMAL); ATLASSERT(dwRet > 32); return 0; }
void CDetailDlg::SelectItem(int iItem) { // This method is called when user selects an item. // We need to open the item for preview. CErrorReportSender* pSender = CErrorReportSender::GetInstance(); CCrashInfoReader* pCrashInfo = pSender->GetCrashInfo(); // Look for n-th item ERIFileItem* pFileItem = pCrashInfo->GetReport(m_nCurReport)->GetFileItemByIndex(iItem); if(pFileItem==NULL) return; // Update preview control m_previewMode = PREVIEW_AUTO; m_textEncoding = ENC_AUTO; m_filePreview.SetFile(pFileItem->m_sSrcFile, m_previewMode); }
LRESULT CDetailDlg::OnPopupOpen(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) { CErrorReportSender* pSender = CErrorReportSender::GetInstance(); CCrashInfoReader* pCrashInfo = pSender->GetCrashInfo(); // Get count of selected list items int nItem = -1; int nSelected = 0; int i; for(i=0; i<m_list.GetItemCount(); i++) { // If list item selected if(m_list.GetItemState(i, LVIS_SELECTED)!=0) { nItem=i; nSelected++; } } if(nSelected!=1) return 0; // Should be exactly one item selected // Look for n-th item ERIFileItem* pFileItem = pCrashInfo->GetReport(m_nCurReport)->GetFileItemByIndex(nItem); if(pFileItem==NULL) return 0; // Get file name CString sFileName = pFileItem->m_sSrcFile; // Open the file with shell-provided functionality DWORD_PTR dwRet = (DWORD_PTR)::ShellExecute(0, _T("open"), sFileName, 0, 0, SW_SHOWNORMAL); ATLASSERT(dwRet > 32); dwRet; return 0; }
LRESULT CDetailDlg::OnPopupAddMoreFiles(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) { // Display "Open File" dialog. CFileDialog dlg(TRUE, _T("*.*"), NULL, OFN_PATHMUSTEXIST|OFN_ALLOWMULTISELECT, _T("All Files (*.*)\0*.*\0\0"), m_hWnd); INT_PTR result = dlg.DoModal(); if(result==IDOK) { // Parse the list of files TCHAR* str = dlg.m_ofn.lpstrFile; std::vector<CString> asItems; CString sItem; int i; for(i=0; ; i++) { if(str[i]==0) { // End of item if(sItem.IsEmpty()) break; // End of multi-string asItems.push_back(sItem); sItem.Empty(); continue; } sItem += str[i]; } std::vector<ERIFileItem> aFiles; if(asItems.size()==1) { // Single file to add CString sFileName = asItems[0]; ERIFileItem fi; fi.m_bAllowDelete = true; fi.m_bMakeCopy = true; fi.m_sDestFile = Utility::GetFileName(sFileName); fi.m_sSrcFile = sFileName; aFiles.push_back(fi); } else if(asItems.size()>1) { // Several files to add unsigned j; for(j=1; j<asItems.size(); j++) { CString sFileName = asItems[0]+_T("\\")+asItems[j]; ERIFileItem fi; fi.m_bAllowDelete = true; fi.m_bMakeCopy = true; fi.m_sDestFile = Utility::GetFileName(sFileName); fi.m_sSrcFile = sFileName; aFiles.push_back(fi); } } // Add files to crash report CErrorReportSender* pSender = CErrorReportSender::GetInstance(); CCrashInfoReader* pCrashInfo = pSender->GetCrashInfo(); pCrashInfo->AddFilesToCrashReport(m_nCurReport, aFiles); // Update file items list FillFileItemList(); // Force parent to recalculate report size HWND hWndParent = GetParent(); if(::IsWindow(hWndParent)) ::SendMessage(hWndParent, WM_REPORTSIZECHANGED, m_nCurReport, 0); } return 0; }
LRESULT CErrorReportDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) { CErrorReportSender* pSender = CErrorReportSender::GetInstance(); CCrashInfoReader* pCrashInfo = pSender->GetCrashInfo(); // Mirror this window if RTL language is in use. CString sRTL = pSender->GetLangStr(_T("Settings"), _T("RTLReading")); if(sRTL.CompareNoCase(_T("1"))==0) { Utility::SetLayoutRTL(m_hWnd); } // Set dialog caption. SetWindowText(pSender->GetLangStr(_T("MainDlg"), _T("DlgCaption"))); // Center the dialog on the screen. CenterWindow(); HICON hIcon = NULL; // Get custom icon. hIcon = pCrashInfo->GetCustomIcon(); if(hIcon==NULL) { // Use default icon, if custom icon is not provided. hIcon = ::LoadIcon(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDR_MAINFRAME)); } // Set window icon. SetIcon(hIcon, 0); // Get the first icon in the EXE image and use it for header. m_HeadingIcon = ExtractIcon(NULL, pCrashInfo->GetReport(0)->GetImageName(), 0); // If there is no icon in crashed EXE module, use default IDI_APPLICATION system icon. if(m_HeadingIcon == NULL) { m_HeadingIcon = ::LoadIcon(NULL, MAKEINTRESOURCE(IDI_APPLICATION)); } // Init controls. m_statSubHeader = GetDlgItem(IDC_SUBHEADER); m_link.SubclassWindow(GetDlgItem(IDC_LINK)); m_link.SetHyperLinkExtendedStyle(HLINK_COMMANDBUTTON); m_link.SetLabel(pSender->GetLangStr(_T("MainDlg"), _T("WhatDoesReportContain"))); m_linkMoreInfo.SubclassWindow(GetDlgItem(IDC_MOREINFO)); m_linkMoreInfo.SetHyperLinkExtendedStyle(HLINK_COMMANDBUTTON); m_linkMoreInfo.SetLabel(pSender->GetLangStr(_T("MainDlg"), _T("ProvideAdditionalInfo"))); m_statEmail = GetDlgItem(IDC_STATMAIL); m_statEmail.SetWindowText(pSender->GetLangStr(_T("MainDlg"), _T("YourEmail"))); m_editEmail = GetDlgItem(IDC_EMAIL); m_editEmail.SetWindowText(pSender->GetCrashInfo()->GetPersistentUserEmail()); m_statDesc = GetDlgItem(IDC_DESCRIBE); m_statDesc.SetWindowText(pSender->GetLangStr(_T("MainDlg"), _T("DescribeProblem"))); m_editDesc = GetDlgItem(IDC_DESCRIPTION); m_statIndent = GetDlgItem(IDC_INDENT); m_chkRestart = GetDlgItem(IDC_RESTART); CString sCaption; sCaption.Format(pSender->GetLangStr(_T("MainDlg"), _T("RestartApp")), pSender->GetCrashInfo()->m_sAppName); m_chkRestart.SetWindowText(sCaption); m_chkRestart.SetCheck(BST_CHECKED); m_chkRestart.ShowWindow(pSender->GetCrashInfo()->m_bAppRestart?SW_SHOW:SW_HIDE); m_statConsent = GetDlgItem(IDC_CONSENT); // Init font for consent string. LOGFONT lf; memset(&lf, 0, sizeof(LOGFONT)); lf.lfHeight = 11; lf.lfWeight = FW_NORMAL; lf.lfQuality = ANTIALIASED_QUALITY; _TCSCPY_S(lf.lfFaceName, 32, _T("Tahoma")); CFontHandle hConsentFont; hConsentFont.CreateFontIndirect(&lf); m_statConsent.SetFont(hConsentFont); // Set text of the static if(pSender->GetCrashInfo()->m_sPrivacyPolicyURL.IsEmpty()) m_statConsent.SetWindowText(pSender->GetLangStr(_T("MainDlg"), _T("MyConsent2"))); else m_statConsent.SetWindowText(pSender->GetLangStr(_T("MainDlg"), _T("MyConsent"))); // Init Privacy Policy link m_linkPrivacyPolicy.SubclassWindow(GetDlgItem(IDC_PRIVACYPOLICY)); m_linkPrivacyPolicy.SetHyperLink(pSender->GetCrashInfo()->m_sPrivacyPolicyURL); m_linkPrivacyPolicy.SetLabel(pSender->GetLangStr(_T("MainDlg"), _T("PrivacyPolicy"))); BOOL bShowPrivacyPolicy = !pSender->GetCrashInfo()->m_sPrivacyPolicyURL.IsEmpty(); m_linkPrivacyPolicy.ShowWindow(bShowPrivacyPolicy?SW_SHOW:SW_HIDE); m_statCrashRpt = GetDlgItem(IDC_CRASHRPT); m_statHorzLine = GetDlgItem(IDC_HORZLINE); // Init OK button m_btnOk = GetDlgItem(IDOK); m_btnOk.SetWindowText(pSender->GetLangStr(_T("MainDlg"), _T("SendReport"))); // Init Cancel button m_btnCancel = GetDlgItem(IDC_CANCEL); if(pSender->GetCrashInfo()->m_bQueueEnabled) m_btnCancel.SetWindowText(pSender->GetLangStr(_T("MainDlg"), _T("OtherActions"))); else m_btnCancel.SetWindowText(pSender->GetLangStr(_T("MainDlg"), _T("CloseTheProgram"))); // If send procedure is mandatory... if(pSender->GetCrashInfo()->m_bSendMandatory) { // Hide Cancel button m_btnCancel.ShowWindow(SW_HIDE); // Remove Close button SetWindowLong(GWL_STYLE, GetWindowLong(GWL_STYLE) & ~WS_SYSMENU); } // Init font for heading text memset(&lf, 0, sizeof(LOGFONT)); lf.lfHeight = 25; lf.lfWeight = FW_NORMAL; lf.lfQuality = ANTIALIASED_QUALITY; _TCSCPY_S(lf.lfFaceName, 32, _T("Tahoma")); m_HeadingFont.CreateFontIndirect(&lf); // Init control positions m_Layout.SetContainerWnd(m_hWnd); m_Layout.Insert(m_linkMoreInfo); m_Layout.Insert(m_statIndent); m_Layout.Insert(m_statEmail, TRUE); m_Layout.Insert(m_editEmail, TRUE); m_Layout.Insert(m_statDesc, TRUE); m_Layout.Insert(m_editDesc, TRUE); m_Layout.Insert(m_chkRestart); m_Layout.Insert(m_statConsent); m_Layout.Insert(m_linkPrivacyPolicy); m_Layout.Insert(m_statCrashRpt); m_Layout.Insert(m_statHorzLine, TRUE); m_Layout.Insert(m_btnOk); m_Layout.Insert(m_btnCancel, TRUE); // By default, hide the email & description fields. // But user may override the default. ShowMoreInfo(pSender->GetCrashInfo()->m_bShowAdditionalInfoFields); // Create progress dialog m_dlgProgress.Create(m_hWnd); m_dlgProgress.Start(TRUE); // register object for message filtering and idle updates CMessageLoop* pLoop = _Module.GetMessageLoop(); ATLASSERT(pLoop != NULL); if(pLoop) { pLoop->AddMessageFilter(this); } UIAddChildWindowContainer(m_hWnd); return TRUE; }