void TBmpViewWindow::CmAutoClipView( AutoClipView =!AutoClipView; //Check AutoClipView according to flag void TBmpViewWindow:CeAutoClipView(TCommandEnabler&ce) ce.SetCheck(AutoClipView TCommandEnabler::Checked [CommandEnabler:Unchecked): static TOpenSaveDialog::TData data OFN_HIDEREADONLY |OFN_FILEMUSTEXIST|OFN_NOREADONLYRETURN, “Bitmap Files(k,BWP)l*,bpl“, "BMP* if (TFileOpenDialog(this,data).Execute()==IDOK){ char fileTitle[MAXPATH]: TOpenSaveDialog::GetFileTitle(data.FileName,fileTitle,MAXPATH): LoadBitmapFile(fileTitle); SetCaption(strlwr(fileTitle)): //Adjust the Scroller range so that the the origin is the /upper-most scrollable point and the corner is the bottom-most. 1 void TBmpViewWindow::AdjustScroller() TRect clientRect GetclientRect():
void TBmpViewWindow::CmAutoClipView() { AutoClipView = !AutoClipView; } // // Check AutoClipView according to flag // void TBmpViewWindow::CeAutoClipView(TCommandEnabler& ce) { ce.SetCheck(AutoClipView ? TCommandEnabler::Checked : TCommandEnabler::Unchecked); } void TBmpViewWindow::CmFileOpen() { static TOpenSaveDialog::TData data ( OFN_HIDEREADONLY|OFN_FILEMUSTEXIST|OFN_NOREADONLYRETURN, "Bitmap Files (*.BMP)|*.bmp|", 0, "", "BMP" ); if (TFileOpenDialog(this, data).Execute() == IDOK) { char fileTitle[MAXPATH]; TOpenSaveDialog::GetFileTitle(data.FileName, fileTitle, MAXPATH); LoadBitmapFile(fileTitle); SetCaption(strlwr(fileTitle)); } } // // Adjust the Scroller range so that the the origin is the // upper-most scrollable point and the corner is the // bottom-most. // void TBmpViewWindow::AdjustScroller() { TRect clientRect = GetClientRect();
//only show scrollbars when img is larger than if (Fit) Scroller->SetRange(0,0); else TPoint Range(Max(PixelWidth-clientRect.Width(,0), Max(PixelHeight-clientRect.Height(),0)); Scroller->SetRange(Range.x,Range.y); 1 Scroller->ScrollTo(0,0) //if (!GetUpdateRect(clientRect,FALSE)) Invalidate(TRUE): } //Reset scroller range. void TBmpViewWindow::EvSize(UINT SizeType,TSize&Size) TWindow::EvSize(SizeType Size): if (SizeType !=SIZEICONIC) AdjustScroller(): Invalidate(FALSE); 1 //Somebody changed the palette.If its not us,then we need to update. / void pndPeChanged(AN)kdPoChg if (hWndPalChg !HWindow) UpdatePalette(TRUE)://pass FALSE to UpdateColors()instead of repaint /We need to re-realize the logical palette each time /we regain the input focus
// only show scrollbars when img is larger than // the client area and we are not stretching to fit. // if (Fit) Scroller->SetRange(0, 0); else { TPoint Range(Max(PixelWidth-clientRect.Width(), 0), Max(PixelHeight-clientRect.Height(), 0)); Scroller->SetRange(Range.x, Range.y); } Scroller->ScrollTo(0, 0); // if (!GetUpdateRect(clientRect, FALSE)) Invalidate(TRUE); } // // Reset scroller range. // void TBmpViewWindow::EvSize(UINT SizeType, TSize& Size) { TWindow::EvSize(SizeType, Size); if (SizeType != SIZEICONIC) { AdjustScroller(); Invalidate(FALSE); } } // // Somebody changed the palette. If its not us, then we need to update. // void TBmpViewWindow::EvPaletteChanged(HWND hWndPalChg) { if (hWndPalChg != HWindow) UpdatePalette(TRUE); // pass FALSE to UpdateColors() instead of repaint } // // We need to re-realize the logical palette each time // we regain the input focus //
bool TBmpViewWindow::EvQueryNewPalette( return UpdatePalette(TRUE): /Use this message temporarily until the palette msgs get routed to us void TBmpViewWindow::EvSetFocus(HWND) UpdatePalette(TRUE) void TBmpViewWindow::EvDrawClipboard( if (TClipboardViewer::DoDrawClipboard()==esComplete) return; if (AutoClipView) CmPaste(): void TBmpViewWindow::EvDestroy() if (TClipboardViewer::DoDestroy()==esComplete) eturn TWindow::EvDestroy() hool TBmpViewWindow::UpdatePalette(bool alwaysRepaint) if (Palette)( TClientDC clientDC(*this): #if defined(WIN32 Palette->UnrealizeObject( #endif TRACEX(BmpView, 2. "UpdatePalette:Palette: hex (UINT)(HPALETTE)*Palette): clientDC.SelectObject(*Palette,FALSE): if (clientDC.RealizePalette()>0)
bool TBmpViewWindow::EvQueryNewPalette() { return UpdatePalette(TRUE); } // // Use this message temporarily until the palette msgs get routed to us // void TBmpViewWindow::EvSetFocus(HWND) { UpdatePalette(TRUE); } void TBmpViewWindow::EvDrawClipboard() { if (TClipboardViewer::DoDrawClipboard() == esComplete) return; if (AutoClipView) CmPaste(); } void TBmpViewWindow::EvDestroy() { if (TClipboardViewer::DoDestroy() == esComplete) return; TWindow::EvDestroy(); } bool TBmpViewWindow::UpdatePalette(bool alwaysRepaint) { if (Palette) { TClientDC clientDC(*this); #if !defined(_WIN32_) Palette->UnrealizeObject(); #endif // TRACEX(BmpView, 2, "UpdatePalette::Palette: " << hex << (UINT)(HPALETTE)*Palette); clientDC.SelectObject(*Palette, FALSE); if (clientDC.RealizePalette() > 0)
if (alwaysRepaint) Invalidate(FALSE) clientDC.UpdateColors(); /TRACEX(BmpView,2,"Leave UpdatePalette(TRUE)"); return TRUE: //TRACEX(BmpView,2."Leave UpdatePalette(FALSE)"): return FALSE 1 /∥Responds to ing Paint age by redrawing the bitmap //The Scroller's BeginView method,which sets the viewport origin /relative to the present scroll position,has been called by Twindow's /EvPaint /Note that we Invalidate()ourselves with false to avoid the background //paint flicker.Thats why we use //The code can use either the Bitmap member with Stretch-and Bit-Blts, /or use the Dib member with Stretch-and Set-DIBits. oid IBmpViewWindow:Paint(TDC&dc,bool,TRect&) TRect clientRect GetClientRect(); dc.SelectObject(*BkgndBrush); if (Bitmap) if(pMemDC) if (Palette)( dc.Selectobject (*Palette,FALSE): dc.RealizePaletteo: pMemDC->SelectObject(*Palette,FALSE) Rop=SRCCOPY: TRect imgRect(0,0,PixelWidth,PixelHeight) //dc.PatBlt(imgRect,PATCOPY): /for(int j=0:j<=128:j++) /for(int i=0:i<=255:i++)pMemDC->SetPixel(j,i,TColor(120));
if (alwaysRepaint) Invalidate(FALSE); else clientDC.UpdateColors(); // TRACEX(BmpView, 2, "Leave UpdatePalette(TRUE)"); return TRUE; } // TRACEX(BmpView, 2, "Leave UpdatePalette(FALSE)"); return FALSE; } // // Responds to an incoming Paint message by redrawing the bitmap. // The Scroller's BeginView method, which sets the viewport origin // relative to the present scroll position, has been called by TWindow's // EvPaint // Note that we Invalidate() ourselves with false to avoid the background // paint flicker. Thats why we use // // The code can use either the Bitmap member with Stretch- and Bit- Blts, // or use the Dib member with Stretch- and Set- DIBits. // void TBmpViewWindow::Paint(TDC& dc, bool, TRect&) { TRect clientRect = GetClientRect(); dc.SelectObject(*BkgndBrush); if (Bitmap) { if(pMemDC) if (Palette) { dc.SelectObject(*Palette, FALSE); dc.RealizePalette(); pMemDC->SelectObject(*Palette, FALSE); } Rop=SRCCOPY; TRect imgRect(0,0, PixelWidth, PixelHeight); // dc.PatBlt(imgRect, PATCOPY); // for(int j=0;j<=128;j++) // for(int i=0;i<=255;i++)pMemDC->SetPixel(j,i,TColor(120));
dc.BitBlt (imgRect.*pMemDC.TPoint(0.0).Rop) void if(Dib!=0)delete Dib: Dib dib: if(Palette!=o)delete palette Palette=new elete Bitmap: Bitmap new TBitmap (*Dib,Palette); if(pMemDC!=)delete pMemDC: ((ry -SelectObject(*Bitmap) PixelWidth Dib->Width(): PixelHeight Dib->Height(); /unsigned char far *buf; /if((buf=(unsigned char far*)farmalloc(TotalPixel))==NULL) //MessageBox("Cannot malloc memory for displaying bitmap file", GetApplication (->GetName(.MB 0K): /for(unsigned long i=0:i<=(unsigned long)65535:i++)buf[i]=0: /Bitmap->SetBitmapBits((unsigned long)65535,buf): /farfree(buf): UpdatePalette(TRUE) AdjustScroller(; #if defined(PAINT_ICON) Parent->SetIcon(0,0)://enable to paint the icon from the bitmap #endif /Test if the passed resource is a Windows 3.0(or PM 1.x)DI bitmap /∥and if so read it
dc.BitBlt(imgRect, *pMemDC, TPoint(0,0), Rop); } } void TBmpViewWindow::SetupFromDib(TDib* dib) { if(Dib!=0)delete Dib; Dib = dib; if(Palette!=0)delete Palette; Palette = new TPalette(*Dib); if(Bitmap!=0)delete Bitmap; Bitmap = new TBitmap(*Dib, Palette); if(pMemDC!=0)delete pMemDC; pMemDC=new TMemoryDC; ((TMemoryDC*)pMemDC)->SelectObject(*Bitmap); PixelWidth = Dib->Width(); PixelHeight = Dib->Height(); //****Change the Image Pixels*****// // unsigned long TotalPixel=PixelWidth*PixelHeight-1; // unsigned char far *buf; // if((buf=(unsigned char far*)farmalloc(TotalPixel))==NULL) // { MessageBox("Cannot malloc memory for displaying bitmap file", GetApplication()->GetName(), MB_OK); // CloseWindow(0); // } // for(unsigned long i=0;i<=(unsigned long)65535;i++)buf[i]=0; // Bitmap->SetBitmapBits((unsigned long)65535,buf); // farfree(buf); //****************************************// UpdatePalette(TRUE); AdjustScroller(); #if defined(PAINT_ICON) Parent->SetIcon(0, 0); // enable to paint the icon from the bitmap #endif } // // Test if the passed resource is a Windows 3.0 (or PM 1.x) DI bitmap // and if so read it