What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » How to get the coordinates of the window on the desktop?

How to get the coordinates of the window on the desktop?
Author: Message:
matoja
New Member
*


Posts: 5
Joined: Oct 2010
O.P. RE: Problem Packing
I have one question not related to this. How to get the coordinates of the window on the desktop? if someone knows that ,please write a sample code, I looked at win32 know how to set  parameter with call like "MoveWindow", but don't know how to read one.
I tried with Call2 but no luck.

What i am doins it thet i whant one window folowing other , so if i move one window with mouse other one need to folow thet one.

I will use "MoveWindow" for moving second window , but i need cordinates of first one so i can know where to move second one.
:)
10-30-2010 10:40 PM
Profile E-Mail PM Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15519
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: Problem Packing
There are a couple of APIs you can use to get the windows' positions. The difference is in how they return the coordinates and in what form and what extra info they can return (other info you might need btw).

Note that since you're planning to use the MoveWindow API the coordinates need to be in screen coordinates. So it might be needed to convert the returned coordinates or width and height into screen coordinates first. But also note that you can also use the SetWindowPos API which makes it also possible to set the Z-order of the window. Which is actually something you'd might to consider if you want to make a window 'following' another window, while being visible but remaining inactive, depending on what that 'following' window exactly is meant to do.

The GetWindowRect is the simpliest API you can use to get coordinates. It returns the dimensions in a RECT structure as screen coordinates.

The GetWindowInfo returns the window coordinates in the rcWindow member of the returned WINDOWINFO structure.

The GetWindowPlacement returns the state and the restored, minimized, and maximized positions of a window in the returned WINDOWPLACEMENT structure.

But, depending on what the function is of that 'following' window, you might also want to consider using an API like GetClientRect which will, like GetWindowRect, return dimensions in a RECT structure, but for the client area of the window. Which is the area inside the borders of the window. Because borders are not always the same size, especially not across different Windows versions, it is not as easy as subtracting or adding a fixed number to compensate for the border width. That is something you should never do and is bound to give you problems and wrong results. Hence the use for the GetClientRect API.

---

If you ever come across another similar problem of not knowing what API to use. You can look in the MSDN library for the list of available APIs by subject. For APIs regarding windows you have the list here.

---

PS: To make a window 'following' another window, you need that main window to be subclassed so that your code is informed when that main window is moved around, minimized, restored, destroyed, etc... The poor-man's solution is to use a timer which checks the main window every so often, but this is really something you should try to avoid to do for various reasons, especially performances reasons!! It is also considered bad coding in many cases. Also consider making that main window a parent of the 'following' window (see parent/child systems).

This post was edited on 10-31-2010 at 05:46 PM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
10-31-2010 10:34 AM
Profile PM Find Quote Report
matoja
New Member
*


Posts: 5
Joined: Oct 2010
O.P. RE: How to get the coordinates of the window on the desktop?
Thank you for your good advice.
Maybe I was not clear with the question, I was curious how to get that information back from some functions (I use msdn constant), and the problem was a pointer. I program with C, C + + and there you can specify a pointer int * a; , and the address &a and similarly. Since there is no such option I thought that JavaScript automatically detects when the pointer is a var;. A friend found it in JavaScript there are no such pointers and took advantage of MPLSScripting Interop.Allocate (), for it come to data.
Now I can continue to adventure through JavaScript. :)
10-31-2010 12:56 PM
Profile E-Mail PM Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15519
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: How to get the coordinates of the window on the desktop?
Correct. Generally speaking you can't use Windows APIs in Javascript. But Plus! scripting does allows this thru the use of its own Interop commands (see the Plus! Scripting Help file). It also allows you to create allocated memory spaces (which is in essence all what a pointer is) and thus allows you to get and set data structures, needed for interacting with many Windows APIs.

I have some alcohol in my body :p, so  beware of mistakes :p.... schol

This post was edited on 10-31-2010 at 05:53 PM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
10-31-2010 05:52 PM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On