@@ -1718,138 +1718,24 @@ pCmdUI->Enable ();
17181718}
17191719
17201720
1721- #if _MSC_VER < 1400
1722-
1723- #define VERSION_6 MAKELONG (0 , 6 )
1724-
1725- // from Worstje
1726-
1727- void CTextView::Serialize(CArchive& ar)
1728- // Read and write CTextView object to archive, with length prefix.
1729- {
1730- ASSERT_VALID (this );
1731- ASSERT (m_hWnd != NULL );
1732- if (ar.IsStoring ())
1733- {
1734- UINT nLen = GetBufferLength ();
1735- ar << (DWORD)nLen;
1736- WriteToArchive (ar);
1737- }
1738- else
1739- {
1740- DWORD dwLen;
1741- ar >> dwLen;
1742- if (dwLen > GetEditCtrl ().GetLimitText ())
1743- // Larger than edit control limit. Call SetLimitText() to set your own max size.
1744- // Refer to documentation for EM_LIMITTEXT for max sizes for your target OS.
1745- AfxThrowArchiveException (CArchiveException::badIndex);
1746- UINT nLen = (UINT)dwLen;
1747- ReadFromArchive (ar, nLen);
1748- }
1749- ASSERT_VALID (this );
1750- }
1751-
1752- void CTextView::ReadFromArchive (CArchive& ar, UINT nLen)
1753- // Read certain amount of text from the file, assume at least nLen
1754- // characters (not bytes) are in the file.
1755- {
1756- ASSERT_VALID (this );
1757-
1758- LPVOID hText = LocalAlloc (LMEM_MOVEABLE, (nLen+1 )*sizeof (TCHAR));
1759-
1760- // LPVOID hText = LocalAlloc(LMEM_MOVEABLE, static_cast<UINT>(::ATL::AtlMultiplyThrow(static_cast<UINT>(nLen+1),static_cast<UINT>(sizeof(TCHAR)))));
1761- if (hText == NULL )
1762- AfxThrowMemoryException ();
1763-
1764- LPTSTR lpszText = (LPTSTR)LocalLock (hText);
1765- ASSERT (lpszText != NULL );
1766- if (ar.Read (lpszText, nLen*sizeof (TCHAR)) != nLen*sizeof (TCHAR))
1767- {
1768- LocalUnlock (hText);
1769- LocalFree (hText);
1770- AfxThrowArchiveException (CArchiveException::endOfFile);
1771- }
1772- // Replace the editing edit buffer with the newly loaded data
1773- lpszText[nLen] = ' \0 ' ;
1774-
1775-
1776- #ifndef _UNICODE
1777- if (_AfxGetComCtlVersion () >= VERSION_6)
1778- {
1779- // set the text with SetWindowText, then free
1780- BOOL bResult = ::SetWindowText (m_hWnd, lpszText);
1781- LocalUnlock (hText);
1782- LocalFree (hText);
1783-
1784- // make sure that SetWindowText was successful
1785- if (!bResult || ::GetWindowTextLength (m_hWnd) < (int )nLen)
1786- AfxThrowMemoryException ();
1787-
1788- // remove old shadow buffer
1789- delete[] m_pShadowBuffer;
1790- m_pShadowBuffer = NULL ;
1791- m_nShadowSize = 0 ;
1792-
1793- ASSERT_VALID (this );
1794- return ;
1795- }
1796- #endif
1797-
1798- LocalUnlock (hText);
1799- HLOCAL hOldText = GetEditCtrl ().GetHandle ();
1800- ASSERT (hOldText != NULL );
1801- LocalFree (hOldText);
1802- GetEditCtrl ().SetHandle ((HLOCAL)hText);
1803- Invalidate ();
1804- ASSERT_VALID (this );
1805- }
1806-
1807- void CTextView::WriteToArchive (CArchive& ar)
1808- // Write just the text to an archive, no length prefix.
1809- {
1810- ASSERT_VALID (this );
1811- LPCTSTR lpszText = LockBuffer ();
1812- ASSERT (lpszText != NULL );
1813- UINT nLen = GetBufferLength ();
1814- TRY
1815- {
1816- ar.Write (lpszText, nLen*sizeof (TCHAR));
1817- }
1818- CATCH_ALL (e)
1819- {
1820- UnlockBuffer ();
1821- THROW_LAST ();
1822- }
1823- END_CATCH_ALL
1824- UnlockBuffer ();
1825- ASSERT_VALID (this );
1826- }
1827-
1828- #endif // _MSC_VER < 1400
1829-
18301721void CTextView::SerializeRaw (CArchive& ar)
1831- // Read/Write object as stand-alone file.
1722+ // Read/Write object as stand-alone file.
18321723{
1833- ASSERT_VALID (this );
1834- if (ar.IsStoring ())
1835- {
1836- WriteToArchive (ar);
1837- }
1838- else
1839- {
1840- CFile* pFile = ar.GetFile ();
1841- ASSERT (pFile->GetPosition () == 0 );
1842- ULONGLONG nFileSize = pFile->GetLength ();
1843- if (nFileSize/sizeof (TCHAR) > GetEditCtrl ().GetLimitText ())
1844- {
1845- // Larger than edit control limit. Call SetLimitText() to set your own max size.
1846- // Refer to documentation for EM_LIMITTEXT for max sizes for your target OS.
1847- AfxMessageBox (AFX_IDP_FILE_TOO_LARGE);
1848- AfxThrowUserException ();
1849- }
1850- // ReadFromArchive takes the number of characters as argument
1851- ReadFromArchive (ar, (UINT)nFileSize/sizeof (TCHAR));
1852- }
1853- ASSERT_VALID (this );
1854- }
1724+ ASSERT_VALID (this );
1725+
1726+ if (ar.IsStoring ())
1727+ {
1728+ WriteToArchive (ar);
1729+ }
1730+ else
1731+ {
1732+ CFile* pFile = ar.GetFile ();
1733+ ASSERT (pFile->GetPosition () == 0 );
1734+ DWORD nFileSize = pFile->GetLength ();
1735+ // ReadFromArchive takes the number of characters as argument
1736+ ReadFromArchive (ar, (UINT)nFileSize/sizeof (TCHAR));
1737+ }
1738+ ASSERT_VALID (this );
1739+ } /* end of CTextView::SerializeRaw */
1740+
18551741
0 commit comments