|
From: Noorez K. <lor...@ho...> - 2005-07-08 20:37:39
|
I am having trouble with reading from a text file in my program. For
testing, I used notepad and typed and let word-wrap put text on the next
line. I typed a lot into this file. I then used my program to try and open
it but it froze. If I use the enter key to put in the newline then my
program works. Whats wrong with it?
#include "SML.h"
// Function called from WindowProcedure to open text
void OpenText(HWND main, HWND hEdit)
{
ifstream openTextFile; // Handle to file
// Filter files visible in the open dialog box
char* filter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0\0";
char* inLine = new char[900];
int nLength;
// Init the properties of the open dialog box
getOFNproperties(main, &dialogProperties, currentFileName, filter);
// Show the dialog and get the information
if( !GetOpenFileName(&dialogProperties) )
{
return; // Return if user cancels
}
openTextFile.open(currentFileName);
SetDlgItemText(main, IDC_MAIN_EDIT, ""); // Clear the edit control
int cntr = 1;
// Loop unitl the end of file is reached
while( !openTextFile.eof() )
{
nLength = GetWindowTextLength(GetDlgItem(main, IDC_MAIN_EDIT));
openTextFile.getline(inLine,9000);
// A new line must have a "\r\n" so test for both
if( inLine[ strlen(inLine) -1 ] != '\r' )
{
strcat(inLine,"\r");
}
if( inLine[ strlen(inLine) -1] != '\n' )
{
strcat(inLine,"\n");
}
// And the message onto the edit control
SendMessage( GetDlgItem(main, IDC_MAIN_EDIT), EM_SETSEL,
(WPARAM)nLength,
(LPARAM)nLength );
SendMessage( GetDlgItem(main, IDC_MAIN_EDIT), EM_REPLACESEL,
(WPARAM)FALSE,
(LPARAM)inLine );
delete inLine;
inLine = new char[900];
}
untitled = false;
edited = false;
return;
}
_________________________________________________________________
Designer Mail isn't just fun to send, it's fun to receive. Use special
stationery, fonts and colors.
http://join.msn.com/?pgmarket=en-ca&page=byoa/prem&xAPID=1994&DI=1034&SU=http://hotmail.com/enca&HL=Market_MSNIS_Taglines
Start enjoying all the benefits of MSN® Premium right now and get the
first two months FREE*.
|