我正在设计一个伴随我们的电话系统的播放器应用程序。当我们的呼叫者接听电话时,它会记录每个电话。他们可以进入列表模块,找到录音并双击,这将打开我的播放器。我遇到的问题是,如果说话者接到另一个电话,我的播放器就不知道它并继续播放。我正在寻找一种方法来监控特定区域的屏幕,当它看到黄色或红色而不是蓝色时,它会暂停我的播放器。
手机系统没有我可以挂钩的任何API,所以我必须以另一种方式尝试。
屏幕分辨率永远不会改变,并且他们接收呼叫的队列按钮将始终是静态的。当他们接到电话时,一小块区域会从背景颜色变为蓝色变为黄色或红色以表示呼叫。
有什么建议吗?
**编辑 最终代码基于以下答案和问题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
答案 0 :(得分:0)
我很确定这就是你想要的:
http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.getpixel.aspx
祝你好运!编辑:
我忘了您必须提供设备上下文(hDC
)才能使GetPixel
正常工作。有时很难处理hWnd
所需的窗口句柄(GetDC
),因此您只需使用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
答案 1 :(得分:0)
您可以使用Win32 API中的PrintWindow
函数来获取特定窗口的位图。然后,您可以使用Bitmap.GetPixel
:
您需要使用DllImport
导入此(可能还有更多功能):
<DllImport("user32.dll")> _
Private Shared Function PrintWindow(hwnd As IntPtr, hdcBlt As IntPtr, nFlags As UInteger) As Boolean
以下是捕获窗口的小示例代码:
Using bm As New Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format16bppRgb555)
Dim g As Graphics = Graphics.FromImage(bm)
Dim hdc As IntPtr = g.GetHdc()
PrintWindow(hwnd, hdc, 0) 'hwnd is the window handle of the phone application
g.ReleaseHdc(hdc)
g.Flush()
Return Image.FromHbitmap(bm.GetHbitmap())
End Using
但是:试着看看是否真的没有其他方法可以解决这个问题。捕获屏幕将是一个脆弱的解决方案,只能在下次更新调用软件时等待中断。