|
Hey all.
I've got a text file that I am trying to modify, but am running into some problems. Here's the code that I am using:
CStdioFile myFile;
myFile.Open("c:\\temp\\test1.txt",CFile::modeReadWrite);
myFile.Seek(40,CFile::begin);
myFile.WriteString("this is the replaced line\n");
myFile.Close();
It kind of works, but what is happening is it is overwriting the contents of the next lines and I can't figure out how to get around this. Ie, the file looks like this before I run it
line 0
line 1
line 2
line 3
line 4
line 5
line 6
line 7
line 8
line 9
then, after i execute the above statements
line 0
line 1
line 2
line 3
line 4
this is the replaced line
e 8
line 9
So, when the newly modified text is written, if it happens to be longer than the original line, it will write over other lines below it, instead of "appending" so to speak, making the file look like:
...
line 3
line 4
this is the replaced line
line 6
line 7
line 8
... if I do something like "...WriteString("line Z"), it replaces it fine because the new string matches the length of the one that's in the file. Any ideas on how to replace an entire line in a text file (each line is ended with \n) without overwriting following lines?
Thanks
|
|
|
|
|
U have to store remaining lines( after 4 line) in some other temporary buffer , then insert what ever content u want insert , once again append temporary buffer.
|
|
|
|
|
hi,
How can i make Directory at Run time ona specifc Path if it is not there.... nad if it is already present how can i chk it..
thanx
|
|
|
|
|
One solution is CreateDirectory().
Kuphryn
|
|
|
|
|
if the Directory is already Exist ... then i not wanna that to show my client it is already
i just want to skip that step..
how can i do it
|
|
|
|
|
The OS will not create the directory if it already existed.
Kuphryn
|
|
|
|
|
You may check if the folder exists with GetFileAttributes()
|
|
|
|
|
Wildcards don't seem to work in CFile::Remove, for example:
CFile::Remove("c:\\junk\\*.dat"). Should this work or is there a better (correct) way?
|
|
|
|
|
You need to do a file search for wild cards like using CFindFile in MFC and other Win32 APIs provided.
Sonork 100.41263:Anthony_Yio
Life is about experiencing ...
|
|
|
|
|
Perhaps SHFileOperation would help?
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
can someone help me with or point me in the right place so i can figure out how to use a button to copy from a edit box i can do it but i have to click on the edit box first then click the button and i dont want to have to do it that way
|
|
|
|
|
Simply add a message handler for the button click. Access the edit control's text via GetWindowText().
Kuphryn
|
|
|
|
|
I am trying to create a DLL plugin to another application which launches an MFC CFrameWnd from a function in the DLL that gets called by the application. The problem I am having is that some of my messages are going missing. The message that highlights the menu when the Alt key is pressed is missing and the menu does not get highlighted. Also, I have a CDialogBar control that the Tabs and Enters do not work.
I have created a Regular MFC DLL in .NET 2003 but I do not create the window in the CWinApp InitInstance function. I create it in a seperate function that gets called by the parent application that consumes the DLL. I am thinking that this might be the cause of my problem but I do not want to create the window when the plugin gets loaded. Should I be creating an MFC Extension DLL instead?
Any ideas what could be going wrong?
Thanks
|
|
|
|
|
|
Hello everyone,
I want to use the CArray template class, but I am having difficulty getting it loaded. What I mean is that when I load the header file that defines it, "afxtempl.h", I get the following error:
[code]
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\atlmfc\include\afxv_w32.h(18):
fatal error C1189: #error : WINDOWS.H already included.
MFC apps must not #include <windows.h>
[/code]
I'm kind of stuck as to what to do. I noticed that code posted online seems to include "stdafx.h" instead of "afxtempl.h". I think this file is a generated file, but I'm not sure how to go about generating it.
This is my first post, so please let me know if I need to include additional information.
Thanks,
-Jash
|
|
|
|
|
When you load MFC, it will initialize the windows.h for you. Loading windows.h again will cause redundancy.
It a better practice of placing your MFC headers in your stdafx.h along with other MFC headers like
#include <afxwin.h> // MFC core and standard components
#include <afxext.h> // MFC extensions
#include <afxtempl.h>
<B>Sonork 100.41263:Anthony_Yio
Life is about experiencing ... </B>
|
|
|
|
|
Hi,
I need to create a CHeaderCtrl that contains sub-headers.
Any suggestions would be highly appreciated.
Here is what I need:
-------------------------------
|Title1|Red_Geen_Blue|Title3|
-------------------------------
|Title1|Red|Green|Blue|Title3|
-------------------------------
|data1|Red|Green|Blue|data3|
|data2|Red|Green|Blue|data3|
|data3|Red|Green|Blue|data3|
-------------------------------
In this example, this table contains 5 columns and 3 rows.
The header of this table contains 2 rows. First row is for
the main title, second row is for the real title of each
column.
(The example of the table headers that contains multiple lines
does not help me to resolve this problem.)
Thank you in advance for your help.
Boilam
|
|
|
|
|
|
OK, this is silly.
I have Visual C++6.0 with SP6 because it's what we use at work.
I have WinXP at home, everything updates SP1 etc.
When adding a MFC derived class to a MDI project CObject doesn't appear in the list of MFC classes !
Any ideas ?
The tigress is here
|
|
|
|
|
This looks like a bug in your installation, or a missing setting.
Have you checked all directory settings of Visual Studio. It uses those directories to discover the base classes available in the wizards, I think. Or, at least I've been able to add my headers/C++ files to these directories and be able to derive from them using the wizards.
Is the CObject available for derivation in other project types ? If it is, then it's a bug in the program. My Visual Studio 2003 allows derivation from CObject without problems.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
I have Visual C++.NET and that allows derivation from CObject and I have tried Visual C++6.0 on Winows 200- and that doesn't
At the moment I'm doing it manually but I'll have a look at the directory settings later.
Thanks
Elaine
The tigress is here
|
|
|
|
|
hi all,
i am working on a program that requires loading a bitmap using win32 and then allows the user to click on the bitmap and then uses the clicked points for further processing. also i need to display line segments to the clicked points from the origin.
i have been able to load the bitmap and get the points by handling the WM_LBUTTONDOWN message. but i am have been unsucessful in displaying the line segments, please provide some suggestions !!! thanks in advance
|
|
|
|
|
First Draw Bitmap then Draw line..then that will come over it...
Bitmap draw you know...
line draw as follow...
BOOL CXYZLine::Draw(CDC* pDC)
{
CPen penRuler;
if (!penRuler.CreatePen(m_nPenStyle, m_nPenWidth, m_LineColor))
return FALSE;
CPen* pOldPen = pDC->SelectObject(&penRuler);
pDC->MoveTo(m_ptStart);
pDC->LineTo(m_ptEnd);
pDC->SelectObject(pOldPen);
if(m_bSelected) DrawTracker(pDC);
return TRUE;
}
this is only I can help you...
Bye...
---Sumit Kapoor---
|
|
|
|
|
Hi,
Does anyone know how to make CFileDialog show in the image thumbnail view? Doesn't seem to be straight forward and looks like a little hackery might be required.
Thanks in advance
Rich
|
|
|
|
|
I've tried and failed See the comments at the end of this[^] article for some of the gory details.
Rob Manderson
I'm working on a version for Visual Lisp++
|
|
|
|