HOME Delphi SaveToFile File I/O Status Check Print TJpegImage CreateFile TBitmap GetDriveType Screen Shot SW_HIDE SW_SHOW CreateFontIndirect Is Audio CD TColor cmWhiteness TPrintDialog Print Dialog Transparent Text Out Rotating Text ShowWindow Delphi Folder Navigation Dialog GetVolumeInformation HIcon Hide Taskbar HTML Color Value Icon to Bitmap Conversion GetDC LoadFromFile OPEN_EXISTING PItemIDList Print Text Files Rotate Bitmap Rotated Text Drawing Save image to clipboard SHGetPathFromIDList SHBrowseForFolder EndPath Animated Icon BeginPath BrowseInfo ColorToHtml confirm CopyRect Delphi File System Control Delphi Graphics and Drawing DrawCursor DrawIcon DrawMarquee DrawTextOnDesktop GetWindowDC ExtractAssociatedIcon Fade Out File Delete with UNDO File is in use FILE_ATTRIBUTE_NORMAL Focus GENERIC_READ GENERIC_WRITE WNetGetConnection GetDesktopWindow

SAVETOFILE.ZIP

Show *any* graphics as Glyph on a SpeedButton   (created at Sep 10, 2007)   123  

TBitBtn and TSpeedButton accept only BMP pictures, if you have some other picture format, like ICO or JPG, (in an Image component) you want to show as a Glyph, you'll need to "transform" it to Bitmap, here's how:

Rotate Bitmap (any angle, any center of rotation)   (created at Sep 10, 2007)   61  

Here's how to rotate a TBitmap at any angle:Const PixelMax = 32768;Type   pPixelArray = ^TPixelArray;   TPixelArray = Array[0..PixelMax-1] Of TRGBTriple;Procedure RotateBitmap_ads(   SourceBitmap : TBitmap;   out Des...

TImage.Bitmap fade out   (created at Sep 10, 2007)   60  

Put a TImage (Image1) on a Delphi form and load a bitmap of 24 bits or 32 bits in it; put a TButton (Button1) and put this code in its OnClick event:procedure TForm1.Button1Click(Sender: TObject) ;  procedure FadeOut(const BMP:TImage; Pause:integer) ;...

TDesktopCanvas - draw on Windows Desktop   (created at Sep 10, 2007)   77  

This canvas class allows you to access the Windows Desktop, and draw on it.type   TDesktopCanvas = class(TCanvas)   private     DC : hDC;     function GetWidth:Integer;     function GetHeight...

TColor to HTML color   (created at Sep 10, 2007)   54  

Put a TColorDialog (ColorDialog1), a TLabel (Label1) and a TButton (Button1) in your form, and assign the Button1.OnClick procedure as follows:procedure TForm1.Button1Click(Sender: TObject) ;  function ColorToHtml(DColor:TColor):string;  var ...

Rotating Text   (created at Sep 10, 2007)   35  

Here is an example of text output that is rotated 45 degrees: procedure TForm1.Button1Click(Sender: TObject) ; var   lf : TLogFont;   tf : TFont; begin   with Form1.Canvas do begin     Font.Name := 'Arial';     Font.Size ...

Get Cursor Image (draw it on a Canvas)   (created at Sep 10, 2007)   261  

The DrawCursor procedure draws a current cursor image on ACanvas at the Position point: procedure DrawCursor (ACanvas:TCanvas;                       Position:TPoint) ; var   HCursor : THandle; beg...

Paint a Form with a tiled bitmap image   (created at Sep 10, 2007)   65  

Here's how to draw tiled bitmap image on a Form:type   TForm1 = class(TForm)     procedure FormCreate(Sender: TObject) ;     procedure FormPaint(Sender: TObject) ;     procedure FormClose(Sender: TObje...

Is Point in Polygon?   (created at Sep 10, 2007)   39  

This solution checks how many times you cross a line to pass from point X,Y to the edge of the polygon...function PtInPoly(const Points: Array of TPoint; X,Y: Integer): Boolean;var Count, K, J : Integer;begin  Result := False;  Count := Length(Po...

Implementing a lasso drawing technique   (created at Sep 10, 2007)   50  

Here's one approach to drawing a lasso rectangle using Delphi:1. In the OnMouseDown event for the formthat you are 'lasso-ing' controls on:bMarquee := True;ptOrigin := Point(X,Y) ;ptMove := Point(X,Y) ;Pen.Color := clBlack;Pen.Width := 1;Pen.Style := psDas...

Grayscaling a bitmap ?   (created at Sep 10, 2007)   81  

This example uses an averaging mechanism to obtain grayscale intensity on a pixel-by-pixel basis. Specifically, it averages the Red, Green and Blue component values of a color and assigns that value back to each RGB component. Usage: GrayScale(Image1.Pictu...

Convert a BMP to a JPG   (created at Sep 10, 2007)   40  

You can easily convert a BMP image to a JPG (JPEG) image:{Usage:BMPtoJPG('mybitmap.bmp','myjpeg.jpg')}function BMPtoJPG   (var BMPpic, JPGpic: string):boolean;var Bitmap: TBitmap;    JpegImg: TJpegImage;begin  Result:=False;  ...

How to convert HIcon to TIcon ?   (created at Sep 10, 2007)   45  

Many Windows API functions return a HIcon value (handle to Icon). Here's how to "convert" a HIcon to TIcon (object) For example, when using ExtractIcon to get icon from file, the resulting value is of the HICON type. The answer is: Create a TIcon object an...

Extract an icon from an Windows application and paint on a Form   (created at Sep 10, 2007)   55  

This tip shows how to extract the associated icon and draw it into a small area of the form (e.g. Notepad icon)?procedure TForm1.Button1Click(Sender: TObject) ; var   IconIndex : word;   h : hIcon; begin   IconIndex := 0;   h:=ExtractAs...

How to draw transparent text on Windows Desktop   (created at Sep 10, 2007)   52  

Here's how to draw transparent text on the Windows Desktop: { Usage:   DrawTextOnDesktop('About Delphi Programming'): } procedure DrawTextOnDesktop(TextToDraw: string) ; var   Handle: HWND;   Dc: HDC;   ACanvas: TCanvas; begin   Ha...

How to draw rotated text   (created at Sep 10, 2007)   38  

How to draw rotated textThis example creates a rotated font and displays it on the form by assigning the handle of the rotated to the Form’s Canvas Font via the Font’s Handle property. Rotating fonts is a straightforward process, so long as the Windows Fon...

How to convert an ICO to a BMP   (created at Sep 10, 2007)   40  

If you have an icon file (ICO) and want to convert it to a bitmap image, use the following code: Procedure IcoToBmp; var   Icon : TIcon;   Bitmap : TBitmap; begin   Icon := TIcon.Create;   Bitmap := TBitmap.Create;   Icon.LoadFromF...

How to Convert Pixels to Millimeters   (created at Sep 10, 2007)   55  

If you need to convert pixel value to millimeters (inches, centimeters, etc.) use the code provided here.The code uses the API function GetDeviceCaps to get the metrics you need.procedure PixelsPerMM(   canvas: TCanvas;   var x, y: sing...

How to capture Windows Desktop to Bitmap   (created at Sep 10, 2007)   59  

Here's a piece of Delphi code capable of capturing the Windows Desktop image into a TBitmap object:procedure ScreenShot(DestBitmap : TBitmap) ; var   DC : HDC; begin   DC := GetDC (GetDesktopWindow) ;   try   DestBitmap.Width := GetDevi...

Cut a rectangle from an Image to Clipboard   (created at Sep 10, 2007)   98  

Cutting a graphic to the Clipboard is like copying it, but you also erase the graphic from the source.procedure CutToClipboard   (AnImage:TImage; ARect:TRect) ;var b:TBitmap;begin 

Convert TColor to Hex & Hex to TColor   (created at Sep 10, 2007)   44  

Here are two simple functions to convert color values from TColor to Hex (HTML) and vice versa:function TColorToHex(Color : TColor) : string;begin   Result :=     IntToHex(GetRValue(Color), 2) +     IntToHex(GetGValu...

Does my CD-ROM drive contain an audio CD?   (created at Sep 10, 2007)   37  

We can use the Windows API function GetDriveType() to test if the drive is a CD-ROM drive then use the Windows API function GetVolumeInformation() to test if the VolumeName is 'Audio CD'.function IsAudioCD(Drive : char) : bool;var   DrivePath : s...

Convert a mapped drive to a full UNC path   (created at Sep 10, 2007)   86  

Universal/Uniform Naming Convention. A UNC path describes the location of a volume, directory, or file.The format for a UNC path is \servervolumedirectoryfile and is not case-sensitive. For example:    \Shared1_svrShared1WGroupsNetworkOrders.xlsR...

Checking If File Is In Use   (created at Sep 10, 2007)   55  

IsFileInUse will return true if the file is locked for exclusive access. It would fail if the file doesn't exist at all. function IsFileInUse(fName : string) : boolean;var    HFileRes : HFILE;begin    Result := false;    if no...

Browse for Computers, Folders, Files and Printers   (created at Sep 10, 2007)   49  

By using the SHBrowseForFolder Windows API function and Delphi we can invoke a Windows system dialog used to browse for files and folders on users hard drive as well as network computers and printers. First, let's look at what SHBrowseForFolder needs. Here...

How to draw Transparent Text on bitmap   (created at Sep 01, 2007)   61  

You can set transparent mode by calling SetBkMode function.procedure TForm1.Button1Click(Sender: TObject);begin  with Image1.Picture.Bitmap.Canvas do  begin    Font.Color  := clBlue;    Brush.Style := bsclear;   ...

How Do I Remove The Application Icon From The Taskbar?   (created at Aug 25, 2007)   46  

To remove the icon from the taskbar, you need to call a Windows API call:BOOL ShowWindow(HWND hwnd,int nCmdShow);Delphi makes it very easy to use this command. All you need to do is supply the Application.handle and SW_HIDE to remove the icon from the task...

How To Show The Print Dialog And Print Text Files   (created at Aug 25, 2007)   69  

This code show an example of how to print a text of a RichEdit component.unit Unit1; interface uses   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,   StdCtrls, ComCtrls; type   TForm1 = class(TForm)     ...

How To Make An Animated Application Icon   (created at Aug 25, 2007)   80  

Show how to create an animated icon in your programvar  icon1:Boolean; ... procedure TForm1.Timer1Timer(Sender: TObject); begin   if icon1=false then   begin     Application.icon:=Image1.Picture.Icon;      icon1:=tru...

How To Pass The Focus To The Next/prior Control   (created at Aug 25, 2007)   70  

Shows how to activate the next or prior control in a formnext control: SendMessage(Form1.Handle, WM_NEXTDLGCTL, 0, 0); prior control: SendMessage(Handle, WM_NEXTDLGCTL, 1, 0);