Declare Function SetPixel Lib "gdi32.dll" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal crColor As Long) As Long
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.
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.
None.
' 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
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