Site hosted by Angelfire.com: Build your free website today!

Grower 1.0 (Beta)

Well, the question is: why i did this?
There are several reasons but the most important is that i was boring.
You see, i am working on a company that every development is done by someone else while i am "doomed" to a phone and its wire.
OK, stop crying.

I was intrigue how windows does the job so i decided to put the hands on and see what would happens if...
This project shows several things. It shows you:
For this project you need a form (frmMain), a PictureBox control (Pic) and a module to hold timer API functions (modTmr).
The code is fully commented so i think you wouldn't have problems trying to understand.
Level: Intermediate
Form Code:
'General declarations section
Option Explicit
' Type to use for screen coordinates
Dim pt As POINTAPI
Private Type POINTAPI
        X As Long
        Y As Long
End Type

Dim glHwnd As Long            ' To hold the handle of Desktop Window
Dim glDC As Long              ' To hold Device Context Handle of Desktop Window
Dim x2 As Long, y2 As Long    ' Variables to hold result coordinates

' Get the coordinates of cursor position on screen
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
' Get Device Context handle
Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
' Get the hadle to Desktop Window
Private Declare Function GetDesktopWindow Lib "user32" () As Long
' To paste and grow a rectangle of Desktop Window
Private Declare Function StretchBlt Lib "gdi32" (ByVal hdc As Long, _
                                                 ByVal X As Long, _
                                                 ByVal Y As Long, _
                                                 ByVal nWidth As Long, _
                                                 ByVal nHeight As Long, _
                                                 ByVal hSrcDC As Long, _
                                                 ByVal xSrc As Long, _
                                                 ByVal ySrc As Long, _
                                                 ByVal nSrcWidth As Long, _
                                                 ByVal nSrcHeight As Long, _
                                                 ByVal dwRop As Long) _
                                                 As Long

' Values to set form the Top Most window
' It doesn't works on XP and better if it is compiled!
Const HWND_TOPMOST = -1
Const HWND_NOTOPMOST = -2
Const SWP_NOSIZE = &H1
Const SWP_NOMOVE = &H2
Const SWP_NOACTIVATE = &H10
Const SWP_SHOWWINDOW = &H40
Private Declare Sub 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)

Sub DrawFromScreen()
' get the coordinates of screen where the mouse is
GetCursorPos pt
' Quit 50 pixels: used to grab the image, closing to
' set a rectangle with cursor in the middle of it.
x2 = pt.X - 50: y2 = pt.Y - 50

'
Me.Caption = "Grower 1.0 - X: " & pt.X & " / Y: " & pt.Y

With Pic
   ' Paint the rectangle of screen in picture box control.
   StretchBlt .hdc, 0, 0, .Width, .Height, glDC, _
              IIf(x2 < 50, 0, x2), IIf(y2 < 50, 0, y2), 100, 100, vbSrcCopy
End With

End Sub

Private Sub Form_Load()
' Set the form the top most window
SetWindowPos Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, _
             SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE

glHwnd = GetDesktopWindow()
glDC = GetWindowDC(glHwnd)

' Timer values
tmrInterval = 75  'milliseconds
SetTimer Me.hwnd, tmrID, tmrInterval, AddressOf TimerProc
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
' DONT't FORGET to do this
Also, don't stop the project with Stop button in IDE!!!!!
KillTimer Me.hwnd, tmrID
End Sub

Private Sub Form_Resize()
With Me
   If .WindowState <> vbMinimized Then
      Pic.Width = .ScaleWidth
      Pic.Height = .ScaleHeight
   End If
End With
End Sub
Module Code:
Option Explicit

Public Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, _
               ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Public Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) _
	       As Long

Public tmrInterval As Long
Public tmrID As Long
Public Sub TimerProc(ByVal hwnd As Long, _
                     ByVal nIDEvent As Long, _
                     ByVal uElapse As Long, _
                     ByVal lpTimerFunc As Long)
   frmMain.DrawFromScreen
End Sub
Or you can download the project here.


©2003 - Richie Simonetti