枣庄鲁南数据中心招聘:VB6-程序运行后不停的消耗内存问题

来源:百度文库 编辑:杭州交通信息网 时间:2024/04/20 21:09:25
我设计一个程序,功能是读出并显示鼠标所指向的点的颜色
一个时间控件,每200毫秒读一次
一个标签控件,显示色彩值
窗口背影显示色彩
程序如下:

'调用的APT函数
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) 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 Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function ScreenToClient Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long

Private Type POINTAPI '定义点类型
x As Long
y As Long
End Type

'-------------------------------------
Private Sub Timer1_Timer()
On Error Resume Next
Dim p As POINTAPI
GetCursorPos p
Dim h As Long, dc As Long
h = WindowFromPoint(p.x, p.y)
ScreenToClient h, p
dc = GetDC(h)
Me.BackColor = GetPixel(dc, p.x, p.y) '在背影上显示色彩

n = GetPixel(dc, p.x, p.y) '计算出色彩的RGB值并显示
n3 = Int(n / 256 / 256)
n = n Mod 256
n2 = Int(n / 256)
n1 = n Mod 256
Me.Label1.Caption = n1 & n2 & n3

End Sub

程序运行后,我发现内存在不断的减少(windows“系统信息”里的系统资源一项),最后再运行别的程序提示内存不足
请问是怎么回事
====================================
请问怎么释放,语句是什么,多谢指点

你用过GetDC之后,请使用ReleaseDC这个API把它释放掉,否则的话,每200ms你的系统资源就被这个程序吃掉一点,吃掉一点。。。最终。。你的系统资源不足了

使用了“设备环境”以后需要释放。