[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 962
  • Last Modified:

mfc sdi open and display file

Hi, how do I open a text or binary file and display it in my sdi form? I would also like to display the file name and path in a separate edit box.
0
sassy4sure
Asked:
sassy4sure
  • 6
  • 4
  • 2
1 Solution
 
cupCommented:
How exactly do you intend to display the binary file?  Binary files could be full of control characters.  Will you be displaying it as an image, hex translations of each byte/word or some other special representation?
0
 
sassy4sureAuthor Commented:
Well I have decided to use a simpler windows form. I have already opened the file and have the filename visible in the textbox. The problem is I want to program a button that on click displays the file in another multiline text box. I am not sure how it should be displayed though. The file hold records in columns and rows.
How do I code the display button to get the filename that is currently open and display it to the multiline button?
0
 
cupCommented:
I'm confused about the design.  Is this right

You have a form with

1) A filename in a text box
2) An empty multiline text box
3) A button which tells the program to populate the multiline box with the contents of the filename specified in the single line text box
4) Other bits that you haven't mentioned

What you want to do is to populate 2 when 3 is pressed.  If this is correct and you have a sort of grid in the file, then 2 needs to be either a list control or a listview control not a text box

WIth a list control, pack each line of the file into a string.  All cells are separated by tabs.  As you write them to the control, they will appear in columns.

With a list view, you have more control.  You can address different cells, change headers etc.  You can even change the backgrounds of different cells and vary the widths.
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
sassy4sureAuthor Commented:
ok but how do I code the button to  populate the list view using the filename in the other textbox?
0
 
cupCommented:
I'm assuming you're using dynamic data exchange.  The filename in the text box should be in the CString you've nominated for the text box.   On the button press for that button,  grab that cstring, open the file, read the data and populate.

There are lots of examples of how to populate listviews on the net.  Here are a couple

http://www.codeproject.com/listctrl/listctrldemo.asp
http://www.codeproject.com/listctrl/clistctrl_insertrow.asp

What you have to remember about listviews is that only the first column is selectable.  If you want another column to be selectable, you have to rearrange the column order.

If you wish to do fancy things like colouring the cells in the listviews, have a look at

http://www.codeguru.com/cpp/controls/listview/
0
 
sassy4sureAuthor Commented:
I think I would like to try opening it in a textbox. I know this is possible but I am as yet unable to find any examples of it. As i said i am no longer using MFC.I'm just using a simple windows  form application.
0
 
cupCommented:
Penny just dropped: you want to code this using SDK.  I'll see if I can find some sample code for you.  The samples used to come with the help on the earlier versions of their C++ compiler.

Alternatively if you want to do a search (I won't be able to do anything for the next 15 hours as I'll be at work), you need to look for the Windows CE sample code under Platform SDK on the visual studio help.  Windows CE does not support MFC - it is too bulky for mobile phones.
0
 
AndyAinscowCommented:
>>>simple windows  form application

Are we talking .net here ?
0
 
cupCommented:
In VS help, look up

"word processing" edit control

under Windows User Interface subset.
0
 
sassy4sureAuthor Commented:
>>Are we talking .net here ?

Yes which I am extremely new to

>>"word processing" edit control
under Windows User Interface subset.

I don't think this is what I'm talking about here is what I have for the button's on click event

private: System::Void OnClickedDisplayFile(System::Object^  sender, System::EventArgs^  e) {

            Stream^ myStream;
             this->textBox2->Clear();

            if ( (myStream = openFileDialog1->OpenFile()) != nullptr )
         {
                  
           textBox2.text=myStream /// Here I am trying to display the opened file in a multiline textbox

            myStream->Close();
         }
      }
0
 
cupCommented:
Oh well, I got the wrong end of the stick when you said you weren't using MFC.  I thought you were using SDK.  Sorry - I don't know anything about the managed stuff or Microsoft's new found use of ^ (which is not in any C++ standard).  I'll leave it to some other MVP to help you.
0
 
AndyAinscowCommented:
There are areas specific to .net (the areas you have posted this question in are not the .net areas)

I would suggest you open another question in a .net area (20 points) and clearly note it is a link question to this question - no comments desired there so you can delete it later.  Copy the www adress of this question and paste it into the new question.


ps. I think cup has shown you how to code the logic, just missing a bit of .net specific stuff.  (I don't have time to help out with some code here).
0

Featured Post

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

  • 6
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now