I am attempting to create an app that will run "on top" of another app.
My app will create a transparent window over the other app for the
purpose of displaying information.
I am able to create my transparent app but cannot get the size and
position of the other app. I can get the handle of the other app using
the DllImport("user32")...FindWindow method. However, when I try to
get this size/position of this other window using
DllImport("gdi32")...GetBoundsRect it does not assign any value to the
Rectangle object referenced by GetBoundsRect.
I believe my problem lies in the 'flags' attribute of GetBoundsRect.
The method signature is as follows:
[DllImport("gdi32.dll")]
public static extern int GetBoundsRect(int hWnd, // handle to window
ref Rectangle rect, // bounding rectangle
int flags); // function options
All of the documentation I have found on this method refer to only one
valid value for the 'flags' variable: DCB_RESET (Clears the bounding
rectangle after returning it. If this flag is not set, the bounding
rectangle will not be cleared.) I cannot figure out how to set or
retrieve this value. Do I need to get this value from somewhere or do
I need to initialize in my program before using? Any help would be
appreciated.
I am fairly new to C# (coming from a Java background) and am using
Visual Studio 2005 Professional.
TIA,
Brian Enderle 4 6146 Br*****@gmail.com wrote: I am attempting to create an app that will run "on top" of another app. My app will create a transparent window over the other app for the purpose of displaying information.
I am able to create my transparent app but cannot get the size and position of the other app. I can get the handle of the other app using the DllImport("user32")...FindWindow method. However, when I try to get this size/position of this other window using DllImport("gdi32")...GetBoundsRect it does not assign any value to the Rectangle object referenced by GetBoundsRect.
I believe my problem lies in the 'flags' attribute of GetBoundsRect. The method signature is as follows:
[DllImport("gdi32.dll")] public static extern int GetBoundsRect(int hWnd, // handle to window ref Rectangle rect, // bounding rectangle int flags); // function options
All of the documentation I have found on this method refer to only one valid value for the 'flags' variable: DCB_RESET (Clears the bounding rectangle after returning it. If this flag is not set, the bounding rectangle will not be cleared.) I cannot figure out how to set or retrieve this value. Do I need to get this value from somewhere or do I need to initialize in my program before using? Any help would be appreciated.
I am fairly new to C# (coming from a Java background) and am using Visual Studio 2005 Professional.
TIA, Brian Enderle
Hi Brian,
Instead, try using GetWindowRect: http://tinyurl.com/bd7eb
--
Hope this helps,
Tom Spink
Brian, However, when I try to get this size/position of this other window using DllImport("gdi32")...GetBoundsRect it does not assign any value to the Rectangle object referenced by GetBoundsRect.
GetBoundsRect isn't the function you want to use (it works on device
contexts, not windows). Have a look at GetWindowRect instead.
And you can't use a System.Drawing.Rectangle as the parameter type,
since it doesn't have the same layout as the GDI RECT struct.
Mattias
--
Mattias Sjögren [C# MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Thanks for the quick replies. GetWindowRect works great but brings up
another question: I would like to have my transparent app lie within
the client area of the other app. I can use GetClientRect to get the
size of this area but how do I properly position it with respect to the
other app, ie; how do I account for the frame, toolbars, etc.?
GetClientRect returns the size of the client rectangle but not the
position of the rectangle within the window. Using Spy++ Client Rect.
shows the coordinates of the client rectangle relative to the window
but when I use the method (GetClientRect) within my program all I get
is the rectangle size (598, 0, 799, 0).
Thanks again,
Brian Enderle
Tom Spink wrote: Br*****@gmail.com wrote:
I am attempting to create an app that will run "on top" of another app. My app will create a transparent window over the other app for the purpose of displaying information.
I am able to create my transparent app but cannot get the size and position of the other app. I can get the handle of the other app using the DllImport("user32")...FindWindow method. However, when I try to get this size/position of this other window using DllImport("gdi32")...GetBoundsRect it does not assign any value to the Rectangle object referenced by GetBoundsRect.
I believe my problem lies in the 'flags' attribute of GetBoundsRect. The method signature is as follows:
[DllImport("gdi32.dll")] public static extern int GetBoundsRect(int hWnd, // handle to window ref Rectangle rect, // bounding rectangle int flags); // function options
All of the documentation I have found on this method refer to only one valid value for the 'flags' variable: DCB_RESET (Clears the bounding rectangle after returning it. If this flag is not set, the bounding rectangle will not be cleared.) I cannot figure out how to set or retrieve this value. Do I need to get this value from somewhere or do I need to initialize in my program before using? Any help would be appreciated.
I am fairly new to C# (coming from a Java background) and am using Visual Studio 2005 Professional.
TIA, Brian Enderle
Hi Brian,
Instead, try using GetWindowRect: http://tinyurl.com/bd7eb
-- Hope this helps, Tom Spink Br*****@gmail.com wrote: Thanks for the quick replies. GetWindowRect works great but brings up another question: I would like to have my transparent app lie within the client area of the other app. I can use GetClientRect to get the size of this area but how do I properly position it with respect to the other app, ie; how do I account for the frame, toolbars, etc.?
GetClientRect returns the size of the client rectangle but not the position of the rectangle within the window. Using Spy++ Client Rect. shows the coordinates of the client rectangle relative to the window but when I use the method (GetClientRect) within my program all I get is the rectangle size (598, 0, 799, 0).
Thanks again, Brian Enderle
Tom Spink wrote: Br*****@gmail.com wrote:
> I am attempting to create an app that will run "on top" of another app. > My app will create a transparent window over the other app for the > purpose of displaying information. > > I am able to create my transparent app but cannot get the size and > position of the other app. I can get the handle of the other app using > the DllImport("user32")...FindWindow method. However, when I try to > get this size/position of this other window using > DllImport("gdi32")...GetBoundsRect it does not assign any value to the > Rectangle object referenced by GetBoundsRect. > > I believe my problem lies in the 'flags' attribute of GetBoundsRect. > The method signature is as follows: > > [DllImport("gdi32.dll")] > public static extern int GetBoundsRect(int hWnd, // handle to window > ref Rectangle rect, // bounding rectangle > int flags); // function options > > > All of the documentation I have found on this method refer to only one > valid value for the 'flags' variable: DCB_RESET (Clears the bounding > rectangle after returning it. If this flag is not set, the bounding > rectangle will not be cleared.) I cannot figure out how to set or > retrieve this value. Do I need to get this value from somewhere or do > I need to initialize in my program before using? Any help would be > appreciated. > > I am fairly new to C# (coming from a Java background) and am using > Visual Studio 2005 Professional. > > TIA, > Brian Enderle
Hi Brian,
Instead, try using GetWindowRect: http://tinyurl.com/bd7eb
-- Hope this helps, Tom Spink
Hi Brian,
Are you still trying to pass a System.Drawing.Rectangle as the parameter?
This won't work, because GetWindowRect and related functions using a 'Rect'
structure are not the right layout. You'll need to do something like this:
///
[StructLayout(LayoutKind.Sequential)]
public struct NativeRect
{
public int left;
public int top;
public int right;
public int bottom;
}
///
(This is all from memory, I think I got the attribute right)
Then pass a NativeRect in as the parameter, this should give you the correct
rectangle co-ordinates.
--
Hope this helps,
Tom Spink This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Michael Bierman |
last post by:
Please forgive the simplicy of this question. I have the following code
which attempts to determine the color of some text and set other text
to match that color. It works fine in Firefox, but does...
|
by: fleemo17 |
last post by:
My organization is developing a set of "standards" for websites built
inhouse. The first question that comes to mind is what would be a good
standard default size for <p> text? 12 point? Which...
|
by: Stuart Norris |
last post by:
Dear Group,
I am having a problem setting SocketOptionName.SendTimeout on a client
TCPIP application using the sockets in .NET. From the on-line help it
is possible to set a...
|
by: Microsoft |
last post by:
I'm not sure where to physically place my subroutines in vb.net I get
namespace and not declared errors...
Imports System
Imports System.Management
Public Class Form1
|
by: Roger Withnell |
last post by:
How to I find out what size text the browser is set to?
Thanks in anticipation.
|
by: DBC User |
last post by:
I came across the application setting feature today and it is pretty
cool. I would like to know if someone can help me in the following
situation.
In my current project, On form closing I take the...
|
by: windows_mss |
last post by:
When I Select Source & Destination Dynamically,
Path Getting Scatter Across The Map...
hi,
i can able to get the Correct Route and Path for the corresponding Source
and destination, like...
|
by: Andrus |
last post by:
..NET 2 Winforms application.
How to create new setting and set it default value in userSettings section
of app.config file or overwrite existing setting value ?
I found code below in this list...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |