By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,266 Members | 1,300 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,266 IT Pros & Developers. It's quick & easy.

Screen Mate Creation

P: n/a
I am trying to create a screen mate similar to the popular sheep program
which can run around the screen on top of other windows currently visible on
the screen This will require me to obtain an outline of the forms currently
being displayed on the screen so that my screen mate can run around on them.
Aditional to this I will need to know how to display a form which is partly
transparent around the edges. I have seen this done many times before.

Thanks for the assistance everyone.
Nov 21 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
"David Pendrey" <fa*******@dodo.com.au> schrieb:
I am trying to create a screen mate similar to the popular sheep program
which can run around the screen on top of other windows currently visible
on the screen This will require me to obtain an outline of the forms
currently being displayed on the screen so that my screen mate can run
around on them.
P/invoke on 'EnumWindows'/'GetWindowRect' (MSDN,
<URL:http://www.pinvoke.net/>).
Aditional to this I will need to know how to display a form which is
partly transparent around the edges. I have seen this done many times
before.


Region from Bitmap
<URL:http://www.bobpowell.net/region_from_bitmap.htm>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #2

P: n/a
Thanks for the advice. The region from bitmap looks exactly like what I want
but I can't find out how to use the GetWindowRect function. I can find out
how it is used but it seems to need a window identifier. I need to be able
to find the location of every window currently open. Does this mean I have
to iterate through every possible window ID or is there another API for
doing this? Thanks again for the advice.
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:Ol****************@TK2MSFTNGP10.phx.gbl...
"David Pendrey" <fa*******@dodo.com.au> schrieb:
I am trying to create a screen mate similar to the popular sheep program
which can run around the screen on top of other windows currently visible
on the screen This will require me to obtain an outline of the forms
currently being displayed on the screen so that my screen mate can run
around on them.


P/invoke on 'EnumWindows'/'GetWindowRect' (MSDN,
<URL:http://www.pinvoke.net/>).
Aditional to this I will need to know how to display a form which is
partly transparent around the edges. I have seen this done many times
before.


Region from Bitmap
<URL:http://www.bobpowell.net/region_from_bitmap.htm>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #3

P: n/a
"David Pendrey" <fa*******@dodo.com.au> schrieb:
but it seems to need a window identifier. I need to be able to find the
location of every window currently open. Does this mean I have to iterate
through every possible window ID or is there another API for doing this?


As I already said in my previous post, you can enumerate windows (window
handles) by suing the 'EnumWindows' function with a callback.

'EnumWindows' Function
<URL:http://msdn.microsoft.com/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowfunctions/enumwindows.asp>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #4

P: n/a
Ok, I have figured out what you meant now. However I can not find a way to
call the EnumWindowsProc function. I found sample code which said to declare
the function like this

Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Integer,
ByVal lParam As Integer) As Integer

This fails when i call it with

retval = EnumWindows(AddressOf EnumWindowsProc, 0)

The error provided is because Integer is not a delegate type. I have tried
to fiddle around with delegates but to no luck. I'm fairly sure that I can
get the rest to work after this function is being called correctly. Sorry to
be such a hassle.

Kind regards,
David Pendrey
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:Ou**************@tk2msftngp13.phx.gbl...
"David Pendrey" <fa*******@dodo.com.au> schrieb:
but it seems to need a window identifier. I need to be able to find the
location of every window currently open. Does this mean I have to iterate
through every possible window ID or is there another API for doing this?


As I already said in my previous post, you can enumerate windows (window
handles) by suing the 'EnumWindows' function with a callback.

'EnumWindows' Function
<URL:http://msdn.microsoft.com/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowfunctions/enumwindows.asp>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #5

P: n/a
David,

"David Pendrey" <fa*******@dodo.com.au> schrieb:
This fails when i call it with

retval = EnumWindows(AddressOf EnumWindowsProc, 0)

The error provided is because Integer is not a delegate type. I have tried
to fiddle around with delegates but to no luck.


Take a look at the code in this sample:

<URL:http://groups.google.de/groups?selm=uh24OrXfCHA.1652%40tkmsftngp09>

If you need further assistence on this issue, feel free to ask...

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #6

P: n/a
Herfried ,
I am now having problems getting the EnumParentProc function to call the
GetWindowRect function. I am getting a null object reference when the
GetWindowRect function is called. I have run the code in debug mode and
found that the RECT object is created, and the hWnd is being passed in from
the Win API. I have tried to modify the code so that the values being passed
are integers or integer pointers and tried all different combinations but
this did not seem to effect the output. I am trying to create a module
within my project to handle the window positions which updates its
information when the WindowsLocate function is called. I have included my
code here. Any help would be appreciated.

Regards, David
Module mWindowLocations

Private Delegate Function EnumWindowsProc(ByVal hWnd As IntPtr, ByVal lParam
As IntPtr) As Boolean

<System.Runtime.InteropServices.DllImport("user32" , SetLastError:=True)> _

Private Function EnumWindows(ByVal ewp As EnumWindowsProc, ByVal lParam As
IntPtr) As Boolean

End Function

Private mWindows As New Collection

Private Structure RECT

Dim Left As Long

Dim Top As Long

Dim Right As Long

Dim Bottom As Long

End Structure

Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As IntPtr,
ByVal lpRect As RECT) As Long

Private ewp As EnumWindowsProc = New EnumWindowsProc(AddressOf
EnumParentProc)

Public Sub WindowsLocate()

Do While mWindows.Count > 0

mWindows.Remove(1)

Loop

' *** Place this code wherever you want to enumerate the windows. ***

Dim retval As Long ' return value

' Use the above callback function to list all of the enumerated windows.
Note that lParam is

' set to 0 because we don't need to pass any additional information to the
function.

retval = EnumWindows(ewp, IntPtr.Zero)

End Sub



' Display the title bar text of all top-level windows. This

' task is given to the callback function, which will receive each handle
individually.

' Note that if the window has no title bar text, it will not be displayed
(for clarity's sake).

' *** Place this code in a module. This is the callback function. ***

' This function displays the title bar text of the window identified by
hwnd.

Private Function EnumParentProc(ByVal hWnd As IntPtr, ByVal lParam As
IntPtr) As Boolean

Dim R As RECT

GetWindowRect(hWnd, R)

mWindows.Add(R)

EnumParentProc = True ' return value of 1 means continue enumeration

End Function

End Module
Nov 21 '05 #7

P: n/a
"David Pendrey" <fa*******@dodo.com.au> schrieb:
I am now having problems getting the EnumParentProc function to call the
GetWindowRect function. I am getting a null object reference when the
GetWindowRect function is called. I have run the code in debug mode and
found that the RECT object is created, and the hWnd is being passed in
from the Win API.
[...]
Module mWindowLocations

Private Delegate Function EnumWindowsProc(ByVal hWnd As IntPtr, ByVal
lParam As IntPtr) As Boolean

<System.Runtime.InteropServices.DllImport("user32" , SetLastError:=True)> _

Private Function EnumWindows(ByVal ewp As EnumWindowsProc, ByVal lParam As
IntPtr) As Boolean

End Function

Private mWindows As New Collection

Private Structure RECT

Dim Left As Long

Dim Top As Long

Dim Right As Long

Dim Bottom As Long
'Long' -> 'Int32'.
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As IntPtr,
ByVal lpRect As RECT) As Long
'ByVal lpRect' -> 'ByRef lpRect'. ') As Long' -> ') As Int32'.
Dim retval As Long ' return value


=> 'retval As Int32'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #8

P: n/a
Herfried,
I am very thankfull for your help so far. I should have thought of this
sooner but is there a way to find the topmost window at a specified X,Y
position on the screen? Using what I have so far it returns much more
windows than I would have expected, which is going to impact on the
performance. Thanks again for the help so far

Regards,
David
Nov 21 '05 #9

P: n/a
David,

"David Pendrey" <fa*******@dodo.com.au> schrieb:
I am very thankfull for your help so far. I should have thought of this
sooner but is there a way to find the topmost window at a specified X,Y
position on the screen? Using what I have so far it returns much more
windows than I would have expected, which is going to impact on the
performance.


P/Invoke 'WindowFromPoint'. Untested:

\\\
Public Structure POINT
Public x As Int32
Public y As Int32
End Structure

Public Declare Function WindowFromPoint Lib "User32.dll" ( _
ByRef Point As POINT _
) As IntPtr
..
..
..
Dim pt As POINT
pt.x = ...
pt.y = ...
Dim hwnd As IntPtr = WindowFromPoint(pt)
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 21 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.