[comp.windows.ms.programmer] New Instance x,y offset.

schansen@amc.com (Scott Hansen) (05/10/91)

I have a relatively novice question in regards to multiple instances of
a program.  I would like to offset each instance's x,y position when a
new copy is executed.  It is easy to tell if multiple copies are running
with 'hPrevInstance', but I what to be able to pass the previous intance's
x,y to the new copy for offsetting.

I tried using 'GetInstanceData()' but I don't think I fully understand its
usage.  Any tips or suggestions would be greatly appreciated.

-Scott



-- 
==============================================================================
Scott Hansen (schansen@amc.com)           Sysop...:  The Crystal Chip 
Applied Microsystems Corporation          BBS.....:  (206) 226-6550    
Redmond, Washington  98073                Voice...:  (206) 882-5322

risto@tuura.UUCP (Risto Lankinen) (05/13/91)

schansen@amc.com (Scott Hansen) writes:

>I have a relatively novice question in regards to multiple instances of
>a program.  I would like to offset each instance's x,y position when a
>new copy is executed.  It is easy to tell if multiple copies are running
>with 'hPrevInstance', but I what to be able to pass the previous intance's
>x,y to the new copy for offsetting.

>I tried using 'GetInstanceData()' but I don't think I fully understand its
>usage.  Any tips or suggestions would be greatly appreciated.

Hi!

Use the FindWindow() to get the hWnd of the previous instance, then use the
GetWindowRect() to find out its size.

Or, to use GetInstanceData() there must be a global variable of type RECT,
where an instance stores its size (using the GetWindowRect() ) each time it
gets a WM_SIZE message.  An instance being initialized copies the initial
values of the RECT by using the GetInstanceData(), creates its window using
these values' calculated offset{-s}.  A nice touch would be to read the RECT
initial values from a private profile file for the first instance without
offsetting them at all, to inherit the size from the application's latest
ancestor (being careful with the very first invocation of the application,
when there's no profile entry for the size at all).

Terveisin: Risto Lankinen
-- 
Risto Lankinen / product specialist ***************************************
Nokia Data Systems, Technology Dept *  2                              2   *
THIS SPACE INTENTIONALLY LEFT BLANK * 2 -1 is PRIME!  Now working on 2 +1 *
replies: risto@yj.data.nokia.fi     ***************************************

kensy@microsoft.UUCP (Ken SYKES) (05/14/91)

In article <1991May9.190903.16601@amc.com> schansen@polaris.amc.com (Scott Hansen) writes:
>I have a relatively novice question in regards to multiple instances of
>a program.  I would like to offset each instance's x,y position when a
>new copy is executed.  It is easy to tell if multiple copies are running
>with 'hPrevInstance', but I what to be able to pass the previous intance's
>x,y to the new copy for offsetting.
>
>I tried using 'GetInstanceData()' but I don't think I fully understand its
>usage.  Any tips or suggestions would be greatly appreciated.
>
>-Scott

Here is how GetInstanceData works.  A given program has a set of variables
in its data segment (its globals).  The thing to note is the OFFSET of a
variable in a data segment remains the same, regardless of the number of
instances.  So GetInstanceData allows you to copy  global variable's 
contents from one instance to another by specifying the instance (to establish
the data segment) and the address of the global (to establish the offset.)
Make sense?

Ken Sykes
Disclaimer: The above opinions are solely my own.