Windows API Guide: RestartDialog Function


Declare Function SetPixel Lib "gdi32.dll" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal crColor As Long) As Long

Platforms

  • Windows 95: Supported.
  • Windows 98: Supported.
  • Windows NT: Requires Windows NT 3.1 or later.
  • Windows 2000: Supported.
  • Windows CE: Requires Windows CE 1.0 or later.

Description & Usage

SetPixel sets the color of a single pixel on a device. Because of color matching on the device, sometimes the color actually used on the device may differ from the color specified by the function. The function will fail if the pixel specified is not visible or out of range when the function is called.

Return Value

If an error occured, the function returns -1 (call GetLastError to get the error code). If successful, the function returns the RGB value of the color which was actually used to color the pixel on the device.

Visual Basic-Specific Issues

None.

Parameters

hdc
A handle to a device context to the device to color a pixel of.
X
The x-coordinate of the pixel to color.
Y
The y-coordinate of the pixel to color.
crColor
The RGB value of the color to set the pixel to.

Example

' This code is licensed according to the terms and conditions listed here. ' Randomly color all the pixels in window Form1.  This example ' gets the rectangle of Form1 and iterates through all the points ' (pixels) inside of it. Dim winrect As RECT  ' rectangle of window Form1 Dim rgbval As Long  ' RGB value of the randomly selected color Dim x As Long, y As Long  ' counters for x and y coordinates Dim retval As Long  ' return value ' Get the rectangle of window Form1. retval = GetWindowRect(Form1.hWnd, winrect) ' Loop through each pixel within Form1. For y = 0 To winrect.bottom - winrect.top   For x = 0 To winrect.right - winrect.left     ' Select a random color by choosing a value between 0 and 255     ' inclusive for each component of the color.     rgbval = RGB(Int(256 * Rnd), Int(256 * Rnd), Int(256 * Rnd))     ' Set the pixel to the color above.     retval = SetPixel(Form1.hDC, x, y, rgbval)   Next x Next y

See Also

GetPixel, SetPixelV

Category

Bitmaps

Go back to the alphabetical Function listing.
Go back to the Reference section index.


Last Modified: September 3, 1999
This page is copyright © 1999 Paul Kuliniewicz. Copyright Information Revised October 29, 2000
Go back to the Windows API Guide home page.
E-mail: vbapi@vbapi.com Send Encrypted E-Mail
This page is at http://www.vbapi.com/ref/s/setpixel.html



Windows API Guide
Windows API Guide - Reference - Volume 1: Version 3.0 For the MS-DOS and PC-DOS Operating Systems
ISBN: B001V0KQIY
EAN: N/A
Year: 1998
Pages: 610

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net