2012-04-05 65 views
0

我正在设计一个伴随我们电话系统的播放器应用程序。当我们的呼叫者接听电话时,它会记录每个电话的录音。他们可以进入列表模块,找到录音并双击,这会打开我的播放器。我遇到的问题是,如果听筒接到另一个电话,我的播放器不知道它,并且会继续播放。我正在寻找一种方法来监视特定区域的屏幕,当它看到黄色或红色而不是蓝色时,它会暂停我的播放器。在Visual Basic中监视某个颜色的屏幕区域

电话系统没有任何我可以挂接的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

http://stackoverflow.com/a/28257727/4515800 有你的答案,riiiiiiiight这里Geezzer;)^^^^^^^^^ – Turner 2015-01-31 23:47:31

+0

@@@@@@@@@@@ @ 回答BELOW 的http://计算器。COM/A /4515800分之28257727 @@@@@@@@@@@@@ – Turner 2015-01-31 23:50:53

回答

0

我敢肯定这是你想要什么:

http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.getpixel.aspx

祝你好运!

编辑:

我忘了,你必须给设备上下文(hDC)有GetPixel工作。有时很难处理GetDC需要的窗口句柄(hWnd),因此您可以简单地使用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 
+0

我已经得到了所呈现的这些网站上的其他代码的形式运行的测试应用程序。该示例允许您移动鼠标并捕获光标位置的像素颜色。我修改它来检查5个像素。现在集成到我的播放器中。我会在正常工作时发布正确的代码。谢谢! – 2012-04-06 15:55:36

+0

代码发布...但得到一个内存泄漏.... – 2012-04-06 19:27:09

+0

正确的工作代码张贴在上面。 – 2012-04-07 03:52:08

0

可以使用PrintWindow函数从Win32 API来获取位图的一个特定的窗口。然后,您可以用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 

但是:试着看看是否真的没有另一种方法来解决这个问题。捕获屏幕将是一个脆弱的解决方案,只能等待下一次更新的调用软件。