/*[]=====================================================================[]*/ /*[] LEADTOOLS for Windows(Class Library) - Version 11 []*/ /*[] []*/ /*[] []*/ /*[] Copyright (c) 1991-2000 LEAD Technologies, Inc. []*/ /*[] All Rights Reserved. []*/ /*[]=====================================================================[]*/ /*---(LoadCB)--------------------------------------------------------------- We have made the assumption that the user has the knowledge of Object Oriented programing of C under Windows. This example will: 1. load an image from a file, whose name is sent through the command line, using a callback function, 2. display the image as it is loaded. We used LFile::LoadFile(), passing LoadImageCB as its callback function. LFile::LoadFile() 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::LoadFile() 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::LoadFile() is requested to load the image as a 24 bit image. Usage: LOADCB --------------------------------------------------------------------------*/ // LdCBView.cpp : implementation of the CLoadCBView class // #include "stdafx.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CLoadCBView IMPLEMENT_DYNCREATE(CLoadCBView, CView) BEGIN_MESSAGE_MAP(CLoadCBView, CView) //{{AFX_MSG_MAP(CLoadCBView) ON_WM_TIMER() ON_WM_CREATE() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CLoadCBView construction/destruction CLoadCBView::CLoadCBView() { // TODO: add construction code here m_nCounter=0; m_hOrigCursor = 0; } CLoadCBView::~CLoadCBView() { } ///////////////////////////////////////////////////////////////////////////// // CLoadCBView drawing void CLoadCBView::OnDraw(CDC* pDC) { CLoadCBDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); // TODO: add draw code for native data here HPALETTE hOldPalette = NULL; if ( m_LeadBitmap.GetPalette() ) hOldPalette = SelectPalette (pDC->GetSafeHdc() , m_LeadBitmap.GetPalette(), TRUE); m_LeadBitmap.Paint()->SetDC ( pDC->GetSafeHdc() ); m_LeadBitmap.Paint()->PaintDC(); if (hOldPalette) SelectPalette (pDC->GetSafeHdc() ,hOldPalette, TRUE); } ///////////////////////////////////////////////////////////////////////////// // CLoadCBView diagnostics #ifdef _DEBUG void CLoadCBView::AssertValid() const { CView::AssertValid(); } void CLoadCBView::Dump(CDumpContext& dc) const { CView::Dump(dc); } CLoadCBDoc* CLoadCBView::GetDocument() // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CLoadCBDoc))); return (CLoadCBDoc*)m_pDocument; } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CLoadCBView message handlers L_INT CLoadCBView::LoadSaveFunction() { LUserFile UserLeadFile ; FILEINFO FileInfo; CLoadCBApp* CApplication = ( CLoadCBApp* ) AfxGetApp(); UserLeadFile.SetBitmap ( &m_LeadBitmap ); UserLeadFile.SetFileName ( (L_TCHAR*)(LPCTSTR) CApplication->m_strFileName ); UserLeadFile.EnableCallBack ( TRUE ); FileInfo.uStructSize = sizeof(FILEINFO); L_INT nRet = UserLeadFile.GetInfo( &FileInfo , sizeof(FILEINFO)); if(nRet!=SUCCESS) return nRet; UserLeadFile.m_pView = this; nRet = UserLeadFile.LoadFile (FileInfo.BitsPerPixel, ORDER_BGR, LOADFILE_ALLOCATE | LOADFILE_STORE ); return nRet; } BOOL CLoadCBView::OnCommand(WPARAM wParam, LPARAM lParam) { // TODO: Add your specialized code here and/or call the base class HCURSOR hOldCursor; KillTimer( IDT_TIMER1 ); hOldCursor=SetCursor( LoadCursor(NULL,IDC_WAIT) ); if ( !( lParam || wParam ) ) { L_INT nRet = LoadSaveFunction(); if ( nRet != SUCCESS ) { LBase::DisplayError( AfxGetMainWnd()->GetSafeHwnd (), nRet ); return 0; } } SetCursor( hOldCursor ); AfxGetMainWnd()->SetWindowText ( _T("LEADTOOLS Sample Application, Example Is Complete (Class library)")); return CView::OnCommand(wParam, lParam); } void CLoadCBView::OnTimer(UINT nIDEvent) { m_nCounter++ ; switch( m_nCounter ) { case 1: m_hOrigCursor = SetCursor ( LoadCursor ( NULL, IDC_SIZENS ) ); break; case 2: SetCursor ( LoadCursor ( NULL, IDC_SIZENESW ) ); break; case 3: AfxGetMainWnd()->SetWindowText ( _T("LEADTOOLS Sample Application - Calling the Load Function")); PostMessage ( WM_COMMAND ); SetCursor ( m_hOrigCursor ); break; } CView::OnTimer( nIDEvent ); } int CLoadCBView::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CView::OnCreate(lpCreateStruct) == -1) return -1; // TODO: Add your specialized creation code here m_nTimer = SetTimer ( IDT_TIMER1, 1000, NULL ); m_LeadBitmap.SetDisplayMode ( DISPLAYMODE_ORDEREDDITHER, DISPLAYMODE_ORDEREDDITHER); return 0; } L_BOOL CLoadCBView::HandlePalette(UINT uMsg,HWND hWnd) { //return 0; 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; }