我在编写一个取屏幕颜色的程序 每次运行几次后 就会发现当你运行别的东西的时候系统弹出 "没有足够的内存来运行...." 小弟用的是98+VB6 可以确定不是系统和VB6的问题
程序中用了以下几个API
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Const HWND_TOPMOST = -1
Private Const SWP_SHOWWINDOW = &H40
Dim wh As POINTAPI
不知道是不是程序设计出了什么问题??????

解决方案 »

  1.   

    算了,给你源码吧
    dcDesktop = GetDC(0)
    lresult = GetPixel(dcDeskTop,x,y)
    ReleaseDC dcDesktop
      

  2.   

    Option Explicit
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
    Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
    Private Type POINTAPI
    x As Long
    y As Long
    End Type
    Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
    Private Const HWND_TOPMOST = -1
    Private Const SWP_SHOWWINDOW = &H40
    Dim wh As POINTAPI
    Dim a, b, c, d As Integer
    Dim s As Integer
    Dim y1, y2, y3 As StringPrivate Sub Form_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
    If s = 3 Then
    Label2(0).Caption = y1
    Label2(1).Caption = y2
    Label2(2).Caption = y3
    s = 0
    End If
    s = s + 1
    Select Case s
    Case 1
    Label2(0).Visible = True
    Label2(0).Caption = Label2(0).Caption & "#" & Hex(a)
    Picture2(0).BackColor = RGB(b, c, d)
    Case 2
    Label2(1).Visible = True
    Label2(1).Caption = Label2(1).Caption & "#" & Hex(a)
    Picture2(1).BackColor = RGB(b, c, d)
    Case 3
    Label2(2).Visible = True
    Label2(2).Caption = Label2(2).Caption & "#" & Hex(a)
    Picture2(2).BackColor = RGB(b, c, d)
    End Select
    End If
    End SubPrivate Sub Form_Load()
    Dim w As Long
    Dim h As Long
    Dim c As Long
    w = form1.Width
    h = form1.Height
    c = SetWindowPos(Me.hwnd, HWND_TOPMOST, Me.CurrentX, Me.CurrentY, w / 15, h / 15, SWP_SHOWWINDOW)
    y1 = "你第一次选定的颜色为:"
    y2 = "你第二次选定的颜色为:"
    y3 = "你第三次选定的颜色为:"
    End SubPrivate Sub Timer1_Timer()
    GetCursorPos wh
    a = GetPixel(GetDC(0), wh.x, wh.y)
    b = a And &HFF '分离出红色
    c = (a And 65280) \ 256 '分离出绿色
    d = (a And &HFF0000) \ 65536 '分离出蓝色
    Label1.Caption = "点的RGB:(" & b & "," & c & "," & d & ")"
    Label3.Caption = "16进制色:0x" & Hex(a)
    Label4.Caption = "网页颜色:#" & Hex(a)
    Picture1.BackColor = RGB(b, c, d)
    End Sub
    谢谢大家帮忙看看