.net and integration

331 views
Skip to first unread message

Hank Finley

unread,
Feb 15, 2010, 12:45:03 AM2/15/10
to MapInfo-l
Hi,

just checking out the user guide, and it says you can embed a map into an external program, just curious whether it is possible to embed the actual application window so as you when you want to, you can view table browsers, maps, etc. Or is it that you can create a container then add these different windows to it?
If it is the later, can you still minimize, maximize and shift these sub windows as you would in MapInfo?

Thanks Hank

Lars I. Nielsen (GisPro)

unread,
Feb 15, 2010, 1:36:54 AM2/15/10
to mapi...@googlegroups.com
Hi Hank,

You may or may not be able to reparent Pro's main window, but I doubt it.

One thing to understand about "embedded" windows, is that Pro still maintains these windows behind the scenes, even though they gui-wise seem to be a part of another program. Pro creates the child windows (mappers, browsers etc.) and normally inserts itself as their "parent". What embedding these windows into another app involves, is just inserting another app as their (gui) "parent". However, such re-parenting is only a gui thing, not a real behind-the-scenes integration.

So first of all, MapInfo Pro needs to be installed on any machine that will run your app. Then you need to recognize that Pro is a COM based app, not .net, so you need to create a connection to it as such. And lastly you need to feed Pro with MapBasic commands to create and maintain the child windows you want to embed. Not your normal kind of .net embedding :-)


Best regards / Med venlig hilsen
Lars I. Nielsen
GIS & DB Integrator
GisPro


Hank Finley skrev:
--
You received this message because you are subscribed to the Google Groups "MapInfo-L" group.
To post to this group, send email to mapi...@googlegroups.com.
To unsubscribe from this group, send email to mapinfo-l+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mapinfo-l?hl=en.

Nathan Woodrow

unread,
Feb 15, 2010, 5:41:33 PM2/15/10
to MapInfo-L
Hank,

You can re-parent the whole MapInfo Pro application window if you
wish, however I am not sure when you would want to do this and might
give a bad user experience if done wrong.

But if you really want to do it then here is some C# code that will
work(just tested it), first add a picture box to your form then add
this code somewhere:

==CODE====

[DllImport("User32", CharSet = CharSet.Auto, ExactSpelling = true)]
internal static extern IntPtr SetParent(IntPtr hWndChild, IntPtr
hWndParent);

public void DoIt()
{
// Start MapInfo.
MapInfoApplication mapinfo = new MapInfoApplication();
// Get the handle
string handle = mapinfo.Eval("SystemInfo(9)");
IntPtr oldhandle = new IntPtr(Convert.ToInt32(handle));
mapinfo.Visible = true;
// Set the parent to the picture box.
SetParent(oldhandle, this.pictureBox1.Handle);
}

==END CODE===

the result should look something like this:

http://mapinfo-l.googlegroups.com/web/Re-parented%20whole%20MapInfo%20Pro%20application.bmp?gsc=iUB4JwsAAADGQzNB3-1qa5S0sLkLMKDM

Hope this helps.
Nathan

Hank Finley

unread,
Feb 15, 2010, 11:21:46 PM2/15/10
to mapi...@googlegroups.com
Hi Nathan,

I've got a package piece of software that I'd like MapInfo to be a part of, all my users already have Pro 10 and I'd like to give a more translucent feel.

The image at the link is exactly what I'm looking for. Is there also a way to get rid of the bar at the top? Not the menus just the window bar.

Thanks so far Hank

Nathan Woodrow

unread,
Feb 15, 2010, 11:57:44 PM2/15/10
to mapi...@googlegroups.com
Sure just add this code:

        //Sets window attributes
        [DllImport("USER32.DLL")]
        public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);

        //Gets window attributes
        [DllImport("USER32.DLL")]
        public static extern int GetWindowLong(IntPtr hWnd, int nIndex);

        //assorted constants needed
        public static int GWL_STYLE = -16;
        public static int WS_CHILD = 0x40000000; //child window
        public static int WS_BORDER = 0x00800000; //window with border
        public static int WS_DLGFRAME = 0x00400000; //window with double border but no title
        public static int WS_CAPTION= WS_BORDER | WS_DLGFRAME; //window with a title bar

and in a the DoIt method I had before, use 

         //get current window style of child form
         int style = GetWindowLong(oldhandle, GWL_STYLE);
         //take current window style and remove WS_CAPTION from it
         SetWindowLong(oldhandle, GWL_STYLE, (style & ~WS_CAPTION));
         //Max the MapInfo pro window to take up the whole control.
         mapinfo.Do("Set Window 1011 Max");

after the SetParent call.

Hope this helps.

Nathan Woodrow

unread,
Feb 19, 2010, 1:21:00 AM2/19/10
to MapInfo-L
Hi All,

I have posted this information on my blog, so it is a bit easier for
people to find it later if needed:

http://woostuff.wordpress.com/2010/02/19/embedding-the-whole-mapinfo-application-in-a-net-form/

Regards,
Nathan

> > On Tue, Feb 16, 2010 at 8:41 AM, Nathan Woodrow <madman...@gmail.com>wrote:
>
> >> Hank,
>
> >> You can re-parent the whole MapInfo Pro application window if you
> >> wish, however I am not sure when you would want to do this and might
> >> give a bad user experience if done wrong.
>
> >> But if you really want to do it then here is some C# code that will
> >> work(just tested it), first add a picture box to your form then add
> >> this code somewhere:
>
> >> ==CODE====
>
> >> [DllImport("User32", CharSet = CharSet.Auto, ExactSpelling = true)]
> >> internal static extern IntPtr SetParent(IntPtr hWndChild, IntPtr
> >> hWndParent);
>
> >> public void DoIt()
> >> {
> >>            // Start MapInfo.
> >>            MapInfoApplication mapinfo = new MapInfoApplication();
> >>            // Get the handle
> >>            string handle = mapinfo.Eval("SystemInfo(9)");
> >>            IntPtr oldhandle = new IntPtr(Convert.ToInt32(handle));
> >>            mapinfo.Visible = true;
> >>            // Set the parent to the picture box.
> >>            SetParent(oldhandle, this.pictureBox1.Handle);
> >> }
>
> >> ==END CODE===
>
> >> the result should look something like this:
>

> >>http://mapinfo-l.googlegroups.com/web/Re-parented%20whole%20MapInfo%2...


>
> >> Hope this helps.
> >> Nathan
>
> >> On Feb 15, 3:45 pm, Hank Finley <asse...@gmail.com> wrote:
> >> > Hi,
>
> >> > just checking out the user guide, and it says you can embed a map into
> >> an
> >> > external program, just curious whether it is possible to embed the
> >> actual
> >> > application window so as you when you want to, you can view table
> >> browsers,
> >> > maps, etc. Or is it that you can create a container then add these
> >> different
> >> > windows to it?
> >> > If it is the later, can you still minimize, maximize and shift these sub
> >> > windows as you would in MapInfo?
>
> >> > Thanks Hank
>
> >> --
> >> You received this message because you are subscribed to the Google Groups
> >> "MapInfo-L" group.
> >> To post to this group, send email to mapi...@googlegroups.com.
> >> To unsubscribe from this group, send email to

> >> mapinfo-l+...@googlegroups.com<mapinfo-l%2Bunsubscribe@googlegroups .com>


> >> .
> >> For more options, visit this group at
> >>http://groups.google.com/group/mapinfo-l?hl=en.
>
> >  --
> > You received this message because you are subscribed to the Google Groups
> > "MapInfo-L" group.
> > To post to this group, send email to mapi...@googlegroups.com.
> > To unsubscribe from this group, send email to

> > mapinfo-l+...@googlegroups.com<mapinfo-l%2Bunsubscribe@googlegroups .com>

Reply all
Reply to author
Forward
0 new messages