|
I am asking again,
maybe nobody noticed the question.
Or maybe the problem is really 'real'
An Edit control of Microsoft ( both normal or RichEdit ) is not able to count right the CRLF characters ! Yes, just the ones that Microsoft itself keeps alive !
What it does is just to ignore the '\r' characters in the count, both when using EM_GETSEL and EM_SETSEL
Does anyone knows how to do it right ?
Thank you very much for any answer
Marcello
|
|
|
|
|
Marcello wrote:
Does anyone knows how to do it right ?
What do you mean do it right?
You want to use both \r\n inside your CEdit control?
Why?
Are you saving content to a file and need the CRLF?
If so, why not just (before saving) search and replace all \n with \r\n and then save to file?
Cheers : )
The word of the day is legs, let's go back to my house and spread the word
|
|
|
|
|
Thank you for the answer.
I use the multiplatform VCF library and helping on it.
The fact is the in the library we need to introduce a Control that has the data model separated from the view ( which is the Microsoft's Edit control ).
In this way this bug becomes really evident.
For multipurpose need we cannot put the text in a canonized form ( like replacing all the \r\n with \n and similar things.
I made a workaround, which is to count all the CR characters both before the beginning of a selection and inside the selection itself, and then make some adjust to the counts. But this code is CPU consuming and more orrible than it seems.
Because I it is the third time I am posting this problem
and you are the only (nice) person who answered, I guess this is just another of Microsoft's bugs.
Cheers,
Marcello
|
|
|
|
|
Perhaps you could look at some of the edit controls here on CP and modify them enough to suit your needs?
Cheers
The word of the day is legs, let's go back to my house and spread the word
|
|
|
|
|
Yes. It is a good idea.
Maybe I will find something.
Thank you !
Marcello
|
|
|
|
|
Hi everyone!
I'm trying to do a Speech application. It must read what the user writes in the edit box or the content from a text file. When it reads the text from that file and then tries to fill the edit box I get the file content but I get some garbage too. The part of the code in with I use files is this:
CFileDialog m_ldFichero(TRUE);
CFile m_Fichero;
char buffer[200];
int iTexto = 0;
DWORD nBytesLeidos;
CString m_snombre;
CFileException e;
DWORD longFichero;
if (m_ldFichero.DoModal() == IDOK)
{
m_snombre= m_ldFichero.GetFileName();
m_Fichero.Open(m_snombre, CFile::modeRead, &e);
longFichero = m_Fichero.GetLength();
nBytesLeidos = m_Fichero.Read(buffer,longFichero);
m_sTexto=buffer;
m_Fichero.Close();
UpdateData(FALSE);
}
When running the application I get the text and "ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÄÈJ_X" too.
I don't know what could I do or how could I eliminate that garbage... Please, some help!.
Thank you in advance
I'm lost... SOS
|
|
|
|
|
This happens because of the way you create the receiving buffer. You just create a variable that gets placed somewhere on your computer's memory. The memory contents, however, is NOT cleared. So, when you create the buffer, you can instantly use it to read and/or write characters to the memory it reserves for itself.
In order to clear the targetted area, you need to use some memory handling routines. Here is an example of how to clear the memory area:
char buffer[200];<DIV>
ZeroMemory( &buffer[0], sizeof(buffer) );<DIV>
It will be filled from the first character up to the amount 'longFichero',
and the rest of the buffer is left empty (null characters). Hope this will help you out. An alternative method is to create a CString object, and read your data into that one. The CString object can automatically grow as a result of string operations (Append, Format, Insert etc), so you don't necessarily need to specify the amount of bytes to read.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Thank you very much, the application is OK now
Can you tell me how could I save a text in an inexistent file? It is, it must create a File and save the text from the Text editor with a click in a button.
Best regards!!!
|
|
|
|
|
You can do this by creating a CFile object and opening a file with it. On the CFile's constructor or the Open member function, you can specify a flag to tell the program that it is to create a new file.
Here's an excerpt from MSDN:
CFile::modeCreate - Directs the constructor to create a new file. If the file exists already, it is truncated to 0 length.
I think this is what you wanted. See the CFile constructor for additional flags that you might find useful. As for the implementation, just create a message handler for the button click, then open and write to the file in there.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Well, finally it works!! But I've got a problem with buffer... I need to save the text from the Edit Box but it is a CString by definition and what I have to save in the file is char buffer[lenght] and they aren't compatible. I can't do
buffer=m_sTexto;
and the sentence
m_Fichero.Write(m_sTexto, sizeof(m_sTexto));
is no OK, so I'm lost again!! How could I convert the type or write the Edit Box content in my file?
Thank you
|
|
|
|
|
In here you need a conversion routine..
The CString object can be cast into type LPCTSTR by adding the conversion operation in front of the object. Then just use some sort of string copying routine, such as strcpy to copy characters. LPCTSTR is defined as const char* .
Here's a code fragment to help you get the idea:
char buffer[length];
CString m_sTexto;<DIV>
strcpy( &buffer[0], (LPCTSTR)m_sTexto );<DIV>
m_Fichero.Write( &buffer[0], sizeof(buffer) );
m_Fichero.Write( (LPCTSTR)m_sTexto, sizeof(m_sTexto) ); I am not 100% sure of the lower implementation, as I have never used it. According to the documentation, it should work properly.. Test it if you feel brave
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Well, I felt brave at the beginning but it seems to be for really brave people
I've tried with
m_Fichero.Write( (LPCTSTR)m_sTexto, sizeof(m_sTexto) );
but nothing is saved in the new file.
Then I used the other one implementation, but there is some trouble with my code (That's no strange, isn't it? ). Well I think the trouble is the CString variable. Must it be initialized? Where could I do it? I can't use ZeroMemory function (can I?). If it has to be initialized, it must be done before the user could write in the edit box...
When I've tried
strcpy( &buffer[0], (LPCTSTR)m_sTexto );
m_Fichero.Write( &buffer[0], sizeof(buffer) );
lots (200) of identical symbols (squares) have been saved but I had written some words in the edir box
Thanks
(I'm very sorry because I have lots of foolish doubts but I've just begun with Visual C++ and all of this is new to me. I hope you'll not be fed up with me & my questions . Thanks a lot!)
I have no idea
|
|
|
|
|
It is ok to ask questions and seek for answers, as long as you do it politely and with a gentelmanic approach. I'm not fed up with you or with your questions either. Afterall, when I get you to understand this, I have someone else who can give advice to another person asking perhaps the same thing.
Now, off with the question. I was quite sure that the second implementation would not work, but the first one should have. Like you said, there were some squares written into the file. This means that the writing routine works properly and something gets saved. In the start of your routine, have you called UpdateData( TRUE ) to tell your program to move the data from the edit box to the CString member ? If you did not already know, there is a system called Dialog Data Exchange (or DDX, for short) at work in your dialog. This system is responsible for moving data and control between (to and back) the actual controls of the dialog and the variables bound to them. You can find a function called DoDataExchange from your dialog's implementation.
In order to determine that the data gets moved corretly, you can use the TRACE-macros in a debug build of your application. These macros are very useful in dumping object or other data into the output window of the debugger. For example, after calling UpdateData , you could use TRACE1-macro to determine that the correct text was copied into the CString variable. Then, you can use the same macro again to see that data gets copied into the character buffer properly.
Perhaps these will help, most importantly, learn about and get to know how to use the TRACE-macros properly. They are an important key to displaying debug-time status information, if you don't want to use message boxes. Try adding a few of those macros inbetween the function calls in your application and see what get's printed into the output window.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Well, it works!
I'd written UpdateData(TRUE) in the wrong place (my brain and me... ) and when you have suggested me about this I realised!
The squares are blank spaces. I was using wordpad instead of notepad and there, in wordpad, they appear in this squared way, but if I open the file in the application or in notepad it is OK, so we got it and the files work perfectly!
I just only need to change voices in my speech application to finish this phase (I have 4 phases in total in this project ).
Do you know something about speech with Visual C++? I've asked here in other threads but nobody reply them
I only have some doubts.
Thank you for your great help!
I have no idea
|
|
|
|
|
Good that it works.
As for the text-to-speech conversion, I would start from the Microsoft Speech[^] site. Register for a download of the MS Speech API SDK, then consult it's documentation to learn how to use it.
I can't give you any source code on this matter, because I neither have any nor do I have the SDK installed. You must explore the SDK yourself.. But isn't that part of the fun ?
EDIT: The Microsoft Speech SDK doesn't require registration, it seems. Here's a link to the actual download site: download here[^]
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Thank you very much for your help
I had already read that documentation and I have some questions about the information that I got there, but I can find nobody who helps me, so I'm "alone in the dark". I'll be patient...
Thank you anyway
I have no idea
|
|
|
|
|
Hi again!
I'd like to get a warning window when the file that the user is trying to save already exists so that user could choose if overwrites it or not. Which funtions could I use?
Now my code is:
LPCTSTR sFiltros="Text Files (*.txt)|*.txt|All Files (*.*)|*.*||";
CFileDialog m_ldFichero(FALSE,"txt","*.txt",NULL,sFiltros);
CFile m_Fichero;
char buffer[200];
CString m_snombre;
CFileException e;
ZeroMemory(&buffer[0], sizeof(buffer));
if (m_ldFichero.DoModal() == IDOK)
{
m_snombre= m_ldFichero.GetFileName();
UpdateData(TRUE);
m_Fichero.Open(m_snombre, CFile::modeCreate | CFile::modeReadWrite, &e);
strcpy(&buffer[0],(LPCTSTR)m_sTexto);
m_Fichero.Write(&buffer[0], sizeof(buffer));
m_Fichero.Close();
}
}
Thank you!!
I have no idea
|
|
|
|
|
I think the standard CFileDialog class is capable of handling a situation where a file already exists. Have you actually tried with this implementation ? It should notify that the file already exists. At least it does so for me..
But, if it doesn't work so for you, you can always derive a new class from CFileDialog, and override it's OnFileNameOk virtual function. This function is called to validate a filename entered into the dialog box. In this handler, just do a quick test and attempt to open the file. If the attempt fails, the file doesn't exist. If it doesn't, then it exists. According to the return value, display a quick message box with a notification of this issue, and a choice for the user to accept the file overwrite.
I can't provide any ready code, because I have never needed to do this myself. See the CFileDialog documentation for information about the overriddable function.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
I found it!
I had to use OFN_OVERWRITEPROMPT flag in CFileDialog function so that it works.
Thank you for your help
|
|
|
|
|
Hey everyone,
I have been seeing a bunch of different software that is layed out like microsoft outlook. It has the outlook bar and it basically looks like outlook. Does anyone know how you can create this look? I am not necessarly looking for code, but is MFC used, OpenGL or is there a template out there? I have seen it in 2 different software vendors. Thanks everyone!
|
|
|
|
|
BrockVnm wrote:
I have been seeing a bunch of different software that is layed out like microsoft outlook. It has the outlook bar and it basically looks like outlook. Does anyone know how you can create this look? I am not necessarly looking for code, but is MFC used, OpenGL or is there a template out there? I have seen it in 2 different software vendors. Thanks everyone
Most MFC libraries such as CodeJock and Dundas, have all the code necessary for building Outlook interfaces. (It is usual one of the sample apps they use to show off their toolkits).
I'm sure there are a couple of samples floating around in CodeProject. A search for Outlook Bar here at CP, should bring up a couple.
Michael
But you know when the truth is told,
That you can get what you want or you can just get old,
Your're going to kick off before you even get halfway through.
When will you realise... Vienna waits for you? - "The Stranger," Billy Joel
|
|
|
|
|
where can I get codejock and dundas and is this something that you would recommended using? I am just beginning to learn MFC and I thinking of how i would lay out my interface. I thought these interfaces were nice, but I am not sure if this is a good option?
Thanks!
|
|
|
|
|
Dundas[^] and Codejock[^]
However if your learning MFC I wouldn't suggest using these libraries becuz I believe they are a couple 100 bux. They are typically designed for professional commercial applications.
Cheers
The word of the day is legs, let's go back to my house and spread the word
|
|
|
|
|
Hi guys,
I've been asked to add some RS232 functionality to an app. From what I know RS232 is a protocol which is used over serial connections. I've not been able to find anything on CodeProject to help or explain it anymore.
Does anyone know a good article introducing the subject?
Many thanks,
Simon
|
|
|
|
|
Having spent many years maintaining (and expanding/modifying) a network based entirely on serial ports, I know how frustrating it is to find info on this ancient standard. Start here[^], and remember that Google is your friend.
Oh, and if you have to do any programming for it there are a few serial communications articles on CodeProject. But save those for reading after you have a basic familiarity with the protocol - they'll make a lot more sense then.
"Another day done - All targets met; all systems fully operational; all customers satisfied; all staff keen and well motivated; all pigs fed and ready to fly" - Jennie A.
|
|
|
|
|