Quick Search for:  in language:    
SPY,Heres,little,code,using,apps,slaved,over,
   Code/Articles » |  Newest/Best » |  Community » |  Jobs » |  Other » |  Goto » | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
Visual Basic Stats

 Code: 3,149,602. lines
 Jobs: 144. postings

 How to support the site

 
Sponsored by:

 

You are in:

 
 
PDC 2003: Make the connection
Login



Latest Code Ticker for Visual Basic.
Click here to see a screenshot of this code!HistoryWriter Add-In V.1
By Zvonko Kostovski on 9/3

(Screen Shot)

Click here to see a screenshot of this code!Control Winamp
By Dennis Wollentin on 9/3

(Screen Shot)

Fake Virus Version 1.0
By C.J. Laing on 9/3


][String Encoder
By Andron Smth on 9/3


Font Catalog
By Bill Adams on 9/3


professional search
By Ziad Said on 9/3


Click here to see a screenshot of this code!Drew's Meta Tag Generator
By Drew Phillips on 9/3

(Screen Shot)

Fast BruteForce Class
By §e7eN on 9/3


Click here to see a screenshot of this code!Lotus Domino Exploit Scanner
By §e7eN on 9/3

(Screen Shot)

Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!





Affiliate Sites



 
 
   

Window Selector (Like SPY++)

Print
Email
 

Submitted on: 3/2/2000
By: Jolyon Bloomfield 
Level: Advanced
User Rating: By 4 Users
Compatibility:VB 5.0, VB 6.0

Users have accessed this code 10212 times.
 
(About the author)
 
     Here's a little bit of code that I'm using in one of my apps. I slaved over it for 3 nights, so I thought that others might also like to use it. Basically, it Displays a bounding box around the window that the cursor is over, just like selecting a window in Microsoft SPY++. (I decompiled it and monitored it and used dependancies and all sorts of junk from there too, in hope of imitating it). So here it is. This code snippet uses window regions, hDC's, System Objects, and basically complex drawing API's. It also shows how to clean up after yourself (I.e., Release memory correctly). Although it uses advanced techniques, you should get an idea of how graphics sort of work from here. Highly commented code, so as to maximise the knowledge that you can get from here. Please leave comments, as the feedback makes the program. If you like it, please vote :o) Jolyon Bloomfield February 2000
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.

'**************************************
' Name: Window Selector (Like SPY++)
' Description:Here's a little bit of cod
'     e that I'm using in one of my apps. I sl
'     aved over it for 3 nights, so I thought 
'     that others might also like to use it. B
'     asically, it Displays a bounding box aro
'     und the window that the cursor is over, 
'     just like selecting a window in Microsof
'     t SPY++. (I decompiled it and monitored 
'     it and used dependancies and all sorts o
'     f junk from there too, in hope of imitat
'     ing it). So here it is.
This code snippet uses window regions, hDC's, System Objects, and basically complex drawing API's. It also shows how To clean up after yourself (I.e., Release memory correctly).
Although it uses advanced techniques, you should Get an idea of how graphics sort of work from here. Highly commented code, so as To maximise the knowledge that you can get from here.
Please leave comments, as the feedback makes the program. If you like it, please vote :o)
Jolyon Bloomfield February 2000
' By: Jolyon Bloomfield
'
' Assumes:Fancy Stuph using lots of Wind
'     ow API calls
'
' Side Effects:None known, unless your a
'     pp hangs
'
'This code is copyrighted and has' limited warranties.Please see http://w
'     ww.Planet-Source-Code.com/vb/scripts/Sho
'     wCode.asp?txtCodeId=6362&lngWId;=1'for details.'**************************************

'
' Sorry I haven't put the declarations i
'     n it's box and all that jazz, but I did 
'     it like this
' So that you could select it all and ju
'     st place it into a new form.
' Yes, it's that easy. Create a new form
'     , copy and paste this code.
' Then click on the form and hold down t
'     he mouse, and drag over to another windo
'     w.
'
' Jolyon Bloomfield, February 2000
'
' A note to using this code: I guess sin
'     ce I've put it here, anybody can use it.
'     
' If you do, please give me credit for t
'     he hard work that I put into this.
' It wasn't an easy process, and I don't
'     want anybody taking credit for my work.
'
'
' The only bug I've found, is that when 
'     a window is maximised, it has coordinate
'     s
' that exceed the bounding area of the s
'     creen. I tried to offset this effect,
' but gave up.
'
Option Explicit' Require variable Declaration
' PointAPI and RECT are the two most com
'     mon structures used in graphics in Windo
'     ws

Private Type POINTAPI
    X As Long
    Y As Long
    End Type
Private Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
    End Type
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long' Get the cursor position
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long' Get the handle of the window that is foremost on a particular X, Y position. Used here To get the window under the cursor
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long ' Get the window co-ordinates in a RECT structure
Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long ' Retrieve a handle For the hDC of a window
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long ' Release the memory occupied by an hDC
Private Declare Function CreatePen Lib "gdi32" (ByVal nPenStyle As Long, ByVal nWidth As Long, ByVal crColor As Long) As Long' Create a GDI graphics pen object
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long' Used to select brushes, pens, and clipping regions
Private Declare Function GetStockObject Lib "gdi32" (ByVal nIndex As Long) As Long ' Get hold of a "stock" object. I use it to get a Null Brush
Private Declare Function SetROP2 Lib "gdi32" (ByVal hdc As Long, ByVal nDrawMode As Long) As Long' Used To set the Raster OPeration of a window
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long' Delete a GDI Object
Private Declare Function Rectangle Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long' GDI Graphics- draw a rectangle using current pen, brush, etc.
Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long ' Set mouse events only For one window
Private Declare Function ReleaseCapture Lib "user32" () As Long' Release the mouse capture
Private Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long ' Create a rectangular region
Private Declare Function SelectClipRgn Lib "gdi32" (ByVal hdc As Long, ByVal hRgn As Long) As Long ' Select the clipping region of an hDC
Private Declare Function GetClipRgn Lib "gdi32" (ByVal hdc As Long, ByVal hRgn As Long) As Long' Get the Clipping region of an hDC
    Private Const NULL_BRUSH = 5' Stock Object
    Private Selecting As Boolean ' Amd I currently selecting a window?
    Private BorderDrawn As Boolean' Is there a border currently drawn that needs To be undrawn?
    Private Myhwnd As Long ' The current hWnd that has a border drawn on it
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

' Set the selecting flag Selecting = True ' Capture all mouse events to this windo ' w (form) SetCapture Me.hwnd ' Simulate a mouse movement event to dra ' w the border when the mouse button goes ' down Form_MouseMove 0, Shift, X, Y End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
' Security catch to make sure that the g ' raphics don't get mucked up when not sel ' ecting If Selecting = False Then Exit Sub ' Call the "Draw" subroutine Draw End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
' If not selecting, then skip If Selecting = False Then Exit Sub ' Clean up the graphics drawn UnDraw ' Release mouse capture ReleaseCapture ' Not selecting Selecting = False ' Reset the variable Myhwnd = 0 End Sub
Private Sub Draw()
Dim Cursor As POINTAPI' Cursor position Dim RetVal As Long' Dummy returnvalue Dim hdc As Long' hDC that we're going To be using Dim Pen As Long' Handle To a GDI Pen object Dim Brush As Long ' Handle To a GDI Brush object Dim OldPen As Long' Handle To previous Pen object (to restore it) Dim OldBrush As Long ' Handle To previous brush object (to restore it) Dim OldROP As Long' Value of the previous ROP Dim Region As Long' Handle To a GDI Region object that I create Dim OldRegion As Long ' Handle To previous Region object For the hDC Dim FullWind As RECT ' the bounding rectangle of the window in screen coords Dim Draw As RECT ' The drawing rectangle ' ' Getting all of the ingredients ready ' ' Get the cursor GetCursorPos Cursor ' Get the window RetVal = WindowFromPoint(Cursor.X, Cursor.Y) ' If the new hWnd is the same as the old ' one, skip drawing it, so to avoid flicke ' r If RetVal = Myhwnd Then Exit Sub ' New hWnd. If there is currently a bord ' er drawn, undraw it. If BorderDrawn = True Then UnDraw ' Set the BorderDrawn property to true, ' as we're just about to draw it. BorderDrawn = True ' And set the hWnd to the new value. ' Note, I didn't do it before, because t ' he UnDraw routine uses the Myhwnd variab ' le Myhwnd = RetVal ' Print the hWnd on the form in Hex (jus ' t so see what windows are at work) Me.Cls Me.Print Hex(Myhwnd) ' You could extract other information fr ' om the window, such as window title, ' class name, parent, etc., and print it ' here, too. ' Get the full Rect of the window in scr ' een co-ords GetWindowRect Myhwnd, FullWind ' Create a region with width and height ' of the window Region = CreateRectRgn(0, 0, FullWind.Right - FullWind.Left, FullWind.Bottom - FullWind.Top) ' Create an hDC for the hWnd ' Note: GetDC retrieves the CLIENT AREA ' hDC. We want the WHOLE WINDOW, including ' Non-Client ' stuff like title bar, menu, border, et ' c. hdc = GetWindowDC(Myhwnd) ' Save the old region RetVal = GetClipRgn(hdc, OldRegion) ' Retval = 0: no region 1: Region copied ' -1: error ' Select the new region RetVal = SelectObject(hdc, Region) ' Create a pen Pen = CreatePen(DrawStyleConstants.vbSolid, 6, 0)' Draw Solid lines, width 6, and color black ' Select the pen ' A pen draws the lines OldPen = SelectObject(hdc, Pen) ' Create a brush ' A brush is the filling for a shape ' I need to set it to a null brush so th ' at it doesn't edit anything Brush = GetStockObject(NULL_BRUSH) ' Select the brush OldBrush = SelectObject(hdc, Brush) ' Select the ROP OldROP = SetROP2(hdc, DrawModeConstants.vbInvert)' vbInvert means, whatever is draw, ' invert those pixels. This means that I ' can undraw it by doing the same. ' ' The Drawing Bits ' ' Put a box around the outside of the wi ' ndow, using the current hDC. ' These coords are in device co-ordinate ' s, i.e., of the hDC. With Draw .Left = 0 .Top = 0 .Bottom = FullWind.Bottom - FullWind.Top .Right = FullWind.Right - FullWind.Left Rectangle hdc, .Left, .Top, .Right, .Bottom' Really easy to understand - draw a rectangle, hDC, and coordinates End With
' ' The Washing Up bits ' ' This is a very important part, as it r ' eleases memory that has been taken up. ' If we don't do this, windows crashes d ' ue to a memory leak. ' You probably get a blue screen (altohu ' gh I'm not sure) ' ' Get back the old region SelectObject hdc, OldRegion ' Return the previous ROP SetROP2 hdc, OldROP ' Return to the previous brush SelectObject hdc, OldBrush ' Return the previous pen SelectObject hdc, OldPen ' Delete the Brush I created DeleteObject Brush ' Delete the Pen I created DeleteObject Pen ' Delete the region I created DeleteObject Region ' Release the hDC back to window's resou ' rce pool ReleaseDC Myhwnd, hdc End Sub
Private Sub UnDraw()
' ' Note, this sub is almost identical to ' the other one, except it doesn't go look ' ing ' for the hWnd, it accesses the old one. ' Also, it doesn't clear the form. ' Otherwise, it just draws on top of the ' old one with an invert pen. ' 2 inverts = original ' ' If there hasn't been a border drawn, t ' hen get out of here. If BorderDrawn = False Then Exit Sub ' Now set it BorderDrawn = False ' If there isn't a current hWnd, then ex ' it. ' That's why in the mouseup event we get ' out, because otherwise a border would be ' draw ' around the old window If Myhwnd = 0 Then Exit Sub Dim Cursor As POINTAPI' Cursor position Dim RetVal As Long' Dummy returnvalue Dim hdc As Long' hDC that we're going To be using Dim Pen As Long' Handle To a GDI Pen object Dim Brush As Long ' Handle To a GDI Brush object Dim OldPen As Long' Handle To previous Pen object (to restore it) Dim OldBrush As Long ' Handle To previous brush object (to restore it) Dim OldROP As Long' Value of the previous ROP Dim Region As Long' Handle To a GDI Region object that I create Dim OldRegion As Long ' Handle To previous Region object For the hDC Dim FullWind As RECT ' the bounding rectangle of the window in screen coords Dim Draw As RECT ' The drawing rectangle ' ' Getting all of the ingredients ready ' ' Get the full Rect of the window in scr ' een co-ords GetWindowRect Myhwnd, FullWind ' Create a region with width and height ' of the window Region = CreateRectRgn(0, 0, FullWind.Right - FullWind.Left, FullWind.Bottom - FullWind.Top) ' Create an hDC for the hWnd ' Note: GetDC retrieves the CLIENT AREA ' hDC. We want the WHOLE WINDOW, including ' Non-Client ' stuff like title bar, menu, border, et ' c. hdc = GetWindowDC(Myhwnd) ' Save the old region RetVal = GetClipRgn(hdc, OldRegion) ' Retval = 0: no region 1: Region copied ' -1: error ' Select the new region RetVal = SelectObject(hdc, Region) ' Create a pen Pen = CreatePen(DrawStyleConstants.vbSolid, 6, 0)' Draw Solid lines, width 6, and color black ' Select the pen ' A pen draws the lines OldPen = SelectObject(hdc, Pen) ' Create a brush ' A brush is the filling for a shape ' I need to set it to a null brush so th ' at it doesn't edit anything Brush = GetStockObject(NULL_BRUSH) ' Select the brush OldBrush = SelectObject(hdc, Brush) ' Select the ROP OldROP = SetROP2(hdc, DrawModeConstants.vbInvert)' vbInvert means, whatever is draw, ' invert those pixels. This means that I ' can undraw it by doing the same. ' ' The Drawing Bits ' ' Put a box around the outside of the wi ' ndow, using the current hDC. ' These coords are in device co-ordinate ' s, i.e., of the hDC. With Draw .Left = 0 .Top = 0 .Bottom = FullWind.Bottom - FullWind.Top .Right = FullWind.Right - FullWind.Left Rectangle hdc, .Left, .Top, .Right, .Bottom' Really easy to understand - draw a rectangle, hDC, and coordinates End With
' ' The Washing Up bits ' ' This is a very important part, as it r ' eleases memory that has been taken up. ' If we don't do this, windows crashes d ' ue to a memory leak. ' You probably get a blue screen (altohu ' gh I'm not sure) ' ' Get back the old region SelectObject hdc, OldRegion ' Return the previous ROP SetROP2 hdc, OldROP ' Return to the previous brush SelectObject hdc, OldBrush ' Return the previous pen SelectObject hdc, OldPen ' Delete the Brush I created DeleteObject Brush ' Delete the Pen I created DeleteObject Pen ' Delete the region I created DeleteObject Region ' Release the hDC back to window's resou ' rce pool ReleaseDC Myhwnd, hdc End Sub


Other 11 submission(s) by this author

 

 
Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
Reason:
 
Your Vote!

What do you think of this code(in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments
3/2/2000 4:44:13 PM:elrondir
Could you upload it as a zip, please? 
We're all lazy.
Thanks
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
3/4/2000 2:14:20 PM:J
were not all lazy just 99.99999999& of 
us (including me)
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
3/4/2000 9:03:26 PM:a.shimon
e-mail me ur decompiler please, i've 
been looking for one
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
3/4/2000 10:28:12 PM:Jolyon Bloomfield
Hiyas there,
I'll upload it as a form 
file whenever I get around to it.. I'm 
allowed to be lazy too ;) As for the 
decompilers and jazz, I used Numega 
SoftIce, APISpy and Dependency Walker. 
All really good software!
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
4/14/2000 7:55:51 AM:Burbble
why isn't this a ZIP it's long enough 
to be :)
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
5/10/2000 10:42:03 AM:arnold72
can u mail the decompiler also to me? 
please ... thx ;-))
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
12/27/2000 8:09:40 AM:Vasilis Sagonas
where can I find a decompiler?
thx
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
7/7/2001 9:33:58 PM:gavin
Nice work well done.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
9/3/2001 2:55:50 PM:Stephen
IT'S BEAUTIFUL !
Intriguing name. If 
your a Sheila, all I can say is : I 
wish my girlfriend was a programmer 
like you. If your a Bruce, well, 
No.
You spent 3 days writing it. I'm 
lazy so I spent my 3 days looking for 
it.
It's perfect. Got more comments 
than code. And for the lazies there's 
always the copy-and-paste friendly 
version of the code. 
So young and so 
brilliant. Keep it up.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
4/27/2003 11:58:33 PM:Seb Ramadan (s00p)
Nice work... Could have been a zip 
(like all you lazy people wanted)... 
Zip it and you will get happier (and 
more) people giving you better (by how 
much?) votes...
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.

NOTICE: The author of this code has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular code, please click here.
 
Name:
Comment:

 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | Visual Basic Home | Site Home | Other Sites | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright© 1997 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.  Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.