Home All Groups Group Topic Archive Search About
Author
30 Mar 2005 8:35 AM
David Pendrey
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.

Author
30 Mar 2005 11:58 AM
Herfried K. Wagner [MVP]
"David Pendrey" <fairyd***@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/>
Author
31 Mar 2005 1:18 AM
David Pendrey
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.


Show quoteHide quote
"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
news:OlscQ%23RNFHA.3000@TK2MSFTNGP10.phx.gbl...
> "David Pendrey" <fairyd***@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/>
Author
31 Mar 2005 11:34 AM
Herfried K. Wagner [MVP]
"David Pendrey" <fairyd***@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/>
Author
31 Mar 2005 2:08 PM
David Pendrey
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


Show quoteHide quote
"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
news:OulLBVeNFHA.2468@tk2msftngp13.phx.gbl...
> "David Pendrey" <fairyd***@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/>
Author
31 Mar 2005 5:37 PM
Herfried K. Wagner [MVP]
David,

"David Pendrey" <fairyd***@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/>
Author
3 Apr 2005 1:22 AM
David Pendrey
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
Author
3 Apr 2005 1:44 AM
Herfried K. Wagner [MVP]
Show quote Hide quote
"David Pendrey" <fairyd***@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/>
Author
3 Apr 2005 7:31 AM
David Pendrey
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
Author
3 Apr 2005 11:54 AM
Herfried K. Wagner [MVP]
David,

"David Pendrey" <fairyd***@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/>