vbzero
Aug 21st, 2000, 06:26 AM
The Project's code:
Form:
-------------------
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Dim PicPixelA As Long
Dim PicPixelB As Long
Dim x As Long, y As Long
Dim xp As Long, yp As Long
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Dim DesktopWindow As Long
Private Declare Function GetDC Lib "user32" (ByVal HWND As Long) As Long
Private Sub CompareButton_Click()
On Error Resume Next
CompareButton.Enabled = False
DesktopWindow = GetDesktopWindow
Dim FoundIt As Boolean
FoundIt = False
PicPixelA = GetPixel(PictureBox.hdc, 0, 0)
For x = 0 To Screen.Width - PictureBox.Width
For y = 0 To Screen.Height - PictureBox.Height
PicPixelB = GetPixel(GetDC(DesktopWindow), x, y)
If PicPixelA = PicPixelB Then
FoundIt = True
For xp = 0 To PictureBox.Width
For yp = 0 To PictureBox.Height
PicPixelA = GetPixel(PictureBox.hdc, xp, yp)
PicPixelB = GetPixel(GetDC(DesktopWindow), x + xp, y + yp)
If PicPixelA <> PicPixelB Then
FoundIt = False
xp = PictureBox.Width
yp = PictureBox.Height
End If
Next yp
Next xp
If FoundIt Then
MsgBox "A match was found. The pictures are the same.", vbInformation, "Match found"
CompareButton.Enabled = True
Exit Sub
End If
End If
Next y
Next x
MsgBox "The pictures didn't match at this try.", vbInformation, "No match found"
CompareButton.Enabled = True
Exit Sub
End Sub
Private Sub ExitButton_Click()
On Error Resume Next
End
End Sub
Private Sub Form_Load()
On Error Resume Next
SetCloseButton Me, False
Call SetWindowPos(Me.HWND, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE)
End Sub
-------------------
Module:
-------------------
Option Explicit
Public Declare Function GetSystemMenu Lib "user32" _
(ByVal HWND As Long, ByVal bRevert As Long) As Long
Public Declare Function GetMenuItemCount Lib "user32" _
(ByVal H_MENU As Long) As Long
Public Declare Function RemoveMenu Lib "user32" _
(ByVal H_MENU As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
Public Declare Function DrawMenuBar Lib "user32" (ByVal HWND As Long) As Long
Public Const MF_BYPOSITION = &H400&
Public Const MF_REMOVE = &H1000&
Public 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 Long
Public Const HWND_TOPMOST As Long = -1
Public Const SWP_NOSIZE As Long = &H1
Public Const SWP_NOMOVE As Long = &H2
Public Sub SetCloseButton(T_FORM As Form, Disabled As Boolean)
On Error Resume Next
Dim H_MENU As Long
Dim N_COUNT As Long
If Not Disabled Then
H_MENU = GetSystemMenu(T_FORM.HWND, 0)
N_COUNT = GetMenuItemCount(H_MENU)
Call RemoveMenu(H_MENU, N_COUNT - 1, MF_REMOVE Or MF_BYPOSITION)
Call RemoveMenu(H_MENU, N_COUNT - 2, MF_REMOVE Or MF_BYPOSITION)
DrawMenuBar T_FORM.HWND
Else
H_MENU = GetSystemMenu(T_FORM.HWND, True)
DrawMenuBar T_FORM.HWND
End If
End Sub
-------------------
This should search the desktop for a picture. The program
compares every line and every pixel with the other one
and if there's a match it would send a message.
There must be an error anywhere because even when I remove
the line "On Error Resume Next" the program doesn't respond
after a while.
I built in a counter once to view if the application is
working. This was successfull until the moment the counter
got an internal overflow. The time which was taken for that
was about 5 minutes and about 1% of work was done.
I think it would take hours to search and compare any
pixel on the screen. Is there any other way?
Which solution would be the best here?
I heard something bout a BitBlt() function. Does anyone
know this function and can tell me what it is good for?
Can I use it for my application?
-------------------
thx, sub-zero
Visual Studio 6.0 Enterprise Edition - SP3
Form:
-------------------
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Dim PicPixelA As Long
Dim PicPixelB As Long
Dim x As Long, y As Long
Dim xp As Long, yp As Long
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Dim DesktopWindow As Long
Private Declare Function GetDC Lib "user32" (ByVal HWND As Long) As Long
Private Sub CompareButton_Click()
On Error Resume Next
CompareButton.Enabled = False
DesktopWindow = GetDesktopWindow
Dim FoundIt As Boolean
FoundIt = False
PicPixelA = GetPixel(PictureBox.hdc, 0, 0)
For x = 0 To Screen.Width - PictureBox.Width
For y = 0 To Screen.Height - PictureBox.Height
PicPixelB = GetPixel(GetDC(DesktopWindow), x, y)
If PicPixelA = PicPixelB Then
FoundIt = True
For xp = 0 To PictureBox.Width
For yp = 0 To PictureBox.Height
PicPixelA = GetPixel(PictureBox.hdc, xp, yp)
PicPixelB = GetPixel(GetDC(DesktopWindow), x + xp, y + yp)
If PicPixelA <> PicPixelB Then
FoundIt = False
xp = PictureBox.Width
yp = PictureBox.Height
End If
Next yp
Next xp
If FoundIt Then
MsgBox "A match was found. The pictures are the same.", vbInformation, "Match found"
CompareButton.Enabled = True
Exit Sub
End If
End If
Next y
Next x
MsgBox "The pictures didn't match at this try.", vbInformation, "No match found"
CompareButton.Enabled = True
Exit Sub
End Sub
Private Sub ExitButton_Click()
On Error Resume Next
End
End Sub
Private Sub Form_Load()
On Error Resume Next
SetCloseButton Me, False
Call SetWindowPos(Me.HWND, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE)
End Sub
-------------------
Module:
-------------------
Option Explicit
Public Declare Function GetSystemMenu Lib "user32" _
(ByVal HWND As Long, ByVal bRevert As Long) As Long
Public Declare Function GetMenuItemCount Lib "user32" _
(ByVal H_MENU As Long) As Long
Public Declare Function RemoveMenu Lib "user32" _
(ByVal H_MENU As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
Public Declare Function DrawMenuBar Lib "user32" (ByVal HWND As Long) As Long
Public Const MF_BYPOSITION = &H400&
Public Const MF_REMOVE = &H1000&
Public 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 Long
Public Const HWND_TOPMOST As Long = -1
Public Const SWP_NOSIZE As Long = &H1
Public Const SWP_NOMOVE As Long = &H2
Public Sub SetCloseButton(T_FORM As Form, Disabled As Boolean)
On Error Resume Next
Dim H_MENU As Long
Dim N_COUNT As Long
If Not Disabled Then
H_MENU = GetSystemMenu(T_FORM.HWND, 0)
N_COUNT = GetMenuItemCount(H_MENU)
Call RemoveMenu(H_MENU, N_COUNT - 1, MF_REMOVE Or MF_BYPOSITION)
Call RemoveMenu(H_MENU, N_COUNT - 2, MF_REMOVE Or MF_BYPOSITION)
DrawMenuBar T_FORM.HWND
Else
H_MENU = GetSystemMenu(T_FORM.HWND, True)
DrawMenuBar T_FORM.HWND
End If
End Sub
-------------------
This should search the desktop for a picture. The program
compares every line and every pixel with the other one
and if there's a match it would send a message.
There must be an error anywhere because even when I remove
the line "On Error Resume Next" the program doesn't respond
after a while.
I built in a counter once to view if the application is
working. This was successfull until the moment the counter
got an internal overflow. The time which was taken for that
was about 5 minutes and about 1% of work was done.
I think it would take hours to search and compare any
pixel on the screen. Is there any other way?
Which solution would be the best here?
I heard something bout a BitBlt() function. Does anyone
know this function and can tell me what it is good for?
Can I use it for my application?
-------------------
thx, sub-zero
Visual Studio 6.0 Enterprise Edition - SP3