Так навскидку. Небольшая прога получает цвет пикселя под курсором мыши с экрана и выводит область экрана возле курсора мыши в увеличенном виде (по работе надо было). Смотрится всё по таймеру интервал 100, на форме PictureBox(изображение под курсором) TextBox(HTML цвет) Panel(сам цвет), не одного глюка. Ни и всё .Net.
Option Explicit On
Option Strict On
Imports System.Windows.Forms
Imports System.Math
Public Class Main
#Region " Private Fields"
Private Const SRCCOPY As Int32 = &HCC0020
Private m_grDesktop As Graphics
Private m_bmDesktop As Bitmap
#End Region
#Region "API"
Private Declare Function GetDesktopWindow Lib "user32" () As Int32
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Int32) As Int32
Private Declare Function StretchBlt Lib "gdi32" (ByVal hdc As IntPtr, ByVal x As Int32, ByVal y As Int32, ByVal nWidth As Int32, ByVal nHeight As Int32, ByVal hSrcDC As Int32, ByVal xSrc As Int32, ByVal ySrc As Int32, ByVal nSrcWidth As Int32, ByVal nSrcHeight As Int32, ByVal dwRop As Int32) As Int32
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Int32, ByVal hdc As Int32) As Int32
Private Structure RECT
Dim Left As Int32
Dim Top As Int32
Dim Right As Int32
Dim Bottom As Int32
End Structure
Private Function DesktopImage(ByVal x As Int32, ByVal y As Int32) As Bitmap
Dim desktop_win As Int32 = GetDesktopWindow()
Dim desktop_dc As Int32 = GetDC(desktop_win)
Dim bm As New Bitmap(40, 20)
Dim bm_gr As Graphics = Graphics.FromImage(bm)
Dim bm_hdc As IntPtr = bm_gr.GetHdc
StretchBlt(bm_hdc, 0, 0, 40, 20, desktop_dc, x - 20, y - 10, 40, 20, SRCCOPY)
bm_gr.ReleaseHdc(bm_hdc)
ReleaseDC(desktop_win, desktop_dc)
Return bm
End Function
#End Region
#Region " Private Methods "
Private Sub m_oTimer_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles m_oTimer.Tick
Dim intX As Integer = Windows.Forms.Cursor.Position.X
Dim intY As Integer = Windows.Forms.Cursor.Position.Y
m_bmDesktop = DesktopImage(intX, intY)
Dim oGraphics As Graphics = Graphics.FromImage(m_bmDesktop)
Dim oColor As Color = m_bmDesktop.GetPixel(20, 10)
m_oTextBox.Text = oColor.Name
m_oPanel.BackColor = oColor
Me.m_oPictureBox.Image = m_bmDesktop
End Sub
Private Sub m_oPictureBox_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles m_oPictureBox.Paint
Dim oGraphics As Graphics = e.Graphics
oGraphics.DrawLine(Pens.Red, 195, 100, 205, 100)
oGraphics.DrawLine(Pens.Red, 200, 95, 200, 105)
End Sub
#End Region
End Class
Ответить
|