The example of this article describes the cheating device of "QQ Beauty Find Difference Game" implemented in VB. Share it with everyone for your reference. The details are as follows:
It's quite boring. The principle is very simple. Using VB is slower, but the implementation is easy.
Option ExplicitPrivate Type sPOINT x As Long y As LongEnd TypePrivate Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As LongPrivate Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As LongPrivate Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As LongPrivate Const HWND_TOPMOST& = -1' Place the window at the top of the list and above any Front of the top window Private Const SWP_NOSIZE& = &H1' Keep window size Private Const SWP_NOMOVE& = &H2' Keep the window position Private Sub Form_Load()SetWindowPos Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE' Set the window to always be on top End Sub' Decompose the long RGB value into 3 components Sub ColorRGB(Color As Long, C() As Integer) Const ByN As Integer = 256 Const ByN2 As Long = 65536 C(1) = (Color Mod ByN) C(2) = ((Color Mod ByN2) / ByN) C(3) = (Color / ByN2)End SubPrivate Sub GetPoint() Dim p1( 497, 447) As Long, p2(497, 447) As Long, C1(3) As Integer, C2(3) As Integer 'The array size matches the size of the picture Dim pic1 As sPOINT, pic2 As sPOINT 'Set the screen position of the two pictures pic1.x = 8 pic1.y = 192 pic2.x = 517 pic2.y = 192 Dim h As Long , hD As Long, r As Long, i As Integer, j As Integer hD = GetDC(0) 'Read two pictures For i = 0 To 497 For j = 0 To 447 p1(i, j) = GetPixel(hD, i + pic1.x, j + pic1.y) p2(i, j) = GetPixel(hD, i + pic2.x, j + pic2 .y) Next Next 'Contrast, mark the difference Dim t As Boolean t = True For i = 0 To 497 For j = 0 To 447 Call ColorRGB(p1(i, j), C1()) Call ColorRGB(p2(i, j), C2()) If (Abs(C1(1) - C2(1)) > 30 Or Abs(C1(2) - C2(2)) > 30 Or Abs(C1(3) - C2(3)) > 30) Then t = Not t If t Then Picture1.ForeColor = &H0& Else Picture1.ForeColor = &HFF00& End If Else Picture1.ForeColor = p1(i, j) End If Picture1.PSet (i, j) Next NextEnd SubPrivate Sub Picture1_Click()Me.Visible = FalseDoEventsGetPointMe.Visible = TrueEnd Sub
I hope this article will be helpful to everyone's VB programming.