What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Structures with Allocate? How?

1 votes - 5 average   Structures with Allocate? How?
Author: Message:
Shondoit
Full Member
***

Avatar
Hmm, Just Me...

Posts: 227
Reputation: 15
35 / Male / Flag
Joined: Jul 2006
O.P. Huh?  Structures with Allocate? How?
I haven't worked on Interop.Allocate calls yet, but I'm trying to learn
I don't know how to create a structure...
I need:
WINDOWPLACEMENT {
   INT length;
   INT flags;
   INT showCmd;
   POINT ptMinPosition;
   POINT ptMaxPosition;
   RECT rcNormalPosition;
}

And I believe POINT is:
POINT {
   INT x
   INT y
}

If someone could give me a tut or something ^o) I would be most gratefull

I need this for GetWindowPlacement...
My scripts:                            [Image: shondoit.gif]
+ Timezone
+ Camelo
+ Multisearch
08-29-2006 10:41 PM
Profile PM Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15519
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: Structures with Allocate? How?
A structure is nothing more than a series of bytes. The trick is to know how much bytes...

For this you need to look at what the structures must contain:

(U)INT means an (unsigned) integer, this is 2 bytes long (also known as a WORD).

(actually these types in the WINDOWPLACEMENT structure are defined as UINTs, which are unsigned integers; there's a difference between INT - signed integers, and UINT - unsigned integers)

a POINT and a RECT are structures on their own, they are as long as the individual types used in the structure:

However a POINT structure is:

POINT {
  LONG x;
  LONG y;
}

Thus they are LONGs, not INTs. Since a LONG is 4 bytes (also known as a double word or DWORD) that makes this substructure 8 bytes in total. A RECT structure is defined as:

RECT {
  LONG left;
  LONG top;
  LONG right;
  LONG bottom;
}

thus that makes the RECT structure 16 bytes long.

If we add all this up we come to 3 INTs, 2 POINTs, 1 REC  or  3 INTs, 8 LONGs  or  38 bytes...

So we need to allocate 38 bytes with the Interop.Allocate function to create this particular datablock (aka structure).

code:
Var WINDOWPLACEMENT = Interop.Allocate(38);

Once we have that we either can use the pointer to this allocated memory as a place for the API to store the complete structure, or either we can start to fill the structure on our own with the needed stuff:
code:
WINDOWPLACEMENT.WriteWORD(0, WINDOWPLACEMENT.Size);  // UINT length
WINDOWPLACEMENT.WriteWORD(2, flags);                 // UINT flags
WINDOWPLACEMENT.WriteWORD(4, showCmd);               // UINT showCmd
WINDOWPLACEMENT.WriteDWORD(6, minx);                 // LONG ptMinPosition_x
WINDOWPLACEMENT.WriteDWORD(10, miny);                // LONG ptMinPosition_y
WINDOWPLACEMENT.WriteDWORD(14, maxx);                // LONG ptMaxPosition_x
WINDOWPLACEMENT.WriteDWORD(18, maxy);                // LONG ptMaxPosition_y
WINDOWPLACEMENT.WriteDWORD(22, left);                // LONG rcNormalPosition_left
WINDOWPLACEMENT.WriteDWORD(26, top);                 // LONG rcNormalPosition_top
WINDOWPLACEMENT.WriteDWORD(30, right);               // LONG rcNormalPosition_right
WINDOWPLACEMENT.WriteDWORD(34, bottom);              // LONG rcNormalPosition_bottom
Notice the byte positions at which we write the values of the variables (datablocks start at byte position 0, just as arrays, character positions, etc, not 1. Don't mess this up or your structure will be wrong and unexpected stuff might happen.

Reading the structure works in the same way (after it has been filled by the API of course):
code:
var flags = WINDOWPLACEMENT.ReadWORD(2);  // UINT flags

To use the structure in an API call:
code:
Interop.Call('user32.dll', 'GetWindowPlacement', hWnd, WINDOWPLACEMENT.DataPtr);

-------------

Note that the above code can be made shorter:
code:
with (WINDOWPLACEMENT) {
      WriteWORD(0, Size);     // UINT length
      WriteWORD(2, flags);    // UINT flags
      WriteWORD(4, showCmd);  // UINT showCmd
      etc...
}
use the 'with' statement...

and:
code:
Interop.Call('user32.dll', 'GetWindowPlacement', hWnd, WINDOWPLACEMENT);
DataPtr is the default method when you pass a datablock to the Call method.

;)

This post was edited on 08-30-2006 at 12:29 AM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
08-29-2006 11:47 PM
Profile PM Find Quote Report
Shondoit
Full Member
***

Avatar
Hmm, Just Me...

Posts: 227
Reputation: 15
35 / Male / Flag
Joined: Jul 2006
O.P. RE: Structures with Allocate? How?
Thank you very much, it became a lot clearer now (Y)
My scripts:                            [Image: shondoit.gif]
+ Timezone
+ Camelo
+ Multisearch
08-29-2006 11:52 PM
Profile PM Find Quote Report
deAd
Scripting Contest Winner
*****

Avatar

Posts: 1060
Reputation: 28
– / Male / Flag
Joined: Jan 2006
RE: Structures with Allocate? How?
http://shoutbox.menthix.net/showthread.php?tid=63...d=702413#pid702413

That post is pretty useful when you're working with DataBlocs :)
08-30-2006 12:05 AM
Profile PM Find Quote Report
Shondoit
Full Member
***

Avatar
Hmm, Just Me...

Posts: 227
Reputation: 15
35 / Male / Flag
Joined: Jul 2006
O.P. RE: Structures with Allocate? How?
Lol, I was just reading that when I got a new Alert mail, for a new reply :D
Thanks for the extra info
My scripts:                            [Image: shondoit.gif]
+ Timezone
+ Camelo
+ Multisearch
08-30-2006 12:07 AM
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