Delphi Graphics: Win 32 API

API Calls
Windows Messages
Windows API Tips and Tricks
Other Windows API Resources


API Calls

Also see

- Project JEDI API Conversion Library Graded Packs

Marcel's homepage contains the current version, the JEDI page mostly a previous version. http://members.chello.nl/m.vanbrakel2

- the Delphi RTL Routines

 

Not all API functions are listed here:   only the most common and most likely to be used are here. Delphi does a wonderful job in hiding much of the Windows complexity, so you can focus on the real problem you're trying to solve. I try only to use an API call when Delphi is lacking some feature. For example, why use the LineTo API call when the Canvas.LineTo method is much simpler to use? Or why use API calls to set a Pen Style when the Delphi VCL wraps all the API functionality in a simpler-to-use package?
Graphical API Amazon Link Core API Amazon Link
API Call/ Structure Description/Comments
AddFontResource,
RemoveFontResource
Adding TrueType fonts to windows in code (FAQ 2537D)
AnimatePalette Tomes Graphical, pp. 408-411
Delphi 2 Multimedia, pp. 311-318 to Edit the Palette, pp. 322-330 for Marquee lights

AnimatePalette is for 256-color mode only.

See Ray Lischner's example of palette animation at www.tempest-sw.com/freeware/Delphi/pal10.zip
or via ftp at ftp://ftp.tempest-sw.com/pub/delphi/pal10.zip

See Microsoft's Simulating Palette Animation on Non-Palette Displays:
http://support.microsoft.com/support/kb/articles/q130/4/76.asp

See
- efg's CycleColors example for an alternative in high or true color modes.
- Palette links and info on efg's Delphi Graphics Color Algorithms page

BeginPath How do I use Paths and Geometric Pens? (FAQ 2724D)

Steve Schafer's UseNet Post with BeginPath/CloseFigure/EndPath/StrokeAndFillPath example

Wayne Sherman's UseNet Post with BeginPath/DrawText/EndPath example

BitBlt Henrik PalmÚr's UseNet Post about a transparency solution using BitBlt twice

Harm's UseNet Post with FillAndBlitRect example procedure

Copies bits from one device context to another. Tomes Graphical, pp. 283-285.
Processing Bitmaps Using BitBlt Functions, Delphi 2 Multimedia, pp. 335-343.
Non VCL Bitmap buffering (FAQ 2774D)
Displaying a bitmap on the client area of an MDI parent form (FAQ 176D)
A better way to print a form (TI 1412D)

Blitting Between DCs for Different Devices Is Unsupported (MS Q195830)
BitBlt and Palettes

ChangeDisplaySettings The book The Tomes of Delphi 3: Win32 Graphical API says (p. 23) that Delphi imports ChangeDisplaySettings incorrectly, so you need to manually import it.  The book shows a unit with this in the Interface

   function ChangeDisplaySettings(lpDevMode: PDeviceMode; dwFlags: DWORD):      LongInt; stdcall;

and this in the Implementation:

    function ChangeDisplaySettings; external user32 name 'ChangeDisplaySettingsA';

Changing the display mode settings in code (FAQ 735D)

How to change video modes
www.geocities.com/SiliconValley/Lakes/1636/vidmodes.htm

Davie Reed's UseNet Post with Example

Time for a Change, PC Magazine, Sept 22, 98, p. 251-254: VB code to list available resolutions and change screen resolution using ChangeDisplaySettings

ClientToScreen VAR BasePoint: TPoint;
...
BasePoint := Image.ScreenToClient( ClientToScreen( Point(Bevel1.Left, Bevel1.Top)) );
ClipCursor RestrictCursorToDrawingArea and RemoveCursorRestrictions. For a complete example, see efg's Line Stretch Lab Report.
CloseFigure Steve Schafer's UseNet Post with BeginPath/CloseFigure/EndPath/StrokeAndFillPath example
CombineRgn Use CombineRgn to get the intersection of two regions.  See Lou's UseNet Post.

efg's Printer Demo #2 Lab Report

CopyCursor CopyCursor (FAQ 1067D)
CopyIcon CopyCursor (FAQ 1067D)
CreateBitmap Creates a new bitmap with the specified width, height, and color depth. Tomes Graphical, pp. 289-291.
CreateCompatibleBitmap A better way to print a form (TI 1412D)
CreateEllipticRgn

efg's Printer Demo #2 Lab Report

CreateHalftonePalette Tomes Graphical, pp. 412-413
CreateDIBitmap Creates a device-dependent bitmap (DDB) based on the attributes and image of the specified device-independent bitmap. 

Creating a bitmap from a pixel array (FAQ 1205D)  

CreateDIBSection Creates a Device Independent Bitmap (DIB)
CreateFontIndirect Creates a logical font matching the specified font attributes. Used to create a rotated font. Tomes Graphical, pp. 477-483.

"Drawing text at different angles," pp. 295-297, Delphi Programming Problem Solver, Neil Rubenking.

Chris Hill's UseNet Post about Antialiased Fonts
NolenJ's UseNext Post with CanvasTextOutAngle method

Creating a rotated font (FAQ 615D)

How can I print a rotated font?

CreateIconIndirect How do I create an icon from a bitmap? (FAQ 2748D)

How to Create a Cursor from a Bitmap
Chris Hill's UseNet Post

CreatePalette Creating a palette with more than one entry (FAQ 890D)
Creating a bitmap from a pixel array (FAQ 1205D)   

Tomes Graphical, pp. 414-420
Secrets of Delphi 2, Ray Lischner, pp. 332, 436

See \Program Files\Borland\ Delphin\HELP\Examples\Bitmap\BMPFormU.PAS

See:
-
efg's
ShowDemoOne and ShowDemoMany Lab Reports
- Palette links and info on efg's Delphi Graphics Color Algorithms page

CreatePen Draw On Frame (FAQ 1079D)
CreatePolygonRgn How to Implement Weird Shaped Windows
www.developers.demon.co.uk/wierd.html

Colin Sarsfield's UsetNet Post with an example

How to Make a Polygonal Splash Screen by Michael Barnes www.undu.com/DN970101/00000006.htm

Manipulating Regions with Delphi by Don Monroe www.undu.com/DN961001/00000016.htm

How to make a triangular form
Dudßs Jˇzsef's  UseNet Post

CreatePolyPolygon

Chris Hill's UseNet Post with Example

CreateRectRgn

efg's Printer Demo #2 Lab Report

CreateRectRgnIndirect Sergey Prilutsky's "Using Clipping Regions for Faster GDI Drawing"
DeleteDC Creating a bitmap from a pixel array (FAQ 1205D)  
DeleteObject Non VCL Bitmap buffering (FAQ 2774D)
DrawEllipse TShape descendant that has a star shape and has OnMouseEnter/Leave handlers
Eddie Shipman's UseNet Post
DrawFocusRect Selection rectangle (FAQ 1073D)

Claire Humphrey's UseNet Post with DrawFocusRect example

David Lively in UseNet Posting:  "DrawFocusRect uses an XOR to draw the rectangle. A second draw to the same coordinates will restore the background contents:  A XOR B XOR B == A"

DrawIcon Displaying a file's associated icon (FAQ 2646D)
Creating a resource only DLL (FAQ 1595D)
DrawIconEx How to Create BMP files for Standard Cursors
see  Cursors on efg's Delphi Graphics Algorithm page

Kerstin Thaler's UseNet Post with example

efg's ShowCursor example of displaying cursor at any position on screen 
(based on UseNet Post by Michael Winter)

efg's Cursor Overlay Lab Report

DrawRoundRect TShape descendant that has a star shape and has OnMouseEnter/Leave handlers
Eddie Shipman's UseNet Post
DrawText
DrawTextEx
DrawTextParams
Easiest way to implement word wrap

Mauro Pati˝o's UseNet Post explaining how to use an OnDrawCell to make the fixed row font and text centering different than the remainder of the rows in a TStringGrid component

How can I have a TBitBtn component that has word-wrapped caption? (FAQ 1754D)

Colin Wilson's UseNet Post about DrawTextParams and DrawTextEx

Harm's UseNet Post about using DrawText

Ellipse Non VCL Bitmap buffering (FAQ 2774D)
EndPath see BeginPath
EnumDisplayDevices Obtain information about the display devices in a system
Nemesis' UseNet Post with example
http://msdn.microsoft.com/library/default.asp?URL=/library/psdk/gdi/devcons_2303.htm 
EnumDisplaySettings Changing the display mode settings in code (FAQ 735D)

How to enumerate video modes
www.geocities.com/SiliconValley/Lakes/1636/video.htm

PC Magazine, Sept 22, 98, p. 254: VB code to list available resolutions (and change screen resolution)

EqualRect  
ExtCreatePen Create a geometric pen style.

Joe Hecht's UseNet Post with example
Chris Hill's UseNet Post with example

See Listing 7 in efg's Image Feathering Lab Report

How do I use Paths and Geometric Pens? (FAQ 2724D)

ExtCreatePen info from Microsoft

ExtractAssociatedIcon Displaying a file's associated icon (FAQ 2646D)
ExtractIcon Extracting an icon from a .EXE or .DLL (FAQ 2458D)
Using an icon as the glyph in a TSpeedButton (FAQ 2122D)
Kerstin Thaler's UseNet Post with example
ExtractIconEx Extracting Icons (FAQ 1778D)
Kerstin Thaler's UseNet Post with example
ExtSelectClipRgn Sergey Prilutsky's "Using Clipping Regions for Faster GDI Drawing"
FindResource Using JPEGs from resource files (FAQ 1882D)
Loading bitmaps and cursors from RES files (TI 1081D)
FlashWindow Creating a flashing icon (FAQ 1103D)

// Tomes of Delphi 3 -- Win32 Core API, p. 29:
procedure TForm1.Timer1Timer(Sender:  Object);
begin
  FlashWindow(Handle, TRUE);
  FlashWindow(Application.Handle, TRUE)
end;

FreeLibrary Creating a resource only DLL (FAQ 1595D)
FreeResource Using JPEGs from resource files (FAQ 1882D)
GetCursorInfo Use GetCursorInfo to get the current cursor image no matter which window is active

efg's ShowCursor example of displaying cursor at any position on screen 
(based on UseNet Post by Michael Winter)

GetCursorPos How can I easily move a Window control at runtime (FAQ 896D)
Simulating a mouse move in code (FAQ 2871D)

efg's ShowCursor example of displaying cursor at any position on screen 
(based on UseNet Post by Michael Winter)

GetDC Non VCL Bitmap buffering (FAQ 2774D)
How can I draw directly on the Windows Desktop? (FAQ 2818D)
Creating a bitmap from a pixel array (FAQ 1205D)   

GetDC(0) returns the Device Context for the desktop, which can also be written as
GetDC(hWnd_DeskTop).

GetDeviceCaps Drawing in scale without using Windows Mapping Modes? (FAQ 2736D)
Finding the color depth of a canvas (TI 1507D)
How many colors will my display mode support? (FAQ 741D)
Passing TPrinter handle to GetDeviceCaps (FAQ 2610D)

Index Values
TECHNOLOGY, RASTERCAPS, CURVECAPS, LINECAPS, POLYGONALCAPS, TEXTCAPS

Screen:
Tomes Graphical, pp. 37-52
pp. 329-333, Delphi Programming Problem Solver, Neil Rubenking, for RASTERCAPS, RC_PALETTE

TECHNOLOGY:  Determining if a canvas is a Metafile Canvas?  (FAQ 2638D)

RASTERCAPS to create IsPaletteDevice function: Creating a bitmap from a pixel array (FAQ 1205D)  
RASTERCAPS:  Raster Operations (FAQ 2622D)

GetDeviceCaps(hDC, RASTERCAPS) Description
http://support.microsoft.com/support/kb/articles/q75/9/12.asp

RC_PALETTE: A better way to print a form (TI 1412D)

Printers:
Getting printer capabilities (FAQ 1475D)
efg's Printer Demo #1

GetDeviceGammaRamp Philipp Pammler's Usenet Post with example of using GetDeviceGammaRamp and SetDeviceGammaRamp API calls. Michael Warner's reply that API gamma functions work with few video cards.
GetDIBits Creates a device-independent bitmap (DIB) from a device-dependent bitmap (DDB).
A better way to print a form (TI 1412D)
efg's Printer Demo #1

Andrew Rybenkov's UseNet Post about using GetDIBits/SetDIBits as an alternative to Scanline

GetIconInfo Get "And" mask and an "Or" mask buried in each TIcon
ICOtoBMP.pas.txt
GetNearestColor Color problems in 256 color mode (FAQ 2780D)
GetObject Using the Win API GetObject to get a bitmap (FAQ 2518D)
Painting a rainbow color spectrum onto a form (FAQ 1247D)
GetOutlineTextMetrics Peter Haas' UseNet Post with example of GetOutlineTextMetrics
GetPaletteEntries Retrieves a range of color palette entries from the specified logical palette.
How to use GetPaletteEntries and Convert pf8bit Bitmap to pf24bit Bitmap Using Scanline

p. 436, Secrets of Delphi 2, Ray Lischner

Mike Mormando's UseNet Post about passing NIL parameter to get the number of palette entries.

GetPixel RASTERCAPS: Raster Operations (FAQ 2622D)
GetPrinter Printing in color (FAQ 1650D)
GetRasterizerCaps Checking if TrueType fonts are available (FAQ 2466D)
GetROP2 Tomes Graphical, pp. 146-147
GetStockObject Tomes Graphical, pp. 149-150
GetSystemMetrics Retrieves dimensions in pixels of specific Windows display element. Tomes Graphical, p. 48-49
How can I create an icon from an (sic) bitmap? (FAQ 2748D)
Extracting Icons (FAQ 1778D)
Kerstin Thaler's UseNet Post with example for SM_CYSMICON

Franšois Gaillard's UseNet Post with SM_CYSCREEN and SM_CXSCREEN examples and SystemParametersInfo example

Charles Hacker's UseNet Post with WM_NCPAINT example also showing GetSystemMetrics with parameters SM_CYMENU, SM_CXBORDER and SM_CYCAPTION.

Shannon Broskie's UseNet Post with DrawTitleBarImage function
(SM_CYCAPTION, SM_CXDLGFRAME, SM_CXEDGE, SM_CYSMICON, ....)

GetSystemPaletteEntries pp. 329-333, Delphi Programming Problem Solver, Neil Rubenking
A better way to print a form (TI 1412D)
GetTempPath Save and load metafiles in a BLOB field without using DBImage (FAQ 878D)
GetTextMetrics Determining a memo's number of lines showing (TI 1201D)
GetTickCount Useful for timing purposes. Returns milliseconds (Cardinal or LongWord) since Windows started. Overflows every 49 days (high order bit set after about 24 days -- thanks for the comment, Ray Lischner).
GetWindow How do I get a handle to the Windows 95 Desktop to access the Desktop icons?
Getting the Win95 DeskTop ListView Handle (FAQ 408D)

Eddie Shipman's UseNet Post about capturing top-most image

GetWindowDC Damon Chandler's UseNet Post about Drawing on the Desktop

Gate's UseNet Post about the right method to allocate and release the DC without causing GDI Leak

From the help file: "The GetWindowDC function retrieves the device context (DC) for the entire window, including title bar, menus, and scroll bars. A window device context permits painting anywhere in a window, because the origin of the device context is the upper-left corner of the window instead of the client area."

GetWindowLong Displaying a bitmap on the client area of an MDI parent form (FAQ 176D)
Removing a form's caption bar? (FAQ 908D)
GetWindowPlacement See Neil Rubenking's GetPosFmINI_Internal or SetPosToINI in the AllFuncs.pas unit in his ColorClue PC Magazine utility.
GlobalAlloc, GlobalFree Creating a bitmap from a pixel array (FAQ 1205D)
GlobalLock,
GlobalUnlock
Creating a bitmap from a pixel array (FAQ 1205D)
Printing in color (FAQ 1650D)
GradientFill Peter S÷derman's UseNet Post with example of using GradientFill
Neil Rubenking's UseNet Post about problem using GradientFill
HBITMAP Henrik PalmÚr's UseNet Post about HBITMAP to Image.Canvas
InflateRect How to Draw Marching Ants by Robert Vivrette. "Marching Ants" (sometimes called a marquee rectangle) is essentially an animated rubber-banding line.
http://www.undu.com/DN960901/00000008.htm
InvalidateRect Using InvalidateRect to repaint the entire form (FAQ 1235D)
How can I create an icon from an (sic) bitmap? (FAQ 2748D)
Storing icons in your application for use at runtime? (FAQ 2767D)

How to Draw Marching Ants by Robert Vivrette. "Marching Ants" (sometimes called a marquee rectangle) is essentially an animated rubber-banding line.
http://www.undu.com/DN960901/00000008.htm

Renate Schaaf's UseNet Post about "dirty rectangle" technique with images and postscript.

Invalidate, InvalidateRect, and Flicker:  If you invalidate a whole form, all TLabels will flicker when they're redrawn.  An alternative is to use InvalidateRect with the False parameter to stop this background erase.  Also, Validate/Invalidate can be used for some interesting effects.  efg's Invalidate project shows how Invalidate, InvalidateRect and ValidateRect work.

IsRectEmpty  
LineDDA Fancy Menus, etc.:  Custom Menus, Rotated Text, and Special Lines
www.delphizine.com/features/2000/12/di200012bs_f/di200012bs_f.asp 

How do I plot a line? (FAQ 2934D)

How to Draw Marching Ants by Robert Vivrette. "Marching Ants" (sometimes called a marquee rectangle) is essentially an animated rubber-banding line.
http://www.undu.com/DN960901/00000008.htm

LineTo How can I draw directly on the Windows Desktop? (FAQ 2818D)
LoadBitmap Keeping a glyph's transparent area transparent (FAQ 1385D)
Loading bitmaps and cursors from RES files (TI 1081D)
LoadIcon Storing icons in your application for use at runtime? (FAQ 2767D)
LoadImage Using an animated cursor (FAQ 580D)
LoadImage Alters Color Table with 256 Color Bitmaps (MS Q195831)
LoadLibrary Creating a resource only DLL (FAQ 1595D)
LoadResource Using JPEGs from resource files (FAQ 1882D)
Extracting a JPEG Resource from an EXE (TI 4532D)
LockResource Using JPEGs from resource files (FAQ 1882D)
Loading bitmaps and cursors from RES files (TI 1081D)
Extracting a JPEG Resource from an EXE (TI 4532D)
LockWindowUpdate Prevent Window update (FAQ 1349D) [Use to reduce flicker]
Keeping a glyph's transparent area transparent (FAQ 1385D)

Wayne Sheffield's UseNet Post about using LockWindowUpdate to avoid flicker

LPtoDP Converts points from logical coordinates to device coordinates.
LIMITATION: TPoint structures should specify values no greater than 27 bits. (This is why I still use Doubles in my work!)
MakeObjectInstance Displaying a bitmap on the client area of an MDI parent form (FAQ 176D)
MaskBlt (NT Only)  
Mouse_Event Using mouse_event() to simulate mouse events (FAQ 1241D)
MoveToEx How can I draw directly on the Windows Desktop? (FAQ 2818D)
PatBlt Non VCL Bitmap buffering (FAQ 2774D)
Painting a rainbow color spectrum onto a form (FAQ 1247D)
Fast way to clear a given canvas (FAQ 1187D)

If you paint in White or in Black:
  PatBlt(canvas.Handle,0,0, width, height, WHITENESS)
  PatBlt(canvas.Handle,0,0, width, height, BLACKNESS)

(from post to borland.public.delphi.graphics by J.M. Dozier, 19 Jan 99)

PaintRgn Manipulating Regions with Delphi by Don Monroe
www.undu.com/DN961001/00000016.htm

Chris Hill's UseNet Example

PlgBlt 
(NT/2000 only)
parallelogram block transfer -- can be used to rotate a bitmap but only in NT
See example in Delphi Informant, Jan. 99, pp. 68-71.

Damon Chander's UseNet Post with a PlgBlt function

PolyBezier David Ullrich's UseNet Example
Chris Hill's Usenet Example

Gordon Whittam's UseNet Post with DrawBullet procedure for drawing a bullet using PolyBezier API call.  I tested Gordon's routine with this :

procedure TForm1.Button1Click(Sender: TObject); 
begin 
  DrawBullet(Canvas, Point(Top,Left), Point(Height, Width DIV 2), 400) 
end;

Tomes Graphical, p. 168.

Note:  To avoid a confusion with the TCanvas.PolyBezier call (and a compilation error), use Windows.PolyBezier to invoke this API function.

PolyDraw Not supported in Win 95.  Wayne Sherman's UseNet Post with Win 95 alternative

See Microsoft's HowTo:  How to Get Windows NT PolyDraw functionality in Windows 95.  http://support.microsoft.com/support/kb/articles/Q135/0/59.asp 

Polygon How can I create a dynamic array of TPoints to draw a polygon? (FAQ919D)
PolyPolygon Creating a PolyPolygon using a point array (FAQ 2946D)
PtInRect PtInRegion pixel function (FAQ 2857D)
How can I tell if the mouse is over my form? (FAQ 2759D)

Microsoft's Q121960:  Alternative to PtInRegion for Hit Testing
http://support.microsoft.com/support/kb/articles/Q121/9/60.asp

PtInRegion Manipulating Regions with Delphi by Don Monroe
www.undu.com/DN961001/00000016.htm
RealizePalette Creating a bitmap from a pixel array (FAQ 1205D)
A better way to print a form (TI 1412D)

See Palettes Section of efg's Delphi Graphics Color Page

Rectangle Draw On Frame (FAQ 1079D)
RedrawWindow I once used this to work around a problem:

// Need both InvalidateRect and RedrawWindow to get
// background repainted without flicker
InvalidateRect(SELF.Handle, NIL {whole window},FALSE);

// Don't use Application.ProcessMessages for update, or MouseUp may
// trigger before MouseDown has completed. Use RedrawWindow
RedrawWindow(SELF.Handle, NIL, 0, RDW_UPDATENOW);
ReleaseCapture How can I easily move a Window control at runtime (FAQ 896D)
ReleaseDC How can I draw directly on the Windows Desktop? (FAQ 2818D)
Creating a bitmap from a pixel array (FAQ 1205D)
ResizePalette Increases or decreases the number of palette entries in the specified logical palette.
ScreenToClient  
ScrollDC, ScrollWindow  
ScrollWindowEx // Put a TImage on a form and then click this button
procedure TForm1.Button1Click(Sender: TObject);
  VAR R: TRect;
begin
  R:=Form1.ClientRect;
  ScrollWindowEx(Form1.Handle,
                 5 {pixels right},5 {pixels down},
                 @R,@R,0,nil,SW_INVALIDATE);
end;
SelectClipRgn efg's Printer Demo #2 Lab Report
SelectPalette pp. 329-333, Delphi Programming Problem Solver, Neil Rubenking
Creating a bitmap from a pixel array (FAQ 1205D)
A better way to print a form (TI 1412D)

See Palettes Section of efg's Delphi Graphics Color Page

SelectStockObject Draw On Frame (FAQ 1079D)
SendMessge See Windows Messages below
SetBkMode Drawing transparent text onto a TBitmap (FAQ 2079D)
Bitmaps and captions on TBitBtn (FAQ 1758D)
Making text background transparent (FAQ 627D)
SetConsoleTextAttribute Generating a Windows Console Application (FAQ 747D)
SetCursor Philippe Bruno's E-Mail about changing cursor for a tray application
SetCursorPos Simulating a mouse move in code (FAQ 2871D)

VAR ButtonOriginInScreenCoordinates: TPoint;
...
ButtonOriginInScreenCoordinates := 
     ClientToScreen( Point(BitBtnNo.Left, BitBtnNo.Top) );

Windows.SetCursorPos(
   ButtonOriginInScreenCoordinates.X + BitBtnNo.Width  DIV 2,
   ButtonOriginInScreenCoordinates.Y + BitBtnNo.Height Div 2);

SetDIBColorTable Chris Hill's UseNet Post about SetDIBColorTable
Robert Rossmair's UseNetPost about SetDIBColorTable
Dean Verhoeven's E-mail about using SetDIBColorTable to alter palette of pf8bit bitmap
SetDIBits Copies the bit values from the specified area in the DIB bit values pointed to by the Bits parameter directly into the DDB indicated by the Bitmap parameter.

Andrew Rybenkov's UseNet Post about using GetDIBits/SetDIBits as an alternative to Scanline

SetDIBitsToDevice Note from Joe Hecht (via private E-mail, 19 Jan 99):
"I never recommend SetDIBitsToDevice.  It seems straight forward enough, but at driver level the most difficult of the bitmap functions to implement correctly, and I have enough failures in the real world to discourage its use."
SetMapMode For an application to use true logical coordinates, the mapping mode must be changed.
How can I draw using LoEnglish Mapping Modes? (FAQ 2771D)

Dave Shapiro's UseNet Post explaining "Why is 'y' upside down?" (or how to make the y-axis increase from bottom-to-top instead of top-to-bottom)

Steve Schafer's UseNet Post about SetMapMode not affecting mouse position coordinates:  "The mouse position is always given in terms of screen coordinates. The only variation is that they may be either screen-relative or window-relative. In either case, the GDI mapping mode does not apply."

SetMenuItemBitmaps Small bitmaps in a TPopUpMenu (FAQ 1806D)
SetPixel RASTERCAPS:  Raster Operations (FAQ 2622D)
SetROP2 Sets the foreground mix mode for the specified device context.
SetScrollPosition Trap scrolling messages for the Scrollbars of a TScrollBox (FAQ 942D)
SetStretchBltMode Sets the bitmap stretching mode. Tomes Graphical, pp. 348-352

Windows API documentation says STRETCH_DELETESCANS is "typically used to preserve color in color bitmaps." Image fidelity is not good without this call when using EPIX pxd_StretchDIBits."
     SetStretchBltMode(Bitmap.Canvas.Handle, STRETCH_DELETESCANS);

When a bitmap is compressed as a result of a call to StretchBlt, the colors of some pixels in the original bitmap are lost.  To get the best results when using StretchBlt, set the bitmap stretching mode to ColorOnColor before calling StretchBlt, e.g.,
          SetStretechBltMode(hDC, ColorOnColor).

See efg's Newsgroup Post about using SetStretchBltMode before CopyRect (but not before StretchDraw)

See Microsoft's Bug:  SetStretchBltMode Ignored

SetSysColors Michael Winter's UseNet Post with SetSysColors example
SetSystemCursor Philippe Bruno's E-Mail about changing cursor for a tray application
SetSystemPaletteUse Non-Delphi:
http://msdn.microsoft.com/library/psdk/gdi/colors_0sv9.htm

Also see  Palettes Section of efg's Delphi Graphics Color Page

SetViewPortEx Sets the value for how much is added to a coordinate as it reaches the device coordinate system.
How can I draw using LoEnglish Mapping Modes? (FAQ 2771D)
SetViewportExtEx Sets a factor that is multiplied by the coordinate as it arrives at the device coordinate system.
SetWindowExtEx Sets a factor that is divided out of the coordinate as it leaves the logical coordinate system.
SetWindowLong Displaying a bitmap on the client area of an MDI parent form (FAQ 176D)
Removing a forms caption bar? (FAQ 908D)
SetWindowOrgEx Sets the value for how much is subtracted from a coordinate as it leaves the logical coordinate system.
SetWindowRgn

TTrianglePanel
www.silicmdr.com/downloads/TrianglePanel.zip
TRegionPanel
www.silicmdr.com/downloads/RegionPanel.zip

ShowCursor To turn cursors on or off, use
  ShowCursor(FALSE);
or
  ShowCursor(TRUE);
ShowWindow Hiding your application from the Windows Taskbar (FAQ 574D)
StretchBlt Draws and scales pixels from one device context to another. Tomes Graphical, pp. 275-276
Blitting Between DCs for Different Devices Is Unsupported (MS Q195830)

Draw and StretchDraw methods use the StretchBlt API call.   See Item #1, "How can I print a Bitmap?" or the Printer Demo #1 Lab Report.

StretchBlt and Palettes

Also see SetStretchBltMode above.

Ignacio Alvarez's UseNet Post with modified TransparentStretchBlt function

Shannon Broskie's UseNet Post with DrawTitleBarImage function (shows TransparentStretchBlt)

StretchDIBits Draws and scales a device-independent bitmap onto a device context. Tomes Graphical, pp. 352-356.
pp. 437, Secrets of Delphi 2, Ray Lischner
Getting printer capabilities (FAQ 1475D)
A better way to print a form (TI 1412D)
Blitting Between DCs for Different Devices Is Unsupported (MS Q195830)
efg's Printer Demo #1

efg's Lead Tools-to-Delphi conversions show how to start with a hDIB and end up with a TBitmap.  In particular, look at Method 1. hDIB to TBitmap resulting in bmDDB using StretchDIBits

StrokeAndFillPath Steve Schafer's UseNet Post with BeginPath/CloseFigure/EndPath/StrokeAndFillPath example
Toni Sander's UseNet Post with an alternative to create Outline/Shadow Text
StrokePath How do I use Paths and Geometric Pens? (FAQ 2724D)


See StrokePath example based on UseNet Posting by Gordon Whittam

SubtractRect  
SystemParametersInfo Getting the size of the desktop (FAQ 2567D)
Creating a wallpaper using Delphi (TI 1351D)
Preventing windows task switching (FAQ 509D)

See SystemParametersInfo.Txt for Windows 95 trick to block CTRL+ALT+DEL or ALT+TAB

Toni Sanders' UseNet Post about how to turn off windows font anti-aliasing
Dick Claessens' UseNet Post to switch on the resizing rectangle
Eddie Shipman's UseNet Post about getting the title bar's font name and size

Franšois Gaillard's UseNet Post with SM_CYSCREEN and SM_CXSCREEN examples and SystemParametersInfo example

Non-Delphi:

How to Use SystemParametersInfo API for Control Panel Settings
- SPI_GETWORKAREA = height of windows taskbar
http://support.microsoft.com/support/kb/articles/Q97/1/42.ASP

How To: Determine the Size of the Desktop Area
http://support.microsoft.com/support/kb/articles/Q154/8/23.asp

TBitmap Using the Win API GetObject to get a bitmap (FAQ 2518D)
[Note: See comments under VCL TBitmap.]
TBitmapInfo, TBitmapInfoHeader Creating a bitmap from a pixel array (FAQ 1205D)
TCursorInfo efg's ShowCursor example of displaying cursor at any position on screen 
(based on UseNet Post by Michael Winter)
TextOut Changing the background color of Text (FAQ 990D)
TextOutW Steve Schafer's UseNet Post about how to view Unicode on a form
TLogBrush How do I use Paths and Geometric Pens? (FAQ 2724D)

Chris Hill's UseNet Post with example

TLogFont Creating a rotated font (FAQ 615D)
TLogPalette Creating a bitmap from a pixel array (FAQ 1205D)
A better way to print a form (TI 1412D)
TNonClientMetrics Peter Below's UseNet Post about how to get the Windows title font (and information about TNonClientMetrics)
TPaletteEntry Creating a bitmap from a pixel array (FAQ 1205D)
A better way to print a form (TI 1412D)
TPath, TRegion More Regions!
www.undu.com/Articles/990128c.html
TransparentStretchBlt See StretchBlt
TRGBQuad Creating a bitmap from a pixel array (FAQ 1205D)
TRGBTriple efg's Scanline examples using pf24bit bitmaps
UnionRect  
ValidateRect How to Draw Marching Ants by Robert Vivrette. "Marching Ants" (sometimes called a marquee rectangle) is essentially an animated rubber-banding line.
http://www.undu.com/DN960901/00000008.htm

Invalidate, InvalidateRect, and Flicker:  If you invalidate a whole form, all TLabels will flicker when they're redrawn.  An alternative is to use InvalidateRect with the False parameter to stop this background erase.  Also, Validate/Invalidate can be used for some interesting effects.  efg's Invalidate project shows how Invalidate, InvalidateRect and ValidateRect work.

WarpBlt
(Win 2000)
Non-Delphi:
HOWTO: Display a Bitmap into a Rotated or Non-rectangular Area
http://support.microsoft.com/support/kb/articles/Q186/5/89.ASP

Windows Messages
"Understanding Windows Messaging"
Chapter 5, Delphi 5 Developer's Guide
by Teixeria and Pacheco

Chapter 7, Messaging
Delphi Component Design by Danny Thorpe

General Info Chapter 37, Handling messages, Borland's Delphi 5 Developer's Guide.

Messages, Appendix A, Tomes Graphical, pp. 725-848

Trapping Windows Messages in Delphi (TI 1487D)

Windows Messages
www.delphi-jedi.org/Jedi:VOYFORMS3

CM_MouseEnter
CM_MouseLeave
www.openinfo.se/martin/texterdelphi/mouseex.htm

See ..\Source\VCL\Buttons.PAS, especially the MouseInControl property, for an example of how these messages are used in the VCL. Also see TControl.CMMouseEnter in Controls.PAS, and TApplication.DoMouseIdle in Forms.PAS.

Delphi generates a CM_MouseLeave by monitoring when a different window is getting WM_MouseMove.

In Chapter 13 of  Mastering Delphi 5 (pp. 608-609), Marco Cant¨ shows how to create an "active" TMdActiveButton component that captures CM_MouseEnter and CM_MouseExit events.

Mike Shkolnik's UseNet Post on MouseEnter and MouseExit events

How to detect mouse leaving a control? (CM_MOUSEENTER, CM_MOUSELEAVE)
Rick Rogers UseNet Post

ColorRange.gif (1115 bytes) efg's ColorRange Lab Report  with  TSensitiveImage experiment.

TShape descendant that has a star shape and has OnMouseEnter/Leave handlers.  Eddie Shipman's UseNet Post

EM_SETTABSTOPS Adjusting the tab location in a TMemo component (FAQ 960D)
LB_SETHORIZONTALEXTENT Enabling a horizontal scroll bar for a list box (TI 531D)
LVM_ALIGN How do I get a handle to the Windows 95 Desktop to access the Desktop icons?
Getting the Win95 DeskTop ListView Handle (FAQ 408D)
WM_ACTIVATE Tomes Graphical, p. 725
WM_CHAR Tomes Graphical, p. 729
WM_COMMAND Tomes Graphical, p. 732
WM_COPY, WM_CUT Tomes Graphical, p. 735, 741
WM_DISPLAYCHANGE Tomes Graphical, p. 747

Windows Messages
www.delphi-jedi.org/Jedi:VOYFORMS3

WM_DROPFILES Tomes Graphical, p. 750

Drag and Drop with Files (FAQ 529D)

WM_ENTERSIZEMOVE
WM_EXITSIZEMOVE
Peter Below's UseNet Post showing the pre-Win 95 method of resizing
WM_ERASEBKGND Tomes Graphical, p754

Message sent to a window when it has been invalidated. Tomes Graphical, pp. 754. Can be the cause of flicker -- intercept message to reduce flicker in some cases.

private
...
procedure WmEraseBkgnd(VAR Msg: TWmEraseBkgnd); 
  message Wm_EraseBkgnd;
...
// Tell Windows not to erase the background.
// This reduces the amount of flicker when repainting.
procedure TFormSlideShow.WmEraseBkgnd(var Msg: TWmEraseBkgnd);
begin
  Msg.Result := 1;
end;


pp. 329-333, Delphi Programming Problem Solver, Neil Rubenking
Displaying a bitmap on the client area of an MDI parent form (FAQ 176D)

See \Program Files\Borland\Delphi n\HELP\Examples\Bitmap\BMPFormU.PAS
This example uses 
  m.Result := LRESULT(FALSE),
where LRESULT is a LongInt type.  [I need to resolve the conflict between the "1" in the example above and the FALSE returned in Borland's example.]

WM_GETMINMAXINFO Tomes Graphical, p. 757

- example in efg's MazeMaker Lab Report
- Dets' UseNet Post about form minimum size

WM_HOTKEY Disable PrintScreen with Ctrl + Alt combinations (WMHotKey, RegisterHotKey)
Morten Jacobsen's E-Mail with example
WM_HSCROLL Alex Denissov's UseNet Post with WM_HSCROLL and WM_VSCROLL examples

Tomes Graphical, p. 761

WM_LBUTTONUP Tomes Graphical, p. 770

How can I easily move a Window control at runtime (FAQ 896D)

How to Simulate Visual Basic's SendKeys in Delphi
(wm_lbuttondown and wm_lbuttonup)
www.drdelphi.com/delphi/right/tips/sendkeys.htm

WM_MOUSEMOVE Tomes Graphical, p. 789
WM_NCHITTEST

Message sent to a window when the mouse cursor moves over the window or a mouse button is clicked. Tomes Graphical, pp. 796-797

Moving a form by clicking in its client area (FAQ 2099D)

"Unusual Windows Styles" of 
- Eliminating a form's caption but leaving the border
- Getting the "tiny title bar" effect
in Chapter 1, Delphi Programming Problem Solver by Neil Rubenking, pp. 9-16.

WM_NCMOUSEMOVE Tomes Graphical, p. 802

Trapping non client areas (FAQ 1535D)
Trapping messages in non client area of a form (FAQ 2944D)

WM_NCPAINT Charles Hacker's UseNet Post with WM_NCPAINT example

Tomes Graphical, p. 803

Used to paint the non-client area such as the caption bar and border.

Draw on Frame (FAQ1079D)
Paulo Almeida's UseNet Post about how to change color of caption

Chapter 1, Delphi Programming Problem Solver by Neil Rubenking (p. 23-32)
- Taking over drawing a form's caption
- Putting a button on a form's title bar
- Taking over drawing a form's frame

WM_PAINT Used to paint the client area -- the part inside the window.
Tomes Graphical, pp. 809-810
WM_PASTE Tomes Graphical, p. 814
WM_PALETTECHANGED This message is sent to all top-level and overlapped windows when the currently focused window changes the system palette by realizing a logical palette. Tomes Graphical, pp. 811-812

GetPalette and PaletteChanged, pp. 211-212.
Delphi Component Design by Danny Thorpe

Eddie Shipman's UseNet Post about making a rainbow background on a form

Processing WM_PALETTECHANGED and WM_QUERYNEWPALETTE
Microsoft's Knowledge Base:  http://support.microsoft.com/support/kb/articles/Q77/7/02.ASP

efg's Palette Lab Report

WM_QUERYNEWPALETTE This message is received when a window is receiving keyboard focus indicating it should realize its logical palette. Tomes Graphical, pp. 816-817

see WM_PALETTECHANGED above

WM_SETCURSOR What's This?  Implementing a "What's This?" Help Toolbar Button
www.delphizine.com/features/1998/05/di199805dh_f/di199805dh_f.asp 
WM_SYSCOLORCHANGE http://msdn.microsoft.com/library/psdk/gdi/colors_0hph.htm

INFO: Changing Window Colors with Control Panel
http://support.microsoft.com/support/kb/articles/Q11/2/46.asp

WM_SYSCOMMAND Tomes Graphical, p. 836

How can I easily move a Window control at runtime (FAQ 896D)

Windows Messages
Unit 2.  Simple demo on how to prevent the Windows screen saver from starting
www.delphi-jedi.org/Jedi:VOYFORMS3

WM_UNDO Tomes Graphical, p. 842
WM_USER How can I capture an image from a video source (FAQ 1037D)
WM_VSCROLL Alex Denissov's UseNet Post with WM_HSCROLL and WM_VSCROLL examples

Tomes Graphical, p. 844

WM_WINDOWPOSCHANGED Tomes Graphical, p. 846

Richard's UseNet Post showing WM_WINDOWPOSCHANGED example to get background images drawn on my MDI application

WM_WINDOWPOSCHANGING Tomes Graphical, p. 847

Windows API Tips and Tricks
See "Messages" in Delphi in a Nutshell, pp. 61-62 for an overview

Callbacks pp. 483-495, Delphi Programming Problem Solver, Neil Rubenking
Color Gradient Animation (256-color mode only) Tomes Graphical, pp. 409-411
Colors of the System Palette Delphi 2 Multimedia, Table 6.2, p. 290
Creating a Device-Dependent Bitmap (DDB) from a Device-Independent Bitmap (DIB)

Setting the Image of a DDB from a DIB
Tomes Graphical, pp. 298-300


Tomes Graphical, pp. 343-344
Creating a Device-Independent Bitmap (DIB) from a Device-Dependent Bitmap (DDB) Tomes Graphical, pp. 319-320
Creating a Round Window for an Analog Clock Application Tomes Graphical, pp. 266-268
Device Context Display Device Context Defaults:  list of attributes and values
(The Canvas.Handle is a device context).
http://msdn.microsoft.com/library/psdk/gdi/pantdraw_3xtf.htm 
Display Mode How many colors will my display mode support? (FAQ 741D)

Enumerating All Available Display Modes for Current Display: Tomes Graphical, pp. 33-34

Changing the Display Mode: Tomes Graphical, p. 23.
Displaying a Bitmap with Transparent Pixels Tomes Graphical, pp. 278
Loading a 256-color Bitmap from a Resource Tomes Graphical, pp. 584-585
Manipulating a DIB Using GDI Drawing Functions Tomes Graphical, pp. 279-280
Mapping Logical Coordinates into Device Coordinates xViewport = (xWindow - xWindowOrg)*(xViewportExt/xWindowExt) + xViewPortOrg
yViewport = (yWindow - yWindowOrg)*(yViewportExt/yWindowExt) + yViewportOrg


Tomes Graphical, pp. 14, 26-27, 57, 60-61, 74-78. See Limitation listed above with the LPtoDP API call.
Mapping Modes MM_TEXT, 1:1, no translation

MM_ANISOTROPIC, allows complete flexibility in setting offsets and scaling. Can set different horizontal and vertical factors to stretch (skew) the image.

MM_ISOTROPIC, horizontal and vertical scaling is the same

Tomes Graphical, p. 15, 74
Masks and Bitmaps How can I create an icon from an (sic) bitmap? (FAQ 2748D)
Dynamically drawing a transparent image (FAQ 1794D)
Performing Special Animation Effects by Moving the Clipping Region Tomes Graphical, pp. 242-243
Programmatically Justifying Text Tomes Graphical, pp. 539-541
Raster Operations Tomes Graphical, pp. 277, Appendix B, Tertiary Raster Operation Codes, pp. 849-856.

"The Standard Windows Raster Operations," Delphi 2 Multimedia, pp. 338-342, 361-373.

Tim Roberts' UseNet Post about "What are ROPs?"

"Rubber-band" drawing of a rectangle pp. 310-312, Delphi Programming Problem Solver, Neil Rubenking
Scaling a Bitmap and Retaining the Original Aspect Ratio Tomes Graphical, pp. 275-276
Text Output Functions Tomes Graphical, Chapter 8, pp. 459-559
Using a Multiple Polygon Region as a hot spot. Tomes Graphical, pp. 214-216

Other Windows API Resources

Flicker FAQ www.bcbdev.com/faqs/faq34.htm 
Also see efg's Flicker notes.
Bitmaps and Palettes Secrets of Delphi 2, Ray Lischner, pp. 432-438
Delphi API Library (Project Jedi) www.delphi-jedi.org
Graphics Objects Secrets of Delphi 2, Ray Lischner, pp. 421-428,
Messages and Painting Text Delphi 2 Unleashed, Charles Calvert, pp. 337-363
Raw API Programming Raw API Programming:  When Size and Speed Are Paramount
www.delphizine.com/features/2000/09/di200009aw_f/di200009aw_f.asp 
Windows API Functions
Windows Messages and Resources
Chapters 14 and 15, pp. 483-550, Delphi Programming Problem Solver, Neil Rubenking

Updated 14 Jun 2009
Since 1 Nov 1998