|
|
I can read in a notepad file in entirety, store it in a CString,
and then write it out. I cant do the same for a file in rich text
format. For some reason, I dont get all of the file and when I
write it out and then launch it, it shifted around. Any idea on
how to read in an entire RTF file to a CString and then write it
out?
I put together this code:
CString str; char c;
ifstream In("c:\file.rtf");
while (In)
{
In >> c;
if (In) str += c;
}
In.close();
ofstream Out("c:\\file1.rtf");
int len = str.GetLength();
for (int i=0; i
|
|
|
|
|
DanYELL wrote: I cant do the same for a file in rich text
format. For some reason, I dont get all of the file...
Probably because of the embedded '\0' characters (when using a CString object).
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
Try with a CFile:
1. Open the file
2. Allocate a buffer based on the file length
3. Read into the buffer.
4. Close the file.
5. Write the buffer to another file.
6. Delete the buffer.
This doesn't care about embedded nulls.
The tigress is here
|
|
|
|
|
I think your right that CFile is the solution. I sincerely appreciate
your feedback. My only remaining question is, how can I efficiency
read the entire file into a CString or something other than a buffer.
I have:
char buf[50001];
CFile cfFile ("C:\\Gille.RTF", CFile::modeNoTruncate | CFile::modeRead);
cfFile.Read(buf, 50000);
// open
CFile f;
CFileException e;
char* pFileName = "c:\\Gille2.rtf";
if( !f.Open( pFileName, CFile::modeCreate | CFile::modeWrite, &e ) )
{
#ifdef _DEBUG
afxDump << "File could not be opened " << e.m_cause << "\n";
#endif
}
f.Write(buf, 50000);
The
char buf[50001];
is really bad. I had char buf[501]; and that wasnt big enough for a
1-page file. So I made it bigger. Is there a way to read in exactly
enough and to make the buffer the exact size? Also, what happens if
I read in a 10-page RTF file? How big can a buffer get?
Please, any response you can give me will be greatly appreciated.
Sincerely,
Danielle Brina (an overworked graduate student)
|
|
|
|
|
I know I can use:
cfFile.GetLength();
How can I not use a buffer and instead use something else like
a CString?
|
|
|
|
|
Probably something like:
CString strFileContents;
int nLen = cfFile.GetLength( );
LPTSTR pszBuffer = strFileContents.GetBufferSetLength( nLen + 1 );
cfFile.Read( pszBuffer, nLen );
strFileContents.ReleaseBuffer( );
Note: I didn't run this through a compiler, expect bugs
Wenn ist das Nunstück git und Slotermeyer? Ja! Beierhund das oder die Flipperwaldt gersput!
|
|
|
|
|
|
Hi,
Please give me idea about the function that are declared as follows,
void fun(CString str, ...);
Can I get total no. of strings (arguments) passed to th function?
Also, when I use char instead of CString as arguments data type; it's not working properly.
Thanks.
|
|
|
|
|
if you use ellipsis, then it is more a C function. if so, don't use C++ objects.
if you use C++, then change the ellipsis into a linked list (like std::vector<>) to pass your variable list of parameters
|
|
|
|
|
Aniket Salunkhe wrote: Can I get total no. of strings (arguments) passed to th function?
No, not unless you also specified a terminator.
Aniket Salunkhe wrote: Also, when I use char instead of CString as arguments data type; it's not working properly.
Ok. Without showing the code snippet that does/does not work, what exactly are you hoping for?
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
I am using following function. Is this a correct way?
int CMyListControl::insertItems(int argNo, CString strItem, ...)
{
CString strTemp[10];
LVITEM lvItem;
SetRedraw(FALSE);
lvItem.mask = LVIF_IMAGE | LVIF_TEXT;
lvItem.iItem = CurRow;
for(int i=0; i < argNo ;i++)
{
strTemp[i].Format("%s",*((&strItem)+i));
lvItem.iSubItem = i;
lvItem.pszText = (LPTSTR)(LPCTSTR)(strTemp[i]);
(i==0)?InsertItem(&lvItem):SetItem(&lvItem);
}
return(CurRow++);
}
But i dont want to use 'argNo' as an indiaction of no of 'CString' parameters passed to the function.
Even I failed to use 'char' string in place of 'CString'.
It is giving Error, if I want to use function as,
int CMyListControl::insertItems(int argNo, CString strItem, ..., int Row = -1)
|
|
|
|
|
hi all,
i want to impersonate the Remote Machine. i am going this api's please see it.
LogonUser();
ImpersonateLoggedOnUser();
CopyFile();
RevertToSelf();
CloseHandle();
is this api's are correct to proceed and please provide your suggestions.
thanks,
uday.
uday kiran
|
|
|
|
|
Is the impersonation needed for CopyFile() to succeed?
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
I need to enable a a single CEdit control to show messages from all the languages english, chinese, german, hindi etc, in other terms I wish to make edit control unicode enabled.
1. I create a unicode text(.txt) file, and enter characters from German language like "ÖÄß" etc, and few characters from hindi language "सवबहठ".
2. I read this file using CStdio class, and try to print these characters in my edit control, however i find that string shown on the edit control is "ÖÄß?????".
What am I missing ? what could be done to make it work correctly. Do I need to find a font which supports all the languages in the world and assign this font to my edit control ?
Thanks in advance!
Regards
Suyash
|
|
|
|
|
I am trying the same thing. I tried changing the font of the edit ctrl for the current font for which the character belongs.
But this will make the string look like ÖÄß????? and then make it ???सवबहठ.
So I guess CEdit is of no help.
I tried CRichEdit Control. But this doesnt support unicode atall.
Can any one help?
|
|
|
|
|
Arti,
I tried CRichEdit Control. by default it doesn't support unicode.
l_pWnd->Create( _T( "RichEdit20W" ), NULL, in_dwStyle,
in_rcRect, in_pParentWnd, in_nID );
please note "RichEdit20W" which makes the CRichEditControl unicode enabled, by default its "RichEdit"
hope it helps.
regards
suyash
|
|
|
|
|
i was wondering how do you grey-out / disable the date time picker, is there a flag that can be changed say using a send message?
i have my date time picker as a CDateTimeCtrl type
|
|
|
|
|
Disable:
CDateTimeCtrl yourCtrl;
yourCtrl.EnableWindow(FALSE);
Enable:
CDateTimeCtrl yourCtrl;
yourCtrl.EnableWindow(TRUE); CDateTimeCtrl derives from CWnd, which exposes the EnableWindow function, hence you can use EnableWindow on all CWnd derived objects
- Dy
-- modified at 9:45 Tuesday 11th April, 2006
|
|
|
|
|
Did you try this?
GetDlgItem(IDC_YOUR_DATE_TIME_PICKER)->EnableWindow(FALSE);
regards!
|
|
|
|
|
thanks all, enablewindow works perfect, dont know why i didnt think of that!! i was trying to the the EN_******** to use with a sendmessage!!
|
|
|
|
|
EN_******** messages are for EditBoxes controls
|
|
|
|
|
hi all
i want to show the folder with icons on the dialob box or any other window. and when user clicks on any folder it shows its contents like the windows normally does. how to do this.
Tasleem Arif
|
|
|
|
|
Your question is a bit unclear? What folder, and what dialog box are you referring to?
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
Hi tasleem143 ,
Do you need to icon folder in system?
|
|
|
|