Click here to Skip to main content
16,005,141 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralMFC Pin
kumaraghuru29-Apr-06 20:03
kumaraghuru29-Apr-06 20:03 
GeneralRe: MFC Pin
YaronNir29-Apr-06 20:53
YaronNir29-Apr-06 20:53 
GeneralRe: MFC Pin
kumaraghuru29-Apr-06 21:19
kumaraghuru29-Apr-06 21:19 
GeneralRe: MFC Pin
YaronNir29-Apr-06 21:26
YaronNir29-Apr-06 21:26 
GeneralRe: MFC Pin
kumaraghuru29-Apr-06 21:23
kumaraghuru29-Apr-06 21:23 
GeneralRe: MFC Pin
kumaraghuru29-Apr-06 21:06
kumaraghuru29-Apr-06 21:06 
GeneralRe: MFC Pin
Joe Woodbury29-Apr-06 23:34
professionalJoe Woodbury29-Apr-06 23:34 
AnswerRe: MFC Pin
bob1697230-Apr-06 4:59
bob1697230-Apr-06 4:59 
This will load a text file formatted in ANSI or UNICODE. It's meant to be used in a Doc/View app but you may find it useful to build on. It is in no way complete and it's kinda messy but it gets the data read in nonetheless...

// Assumes compiling for MBCS.
CString m_DataString // Member of document object so view can get to data

if (ar.IsStoring())
{
// TODO: add storing code here

}
else
{
// TODO: add loading code here
ar.Flush(); // Need to get rid of Mr. Hanky before
// calling CArchive::GetFile(). Hidee Ho!

CString sResult="";
CString sFileData="";
int nFlags=IS_TEXT_UNICODE_SIGNATURE;

const CFile * file=ar.GetFile(); // Get a const file pointer from CArchive
int nLength=file->GetLength();
LPSTR pBuffer=sFileData.GetBuffer(nLength+2); // Need 2 bytes for unicode
// null terminator, just in case

ar.Read(pBuffer,nLength); // Read the data in raw

// Append a unicode null terminator to prevent
// one of lifes little oopsees...Don't assume anything
pBuffer[nLength]='\0';
pBuffer[nLength+1]='\0';
nLength+=2; // Adjust 2 bytes for unicode null terminator

if (::IsTextUnicode(pBuffer,nLength,&nFlags)) { // Unicode encoded file

// Get the required buffer size for multibyte buffer
int nResultLength=::WideCharToMultiByte(CP_ACP,0,(PWSTR)pBuffer,-1,
NULL,0,NULL,NULL);

// Do the conversion and save it in member variable for when
// the view is ready to load
::WideCharToMultiByte(CP_ACP,0,(PWSTR)pBuffer,-1,
m_DataString.GetBuffer(nResultLength),
nResultLength,NULL,NULL);
m_DataString.ReleaseBuffer();
sFileData.ReleaseBuffer(); // pBuffer no longer valid

m_DataString.Delete(0,1); // Remove what used to be the
// Unicode byte-order mark 0xFEFF

} else { // File not encoded

sFileData.ReleaseBuffer(); // pBuffer no longer valid
m_DataString=sFileData; // Save it in member variable for when
// the view is ready to load
}
}

-- modified at 11:07 Sunday 30th April, 2006
QuestionActive X Control supporting problem Pin
chybin29-Apr-06 19:19
chybin29-Apr-06 19:19 
AnswerRe: Active X Control supporting problem Pin
YaronNir29-Apr-06 22:18
YaronNir29-Apr-06 22:18 
Questioncontrolling another application Pin
Sam 200629-Apr-06 16:18
Sam 200629-Apr-06 16:18 
AnswerRe: controlling another application Pin
Justin Tay29-Apr-06 18:29
Justin Tay29-Apr-06 18:29 
AnswerRe: controlling another application Pin
YaronNir29-Apr-06 21:29
YaronNir29-Apr-06 21:29 
GeneralRe: controlling another application Pin
Sam 200630-Apr-06 2:20
Sam 200630-Apr-06 2:20 
AnswerRe: Displaying a HTML string in memory that links to an external CSS document Pin
borono29-Apr-06 16:12
borono29-Apr-06 16:12 
Question[Message Deleted] Pin
Tito-K4L29-Apr-06 11:31
Tito-K4L29-Apr-06 11:31 
QuestionConverting a bmp to a raw image Pin
Tito-K4L29-Apr-06 11:30
Tito-K4L29-Apr-06 11:30 
QuestionAdding Functionality to a COM/Ocx Pin
AryaSoft29-Apr-06 11:00
AryaSoft29-Apr-06 11:00 
QuestionGDI+ does not work in release mode Pin
sdancer7529-Apr-06 10:31
sdancer7529-Apr-06 10:31 
Questionhelp plz Pin
big_denny_20029-Apr-06 9:21
big_denny_20029-Apr-06 9:21 
AnswerRe: help plz Pin
Justin Tay29-Apr-06 10:45
Justin Tay29-Apr-06 10:45 
AnswerRe: help plz Pin
Saurabh.Garg29-Apr-06 16:03
Saurabh.Garg29-Apr-06 16:03 
QuestionResponding to CPropertySheet messages Pin
sdancer7529-Apr-06 8:58
sdancer7529-Apr-06 8:58 
QuestionHow To Get Current Module (dll) Handle Pin
Adnan56229-Apr-06 3:50
Adnan56229-Apr-06 3:50 
AnswerRe: How To Get Current Module (dll) Handle Pin
cmk29-Apr-06 5:04
cmk29-Apr-06 5:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.