Mega Code Archive

 
Categories / Delphi / Graphic
 

Using THintWindow To Show an Image

Title: Using THintWindow To Show an Image Question: How Use HintWindow To view an Image Answer: Sometimes you want to show a Hint with some image in it, you can do this by using a THintWindow to show the hint and a TBitmap to the Image, Like this. Type Form1 = class(TForm) Procedure OnMouseDown(X, Y: Integer; Shift: TShiftState ;) Procedure OnMouseUp(X, Y: Integer; Shift: TShiftState ;) Privet MyHintWindow: THintWindow; MyImage: TBitmap; Public End; Implementation Procedure TForm1.OnMouseDown(X, Y: Integer; Shift: TShiftState ;) Begin MyImage := TBitmap.Create; // Create's the Capture Bitmap MyImage.LoadFromFile(C:\WIN..\Blue Lace 16.bmp); //Load's the Imafe From File If ssLeft in Shift then Begin MyHintWindow:=THintWindow.Create; // Create's the HintWindow MyHintWindow.Brush.Bitmap := MyImage //Assgin the MyImage Pointer to the Bruh Bitmap Prorerty MyHintWindow.ActiveHint(Rect(X,Y,X+MyImage.Width, Y+MyImage.Height-2{offset for better Look})) //Show's the Hint End End; Procedure TForm1.OnMouseUp(X, Y: Integer; Shift: TShiftState ;) Begin End; And we can use it in other function like showing repeated view (like Miror). Type Form1 = class(TForm) Image: TImage; Procedure OnImageMouseDown(X, Y: Integer; Shift: TShiftState ;) Procedure OnImageMouseUp(X, Y: Integer; Shift: TShiftState ;) Privet MyHintWindow: THintWindow; MyImage: TBitmap; Public End; Implementation Procedure TForm1.OnImageMouseDown(X, Y: Integer; Shift: TShiftState ;) Begin If ssLeft in Shift then //When Left Mouse Button Cliked do... Begin MyImage := TBitmap.Create; // Create's the Capture Bitmap MyImage.Canvas.CopyRect (Rect(0,0,20,50),Image.Canvas, Rect(X,Y,X+20,Y-20)) // MyHintWindow:=THintWindow.Create; // Create's the HintWindow MyHintWindow.Brush.Bitmap := MyImage //Assgin the MyImage Pointer to the Bruh Bitmap Prorerty MyHintWindow.ActiveHint(Rect(X,Y,X+20,Y+50-2{offset for better Look})) //Show's the Hint End End; Procedure OnImageMouseMove(X, Y: Integer; Shift: TShiftState ;) begin If ssLeft in Shift then //When Left Mouse Button Cliked do... Begin MyImage.Canvas.CopyRect (Rect(0,0,20,50),Image.Canvas, Rect(X,Y,X+20,Y-20)) // MyHintWindow.Brush.Bitmap := MyImage //Assgin the MyImage Pointer to the Bruh Bitmap Prorerty MyHintWindow.ActiveHint(Rect(X,Y,X+20,Y+50-2{offset for better Look})) //Show's the Hint End end; Procedure TForm1.OnImageMouseUp(X, Y: Integer; Shift: TShiftState ;) Begin if MyHinWindow nil then //When MyHinWindow is Created do... MyImage.FreeImage; // Clear's the Captured Bitmap MyImage.Free;// Free's the Captured Bitmap MyHinWindow.Brush.Bitmap.:= nil; //Assgin the Brush Pointer to nil MyHintWindow.ReleaseHandle; //Close the Hint window MyHintWindow.Free;// Free's the HintWindow MyHintWindow := nil//Assgin the MyHintWindow Pointer to nil End End;