What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Basic Questions - LaTeX

Basic Questions - LaTeX
Author: Message:
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
RE: Basic Questions - LaTeX
Ah, it seems like you ran into the same problem every developer goes through when learning to work with Interop.Allocate and memory structures. No worries, I've had the same thing as well. :)

Let's have a look at the RECT structure as defined by MSDN:
code:
typedef struct _RECT {
  LONG left;
  LONG top;
  LONG right;
  LONG bottom;
} RECT, *PRECT;
We first need to know the size of this structure. To do this, we make the sum of the size each individual type takes. In this case, we have 4 LONG values and each LONG takes 4 bytes, so we get 16 bytes as size.
js code:
var wndRect = Interop.Allocate(16);
We can then call GetWindowRect to fill this structure for us.
js code:
Interop.Call("user32.dll", "GetWindowRect", ChatWnd.Handle, wndRect);
As you can see, you were doing pretty well in fact! :D

Now we want to read the individual pieces of the memory structure. Unlike C++, a Plus! script doesn't actually "know" what structure you created, so you'll have to find out where your data is yourself and what type it is.

For instance, if we want to read the value for the left position. Looking back at the MSDN structure definition, we find that this is the first element in the structure, and that it's a LONG of 4 bytes. This means that we have to read the DWORD on position 0 (zero) to get the left position:
js code:
var wndLeft = wndRect.ReadDWORD(0);
On to the next element: the top position. This is the second element in the structure, thus there is one LONG before it. This means we can find it on position 4 in our structure, also as a DWORD. The right position will be 4 bytes further on position 8 and the bottom position will be at position 12.
js code:
var wndTop = wndRect.ReadDWORD(4);
var wndRight = wndRect.ReadDWORD(8);
var wndBottom = wndRect.ReadDWORD(12);
And there you have it! You just read a RECT structure! :D

For the OOP fans here, you can also do this with a nice object:
js code:
var objRect = {
    left:    wndRect.ReadDWORD(0),
    top:    wndRect.ReadDWORD(4),
    right:    wndRect.ReadDWORD(8),
    bottom:    wndRect.ReadDWORD(12)
};

[offtopic]
Blah, I've been beaten again while writing this way too long post.
Hah, at least I beat you here! :P
[/offtopic]

This post was edited on 06-18-2009 at 07:23 PM by Matti.
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
06-18-2009 07:22 PM
Profile E-Mail PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
Basic Questions - LaTeX - by Flippy on 06-17-2009 at 09:14 AM
RE: Basic Questions - LaTeX - by ryxdp on 06-17-2009 at 09:26 AM
RE: Basic Questions - LaTeX - by Flippy on 06-17-2009 at 09:48 AM
RE: Basic Questions - LaTeX - by Flippy on 06-17-2009 at 10:01 AM
RE: Basic Questions - LaTeX - by NanaFreak on 06-17-2009 at 10:11 AM
RE: RE: Basic Questions - LaTeX - by Flippy on 06-17-2009 at 10:14 AM
RE: Basic Questions - LaTeX - by NanaFreak on 06-17-2009 at 10:17 AM
RE: RE: Basic Questions - LaTeX - by Flippy on 06-17-2009 at 10:25 AM
RE: Basic Questions - LaTeX - by NanaFreak on 06-17-2009 at 10:30 AM
RE: Basic Questions - LaTeX - by Flippy on 06-17-2009 at 10:37 AM
RE: Basic Questions - LaTeX - by NanaFreak on 06-17-2009 at 10:51 AM
RE: Basic Questions - LaTeX - by Flippy on 06-17-2009 at 10:59 AM
RE: Basic Questions - LaTeX - by Matti on 06-17-2009 at 12:07 PM
RE: Basic Questions - LaTeX - by Flippy on 06-17-2009 at 12:23 PM
RE: Basic Questions - LaTeX - by Matti on 06-17-2009 at 01:49 PM
RE: Basic Questions - LaTeX - by Flippy on 06-17-2009 at 02:41 PM
RE: Basic Questions - LaTeX - by Flippy on 06-17-2009 at 03:07 PM
RE: Basic Questions - LaTeX - by CookieRevised on 06-17-2009 at 05:54 PM
RE: Basic Questions - LaTeX - by Flippy on 06-17-2009 at 06:14 PM
RE: Basic Questions - LaTeX - by CookieRevised on 06-17-2009 at 06:36 PM
RE: Basic Questions - LaTeX - by Flippy on 06-17-2009 at 07:38 PM
RE: RE: Basic Questions - LaTeX - by CookieRevised on 06-17-2009 at 08:27 PM
RE: Basic Questions - LaTeX - by Flippy on 06-17-2009 at 08:32 PM
RE: Basic Questions - LaTeX - by Flippy on 06-17-2009 at 08:38 PM
RE: Basic Questions - LaTeX - by NanaFreak on 06-17-2009 at 09:02 PM
RE: Basic Questions - LaTeX - by CookieRevised on 06-17-2009 at 09:27 PM
RE: Basic Questions - LaTeX - by Flippy on 06-17-2009 at 10:01 PM
RE: Basic Questions - LaTeX - by foaly on 06-17-2009 at 10:42 PM
RE: Basic Questions - LaTeX - by CookieRevised on 06-18-2009 at 01:42 AM
RE: Basic Questions - LaTeX - by Flippy on 06-18-2009 at 11:29 AM
RE: Basic Questions - LaTeX - by NanaFreak on 06-18-2009 at 11:43 AM
RE: Basic Questions - LaTeX - by Matti on 06-18-2009 at 12:03 PM
RE: Basic Questions - LaTeX - by Flippy on 06-18-2009 at 01:29 PM
RE: Basic Questions - LaTeX - by Matti on 06-18-2009 at 01:52 PM
RE: Basic Questions - LaTeX - by Flippy on 06-18-2009 at 03:32 PM
RE: Basic Questions - LaTeX - by Matti on 06-18-2009 at 03:56 PM
RE: Basic Questions - LaTeX - by Flippy on 06-18-2009 at 04:21 PM
RE: Basic Questions - LaTeX - by Matti on 06-18-2009 at 05:33 PM
RE: Basic Questions - LaTeX - by matty on 06-18-2009 at 05:36 PM
RE: Basic Questions - LaTeX - by Flippy on 06-18-2009 at 05:47 PM
RE: Basic Questions - LaTeX - by Flippy on 06-18-2009 at 06:11 PM
RE: Basic Questions - LaTeX - by Spunky on 06-18-2009 at 07:11 PM
RE: Basic Questions - LaTeX - by Matti on 06-18-2009 at 07:22 PM
RE: Basic Questions - LaTeX - by Flippy on 06-18-2009 at 07:23 PM
RE: Basic Questions - LaTeX - by Flippy on 06-18-2009 at 08:10 PM
RE: Basic Questions - LaTeX - by CookieRevised on 06-19-2009 at 09:14 AM
RE: Basic Questions - LaTeX - by Matti on 06-19-2009 at 01:43 PM
RE: RE: Basic Questions - LaTeX - by CookieRevised on 06-19-2009 at 10:24 PM
RE: Basic Questions - LaTeX - by Flippy on 06-19-2009 at 02:31 PM
RE: Basic Questions - LaTeX - by sabian2008 on 07-30-2009 at 03:38 PM
RE: Basic Questions - LaTeX - by Flippy on 07-30-2009 at 04:36 PM
RE: Basic Questions - LaTeX - by sabian2008 on 08-07-2009 at 01:01 AM


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