Hi, Alex [:)]
I've been attempting to convert the code to VB.NET at the request of a poster to the CF newsgroup. But I've come across a sticking point. The code seems to work fine except for the second call to GetPixel (to set the value of pixelNew). For some reason, the second call returns 248 instead of 16317688. I was wondering if you (or anyone reading this) could help me spot the error. Here's the relavent code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Not (InputPanel1.Enabled) Then
InputPanel1.Enabled = True
Application.DoEvents()
End If
Dim clsidKbdIM As New Guid("{42429667-ae04-11d0-a4f8-00aa00a749b9}")
SipSetCurrentIM(clsidKbdIM.ToByteArray())
Dim hWnd As IntPtr
hWnd = FindWindow("SipWndClass", "")
hWnd = GetWindow(hWnd, GW_CHILD)
Dim hDC As IntPtr
hDC = GetDC(hWnd)
Dim pixel As Integer
pixel = GetPixel(hDC, 2, 2)
Dim clrText As Integer
clrText = ((SystemColors.Window.R) Or _
(SystemColors.Window.G << 8) Or _
(SystemColors.Window.B << 16))
SetPixel(hDC, 2, 2, clrText)
Dim pixelNew As Integer
pixelNew = GetPixel(hDC, 2, 2) ' Returns 248
SetPixel(hDC, 2, 2, pixel)
If (pixel = pixelNew) Then
Dim msg As Message = Message.Create(hWnd, WM_LBUTTONDOWN, New IntPtr(1), New IntPtr(&H90009))
MessageWindow.SendMessage(msg)
msg = Message.Create(hWnd, WM_LBUTTONUP, New IntPtr(0), New IntPtr(&H90009))
MessageWindow.SendMessage(msg)
End If
ReleaseDC(hWnd, hDC)
End Sub
ETA: Here's the dll declarations if needed:
Declare Function FindWindow Lib "coredll" (ByVal wndClass As String, ByVal caption As String) As IntPtr
Declare Function GetWindow Lib "coredll" (ByVal hWnd As IntPtr, ByVal nType As Integer) As IntPtr
Declare Function GetPixel Lib "coredll" (ByVal hdc As IntPtr, ByVal nXPos As Integer, ByVal nYPos As Integer) As Integer
Declare Sub SetPixel Lib "coredll" (ByVal hdc As IntPtr, ByVal nXPos As Integer, ByVal nYPos As Integer, ByVal clr As Integer)
Declare Function GetDC Lib "coredll" (ByVal hWnd As IntPtr) As IntPtr
Declare Sub ReleaseDC Lib "coredll" (ByVal hWnd As IntPtr, ByVal hDC As IntPtr)
Declare Function SipSetCurrentIM Lib "coredll" (ByVal clsid As Byte()) As Boolean
Const WM_LBUTTONDOWN As Integer = &H201
Const WM_LBUTTONUP As Integer = &H202
Const GW_CHILD As Integer = 5
Thanks for taking a look. [:D]
Flynn
If we can't corrupt the youth of today, the adults of tomorrow won't be any fun...