473,383 Members | 1,805 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,383 software developers and data experts.

Determine the size & position of an external program window

HaLo2FrEeEk
404 256MB
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 15828
GaryTexmo
1,501 Expert 1GB
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 Expert 1GB
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 256MB
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
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
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
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
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
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
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
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
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
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
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...
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...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
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,...
0
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$) { } ...
0
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...
0
BarryA
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.