为什么这段程序运行1次没问题,运行2次可以,运行3次就花屏呢?哪里出了问题?
Option Explicit
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 Declare Function SetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long) As LongPrivate Sub Command2_Click()
Dim CFF As ColorConstantsDim i As Integer
Dim j As IntegerDim x As Integer
Dim y As Integer
x = Val(Text1.Text)
y = Val(Text2.Text)
For i = 1 To 100
    For j = 1 To 50
        CFF = GetPixel(GetDC(0), i, j)
        Call SetPixel(Me.hdc, i, j, CFF)
        DoEvents
    Next
Next
End Sub

解决方案 »

  1.   

    有人帮我再试试吗?我的还是不能运行
    环境win2000 server sp3
      

  2.   

    我运行五次没有问题,不过是Win2000P sp3
      

  3.   

    我是点了3次获取屏幕信息按钮,第一次完全能取来,第二次就有最后一点取来是黑色,而第三次窗口就花掉了?
    我不会释放这个DC,用set =nothing or =null or =0 or kill都不行?
      

  4.   

    Option Explicit
    Private Declare Function GetDesktopWindow Lib "user32" () As Long  '+++++++++++
    Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long  '+++++++
    Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc 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 Declare Function SetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long) As LongPrivate Sub Command1_Click()
    Dim CFF As ColorConstantsDim i As Integer
    Dim j As IntegerDim lDesktopDC As Long  '+++++++++++lDesktopDC = GetDC(0)   '+++++++++++For i = 1 To 100
        For j = 1 To 50
            CFF = GetPixel(lDesktopDC, i, j)  '+++++++++++
            SetPixel Me.hdc, i, j, CFF
            DoEvents
        Next
    NextReleaseDC GetDesktopWindow(), lDesktopDC   '++++++++++++End Sub