|
Hi all,
Now I've start to work on another work. I'm looking to read a RTF(Rich Text Format) file. Here is a simple *.rtf file content, which is open using a notepad.
<br />
{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fcharset0 Arial;}}<br />
{\*\generator Msftedit 5.41.15.1507;}\viewkind4\uc1\pard\qc\b\f0\fs20 One\par<br />
Two\par<br />
Three\par<br />
Four\par<br />
Five\par<br />
\pard\b0\par<br />
}<br />
How I get this is, write words One,Two,Three,For,Five on the word pad and do some text formating on it, like bold, change color and few. Then save it as RTF file and open it using notepad. The content is like above. From this content I want to extract written words by me.
Can you guys give some clue for me.
I appreciate your help all the time...
Eranga
|
|
|
|
|
Try to feed with RTF the CP article search engine, maybe a wonderful world is awaiting for you.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Ok, I have start work in this way. Read the file and get the content to a buffer. Then processing it until either '\' or '{' not find, so it should be a text word. Here is the code.
main function
<br />
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])<br />
{<br />
int nRetCode = 0;<br />
<br />
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))<br />
{<br />
_tprintf(_T("Fatal Error: MFC initialization failed\n"));<br />
nRetCode = 1;<br />
}<br />
else<br />
{<br />
CFile rtfFile;
bool err = rtfFile.Open("G:\\Work On\\CPP\\Counter\\TestFile.rtf", CFile::modeReadWrite, NULL);<br />
<br />
if(err != 0)<br />
{<br />
int length = rtfFile.GetLength();<br />
char *pbuff = new char[length];<br />
<br />
rtfFile.Read(pbuff, length);<br />
<br />
<br />
CString text(getText(pbuff));<br />
<br />
cout << (LPCTSTR)text;<br />
<br />
<br />
}<br />
}<br />
<br />
return nRetCode;<br />
}<br />
getText function
<br />
CString getText(const CString & rtf)<br />
{<br />
CString strCopy;
CString ch;
CString str(rtf.GetAt(1));<br />
<br />
BOOL bBrace = FALSE;
BOOL bSlash = FALSE;
BOOL bFirstLetter = FALSE;
<br />
int nLength = rtf.GetLength();
<br />
if (nLength < 4)<br />
{<br />
return "";<br />
}<br />
<br />
for (int i = 0; i < nLength; i++)<br />
{<br />
ch = rtf.GetAt(i);<br />
<br />
if (ch.Find('\\') != -1)<br />
{<br />
bSlash = TRUE;<br />
continue;<br />
}<br />
else if (ch.Find(' ') != -1)<br />
{<br />
bSlash = FALSE;<br />
if (!bFirstLetter)<br />
{<br />
continue;<br />
}<br />
}<br />
else if (ch.Find('{') != -1)<br />
{<br />
bBrace = TRUE;<br />
bSlash = FALSE;<br />
continue;<br />
}<br />
else if (ch.Find('}') != -1)<br />
{<br />
bSlash = FALSE;<br />
bBrace = FALSE;<br />
continue;<br />
}<br />
<br />
if (!bSlash && !bBrace)
{<br />
if (!bFirstLetter)
{<br />
bFirstLetter = TRUE;<br />
}<br />
strCopy += ch;<br />
continue;<br />
}<br />
}<br />
return strCopy;<br />
}<br />
My question is I can call the getText function inside the main function, gives an compilation error. Error is this,
unresolved external symbol "class ATL::CStringT<char,class strtraitmfc_dll<char,class="" atl::chtraitscrt<char=""> > > __cdecl getText(class ATL::CStringT<char,class strtraitmfc_dll<char,class="" atl::chtraitscrt<char=""> > >)" (?getText@@YA?AV?$CStringT@DV?$StrTraitMFC_DLL@DV?$ChTraitsCRT@D@ATL@@@@@ATL@@V12@@Z) referenced in function _main</char,class></char,class>
Can you tell me where I'm going wrong.
I appreciate your help all the time...
Eranga
|
|
|
|
|
What are the header files you included?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
I've only use standard header files.
Actually I can solve it just passing the CString to the getText function as follows.
CString getText(const CString rtf)
But why I can't pass the string as reference.
Also, I want to find the '\pard' string of the full string and replace it with '['. I tried this,
rtf.Replace(_T("\\pard"), _T("["));
It gives another error,
'ATL::CStringT<basetype,stringtraits>::Replace' : 2 overloads have no legal conversion for 'this' pointer<br />
with<br />
[<br />
BaseType=char,<br />
StringTraits=StrTraitMFC_DLL<char><br />
]</char></basetype,stringtraits>
What is mean, I've try this before search the string(ie: before the for loop)
I appreciate your help all the time...
Eranga
|
|
|
|
|
Eranga Thennakoon wrote: I've only use standard header files
In other words?
I made a little test (console without MFC ) project, including atlstr.h to use non-MFC string and I had no compilation issues both for
void getText(CString &str)
{
...
}
and
...
CString s;
s = _T("\\pardHi");
s.Replace(_T("\\pard"), _T("["));
...
the latter setting correctly s = "[Hi"
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Thanks for the replay.
Are you sure this is correct. Gives the compilation error on '_' identifier is not found.
CPallini wrote: s = _T("\\pardHi");
I appreciate your help all the time...
Eranga
|
|
|
|
|
Eranga Thennakoon wrote: Are you sure this is correct. Gives the compilation error on '_' identifier is not found.
CPallini wrote:
s = _T("\\pardHi");
Yes, provided you include the Generic-Text Mappings header tchar.h .
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Ok, I got the points. I've miss the text mappings.
Actually what I want to do is replace '\pard' with '[' from the whole string, that is of the rtf. That is why I use rtf.Replace(_T("\\pard"), _T("["));
If you can send me your mail address. If you can please check my code and let me know where I'm going wrong.
I appreciate your help all the time...
Eranga
|
|
|
|
|
Eranga Thennakoon wrote: Actually what I want to do is replace '\pard' with '[' from the whole string, that is of the rtf. That is why I use rtf.Replace(_T("\\pard"), _T("["));
This is working for me, why don't you use non-MFC CString ?
Eranga Thennakoon wrote: If you can send me your mail address. If you can please check my code and let me know where I'm going wrong.
Well, my e-mail address is available on my profile. But you really don't need it: if you have a programming question please use CP forums.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
CPallini wrote: This is working for me, why don't you use non-MFC CString ?
Oops, sorry that I've use the wrong way. I used the char buffer instead CString.
CPallini wrote: Well, my e-mail address is available on my profile. But you really don't need it: if you have a programming question please use CP forums.
Sorry if I make any trouble to you. Why I'm ask it because I'm fail to explain my question to you. You are right. I have to much deal with forum.
I appreciate your help all the time...
Eranga
|
|
|
|
|
I need to write a voice over ip module applied between 2 hosts for a local network using vc++? Is there anybody can provide me some information or guide or sample on it? I need to solve it within 2 weeks and i don't have any idea yet. In fact i am not really clear on how VoIP function as well.
Sun
modified on Tuesday, December 11, 2007 11:06:57 AM
|
|
|
|
|
Then the first thing you have to do is to search for info about the VoIP and read. If you don't even understand what you will try to do... it will be pretty difficult for you to programm it.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
|
|
|
|
|
Think about the tasks and how to handle each one:
get digitized voice from user
transmit data to other host
receive data from other host
output digitized voice to user
Judy
|
|
|
|
|
Hi All
I need help in initialization list/constructor in abstraction
I have abstract base class -
class ICloth
{
ICloth();
...........
}
class CMyCloth:public ICloth
{
CMyCloth(EColor color, ESize size,EStatus status,EType type,EQuality
quality);
...........
}
class CHighTechCloth:public CMyCloth
{
public:
CHighTechCloth();
...................
}
/////
now in main I try to create CHighTechCloth object, what do I do wrong?
CHighTechCloth* pMyNewCloth = new
CHighTechCloth():ICloth(ICloth::EC_RED,
ICloth::CS_SMALL,
ICloth::CST_NEWCLOTH,
ICloth::CT_EYEGLASSES,
ICloth::EQ_LOW)
|
|
|
|
|
You simply cannot do that.
You have either to provide a default constructor for class CMyCloth (and you've lost the 'per instance members initialization feature')
or a compliant (to class CMyCloth 's one) constructor for CHighTechCloth class , for instance:
class CHighTechCloth:public CMyCloth
{
public:
CHighTechCloth(EColor color,
ESize size,
EStatus status,
EType type,
EQuality quality):
CMyCloth( color, size, status, type, quality)
{}
...
}
BTW compiler error messages usually give meaningful hints.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
my error message was: error C2143: syntax error : missing ';' before ':'
I guess I tried to do the compliant , just wasn't sure how.
I will try it
thanks!!!
|
|
|
|
|
taly wrote: my error message was: error C2143: syntax error : missing ';' before ':'
Well, I have to say that message isn't so illuminating.
taly wrote: I will try it
Good luck!
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Hi...I am working on the MDS 5.0(MFC).In an application i have to use more than 255 ocx. But because of the limitation of VC++ i can not use more than 255 ocx in a single dialog. Is there any solution so than i can use the ocx as per my requirment.
|
|
|
|
|
vineet p singh wrote: But because of the limitation of VC++ i can not use more than 255 ocx in a single dialog.
Really, I'm curious: how did you find that?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Hello,
I have a variable called hwnd which stores a handle to one of the windows created by other process. Is there any way to get notified when the title of the window identified by hwnd changes? Can this be done by hooks or without them? If yes how?
thanks in advance
|
|
|
|
|
Giorgi Dalakishvili wrote: Is there any way to get notified when the title of the window identified by hwnd changes
I think with hook it might be possible. Install a message hook and look for the WM_SETTEXT message.
|
|
|
|
|
my Code is
CString sValue;
fldSource.Value() = _wtof(sValue);
Getting this error
error C2065: '_wtof' : undeclared identifier
Plz help me,
I added headers
#include <stdlib.h><code></code>
|
|
|
|
|
try the strtod() function intead of _wtof.
|
|
|
|
|
Naveen.R wrote: try the strtod() function intead of _wtof.
perhaps wcstod or, better, _tcstod .
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|