/*[]=====================================================================[]*/ /*[] LEADTOOLS for Windows(Class Library) - Version 11 []*/ /*[] []*/ /*[] []*/ /*[] Copyright (c) 1991-2000 LEAD Technologies, Inc. []*/ /*[] All Rights Reserved. []*/ /*[]=====================================================================[]*/ /*---(FeedLoad)--------------------------------------------------------------- We have made the assumption that the user has the knowledge of Object Oriented programing of C under Windows. This example will: 1. simulate receiving data through a comm port by time decoding the file specified on the command line. 2. display the image as it is loaded. We used LFile::StartFeedLoad(), passing LoadImageCB as its callback function. LFile::FeedLoad() calls LoadImageCB periodically, passing a buffer of data. The callback in this example paints the buffer to the screen and loads the data to the bitmap. If the device is 8 bit, then LFile::StartFeedLoad() is requested to load the file as an 8 bit image. If the device is greater than 8 bit (i.e. 16, 24, or 32 bits) then LFile::StartFeedLoad() is requested to load the image as a 24 bit image. Usage: FeedLoad --------------------------------------------------------------------------*/ // FdLdView.cpp : implementation of the CFeedLoadView class // #include "stdafx.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CFeedLoadView IMPLEMENT_DYNCREATE(CFeedLoadView, CView) BEGIN_MESSAGE_MAP(CFeedLoadView, CView) //{{AFX_MSG_MAP(CFeedLoadView) ON_WM_TIMER() ON_WM_CREATE() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CFeedLoadView construction/destruction CFeedLoadView::CFeedLoadView() { // TODO: add construction code here m_nCounter = 0; } CFeedLoadView::~CFeedLoadView() { } ///////////////////////////////////////////////////////////////////////////// // CFeedLoadView drawing void CFeedLoadView::OnDraw(CDC* pDC) { CFeedLoadDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); // TODO: add draw code for native data here HDC hdc; HPALETTE hOldPal = NULL; hdc = pDC->GetSafeHdc(); if (m_LeadBitmap.GetPalette() ) // Is there a palette that needs to be selected? hOldPal = SelectPalette (hdc, m_LeadBitmap.GetPalette(), TRUE); /* Select it */ // Paint it m_LeadBitmap.Paint()->SetDC ( hdc ); m_LeadBitmap.Paint()->PaintDC (); if (hOldPal) // Return old palette, if there is one. SelectPalette (hdc, hOldPal, TRUE); } ///////////////////////////////////////////////////////////////////////////// // CFeedLoadView diagnostics #ifdef _DEBUG void CFeedLoadView::AssertValid() const { CView::AssertValid(); } void CFeedLoadView::Dump(CDumpContext& dc) const { CView::Dump(dc); } CFeedLoadDoc* CFeedLoadView::GetDocument() // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CFeedLoadDoc))); return (CFeedLoadDoc*)m_pDocument; } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CFeedLoadView message handlers void CFeedLoadView::OnInitialUpdate() { CView::OnInitialUpdate(); // TODO: Add your specialized code here and/or call the base class } void CFeedLoadView::OnTimer(UINT nIDEvent) { // TODO: Add your message handler code here and/or call default m_nCounter++; /* Increment the Counter. */ /* Has the image been displayed about 3 seconds? (this is reset in the function Window_OnPaint) */ if (m_nCounter == 1) { m_hOrigCursor = SetCursor (LoadCursor (NULL, IDC_SIZENS)); return; } if (m_nCounter == 2) { SetCursor (LoadCursor (NULL, IDC_SIZENESW)); return; } if (m_nCounter == 3) { AfxGetMainWnd()->SetWindowText (_T("Class Library Sample Application - Calling the Simulated Receive Function")); PostMessage (WM_COMMAND, 0, 0); // Send Message for Processing } SetCursor (m_hOrigCursor); CView::OnTimer(nIDEvent); } BOOL CFeedLoadView::OnCommand(WPARAM wParam, LPARAM lParam) { // TODO: Add your specialized code here and/or call the base class HCURSOR hCursor; CFeedLoadApp* pCApp = (CFeedLoadApp*) AfxGetApp(); /* Kill the timer */ KillTimer (m_nTimer); hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)); m_LeadUserFile.SetBitmap( &m_LeadBitmap ); m_LeadUserFile.SetFileName((L_TCHAR*)(LPCTSTR)pCApp->m_strFileName); m_LeadUserFile.EnableCallBack( TRUE ); // Load the image. L_INT nRet = SimulatedRecv ((L_TCHAR*)(LPCTSTR)pCApp->m_strFileName, m_FileInfo.BitsPerPixel, m_FileInfo.Order, LOADFILE_ALLOCATE | LOADFILE_STORE ); SetCursor (hCursor); if (nRet != SUCCESS) LBase::DisplayError(AfxGetMainWnd()->m_hWnd, nRet); AfxGetMainWnd()->SetWindowText (_T("LEADTOOLS Sample Application, Example Is Complete (Class library)")); return CView::OnCommand(wParam, lParam); } L_INT CFeedLoadView::SimulatedRecv (L_TCHAR * pszFile, L_INT nBitsPerPixel, L_INT nOrder, L_UINT uFlags) { HANDLE hFileOpen; L_UCHAR cBuf[1024]; L_UINT32 dwRead; L_INT nRet; L_UINT32 dwBaseTime; L_UINT32 dwReceiveTotal; L_UINT32 dwReceiveRead; LOADFILEOPTION LoadFileOption; // Display all meaningful scans for Progressive JPEG and CMP files memset( &LoadFileOption, 0, sizeof(LOADFILEOPTION) ); LoadFileOption.Passes = CALLBACK_WHEN_MEANINGFUL; LoadFileOption.Flags |= ELO_ROTATED; LoadFileOption.uStructSize = sizeof(LOADFILEOPTION); dwBaseTime = GetTickCount(); dwReceiveTotal = 0; dwReceiveRead = 0; hFileOpen = CreateFile ( pszFile, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL ); if(hFileOpen== NULL || hFileOpen == INVALID_HANDLE_VALUE) return (ERROR_FILE_OPEN); m_LeadUserFile.m_hDC = GetDC()->GetSafeHdc(); m_LeadUserFile.m_pView = this; nRet = m_LeadUserFile.StartFeedLoad ( 0, nOrder, uFlags, &LoadFileOption); if (nRet != SUCCESS) { CloseHandle(hFileOpen); return (nRet); } for( ; ; ) { dwReceiveTotal = ((GetTickCount() - dwBaseTime) * (SIMULATEDBAUDRATE / 100) / 100); dwRead = (L_UINT32) min(dwReceiveTotal - dwReceiveRead, (L_UINT32) sizeof(cBuf)); if(dwRead) { if ( !ReadFile(hFileOpen, cBuf, dwRead, &dwRead, NULL)) { nRet = ERROR_FILE_READ; break; } if(!dwRead) break; LBuffer LeadBuffer(cBuf,dwRead) ; nRet = m_LeadUserFile.FeedLoad (&LeadBuffer); if (nRet != SUCCESS) break; dwReceiveRead += dwRead; } } CloseHandle (hFileOpen); nRet = m_LeadUserFile.StopFeedLoad (); return (nRet); } void CFeedLoadView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView) { // TODO: Add your specialized code here and/or call the base class if(bActivate==TRUE&&pActivateView==this) HandlePalette(WM_QUERYNEWPALETTE,m_hWnd); CView::OnActivateView(bActivate, pActivateView, pDeactiveView); } int CFeedLoadView::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CView::OnCreate(lpCreateStruct) == -1) return -1; LFile LeadFile; CFeedLoadApp* pCApp = (CFeedLoadApp*) AfxGetApp(); LeadFile.SetFileName((L_TCHAR*)(LPCTSTR)pCApp->m_strFileName); m_FileInfo.uStructSize = sizeof(FILEINFO); L_INT nRet = LeadFile.GetInfo(&m_FileInfo, sizeof(FILEINFO)); if ( nRet != SUCCESS ) { LBase::DisplayError( NULL, nRet); return -1; } /* Reset the counter and start a timer to be used for display delay. */ m_nCounter = 0; m_nTimer = SetTimer (1, 1000, NULL); return 0; } L_BOOL CFeedLoadView::HandlePalette(UINT uMsg,HWND hWnd) { HDC hDC; switch(uMsg) { case WM_PALETTECHANGED: if(m_hWnd== hWnd) return TRUE; case WM_SYSCOLORCHANGE: case WM_QUERYNEWPALETTE: hDC = ::GetDC(m_hWnd); HPALETTE hPalette = m_LeadBitmap.CreatePaintPalette(hDC); L_UINT uColor=0; if(hPalette) { HPALETTE oldPalette = ::SelectPalette(hDC,hPalette,(uMsg==WM_PALETTECHANGED)); uColor=::RealizePalette(hDC); ::SelectPalette(hDC,oldPalette,TRUE); } ::ReleaseDC(m_hWnd,hDC); if(uColor!=0) { InvalidateRect(NULL,false); UpdateWindow(); return TRUE; } break; } return FALSE; }