Declare Function GetPixel Lib "gdi32.dll" (ByVal hdc As Long, ByVal nXPos As Long, ByVal nYPos As Long) As Long
GetPixel determines the color of a specific pixel on a device. The function finds the RGB value of the pixel which is checked.
If an error occured, the function returns &HFFFF. If successful, the function returns the RGB value of the pixel which was checked.
None.
' Fill all of window Form1 with the color which is located at
' coordinate (75,100). Fill the window by filling its rectangle using a
' brush derived from the color of the pixel.
Dim rgbVal As Long ' RGB color of the pixel
Dim hBrush As Long ' handle to the brush we'll create
Dim winrect As RECT ' rectangle of Form1
Dim retval As Long ' return value
' Determine the color of the pixel on Form1 at (75,100).
rgbVal = GetPixel(Form1.hDC, 75, 100)
' Get the dimensions of the rectangle of window Form1.
retval = GetWindowRect(Form1.hWnd, winrect)
' Create a solid brush of that color.
hBrush = CreateSolidBrush(rgbVal)
' Use that brush to fill in all of Form1 (its entire rectangle).
retval = FillRect(Form1.hDC, winrect, hBrush)
' Delete the brush we created to save resources.
retval = DeleteObject(hBrush)
Last Modified: September 2, 1999
This page is copyright © 1999 Paul Kuliniewicz. Copyright Information