Displaying a text file immediately after creating it.

I have a section of code that needs to output to a text file using CStdioFile 
and then immediately display it using notepad.

I have tried the following, but it doesn't find the file.  However, if I go 
to window explorer, the file is there.  Any Ideas?


  CStdioFile af;
  if 
(af.Open(theApp.WORKDIR+"steerprt.txt",CFile::modeCreate|CFile::modeWrite))
    {
      af.WriteString(tstr);
      af.Flush();
      af.Close();
    }
  HWND mainhwnd = GetSafeHwnd();
  ret1 = (int) 
ShellExecute(mainhwnd,"open",theApp.WORKDIR+"steerptr.txt","",theApp.WORKDIR,SW_SHOWNORMAL);


ShellExecute returns 2 (File not found)
0
phil78 (1)
7/9/2008 8:52:00 PM
vc.mfc 33608 articles. 0 followers. Follow

6 Replies
1035 Views

Similar Articles

[PageSpeed] 38

Because one filename is steerprt.txt and the other is steerptr.txt.

AliR.


"Phil" <phil78@sbcglobal.net> wrote in message 
news:7CFE46AE-2347-4C93-AC28-18341ED84BDB@microsoft.com...
>I have a section of code that needs to output to a text file using 
>CStdioFile
> and then immediately display it using notepad.
>
> I have tried the following, but it doesn't find the file.  However, if I 
> go
> to window explorer, the file is there.  Any Ideas?
>
>
>  CStdioFile af;
>  if
> (af.Open(theApp.WORKDIR+"steerprt.txt",CFile::modeCreate|CFile::modeWrite))
>    {
>      af.WriteString(tstr);
>      af.Flush();
>      af.Close();
>    }
>  HWND mainhwnd = GetSafeHwnd();
>  ret1 = (int)
> ShellExecute(mainhwnd,"open",theApp.WORKDIR+"steerptr.txt","",theApp.WORKDIR,SW_SHOWNORMAL);
>
>
> ShellExecute returns 2 (File not found) 


0
AliR3470 (3236)
7/9/2008 9:12:12 PM
"AliR (VC++ MVP)" <AliR@online.nospam> wrote in message 
news:FP9dk.1729$zv7.1050@flpi143.ffdc.sbc.com...
> Because one filename is steerprt.txt and the other is steerptr.txt.

:-). I couldnt figure it out. I had assumed that OP cut-pasted.

--
Ajay


0
ajaykalra (6842)
7/9/2008 9:36:44 PM
That's amazing.  The two names were so close that it was difficult to see 
the difference and it was likely just a typo.  Nice catch.

The error message from ShellExecute was pretty accurate though :o)

Tom

"AliR (VC++ MVP)" <AliR@online.nospam> wrote in message 
news:FP9dk.1729$zv7.1050@flpi143.ffdc.sbc.com...
> Because one filename is steerprt.txt and the other is steerptr.txt.
>
> AliR.
>
>
> "Phil" <phil78@sbcglobal.net> wrote in message 
> news:7CFE46AE-2347-4C93-AC28-18341ED84BDB@microsoft.com...
>>I have a section of code that needs to output to a text file using 
>>CStdioFile
>> and then immediately display it using notepad.
>>
>> I have tried the following, but it doesn't find the file.  However, if I 
>> go
>> to window explorer, the file is there.  Any Ideas?
>>
>>
>>  CStdioFile af;
>>  if
>> (af.Open(theApp.WORKDIR+"steerprt.txt",CFile::modeCreate|CFile::modeWrite))
>>    {
>>      af.WriteString(tstr);
>>      af.Flush();
>>      af.Close();
>>    }
>>  HWND mainhwnd = GetSafeHwnd();
>>  ret1 = (int)
>> ShellExecute(mainhwnd,"open",theApp.WORKDIR+"steerptr.txt","",theApp.WORKDIR,SW_SHOWNORMAL);
>>
>>
>> ShellExecute returns 2 (File not found)
>
> 


0
tserface (3861)
7/9/2008 9:54:33 PM
"Tom Serface" <tserface@msn.com> wrote in message 
news:e6mDg5g4IHA.4856@TK2MSFTNGP02.phx.gbl...
> That's amazing.  The two names were so close that it was difficult to see 
> the difference and it was likely just a typo.  Nice catch.
>
> The error message from ShellExecute was pretty accurate though :o)

Kicker would have been if there was an actual file with that with different 
content. Or even same content.

--
Ajay

>
> Tom
>
> "AliR (VC++ MVP)" <AliR@online.nospam> wrote in message 
> news:FP9dk.1729$zv7.1050@flpi143.ffdc.sbc.com...
>> Because one filename is steerprt.txt and the other is steerptr.txt.
>>
>> AliR.
>>
>>
>> "Phil" <phil78@sbcglobal.net> wrote in message 
>> news:7CFE46AE-2347-4C93-AC28-18341ED84BDB@microsoft.com...
>>>I have a section of code that needs to output to a text file using 
>>>CStdioFile
>>> and then immediately display it using notepad.
>>>
>>> I have tried the following, but it doesn't find the file.  However, if I 
>>> go
>>> to window explorer, the file is there.  Any Ideas?
>>>
>>>
>>>  CStdioFile af;
>>>  if
>>> (af.Open(theApp.WORKDIR+"steerprt.txt",CFile::modeCreate|CFile::modeWrite))
>>>    {
>>>      af.WriteString(tstr);
>>>      af.Flush();
>>>      af.Close();
>>>    }
>>>  HWND mainhwnd = GetSafeHwnd();
>>>  ret1 = (int)
>>> ShellExecute(mainhwnd,"open",theApp.WORKDIR+"steerptr.txt","",theApp.WORKDIR,SW_SHOWNORMAL);
>>>
>>>
>>> ShellExecute returns 2 (File not found)
>>
>>
>
> 

0
ajaykalra (6842)
7/9/2008 11:42:02 PM
See below...
On Wed, 9 Jul 2008 13:52:00 -0700, Phil <phil78@sbcglobal.net> wrote:

>I have a section of code that needs to output to a text file using CStdioFile 
>and then immediately display it using notepad.
>
>I have tried the following, but it doesn't find the file.  However, if I go 
>to window explorer, the file is there.  Any Ideas?
>
>
>  CStdioFile af;
****
    CString pathname = WORKDIR + _T("steerptr.txt");

Note that I didn't see the mis-spelling either, but it wouldn't have affected me because I
would not have tried to use the same string twice.  I would either have done a #define of
the name or I would have stored it in a variable as above, so there would be no
possibility of the error you got.
****
>  if 
>(af.Open(theApp.WORKDIR+"steerprt.txt",CFile::modeCreate|CFile::modeWrite))
****
How many things are already wrong with this? 

It uses theApp for some variable.  This is wrong.  You should not be tossing values into
your CWinApp-derived class as if they are global variables.  If this code is in the
CWinApp class, it does not need to use theApp; if it is not in the CWinApp class, it does
not need to know about it.

The creation of the path in two places looks suspicious, and this was before I saw the
other comments pointing out the typo.  

Do not use "xxx" for literal strings; use _T("xxx") so you are Unicode-aware

Use spaces around binary operators and after commas so the code is readable.

if(af.Open(pathname, CFile::modeCreate | CFile::modeWrite))

Why is it that so many programmers do not believe in readability, but think that the
fewest number of characters typed is the quality measure for code?  If you believe this,
don't code in C, code in APL.
****
>    {
>      af.WriteString(tstr);
>      af.Flush();
****
There is no need to do a flush; this will happen automatically with the close
****
>      af.Close();
>    }
>  HWND mainhwnd = GetSafeHwnd();
****
Why do you need a variable here?
****
>  ret1 = (int) 
>ShellExecute(mainhwnd,"open",theApp.WORKDIR+"steerptr.txt","",theApp.WORKDIR,SW_SHOWNORMAL);
****
ShellExecute(GetSafeHwnd(), _T("open"), pathname, _T(""), WORKDIR, SW_SHOWNORMAL);
****
>
>
>ShellExecute returns 2 (File not found)
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15975)
7/10/2008 1:41:32 AM
Yes, I agree.  That is one of the best reason to use a const or #define for 
these kinds strings.  At least if the file is named wrong it's named the 
same in both places where it is used.  CString works as well of course, but 
if it never needed to change after the initialization making it a const 
would help protect that.

Tom

"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message 
news:jjpa745r8j6rot8tr7td3bkqboqavc86pi@4ax.com...
> See below...
> On Wed, 9 Jul 2008 13:52:00 -0700, Phil <phil78@sbcglobal.net> wrote:
>
>>I have a section of code that needs to output to a text file using 
>>CStdioFile
>>and then immediately display it using notepad.
>>
>>I have tried the following, but it doesn't find the file.  However, if I 
>>go
>>to window explorer, the file is there.  Any Ideas?
>>
>>
>>  CStdioFile af;
> ****
>    CString pathname = WORKDIR + _T("steerptr.txt");
>
> Note that I didn't see the mis-spelling either, but it wouldn't have 
> affected me because I
> would not have tried to use the same string twice.  I would either have 
> done a #define of
> the name or I would have stored it in a variable as above, so there would 
> be no
> possibility of the error you got.
> ****
>>  if
>>(af.Open(theApp.WORKDIR+"steerprt.txt",CFile::modeCreate|CFile::modeWrite))
> ****
> How many things are already wrong with this?
>
> It uses theApp for some variable.  This is wrong.  You should not be 
> tossing values into
> your CWinApp-derived class as if they are global variables.  If this code 
> is in the
> CWinApp class, it does not need to use theApp; if it is not in the CWinApp 
> class, it does
> not need to know about it.
>
> The creation of the path in two places looks suspicious, and this was 
> before I saw the
> other comments pointing out the typo.
>
> Do not use "xxx" for literal strings; use _T("xxx") so you are 
> Unicode-aware
>
> Use spaces around binary operators and after commas so the code is 
> readable.
>
> if(af.Open(pathname, CFile::modeCreate | CFile::modeWrite))
>
> Why is it that so many programmers do not believe in readability, but 
> think that the
> fewest number of characters typed is the quality measure for code?  If you 
> believe this,
> don't code in C, code in APL.
> ****
>>    {
>>      af.WriteString(tstr);
>>      af.Flush();
> ****
> There is no need to do a flush; this will happen automatically with the 
> close
> ****
>>      af.Close();
>>    }
>>  HWND mainhwnd = GetSafeHwnd();
> ****
> Why do you need a variable here?
> ****
>>  ret1 = (int)
>>ShellExecute(mainhwnd,"open",theApp.WORKDIR+"steerptr.txt","",theApp.WORKDIR,SW_SHOWNORMAL);
> ****
> ShellExecute(GetSafeHwnd(), _T("open"), pathname, _T(""), WORKDIR, 
> SW_SHOWNORMAL);
> ****
>>
>>
>>ShellExecute returns 2 (File not found)
> Joseph M. Newcomer [MVP]
> email: newcomer@flounder.com
> Web: http://www.flounder.com
> MVP Tips: http://www.flounder.com/mvp_tips.htm 


0
tserface (3861)
7/10/2008 2:06:12 AM
Reply:

Similar Artilces:

Converting a publisher file to adobe, with editable text
I prepare publisher files, such as postcards, to send to people in my group. I want them to be able to insert their information when applicable. Is there a way to do that in Publisher, or will I neet a different program? Acrobat Pro can create fill-in documents. Word can too. Not so Publisher. -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com "Linda" <Linda@discussions.microsoft.com> wrote in message news:EE418097-D3AA-4B25-80E7-4B625EAF54D9@microsoft.com... >I prepare publisher files, such as postcards, to send ...

Converting XLS file to QIF or to OFX
How do I safely and securely convert an excel file (xls) to a QIF or OFX file? "dreamchaser" wrote: > How do I safely and securely convert an excel file (xls) to a QIF or OFX file? In Excel, save the file to CSV and ustilise iCreateOFX Basic from: http://icreateofx.co.uk/Convert-CSV-to-OFX to convert the saved CSV file to OFX. ...

lost data when opening excel workbooks ; text import wizard popup
When opening many of my excel files ,which all have the same modification date, I come across the text import wizard which states that my text in these files is 'delimited'. All of the files ,including a few word doc.s have had their data changed to show all " y " with two dots above the letter for as far as the eye can see. No import or export has been done with the files and no modifications were done on that date, as far as I know. Is this a corruption problem or is their some 'fix' that I am overlooking. Thanks for any ideas. ...

conversion lotus 123 files to excel -- problem
I am converting lotus123 files to excel2002. One problem is that in lotus, literals are ignored when found in a cell within a formula. Excel on the other hand is not doing this and therefore causing #value errors on all the formulas where this occurs. Is there a way to handle this in excel other than manually having to change all the formulas? ...

Wrapping text in a cell
In a single cell, suppose I want text to appear on two lines. Viz: Case One Case Two How do I do that so that I specify the wrap point? Thanks! If you are typing the data into the cell use Alt-Enter between each string to indicate where you want a line break to occur. Case One<Alt-Enter>Case Two Alt + Enter -- Lilliabeth ------------------------------------------------------------------------ Lilliabeth's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=27741 View this thread: http://www.excelforum.com/showthread.php?threadid=476428 If you...

How do I display two excel pages at the same time?
I want to have two excel pages displayed on my computer at the same time, but when I open both pages it uses the same master excel and when I toggle between the two it won't open both of them up. I'm using office 2003. Thanks for the help. -- snowtime ------------------------------------------------------------------------ snowtime's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=25982 View this thread: http://www.excelforum.com/showthread.php?threadid=393499 Open both and then do windows>arrange and vertical (or any of the other choices, I usuall...

Is it possible to highlight text?
I'd like to highlight just some of the text in a cell - not the entire thing. Thanks Select the cell and in the edit bar you can then select (highlight) some of the text with the mouse and format how you wish, eg bold, different colour, different background colour, different font/font size etc. Hope this helps. Pete This will NOT work in a formula. Works only if all text. -- Don Guillett SalesAid Software dguillett1@austin.rr.com "Pete_UK" <pashurst@auditel.net> wrote in message news:1139215455.134469.285660@z14g2000cwz.googlegroups.com... > Select the cell ...

Create interactive pivot table chart based on item selected
I'm trying to remember how to drag a chart object to the top left cell of a pivot table thus displaying a charted image of the detail item selected. Any suggestions? ...

How do I get excel files to open automatically from directories?
When I try to open excel files from the directory or from desktop I only get a blank worksheet not the file. I have to then go through File Open to get the file I want. There must be a way to have them open automatically. On Mon, 2 Jan 2006 21:22:01 -0800, Damian <Damian@discussions.microsoft.com> wrote: >When I try to open excel files from the directory or from desktop I only get >a blank worksheet not the file. I have to then go through File Open to get >the file I want. > >There must be a way to have them open automatically. Go to Tools -> Options -> Gen...

problem in changing the text of sentences before tables
I am developing a word automation application. In a method of mine, I change the text of some sentences of an opened word file, but the problem is when I change the text of a sentence which located before a table, it will be moved to the first cell of the table. My code is as follow: void myMethod( long startingSentenceNumber, const char *toBeSearched, const char *replacement, bool replace ) { Range currentSentenceRange; Selection sentenceSelection; Sentences sentencesList = m_document.GetSentences(); long sentencesCount = sentencesList.GetCount(); CString replacementCStr(...

Time Zone / Incorrect Dates Displayed to User
When a user in the Central Time zone closes an opportunity and someone in the Mountain Time zone views it, the Actual Close Date is 1 day before the date the person in the Central Time zone selected. For instance... If someone in the Central Time zone closes an opportunity and selects the Actual Close Date as 6/2/2007: -- Users in the Central Time zone see: 6/2/2007 -- But users in the Mountain Time zone see: 6/1/2007 This is a big issue when running monthly reports as it makes some opportunities show in the wrong month... and will put that revenue in the wrong month. It would make mo...

Odd problem with worksheets when opening file
Okay, here's the odd problem that's come up. When you double click on a excel file, excel opens up, but you can onl see the toolbars. The grid area looks like a snapshot of whatever you current background is before the file opened up. If you were showin your desktop, after the excel file opened, you'd still see your deskto in the datagrid area. If you start up a new excel file, then do the File>Open>file name, th file will open correctly. This problem happens across users here. Everyone is currently runnin office 2K. Any ideas on what causes the problem and any...

Outlook 2002 multiple file opening
In Outlook 2000, CTRL A would select all attached picture files, then Open would, in my case, open the files in Paintshop Pro. With the 2002 version I cannot find a way to do this. Any suggestions? ...

"File: send to mail recipient" not working
When users (on WinXP) select file, "send to mail recipient", no response from Outlook 2002. This occurs either when Outlook is open or closed. Problem happens when rt. clicking on .doc, .xls, .pdf's....all files. Any ideas?? Thanks!! ...

Create incident on website : localhost ok
Hello everybody, I'am using /service/serviceportal.aspx when i open a new case in http://localhost:1917/service/serviceportal.aspx it creates the "incident" normally but when i open a new case in http://danubecrm:1917/service/serviceportal.aspx -> Operation failed due to a SQL integrity violation. Platform System.Web.Services.Protocols.SoapException: Server was unable to process request. at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall) at System.W...

Creating a Check Box
I would like to learn how to create a check box. Is there a way to do that? The simplest checkbox (I think) is from the Forms toolbar. So View|tool bars and show that Forms toolbar. Click on the checkbox and then click on the topleft corner where it should be placed. Then draw to the opposite lowerright corner. When you've placed it correctly, right click on it and select "Format Control" On the Control Tab, you can assign a cell link that you can use to determine if the checkbox is checked or not. =if(A1=True,"It's checked","It's not checked") ...

Cannot get my CImageList to display images?
Ok i am successfully diplaying images in my tree controls but not my list controls. I am using the following but not image is being displayed??? int nIndex = mListCtrl.InsertItem(LVIF_IMAGE | LVIF_TEXT,0,"hello", 0,0,7,0L); Where 7 is a valid index into my image list! Please help? That really doesn't help much. Since you got the tree control working I'm assuming that you are calling the list control's SetImageIist. Also for debugging purposes call GetImageCount on your image list to see how many images it loaded. Let me also point out that you can call this ...

owa logout show the page cannot be display
The event 36 was triggered when Outlook Web Access (2003) users clicked the "Log Off" shortcut. The OWA user would receive the following message when logging off: "The page cannot be displayed. I try to search on google, some of newsgroup report follow microsoft article Q318239 can fix the issue. but this article can not found on support.microsoft.com. anyone have experience about event 36 OWA logout issue. Please help ...

Sheet display vrs. Print Preview
Why would a sheet display differently than when it is printed. I have an excel file that looks like it prints on my bosses computer but on my pc the page breaks are different the word warps are different. This makes it difficult to work with because it will not print the same on my pc and his. We are both using Excel 2003. Thanks for helping. This could have a great deal to do with the printer drivers. Are you printing to the same printer? ******************* ~Anne Troy www.OfficeArticles.com www.MyExpertsOnline.com "Byron" <Byron@discussions.microsoft.com> wrote in mes...

is there a way of using a second monitor as a customer display
This is a multi-part message in MIME format. ------=_NextPart_000_018F_01C86B1D.3EAD2F60 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Hello, Does anyone know if rms works with 2 monitors. What I mean can you use a second monitor as customer display or something similar. A lot of pos systems out there use a second monitor as customer display, I m not sure if rms supports that option or not but any help would be appreciated. thanks ------=_NextPart_000_018F_01C86B1D.3EAD2F60 Content-Type: text/html; charset="us-ascii" Content-Transfer-...

Creating Charts for Use in Powerpoint
I have a series of charts that I need to create for a Powerpoin presentation. I thought it would be easy to just create the charts/graphs in Exce and then just cut and paste to the PP-Slides. I'm finding that it isn' quite that easy. Here are some of my problems that I hope someone might be able to she some light on and give me some direction. 1. In Excel how do you control the size of the chart? - When I create a chart 1 and define the data ranges I get a goo looking chart then I thouht, why reinvent the wheel so I just copy th chart to create chart 2 and change the data range, but...

odd files created
Every time I open and edit an excel spreadsheet on a network share, small odd files get created. They are usually no larger than 25-40k and don't have any extensions to them. Looking at the properties page for any file, the file description says File. Anyone know what this is from or how to get rid of them? Permissions are setup correctly for me, Word files don't have this behavior. Excel 2000 SP3 Thanks, Hi Brian, A file the same size as the workbook would be created in the same directory as the workbook. The filename would be nonsensical (or appear to be random) character...

Create Calendar mtg invite template to avoid retyp'g conf no's?
I want to create a calendar template so that I can avoid retyping my conference call details in the location field everytime I create a new invite. How do I do this? In what version of OUtlook? -- Sue Mosher, Outlook MVP Author of Microsoft Outlook 2007 Programming: Jumpstart for Power Users and Administrators http://www.outlookcode.com/article.aspx?id=54 "GM" wrote: > I want to create a calendar template so that I can avoid retyping my > conference call details in the location field everytime I create a new > invite. How do I do this?...

vba to prevent display of default series in doughnut chart
I am generating a doughnut chart using VBA and am having two immediat issues: 1) I am using the following line to ensure that the default chart tha is generated when I invoke the Charts.Add method is a doughnut chart: Application.SetDefaultChart FormatName:=xlDoughnut Is there a more elegant approach to ensuring that any chart create ends up being a doughnut chart, maybe when invoking the Charts.Ad method? I have tried to specify ChartType = xlDoughnut after th Charts.Add method but this does not do the trick every time (see cod snippet below). 2) When the doughnut chart is added (immediat...

Create Login with T-SQL
Hello, I am creating, using T-SQL, a database with its file groups, tables, constraints, etc. Can I also create, using T-SQL, a Login with Username and Password to access that database? Usually, I go to Security > Logins of SSMS to manually create the login. However, if I could do the same using T-SQL I would have it all made automatically. Thanks, Miguel EVERYTHING that the GUI does winds up as tsql executions on the server. :-) Most of them you can generate a script for using the Script menu in the upper left of the current dialog window. This is a great way to ...