473,500 Members | 1,830 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Determine the size & position of an external program window

HaLo2FrEeEk
404 Contributor
I'm updating a program that I wrote a few months back and I need to be able to determine the size and position of other program windows. I'm sure this is possible, but I just can't figure out how. I've tried Google and all of the results that I came up with were dead ends.

Basically I just need to see the location in screen coordinates and the size of the external window. How might I accomplish this?
Nov 4 '10 #1
3 15861
GaryTexmo
1,501 Recognized Expert Top Contributor
I'm wondering if the GetWindowRect function in User32.DLL can help you.

http://msdn.microsoft.com/en-us/libr...8VS.85%29.aspx

The only thing I'm unsure about here is how to get the hWnd of the other windows. I've been looking around but if I put you on the same track as I am, I'm sure you'll find it sooner :)

Here's the thread I found that got me thinking this is how you might do it.
http://stackoverflow.com/questions/3...-c-application

I took a quick glance through what's available in User32.DLL but didn't see anything outright, which doesn't mean it isn't there. I'll see if I can come back to this... but hopefully I've given you something to look into.
Nov 4 '10 #2
GaryTexmo
1,501 Recognized Expert Top Contributor
Ooooh!

http://www.daniweb.com/forums/thread185513.html
http://msdn.microsoft.com/en-us/libr...s.process.aspx

The Process class has a Handle property, so you might be able to get it from there. If you get a chance to try this before I do, let me know how it works! :)
Nov 4 '10 #3
HaLo2FrEeEk
404 Contributor
My apologies for taking so long to reply. I have managed to whip up some code that gathers a list of all running processes and allows me to get rectangle data for the active window. There are a few issues, for example the X and Y loations are correct, but since I have multiple monitors, for some reason my width and height are being displayed wrong. Each monitor is 1920x1200. I've got a window open that is 1696x1056, located at 2032x94, so my rectangle should be:

{X=2032, Y=94, Width=1696, Height=1056}

Intead it s returned as:

{X=2032, Y=94, Width=3728, Height=1150}

However, it seems to be as simple as subtracting the X from the Width and the Y from the Height to get the actual size of the window, so all I'd have to do is:

Expand|Select|Wrap|Line Numbers
  1. Rectangle rect = new Rectangle();
  2. GetWindowRect(hWnd, ref rect);
  3. rect.Width -= rect.X;
  4. rect.Height -= rect.Y;
And I'll have the correct coordinates and size of an external window.

Now I just have to figure out how to detect when I put MY program window over the external one. Hmmm...

I'm finishing up a screenshot program that I wrote that allows the user to position a rectangle anywhere on the screen, size it however they want, then push a button to take a screenshot of that portion of the screen. It started off as a test of my abilities, but it's grown up quite a bit. What I want to do with what I just learned is allow the user to drag the screenshot rectangle over an external window and allow them to lock the rectangle to that window. Armed with this new knowledge, I think I can do it.
Nov 12 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
4454
by: Matthew Maylin | last post by:
I'm trying to call a external program from another. My main program is a GUI buildin borland c++ builder, and my sibbling is compiled Matlab code. I would like to call to the program, passing...
5
8959
by: | last post by:
Maybe I ask something OS depended but maybe not. So I ask: I want to run an external program from my C++ program. I want stdin of external program constructed from a C++ string in my program....
2
2401
by: Cédric Rossé | last post by:
Hello, I have a web application (asp.net, c#) and I'd like to execute an external program (.exe or .cmd) in the server side (which runs the iis server) when the client press a simple button on ...
5
13627
by: ACaunter | last post by:
Hi, I was wondering if there was a way to set the browser window size and position of my asp.net website.. also if i could hide the address bar and buttons... this way i would have more room on...
6
1891
by: Charles Law | last post by:
Suppose my application is running on a client machine, and they report an intermittent problem. It only occurs after the program has been running for a while, and then occasionally fails to perform...
1
1546
by: notregister | last post by:
How do i call out an external program(e.g. abc.exe) while hiding my current window form. when i exit this external program, how do i re-show my window form?
2
1181
by: Tom McL. | last post by:
I have a program I am writing on my desktop computer with a screen resolution of 1024 by 768 when I run the program on my laptop with a screen resolution of 1280 by 768. the size and position of...
8
2200
by: Keith French | last post by:
I am trying to launch an external program within Visual Basic 2005 Express. If it is a simple program it works well with:- myProg = "C:\MyFolder\MyApp.exe"...
3
2063
by: | last post by:
Is there an automatic way to tell a windows to save its size and position, or do I have to save these parameters to the registry when the form quits and then reload them next time?
1
3293
by: ChrisJensen | last post by:
Hello! I'm currently trying to fill in a dialogue box (from an external program) using a VB.Net app. I've succeeded in finding the window handle for the external program (using the...
0
7242
jinu1996
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...
1
6914
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7401
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4928
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4619
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3114
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3112
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
686
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
318
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.