// PaintDoc.cpp : implementation of the CPaintDoc class // #include "stdafx.h" #include "Paint.h" #include "PaintDoc.h" #include "dlgnew.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif extern CPaintApp theApp; ///////////////////////////////////////////////////////////////////////////// // CPaintDoc IMPLEMENT_DYNCREATE(CPaintDoc, CDocument) BEGIN_MESSAGE_MAP(CPaintDoc, CDocument) //{{AFX_MSG_MAP(CPaintDoc) ON_COMMAND(ID_FILE_SAVE_AS, OnFileSaveAs) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CPaintDoc construction/destruction static const WCHAR BASED_CODE _szLicString[] = L"LEADTOOLS OCX Copyright (c) 1991-2001 LEAD Technologies, Inc."; CPaintDoc::CPaintDoc() { CRect rcClient(0,0,1,1); BSTR lpLic = SysAllocString(_szLicString); m_LeadDoc.Create("", 0, rcClient, theApp.m_pMainWnd, 0,NULL,FALSE,lpLic); m_LeadDoc.ShowWindow(SW_HIDE); SysFreeString(lpLic); } CPaintDoc::~CPaintDoc() { m_LeadDoc.DestroyWindow(); // avoid warning messages at debug time } BOOL CPaintDoc::OnNewDocument() { if (!CDocument::OnNewDocument()) return FALSE; TRY { switch(theApp.m_nOpenMode) { case OPENMODE_NEW: return OnNewBitmap(); break; case OPENMODE_PASTE: return OnOpenPaste(); break; default: OutputDebugString("Default\n"); break; } } CATCH_ALL(e) { theApp.DisplayLEADError(ERROR_FAILURE); return FALSE; } END_CATCH_ALL; return TRUE; } ///////////////////////////////////////////////////////////////////////////// // CPaintDoc serialization void CPaintDoc::Serialize(CArchive& ar) { if (ar.IsStoring()) { // TODO: add storing code here } else { // TODO: add loading code here } } ///////////////////////////////////////////////////////////////////////////// // CPaintDoc diagnostics #ifdef _DEBUG void CPaintDoc::AssertValid() const { CDocument::AssertValid(); } void CPaintDoc::Dump(CDumpContext& dc) const { CDocument::Dump(dc); } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CPaintDoc commands BOOL CPaintDoc::OnOpenDocument(LPCTSTR lpszPathName) { //if (!CDocument::OnOpenDocument(lpszPathName)) // return FALSE; int nRet; int nBitsPerPixel=0; int nFileFormat; if(lpszPathName) { m_LeadDoc.GetFileInfo (lpszPathName, 0, 0); nFileFormat = m_LeadDoc.GetInfoFormat(); nBitsPerPixel = m_LeadDoc.GetInfoBits(); if (((nFileFormat == 10) || (nFileFormat == 89 )) && (nBitsPerPixel == 16)) { MessageBox (AfxGetApp()->GetMainWnd()->m_hWnd, "Can't paint to this image.", "Error:", MB_OK | MB_ICONSTOP ) ; return FALSE; } nRet = m_LeadDoc.Load(lpszPathName, 0, theApp.m_iPage, 1); nBitsPerPixel = m_LeadDoc.GetBitmapBits(); theApp.m_iPage = 1; if(nRet) { theApp.DisplayLEADError(nRet); return(FALSE); } else { if (nBitsPerPixel != 1 && nBitsPerPixel != 4 && nBitsPerPixel != 8 && nBitsPerPixel != 16 && nBitsPerPixel != 24) { MessageBox(AfxGetApp()->GetMainWnd()->m_hWnd, "Your image format is not either 1,4,8,16 or 24 bits per pixel", "Error Opening Image", MB_OK|MB_ICONEXCLAMATION); return FALSE; } } return(TRUE); } return(FALSE); } int CPaintDoc::OnNewBitmap() { int nRet; int nBitsPerPixel = 24; CDlgNewFile DlgNewFile; DlgNewFile.m_nHeight = 200; DlgNewFile.m_nWidth = 400; DlgNewFile.m_RadioBpp = 3; nRet = DlgNewFile.DoModal(); if (nRet == IDOK) { switch(DlgNewFile.m_RadioBpp) { case 0: nBitsPerPixel = 1; break; case 1: nBitsPerPixel = 4; break; case 2: nBitsPerPixel = 8; break; case 3: nBitsPerPixel = 24; break; } m_LeadDoc.CreateBitmap( (float)DlgNewFile.m_nWidth, (float)DlgNewFile.m_nHeight, (short)nBitsPerPixel); m_LeadDoc.Fill(RGB(255,255,255)); return TRUE; } return FALSE; } int CPaintDoc::OnOpenPaste() { m_LeadDoc.Paste(0); return(TRUE); }