LRESULT CHexFileDialog::OnPostInit(WPARAM wp, LPARAM lp) { // Set text of "OK" button if (!strOKName.IsEmpty()) SetControlText(IDOK, strOKName); // Restore the window position and size CRect rr(theApp.GetProfileInt("Window-Settings", strName+"X1", -30000), theApp.GetProfileInt("Window-Settings", strName+"Y1", -30000), theApp.GetProfileInt("Window-Settings", strName+"X2", -30000), theApp.GetProfileInt("Window-Settings", strName+"Y2", -30000)); if (rr.top != -30000) GetParent()->MoveWindow(&rr); // Note: there was a crash here until we set 8th // param of CFileDialog (bVistaStyle) c'tor to FALSE. // Restore the list view display mode (details, report, icons, etc) ASSERT(GetParent() != NULL); CWnd *psdv = FindWindowEx(GetParent()->m_hWnd, NULL, "SHELLDLL_DefView", NULL); if (psdv != NULL) { int mode = theApp.GetProfileInt("Window-Settings", strName+"Mode", REPORT); psdv->SendMessage(WM_COMMAND, mode, 0); } return 0; }
CTipDlg::CTipDlg(CWnd* pParent /*=NULL*/) : CDialog(IDD_TIP, pParent) { //{{AFX_DATA_INIT(CTipDlg) m_bStartup = TRUE; //}}AFX_DATA_INIT // We need to find out what the startup and file position parameters are // If startup does not exist, we assume that the Tips on startup is checked TRUE. CHexEditApp *aa = dynamic_cast<CHexEditApp *>(AfxGetApp()); m_bStartup = aa->tipofday_; UINT iFilePos = aa->GetProfileInt(szSection, szIntFilePos, 0); const char *tip_name = "HexEdit.tip"; // Now try to open the tips file in the current directory m_pStream = fopen(tip_name, "r"); if (m_pStream == NULL) { // AP: This bit added by me ----------------------------------------------------------- // Not found so try to open from the .exe dir if ((m_pStream = fopen(GetExePath() + tip_name, "r")) == NULL) // ------------------------------------------------------------------------------------ { VERIFY(m_strTip.LoadString(CG_IDS_FILE_ABSENT)); return; } } // If the timestamp in the INI file is different from the timestamp of // the tips file, then we know that the tips file has been modified // Reset the file position to 0 and write the latest timestamp to the // ini file struct _stat buf; _fstat(_fileno(m_pStream), &buf); CString strCurrentTime = ctime(&buf.st_ctime); strCurrentTime.TrimRight(); CString strStoredTime = aa->GetProfileString(szSection, szTimeStamp, NULL); if (strCurrentTime != strStoredTime) { iFilePos = 0; aa->WriteProfileString(szSection, szTimeStamp, strCurrentTime); } if (fseek(m_pStream, iFilePos, SEEK_SET) != 0) { AfxMessageBox(CG_IDP_FILE_CORRUPT); } else { GetNextTipString(m_strTip); } }
void CMultiplay::FixControls() { name_ctrl_.GetLBText(name_ctrl_.GetCurSel(), macro_name_); if (macro_name_ == DEFAULT_MACRO_NAME) { plays_ = 1; } else { std::vector<key_macro> tmp; CString comment; int halt_lev; long plays; int version; // Version of HexEdit in which the macro was recorded ASSERT(theApp.mac_dir_.Right(1) == "\\"); if (theApp.macro_load(theApp.mac_dir_ + macro_name_ + ".hem", &tmp, comment, halt_lev, plays, version)) plays_ = plays; else { ASSERT(0); plays_ = 1; } } UpdateData(FALSE); // Put number of plays into control }
// Handles control menu commands and system buttons (Minimize etc) void CChildFrame::OnSysCommand(UINT nID, LONG lParam) { CMDIChildWndEx::OnSysCommand(nID, lParam); CHexEditApp *aa = dynamic_cast<CHexEditApp *>(AfxGetApp()); nID &= 0xFFF0; if (nID == SC_MINIMIZE || nID == SC_RESTORE || nID == SC_MAXIMIZE || nID == SC_NEXTWINDOW || nID == SC_PREVWINDOW || nID == SC_CLOSE) { if ((nID == SC_NEXTWINDOW || nID == SC_PREVWINDOW || nID == SC_CLOSE) && aa->recording_ && aa->mac_.size() > 0 && (aa->mac_.back()).ktype == km_focus) { // Next win, prev. win, close win cause focus change which causes a km_focus // for a particular window to be stored. On replay, we don't want to // change to this window before executing this command. aa->mac_.pop_back(); } aa->SaveToMacro(km_childsys, nID); } }
BOOL CHexFileDialog::OnFileNameOK() { // Remember current window pos for when window is reopened CRect rr; GetParent()->GetWindowRect(&rr); theApp.WriteProfileInt("Window-Settings", strName+"X1", rr.left); theApp.WriteProfileInt("Window-Settings", strName+"Y1", rr.top); theApp.WriteProfileInt("Window-Settings", strName+"X2", rr.right); theApp.WriteProfileInt("Window-Settings", strName+"Y2", rr.bottom); // Remember current list view mode ASSERT(GetParent() != NULL); CWnd *psdv = FindWindowEx(GetParent()->m_hWnd, NULL, "SHELLDLL_DefView", NULL); ASSERT(psdv != NULL); CWnd *plv = FindWindowEx(psdv->m_hWnd, NULL, "SysListView32", NULL); ASSERT(plv != NULL); int mode = 0; switch (plv->SendMessage(LVM_FIRST + 143 /*LVM_GETVIEW*/)) { case LVS_ICON: case LVS_SMALLICON: mode = ICON; break; case LVS_REPORT: mode = REPORT; break; case LVS_LIST: mode = LIST; break; default: mode = TILE; break; } theApp.WriteProfileInt("Window-Settings", strName+"Mode", mode); return CFileDialog::OnFileNameOK(); }
void CEmailDlg::OnAttachmentBrowse() { UpdateData(); CHexFileDialog dlgFile("AttachmentDlg", HIDD_FILE_ATTACH, TRUE, NULL, attachment_, OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_DONTADDTORECENT, theApp.GetCurrentFilters(), "Attach", this); if (dlgFile.DoModal() == IDOK) { attachment_ = dlgFile.GetPathName(); UpdateData(FALSE); } }
void CHexFileList::ReadList() { ClearAll(); if (ReadFile()) { // Update m_arrNames to match for (int ii = 0; ii < name_.size() && ii < m_nSize; ++ii) m_arrNames[ii] = name_[name_.size()-ii-1]; } else { // Call base class to get file names from the registry CRecentFileList::ReadList(); // Get other parameters using old registry entries (for backward compatibility) int ii; CString fnum; struct { union { DWORD disp_state_; struct display_bits display_; }; } tt; // Read options for each file of the MRU list for (ii = m_nSize - 1; ii >= 0; ii--) { if (m_arrNames[ii].IsEmpty()) continue; CString ss; ss = m_arrNames[ii]; name_.push_back(ss); ss.MakeUpper(); hash_.push_back(str_hash(ss)); opened_.push_back(time(NULL)); data_.push_back(""); fnum.Format("File%d", ii+1); SetData(name_.size()-1, CMD, theApp.GetProfileInt(fnum, "WindowState", SW_SHOWNORMAL)); SetData(name_.size()-1, TOP, (int)theApp.GetProfileInt(fnum, "WindowTop", -30000)); SetData(name_.size()-1, LEFT, (int)theApp.GetProfileInt(fnum, "WindowLeft", -30000)); SetData(name_.size()-1, BOTTOM, (int)theApp.GetProfileInt(fnum, "WindowBottom", -30000)); SetData(name_.size()-1, RIGHT, (int)theApp.GetProfileInt(fnum, "WindowRight", -30000)); SetData(name_.size()-1, COLUMNS, __min(CHexEditView::max_buf, __max(4, theApp.GetProfileInt(fnum, "Columns", theApp.open_rowsize_)))); SetData(name_.size()-1, GROUPING,__max(2, theApp.GetProfileInt(fnum, "Grouping", theApp.open_group_by_))); SetData(name_.size()-1, OFFSET, __min(atoi(GetData(name_.size()-1, COLUMNS))-1, theApp.GetProfileInt(fnum, "Offset", theApp.open_offset_))); ss = theApp.GetProfileString(fnum, "Scheme"); ss.Replace("|", "_"); // A scheme name may no longer contain a vertical bar (|) SetData(name_.size()-1, SCHEME, ss); ss = theApp.GetProfileString(fnum, "Font"); CString strTemp; AfxExtractSubString(strTemp, ss, 0, ','); SetData(name_.size()-1, FONT, strTemp); AfxExtractSubString(strTemp, ss, 1, ','); SetData(name_.size()-1, HEIGHT, strTemp); ss = theApp.GetProfileString(fnum, "OemFont"); AfxExtractSubString(strTemp, ss, 0, ','); SetData(name_.size()-1, OEMFONT, strTemp); AfxExtractSubString(strTemp, ss, 1, ','); SetData(name_.size()-1, OEMHEIGHT, strTemp); // Read the option values, defaulting to the global (theApp.open_*) values if ((tt.disp_state_ = (int)theApp.GetProfileInt(fnum, "DisplayState", -1)) == -1) if (!tt.display_.hex_area && !tt.display_.char_area) tt.display_.hex_area = TRUE; if (!tt.display_.hex_area) tt.display_.edit_char = TRUE; else if (!tt.display_.char_area) tt.display_.edit_char = FALSE; if (tt.display_.control > 2) tt.display_.control = 0; SetData(name_.size()-1, DISPLAY, tt.disp_state_); SetData(name_.size()-1, DOC_FLAGS, theApp.GetProfileInt(fnum, "KeepTimes", 0)); SetData(name_.size()-1, FORMAT, theApp.GetProfileString(fnum, "FormatFile")); SetData(name_.size()-1, SELSTART, theApp.GetProfileString(fnum, "SelStart64")); SetData(name_.size()-1, SELEND, theApp.GetProfileString(fnum, "SelEnd64")); SetData(name_.size()-1, POS, theApp.GetProfileString(fnum, "Pos64")); SetData(name_.size()-1, MARK, theApp.GetProfileString(fnum, "Mark64")); SetData(name_.size()-1, HIGHLIGHTS, theApp.GetProfileString(fnum, "Highlights")); } // Now delete the recent file list key (and old one) and all files theApp.WriteProfileString(_T("RecentFiles"), NULL, NULL); theApp.WriteProfileString(_T("Recent File List"), NULL, NULL); for (ii = 0; ii < 16; ++ii) // There may be up to 16 entries (some old unused ones) { fnum.Format("File%d", ii+1); theApp.WriteProfileString(fnum, NULL, NULL); // Delete this recent file entry } } ((CMainFrame *)AfxGetMainWnd())->UpdateExplorer(); // make sure our explorer window shows info we have just loaded }
CString CHexEditView::create_header(const char *fmt, long pagenum) { bool bDiskFile = GetDocument()->pfile1_ != NULL; bool bDevice = bDiskFile && GetDocument()->IsDevice(); CString retval; // Return string CString sin = fmt; // Rest of input string int pos; // Posn in string of param. CString ss; // Temporary string CHexFileList *pfl = theApp.GetFileList(); int ii = -1; if (GetDocument()->pfile1_ != NULL) // make sure there is a disk file (pfl requires a disk file name) ii = pfl->GetIndex(GetDocument()->pfile1_->GetFilePath()); CFileStatus status; // Get status of file (for times) if (bDiskFile && !bDevice) GetDocument()->pfile1_->GetStatus(status); while ((pos = sin.Find("&")) != -1) { retval += sin.Left(pos); if (sin.GetLength() > pos + 1) { switch (toupper(sin[pos+1])) { case 'F': if (bDiskFile) retval += GetDocument()->pfile1_->GetFileName(); break; case 'A': if (bDevice) retval += GetDocument()->pfile1_->GetFileName(); else if (bDiskFile) retval += GetDocument()->pfile1_->GetFilePath(); break; case 'P': ss.Format("%ld", long(pagenum)); retval += ss; break; case 'D': retval += print_time_.Format("%x"); break; case 'T': retval += print_time_.Format("%X"); break; case 'N': retval += print_time_.Format("%#c"); break; case 'C': if (bDiskFile && !bDevice) retval += status.m_ctime.Format("%c"); break; case 'M': if (bDiskFile && !bDevice) retval += status.m_mtime.Format("%c"); break; #if 0 // Since we have the file open the last access time is now so don't bother with this one case 'U': if (bDiskFile && !bDevice) retval += status.m_atime.Format("%c"); break; #endif case 'G': if (ii > -1) retval += pfl->GetData(ii, CHexFileList::CATEGORY); break; case 'K': if (ii > -1) retval += pfl->GetData(ii, CHexFileList::KEYWORDS); break; case 'X': if (ii > -1) retval += pfl->GetData(ii, CHexFileList::COMMENTS); break; default: case '&': retval += sin[pos+1]; } sin = sin.Mid(pos+2); } else { sin.Empty(); break; } } retval += sin; return retval; }
void CPassword::OnContextMenu(CWnd* pWnd, CPoint point) { theApp.HtmlHelpContextMenu(pWnd, id_pairs); }
BOOL CPassword::OnHelpInfo(HELPINFO* pHelpInfo) { theApp.HtmlHelpWmHelp((HWND)pHelpInfo->hItemHandle, id_pairs); return TRUE; }
void CMultiplay::OnContextMenu(CWnd* pWnd, CPoint point) { theApp.HtmlHelpContextMenu(pWnd, id_pairs_play); }
void CHexFileList::SetupJumpList() { #if _MFC_VER >= 0x0A00 // earlier versions of MFC do not support CJumpList CJumpList jumpList; if (!jumpList.InitializeList()) return; int maxSlots = jumpList.GetMaxSlots(); // We need to get three list, the total size of which adds up to maxSlots (or less): // recent files: just the last n files of the recent file list // frequent files: the files that have been opened the most (using the open_count_ array) // - we use a priority queue that stores the most frequently opened files // - note that the "highest" priority are the least frequently opened so we can pop them off the top // favorite: the last n files that have CATEGORY of favorite or favourite // - we just store these in a vector and stop when we have enough // Note that we build the recent and frequent lists ourselves, rather than relying on // KDC_RECENT and KDC_FREQUENT so we know what file extensions need to be registered. // This class is a functor used to compare elements added to the frequency priority queue class freq_compare { private: CHexFileList *pfl; public: freq_compare(CHexFileList *pfl): pfl(pfl) { } bool operator() (const int &lhs, const int &rhs) const { return pfl->GetOpenedCount(lhs) > pfl->GetOpenedCount(rhs); } }; // This stores the first "favourite" files found std::vector<int> fav; // This stores the files that have been opened the most typedef std::priority_queue<int, std::vector<int>, freq_compare> freq_type; freq_type freq(freq_compare(this)); for (int ii = name_.size() - 1; ii >= 0; ii--) { if (open_count_[ii] <= 1) { // We don't consider that a single open is "frequent" } else if (freq.size() < maxSlots/3) // fill up to 1/3 of total slots available { freq.push(ii); } else if (open_count_[ii] > open_count_[freq.top()]) { // First get rid of all the lowest frequency elements // Note: This can result in the size of freq dropping unexpectedly (eg: from 10 to 1) if // there are a large number of files with the same open count. This is NOT a bug. int lowest = open_count_[freq.top()]; while (freq.size() > 0 && open_count_[freq.top()] == lowest) { freq.pop(); } freq.push(ii); } if (fav.size() < maxSlots/2) // may fill up to 1/2 of all slots available { CString ss = GetData(ii, CATEGORY); if (ss.CompareNoCase("Favourites") == 0 || ss.CompareNoCase("Favorites") == 0) fav.push_back(ii); } } // work out how many of each to use int numFreq = freq.size(), numFav = fav.size(); ASSERT(numFreq <= maxSlots/3); if (numFreq + numFav > (2*maxSlots)/3) // make sure freq + fav is not more than 2/3 of total numFav = (2*maxSlots)/3 - numFreq; int numRecent = maxSlots - numFreq - numFav; if (numRecent > name_.size()) numRecent = name_.size(); ASSERT(numRecent + numFreq + numFav <= maxSlots); // Make sure we are associated with the extensions of all the files we are adding to the jump list CaseInsensitiveSet ext; // Get extensions of recent files for (int ii = name_.size() - 1; ii >= (int)name_.size() - numRecent; ii--) { ext.insert(CString(::PathFindExtension(name_[ii]))); } // Get extensions of frequently opened files freq_type temp = freq; while (temp.size() > 0) { ext.insert(CString(::PathFindExtension(name_[temp.top()]))); temp.pop(); } // Get extensions of favourite files for (int ii = 0; ii < fav.size(); ++ii) { ext.insert(CString(::PathFindExtension(name_[fav[ii]]))); } // Check if appid or exe name is wrong in "HKCR\HexEdit.file" bool need_reg = false; HKEY hkey; // Check that our "file" registry setting is present in the registry and APPID is correct if (RegOpenKeyEx(HKEY_CLASSES_ROOT, CString(CHexEditApp::ProgID), 0, KEY_QUERY_VALUE, &hkey) != ERROR_SUCCESS) { need_reg = true; // HexEdit file registry setting is not present } else { char buf[1024]; DWORD len = sizeof(buf)-1; CString ss = theApp.m_pszAppID; if (RegQueryValueEx(hkey, "AppUserModelID", NULL, NULL, (LPBYTE)buf, &len) != ERROR_SUCCESS || ss.CompareNoCase(buf) != 0) { need_reg = true; // command line setting is not present or it is using a different .exe } RegCloseKey(hkey); } if (!need_reg) { // Also check that command setting is present and points to our .exe if (RegOpenKeyEx(HKEY_CLASSES_ROOT, CString(CHexEditApp::ProgID) + "\\shell\\open\\command", 0, KEY_QUERY_VALUE, &hkey) != ERROR_SUCCESS) { need_reg = true; // HexEdit file command setting is not present } else { char buf[1024]; DWORD len = sizeof(buf)-1; CString ss; AfxGetModuleFileName(0, ss); // new in MFC 10? ss += " %1"; if (RegQueryValueEx(hkey, NULL, NULL, NULL, (LPBYTE)buf, &len) != ERROR_SUCCESS || ss.CompareNoCase(buf) != 0) { need_reg = true; // command line setting is not present or it is using a different .exe } RegCloseKey(hkey); } } // Put all extensions (that have yet to be registered) into a string for RegisterExtensions CString strExt; for (CaseInsensitiveSet::const_iterator pext = ext.begin(); pext != ext.end(); ++pext) { if (RegOpenKeyEx(HKEY_CLASSES_ROOT, *pext + "\\OpenWithProgids", 0, KEY_QUERY_VALUE, &hkey) != ERROR_SUCCESS && !pext->IsEmpty() ) { strExt += *pext + "|"; need_reg = true; } else { if (RegQueryValueEx(hkey, CHexEditApp::ProgID, NULL, NULL, NULL, NULL) != ERROR_SUCCESS && !pext->IsEmpty() ) { strExt += *pext + "|"; need_reg = true; } RegCloseKey(hkey); } } static const char * explanation = "\nJump Lists were introduced with Windows 7. They are lists of items that are " "quickly accessed by right-clicking the HexEdit icon on the Task Bar. HexEdit " "supports lists of most recently opened items, frequently opened items, and " "those that you mark as favorites.\n\n" "However, for jump lists to work the type(s) of the files in the jump lists " "must be registered as \"openable\" with HexEdit. To associate the above file " "types with HexEdit requires starting a separate application with Administrator " "privileges in order to add registry setting for all users.\n\n" "When prompted please select \"Yes\" in the User Account Control window."; // Only fire up reghelper if need to register something (need_reg is true) // (ie, there are extensions to register OR the appid or exe path is wrong) if (need_reg && !strExt.IsEmpty()) { CString strTmp = strExt; strTmp.Replace("|", " "); if (AvoidableTaskDialog(IDS_REG_REQUIRED, "To use jump lists HexEdit needs to register some file types.\n\n" "Do you wish to associate HexEdit with these files extensions?\n\n" + strTmp, explanation, "File Registration", TDCBF_YES_BUTTON | TDCBF_NO_BUTTON) != IDYES || !theApp.RegisterExtensions(strExt)) { // There is no point in doing anything else if we could not register the file extensions since // even jump list categories KDC_RECENT and KDC_FREQUENT require the extensions to be registered. return; } // TODO: xxx We need keep track of all extensions we have registered in a reg string // xxx so we can unregister them all if necessary. (Perhaps this can be done in // xxx RegHelper.exe, so we know if we added the .ext or just the OpenWithProgids entry) } else if (need_reg) { if (AvoidableTaskDialog(IDS_REG_REQUIRED, "Should HexEdit modify some global registry settings?\n\n", explanation, "Registry Settings", TDCBF_YES_BUTTON | TDCBF_NO_BUTTON) == IDYES) { theApp.RegisterExtensions(""); // set up registry settings without registering any file extensions return; // no need to } } // Add the 3 types of files to the task list CString strCategory; if (theApp.is_us_) strCategory = "Favorites"; else strCategory = "Favourites"; for (int ii = 0; ii < numFav; ++ii) jumpList.AddDestination(strCategory, name_[fav[ii]]); //#define USE_KNOWN_CATEGORIES 1 #ifdef USE_KNOWN_CATEGORIES jumpList.AddKnownCategory(KDC_FREQUENT); jumpList.AddKnownCategory(KDC_RECENT); #else strCategory = "Frequent Files"; for (temp = freq; temp.size() > 0; temp.pop()) jumpList.AddDestination(strCategory, name_[temp.top()]); strCategory = "Recent Files"; for (int ii = name_.size() - 1; ii >= (int)name_.size() - numRecent; ii--) jumpList.AddDestination(strCategory, name_[ii]); #endif jumpList.CommitList(); #endif // _MFC_VER >= 0x0A00 }
void CEmailDlg::OnContextMenu(CWnd* pWnd, CPoint point) { theApp.HtmlHelpContextMenu(pWnd, id_pairs); }
BOOL CMultiplay::OnHelpInfo(HELPINFO* pHelpInfo) { theApp.HtmlHelpWmHelp((HWND)pHelpInfo->hItemHandle, id_pairs_play); return TRUE; }
void CMultiplay::OnPlayOptions() { // Invoke the Options dlg with the macro page displayed theApp.display_options(MACRO_OPTIONS_PAGE, TRUE); }
void CSaveMacro::OnContextMenu(CWnd* pWnd, CPoint point) { theApp.HtmlHelpContextMenu(pWnd, id_pairs_save); }
BOOL CSaveMacro::OnHelpInfo(HELPINFO* pHelpInfo) { theApp.HtmlHelpWmHelp((HWND)pHelpInfo->hItemHandle, id_pairs_save); return TRUE; }