/*[]=====================================================================[]*/ /*[] LEADTOOLS for Windows(Class Library) - Version 11 []*/ /*[] []*/ /*[] []*/ /*[] Copyright (c) 1991-2000 LEAD Technologies, Inc. []*/ /*[] All Rights Reserved. []*/ /*[]=====================================================================[]*/ /*---(Resize)--------------------------------------------------------------- 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, using LFile::LoadFile(), 2. resize the image during loading using the LBuffer::Resize() system, 3. display both the original and resized image during loading, 4. place the resized image over the original in the bitmap, 5. display the "image within an image" bitmap. Usage: RESIZE --------------------------------------------------------------------------*/ // resView.cpp : implementation of the CResView class // #include "stdafx.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CResView IMPLEMENT_DYNCREATE(CResView, CView) BEGIN_MESSAGE_MAP(CResView, CView) //{{AFX_MSG_MAP(CResView) ON_WM_CREATE() ON_WM_TIMER() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CResView construction/destruction CResView::CResView() { // TODO: add construction code here } CResView::~CResView() { } BOOL CResView::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return CView::PreCreateWindow(cs); } ///////////////////////////////////////////////////////////////////////////// // CResView drawing void CResView::OnDraw(CDC* pDC) { CResizeDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); HPALETTE hOldPalette = NULL; HDC hdc = pDC->GetSafeHdc(); m_LBitmap.Paint()->SetDC( hdc ); if(m_LBitmap.GetPalette()) hOldPalette = SelectPalette(hdc, m_LBitmap.GetPalette(), TRUE); m_LBitmap.Paint()->PaintDC(); if(hOldPalette!=NULL) SelectPalette(hdc, hOldPalette, TRUE); } ///////////////////////////////////////////////////////////////////////////// // CResView diagnostics #ifdef _DEBUG void CResView::AssertValid() const { CView::AssertValid(); } void CResView::Dump(CDumpContext& dc) const { CView::Dump(dc); } CResizeDoc* CResView::GetDocument() // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CResizeDoc))); return (CResizeDoc*)m_pDocument; } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CResView message handlers int CResView::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CView::OnCreate(lpCreateStruct) == -1) return -1; m_nTimer = SetTimer(2000,1,NULL); return 0; } BOOL CResView::OnCommand(WPARAM wParam, LPARAM lParam) { // TODO: Add your specialized code here and/or call the base class LBuffer LeadBuffer; FILEINFO FileInfo; LUserFile UserFile; CResizeApp* pTheApp = (CResizeApp*) AfxGetApp(); L_TCHAR * zsFileName = (L_TCHAR *)(LPCTSTR)pTheApp->m_strFileName; UserFile.SetBitmap(&m_LBitmap); UserFile.SetFileName((zsFileName)); if(UserFile.GetInfo(&FileInfo, sizeof(FILEINFO))!=SUCCESS) { UserFile.DisplayErrorFromList(NULL); AfxGetMainWnd()->DestroyWindow(); return 0; } m_LBitmap.Initialize(FileInfo.Width, FileInfo.Height, FileInfo.BitsPerPixel); UserFile.m_pView = this; UserFile.m_nDispRow = 0; UserFile.m_pLeadBuffer = &LeadBuffer; UserFile.m_FileInfo = FileInfo; LeadBuffer.Reallocate(m_LBitmap.GetBytesPerLine()); LeadBuffer.StartResize(FileInfo.Width, FileInfo.Height, FileInfo.Width/2, FileInfo.Height/2) ; UserFile.EnableCallBack(TRUE); L_INT nRet = UserFile.LoadFile (m_LBitmap.GetBitsPerPixel(), m_LBitmap.GetColorOrder(), LOADFILE_ALLOCATE, FileInfo.PageNumber); LeadBuffer.StopResize(); RECT rc; SetRect (&rc, 0, 0,m_LBitmap.GetWidth() ,m_LBitmap.GetHeight()); m_LBitmap.SetDstRect(&rc); return 0; } void CResView::OnTimer(UINT nIDEvent) { // TODO: Add your message handler code here and/or call default KillTimer(m_nTimer); OnCommand(0, 0); } void CResView::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); } L_BOOL CResView::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_LBitmap.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; }