|
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.
|
|
|
|
|
This site helped me out.
http://www.beyondlogic.org/serial/serial.htm
|
|
|
|
|
Thanks a lot for your help guys.
|
|
|
|
|
Hi every body!
pls tell me how to show list member in VC++, I have checked auto lists member check box! but i can't show them!
thanks!
xyz
|
|
|
|
|
My visual c++ sometimes is stubborn and refuses to show the listbox or that little tooltip function prototype thing...but I find after a reboot everything is usually fine.
I think if your using a third-party class(es) you have to actually add the header files to your project before functions prototypes and such will be displayed.
If all else fails you can try ctrl+shift+space...i think that brings up the window in question.
Cheers
The word of the day is legs, let's go back to my house and spread the word
|
|
|
|
|
VC++ gets 'confused' after a while. Delete the file <project>.ncb in the same directory as your project file. This file contains the temporary compile results used for Intellisense.
Software Zen: delete this;
|
|
|
|
|
the messagebox function accepts only text values.how can i show int or long values
|
|
|
|
|
use CString::Format or any other string formatter to create the string to display in the messagebox.
.
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|