473,385 Members | 1,901 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

File opening

Hi.
I am developing a small code in VC++. I have created a GUI where I want to open a file (*.doc or any other I/P or O/P file) with a button click,i.e., when a button is clicked while running specific file should get opened. If it can be achieved through Menu bar that is also OK. Somebody Please help me.
Thank you
Apr 1 '08 #1
8 2300
sicarie
4,677 Expert Mod 4TB
Sure, what do you have so far?
Apr 1 '08 #2
Sure, what do you have so far?
Thank you for your interest.
I have just created MFC application, which on running produces a form. It has a menu bar "Help". Clicking on this gives default "About Dialog box". Instead of this I want to display any '.doc' or similar file when "Help" menu is clicked.
Not a major code is developed till date but I just want to link the file. Same way i want to read/edit the files (as they are in the working directory) by a button click. What else should I give? Any sanps or code?? Please guide.
Regards
Milind
Apr 2 '08 #3
Studlyami
464 Expert 256MB
I'm a little confused, Does the user get to select which file to open (an open file dialog), or does a button link to one specific file?. I find the default menu bar useless especially when creating your own menu bar is really easy to do (check out this link for info.). That tutorial also tells you how to capture when a user has clicked on a menu item. From there when you receive the message saying the user clicked on the menu item you would open the specific file (or an open file dialog to allow the user to select the file). As far as a button is concerned you would capture when the user clicked on the button and then you would perform the same operation as i described in the menu part above. If you don't know how to capture the button click then you need to read some more tutorials. I find that the website given above is very helpful and explains things quite well.
Apr 2 '08 #4
Thank you for the suggestion. I'll go through the manual you suggested and come back to you. By the way, the default FILE->OPEN dialog box actualy does nothing when user try to open any file. I want specificaly : Opening any file for editing or reading purpose by any means (Menu bar or button click). Any particular message map is there for this purpose??
Regards
Apr 3 '08 #5
Studlyami
464 Expert 256MB
Alright now the question comes down to "what do you mean open/ edit the file". If its a word document do you want the item to open up in word? Or, do you mean open the contents into your project allow them to edit it and then save it? The tutorial i gave you above is about menu bars seeing how that isn't your main focus this tutorial will tell you how to capture a button click and how to create an open file dialog (this allows the user to navigate to the file they want), then tells shows you how to open the file using CFile.
Apr 7 '08 #6
Alright now the question comes down to "what do you mean open/ edit the file". If its a word document do you want the item to open up in word? Or, do you mean open the contents into your project allow them to edit it and then save it? The tutorial i gave you above is about menu bars seeing how that isn't your main focus this tutorial will tell you how to capture a button click and how to create an open file dialog (this allows the user to navigate to the file they want), then tells shows you how to open the file using CFile.
Thanks for the reply. that solves my problem halfway.
What if I want to open the doc file in m/s word? Also I tried opening big txt file (containing only numbers). But it could open only few lines out of it. Any suggestions for this?
Apr 8 '08 #7
Studlyami
464 Expert 256MB
What if I want to open the doc file in m/s word?
I really don't know how to open a document in another program, but first i would search google. Then if i still have problems i would post up a new question here in the forums.

As far as opening a large text file could we see your code that you use to: 1. open the file 2. how you read the file 3. any other code you think is relevant.
Apr 8 '08 #8
I really don't know how to open a document in another program, but first i would search google. Then if i still have problems i would post up a new question here in the forums.

As far as opening a large text file could we see your code that you use to: 1. open the file 2. how you read the file 3. any other code you think is relevant.
I am using exactly the same code as given in the tutorial.
Expand|Select|Wrap|Line Numbers
  1.     this->UpdateData();
  2.  
  3.     CFile f;
  4.     //char strFilter[] = { "Doc Files (*.doc)|*.doc|All Files (*.*)|*.*||" }; ///////This Option doesn't work
  5.     char strFilter[] = { "Txt Files (*.txt)|*.txt|All Files (*.*)|*.*||" };
  6.  
  7.     //CFileDialog FileDlg(TRUE, ".doc", NULL, 0, strFilter);
  8.     CFileDialog FileDlg(TRUE, ".txt", NULL, 0, strFilter);
  9.  
  10.     if( FileDlg.DoModal() == IDOK )
  11.     {
  12.         if( f.Open(FileDlg.GetFileName(), CFile::modeRead) == FALSE )
  13.             return;
  14.         CArchive ar(&f, CArchive::load);
  15.  
  16.         ar >>m_edit; // m_edit is CString type member variable associated with the Edit box. 
  17.         //ar >>m_edit; ////writting this line 2nd time has a effect of displaying only the next(2nd) line of the file
  18.         ar.Close();
  19.     }
  20.     else
  21.         return;
  22.  
  23.     f.Close();
  24.     this->UpdateData(FALSE);
  25.  
For some files (typicaly text starting from the first line & first column) Run time Error message comes "An attempt was made to access an unnamed file past its end". For the other files it displays only the first 1 or 2 lines (though I have given HScroll & VScroll options to the Edit box where it is displaying the file).
Regards
Apr 9 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Stewart Midwinter | last post by:
I want to parse a file with ElementTree. My file has the following format: <!-- file population.xml --> <?xml version='1.0' encoding='utf-8'?> <population> <person><name="joe" sex="male"...
1
by: Alfons | last post by:
Hello, I have build a program that can do file transferring between a Windows XP computer and a DOS computer via a serial port. The Windows program I have build in C++ with Visual Studio 6.0....
5
by: zambak | last post by:
Hi I have assignment for some wierd compression alghoritam that will read in from a file convert characters to 5 bit codes and then write out compressed version of the original file. For...
19
by: wetherbean | last post by:
Hi group..I am writing a playlist management protocol where I have a file that holds all the playlists and a file that holds all the songs....before a playlist is created I need to check to see if...
6
by: Can | last post by:
I am trying to create a .dll file using VB.Net Standard using the info from this website http://www.devcity.net/Articles/111/1/vbnet_se_dll.aspx My problem is when I open up the .vbproj file in...
11
by: aldrin | last post by:
I'm trying to run this code under windows xp sp2 using codeblocks v1.0 compiler with great difficulty.There is no problem with running this under KDevelop in linux. Any help would be greatly...
2
by: quicklearner | last post by:
hi I have made a CHM file and I have linked my .CHM file with the controls on the Form in my application which is made in C# 2005. Its working fine . But I want that if user presses 'F1' then when...
14
by: prasadjoshi124 | last post by:
Hi All, I am writing a small tool which is supposed to fill the filesystem to a specified percent. For, that I need to read how much the file system is full in percent, like the output given...
1
by: Sanjeeva K kanakam | last post by:
Hi all, I am developing one application. In that i have created on report file which contains tables, titles and tree view list also by using HTML tags. I am opening this file in my application it...
34
by: Alexnb | last post by:
Gerhard Häring wrote: No, it didn't work, but it gave me some interesting feedback when I ran it in the shell. Heres what it told me: Traceback (most recent call last): File...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.