在 Visual Basic 中监视特定颜色的屏幕区域 [英] Monitor an area of the screen for a certain color in Visual Basic
问题描述
我正在设计一个播放器应用程序来配合我们的电话系统.当我们的呼叫者接听电话时,它会记录每个电话.他们可以转到列表模块,找到录音并双击打开我的播放器.我遇到的问题是,如果呼叫者接到另一个电话,我的播放器不知道并且会继续玩.我正在寻找一种方法来监控特定区域的屏幕,当它看到黄色或红色而不是蓝色时,它会暂停我的播放器.
I'm designing a player application to accompany our phone system. As our calltakers take calls, it makes recordings of each call. They can go to a list module, find a recording and double click, which opens my player. The issue i have is that if the calltaker gets another call, my player doesn't know it and will continue playing. I'm looking for a way to monitor the screen in a particular area and when it sees yellow or red instead of blue, it will pause my player.
电话系统没有任何可以连接的 API,所以我必须以另一种方式尝试.
The phone system does not have any API's that I can hook onto, so I have to try it another way.
屏幕分辨率永远不会改变,他们接听电话的队列按钮将始终是静态的.当他们接到电话时,一小块区域的背景颜色会从蓝色变为黄色或红色,以表示有来电.
The screen resolution never changes and the queue buttons where they receive calls will always be static. When they get a call, a small area changes from the background color blue to yellow or red to indicate a call.
有什么建议吗?
**编辑最终代码基于以下答案和问题 在 Visual Basic 中使用 GetPixel/GetDC 的内存泄漏
**EDIT Final Code based on answers below and question Memory Leak using GetPixel/GetDC in Visual Basic
Private Function CheckforCall()
Dim hDC As IntPtr = GetDC(0)
Try
Dim queue1 As Integer = GetPixel(hDC, 40, 573)
Dim queue2 As Integer = GetPixel(hDC, 140, 573)
Dim queue3 As Integer = GetPixel(hDC, 240, 573)
Dim queue4 As Integer = GetPixel(hDC, 340, 573)
Dim queue5 As Integer = GetPixel(hDC, 440, 573)
If queue1 <> 9990727 Then
lblRinger.Text = "In Calls GOT CALL"
Return True
ElseIf queue2 <> 9990727 Then
lblRinger.Text = "Admin GOT CALL"
Return True
ElseIf queue3 <> 9990727 Then
lblRinger.Text = "Overflow GOT CALL"
Return True
ElseIf queue4 <> 9990727 Then
lblRinger.Text = "Bi-Lingual GOT CALL"
Return True
ElseIf queue5 <> 9990727 Then
lblRinger.Text = "Intercom GOT CALL"
Return True
Else
lblRinger.Text = "No Call"
Return False
End If
Catch ex As Exception
Return False
Finally
ReleaseDC(0, hDC)
End Try
End Function
推荐答案
我很确定这就是您想要的:
I'm pretty sure that this is what you want:
http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.getpixel.aspx
祝你好运!
我忘了您必须提供设备上下文 (hDC
) 才能让 GetPixel
工作.有时很难处理 GetDC
所需的窗口句柄 (hWnd
),因此您可以简单地使用 GetDC(0) 获取整个屏幕的设备上下文代码>.
I forgot you have to give a device context (hDC
) to have GetPixel
work. It's sometimes hard to deal with the window handles (hWnd
) that GetDC
requires, so you can simply get the device context for the entire screen with GetDC(0)
.
从 http://www.vbforums.com/showthread.php 无耻地窃取了代码?t=491397 :
Declare Auto Function FindWindow Lib "user32" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As IntPtr
Declare Function GetDC Lib "user32" (ByVal hWnd As IntPtr) As IntPtr
Declare Function ReleaseDC Lib "user32" (ByVal hwnd As IntPtr, ByVal hdc As IntPtr) As IntPtr
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As IntPtr, ByVal X As Int32, ByVal Y As Int32) As Int32
Public Function GetColorAt(ByVal X As Int32, ByVal Y As Int32) As Int32
Dim hWnd As IntPtr
Dim hDC As IntPtr
hWnd = FindWindow(vbNullString, "RagII")
hDC = GetDC(hWnd)
Dim lColor As Int32 = GetPixel(hDC, X, Y)
ReleaseDC(hWnd, hDC)
Return lColor
End Function
这篇关于在 Visual Basic 中监视特定颜色的屏幕区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!