|
From: Noorez K. <lor...@ho...> - 2005-07-12 04:39:33
|
The open file function of my program appears to be crashing at the line I
marked, when I run the debugger. There might be some other problem causing
it. The function is below:
#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";
std::string inLine;
char* toEditControl;
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 contro
int cntr = 1;
// Loop unitl the end of file is reached
while( !openTextFile.eof() && !openTextFile.fail() )
{
nLength = GetWindowTextLength(GetDlgItem(main, IDC_MAIN_EDIT));
getline(openTextFile,inLine);
toEditControl = (char*)inLine.c_str();
//A new line must have a "\r\n" so test for both
if( toEditControl[ strlen(toEditControl) -1 ] != '\r' )
{
strcat(toEditControl,"\r");
}
if( inLine[ strlen(toEditControl) -1] != '\n' )
{
strcat(toEditControl,"\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)toEditControl );
}
untitled = false;
edited = false;
openTextFile.close();
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*.
|