Author Topic: Displaying Hexadecimal Code of a Binary Data File  (Read 1195 times)

0 Members and 1 Guest are viewing this topic.

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Displaying Hexadecimal Code of a Binary Data File
« on: June 10, 2011, 04:24:47 pm »
I would like to know how to open a binary file and then display the hexadecimal code in a text box.

Code: [Select]
void MainFrame::OpenFile(wxCommandEvent& WXUNUSED(event))
wxFileDialog *OpenDialog = new wxFileDialog(
this, _("Choose a file to open"), wxEmptyString, wxEmptyString,
_("All Files (*.*)|*.*"),
wxFD_OPEN, wxDefaultPosition);
// Creates a "open file" dialog with 4 file types
if (OpenDialog->ShowModal() == wxID_OK) // if the user click "Open" instead of "cancel"
CurrentDocPath = OpenDialog->GetPath();
// Sets our current document to the file the user selected
MainEditBox->LoadFile(CurrentDocPath); //Opens that file

SetTitle( wxString(OpenDialog->GetFilename()) );

I got that code in wxWidgets tutorial to open an ASCII file, but what if it is a binary data file and I want to display the hexadecimal code, or even better, save it as a wxString or a std::string.

Preferably, I want to display the hex code in the MainEditoBox textbox as if it were an hex editor.

Thanks in advance.

Note: I'm using wxWidgets GUI Toolkit.
« Last Edit: June 10, 2011, 04:30:51 pm by Scout »