473,326 Members | 2,588 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Getting window position from IntPtr window handle

Hi

I am looking for a way in C# to use a IntPtr handle to a (possibly
unmanaged) windows form to get the current position of the window on
the desktop. I have tried using Form.FromHandle( handle ) but this
does not work for non .NET windows.

I am expecting to need to use SendMessage somewhere along the line,
but cannot find the correct message to get the window position. Also,
is there a way to perform simple operations on a window such as
BringToFront?

Any help would be very much appreciated!
Many Thanks

Matt
Nov 16 '05 #1
1 15757
Matt,

If you want to get the current position of any window, given the handle,
you can call GetWindowRect through the P/Invoke layer to get the position of
the window relative to the screen.

As for calling BringToFront, I would actually try and get the Control
instance for the window handle. If it exists, then call BringToFront,
otherwise, I would then cobble together code that does it manually (the .NET
control might have an override of BringToFront which has functionality you
want to preserve).

If you have to, you can probably call SetWindowPos to set the Z-order of
the window so that it is at the top of the stack.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Matt" <cs***@fsmail.net> wrote in message
news:d3**************************@posting.google.c om...
Hi

I am looking for a way in C# to use a IntPtr handle to a (possibly
unmanaged) windows form to get the current position of the window on
the desktop. I have tried using Form.FromHandle( handle ) but this
does not work for non .NET windows.

I am expecting to need to use SendMessage somewhere along the line,
but cannot find the correct message to get the window position. Also,
is there a way to perform simple operations on a window such as
BringToFront?

Any help would be very much appreciated!
Many Thanks

Matt

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: DraguVaso | last post by:
Hi, My application has some interaction with an other application. I sometimes need to put the other application to the front. The problem is that I'm not able to get a nice solution to work in...
5
by: DraguVaso | last post by:
Hi, How can you see with a VB.NET-application if the Window of another Application (for exemple an opened Word-Document) is Mimized? Is there also a way to see if it is Maximized? Thanks a...
0
by: Matt Warner | last post by:
Hi guys, A couple of people have already posted questions about similar issues but haven't had any response. Occasionally, sometimes after running the app for a few hours, it bombs out saying...
6
by: DraguVaso | last post by:
Hi, In my application, on some given actions while debugging in Visual Studio, I suddenly get a "System.ComponentModel.Win32Exception was unhandled" Message="Error creating window handle."...
3
by: Christian Westerlund | last post by:
Hi! Does anyone know how to take a "screendump" of a single window? I have tried with some code I found on the Internet but I end up with a picture of the screen with the size of the window. I...
11
by: objectref | last post by:
Hi to all, is there a way to get the window handle of the main window of an application or process ? For example, if someone opens Microsoft Word, he gets a window so he/she can write text....
6
by: kurotsuke | last post by:
Hi, I need to know the position (X, Y cohordinates) of the caret. I'm using the function: private static extern int GetCaretPos(ref POINT lpPoint); I'm actually getting a result but I...
11
by: garyusenet | last post by:
For this first time today I used the System.Diagnositcs namespace to launch a program from my c# code. The program launches OK but I have something which has completely stumped me. The...
2
by: witpo | last post by:
Hi, I would like to display all listview items in one row with scroll bar below it – instead of multiple rows and scroll bar on the right. Someone told me that I can achieve it using...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.