/*[]=====================================================================[]*/ /*[] LEADTOOLS for Windows(Class Library) - Version 11 []*/ /*[] []*/ /*[] []*/ /*[] Copyright (c) 1991-2000 LEAD Technologies, Inc. []*/ /*[] All Rights Reserved. []*/ /*[]=====================================================================[]*/ /*---(StampPut)------------------------------------------------------------ We have made the assumption that the user has the knowledge of Object Oriented programing of C under Windows. This example will: 1. load the image from a file, whose name is sent through the command line, to a bitmap, 2. display the image. 3. call LFile::SaveFile() to compress the image, 4. load the stamp to a bitmap, 5. display the stamp. The compressed file will contain a 70x70 8-bit stamp. Usage: STAMPPUT --------------------------------------------------------------------------*/ // PtStpView.cpp : implementation of the CPutStampView class // #include "stdafx.h" #include "PutStamp.h" #include "PStmpDc.h" #include "PStmpVw.h" #include "MainFrm.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CPutStampView IMPLEMENT_DYNCREATE(CPutStampView, CView) BEGIN_MESSAGE_MAP(CPutStampView, CView) //{{AFX_MSG_MAP(CPutStampView) ON_WM_CREATE() ON_WM_TIMER() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CPutStampView construction/destruction CPutStampView::CPutStampView() { // TODO: add construction code here m_hOrigCursor = NULL; } CPutStampView::~CPutStampView() { } ///////////////////////////////////////////////////////////////////////////// // CPutStampView drawing void CPutStampView::OnDraw(CDC* pDC) { CPutStampDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); // TODO: add draw code for native data here } ///////////////////////////////////////////////////////////////////////////// // CPutStampView diagnostics #ifdef _DEBUG void CPutStampView::AssertValid() const { CView::AssertValid(); } void CPutStampView::Dump(CDumpContext& dc) const { CView::Dump(dc); } CPutStampDoc* CPutStampView::GetDocument() // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CPutStampDoc))); return (CPutStampDoc*)m_pDocument; } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CPutStampView message handlers int CPutStampView::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CView::OnCreate(lpCreateStruct) == -1) return -1; // Reading the source and the destination file from the command line CPutStampApp* ptheApp = (CPutStampApp*)AfxGetApp(); L_INT nPos = ptheApp->m_strFileName.Find(' '); L_INT nLength = ptheApp->m_strFileName.GetLength(); m_strSrcFile = ptheApp->m_strFileName.Left(nPos); m_strDstFile = ptheApp->m_strFileName.Right(nLength - nPos - 1); L_INT nRet = m_LBitmapWnd.Load((L_TCHAR*)(LPCTSTR)m_strSrcFile); if(nRet!=SUCCESS) { m_LBitmapWnd.DisplayErrorFromList(NULL); return -1; } m_LBitmapWnd.SetWndHandle(GetSafeHwnd()); return 0; } /*---[CompressBitmap]-------------------------------------------------------- Syntax: L_VOID CPutStampView::CompressBitmap( VOID ) Parameters: hWnd Window handle of main window. Prototype: PtStpView.h Notes: Process the image by calling LBitmapBase::Save to compress it to a LEAD CMP file format and save an 8 bit 70 by 70 stamp in the compressed file. If L_SaveFile returns FAILURE, print the message "Error # compressing infile" and quit the program. Else, print the message "Compressed 'infile' to 'outfile' successfully". Then load the stamp to the bitmap and display it. --------------------------------------------------------------------------*/ L_VOID CPutStampView::CompressBitmap(VOID) { CString strBuff ; HCURSOR hCursor; SAVEFILEOPTION SaveFileOption; L_INT nRet; hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)); memset(&SaveFileOption,0,sizeof(SaveFileOption)); AfxGetMainWnd()->SetWindowText (_T("Compressing Image With A Stamp...")); /* Compress the bitmap to a LEAD Quality and Size are equally Important compressed format file called 'STAMP.CMP'. */ m_LBitmapWnd.File()->GetDefaultSaveFileOption(&SaveFileOption, sizeof(SAVEFILEOPTION)); SaveFileOption.uStructSize = sizeof(SAVEFILEOPTION); SaveFileOption.Flags |= ESO_SAVEWITHSTAMP; SaveFileOption.StampWidth = 120; SaveFileOption.StampHeight = 120; SaveFileOption.StampBits = 8; nRet = m_LBitmapWnd.Save((L_TCHAR*)(LPCTSTR)m_strDstFile, FILE_CMP, 0, QS, 0, &SaveFileOption); if (nRet != SUCCESS) { LBase::DisplayError(m_hWnd, nRet); SetCursor (hCursor); return; } strBuff.Format(_T("Compressed %s to %s successfully."), m_strSrcFile, m_strDstFile); MessageBox (strBuff, _T("Success")); //AfxGetMainWnd()->SetWindowText (_T("Extracting Stamp From New File...")); /**/ ::SetWindowText(AfxGetMainWnd()->GetSafeHwnd(), _T("Extracting Stamp From New File...")); /* Get the stamp from the file. */ m_LBitmapWnd.File()->SetFileName((L_TCHAR *)(LPCTSTR)m_strDstFile); nRet = m_LBitmapWnd.File()->ReadStamp(); SetCursor (hCursor); if (nRet != SUCCESS) { LBase::DisplayError(m_hWnd, nRet); return; } //AfxGetMainWnd()->SetWindowText (_T("Stamp Displayed, Example Is Complete (Class library) ")); /**/ ::SetWindowText(AfxGetMainWnd()->GetSafeHwnd(), _T("Stamp Displayed, Example Is Complete (Class library) ")); } void CPutStampView::OnTimer(UINT nIDEvent) { m_nCount++; //Increment the Counter if (m_nCount == 1) { m_hOrigCursor = SetCursor (LoadCursor (NULL, IDC_SIZENS)); return; } else if (m_nCount == 2) { SetCursor (LoadCursor (NULL, IDC_SIZENESW)); return; } /* Kill the timer so that we only create the stamp once. */ KillTimer (m_nTimer); CompressBitmap(); // Send Message for CompressStamp. SetCursor (m_hOrigCursor); CView::OnTimer(nIDEvent); } void CPutStampView::OnInitialUpdate() { CView::OnInitialUpdate(); // Reset the counter and start a timer to be used for display delay. m_nCount = 0; m_nTimer = SetTimer (1, 1000, NULL); if (!m_nTimer) { MessageBox ( _T("No Timers Are Available!"), _T("ERROR - Resources")); // No timers are available, so quit the application. AfxGetMainWnd()->PostMessage( WM_DESTROY ); } } void CPutStampView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView) { if(bActivate==TRUE&&pActivateView==this) m_LBitmapWnd.HandlePalette(WM_QUERYNEWPALETTE, 0, 0); CView::OnActivateView(bActivate, pActivateView, pDeactiveView); }