PDA

View Full Version : Programmatically calling Toolbar buttons



Kevin_Williams
11-29-2006, 12:15 PM
Hi,
I was wondering if there was a way to programmatically the toolbar buttons.
I want to make my own custom toolbar instead of using mappoint's navigation and drawing toolbars.
TIA

Wilfried
11-29-2006, 02:06 PM
Hi,

You can send messages for it. There is an article somewhere on this site. Try a search on 'accessing hidden features' or something similar.

Wilfried
11-29-2006, 02:07 PM
Hi,

found it: http://www.mapforums.com/access-some-hidden-features-mappoint2002-activex-control-1118.html?highlight=hidden+features

Kevin_Williams
11-30-2006, 08:05 PM
thanks for the quick response
i tried downloading the zip files, but it seems like the URL is no longer valid...:(

Wilfried
12-01-2006, 08:17 AM
Hi,

This article points the things out: Extending the MapPoint ActiveX Control - Pt. I - MapPoint Articles - MP2K Magazine (http://www.mp2kmag.com/articles.asp?ArticleID=88)

I dont know about the Url. Can you maybe try to contact the author?

Kevin_Williams
12-01-2006, 08:23 PM
Thanks WilFried
I read Extending the MapPoint ActiveX Control - Pt. I (http://www.mp2kmag.com/a88--ActiveX.MapPoint.extend.mappoint.html) and Extending the MapPoint ActiveX Control - Pt. II (http://www.mp2kmag.com/a96--ActiveX.Extending.Spy.mappoint.html) and I think I understand how it works.

I'm trying to implement this in C#.
I saw your code in the "Access some hidden features" thread and it was pretty helpful.

I think I have all the pieces, but I'm not sure how to FindChildWindow in C#...

Wilfried
12-02-2006, 03:56 AM
Hi,

I think it is just a class method to return the windows handle. I think you can use FindWindow. It take the classname and windowcaption, both are optional, it returns the handle. In C# like this:


[DllImport("User32.dll")]
public static extern IntPtr FindWindow(string ClassName, string WindowName);

Kevin_Williams
12-05-2006, 01:20 PM
thanks so much for all your help Wilfried
i got most of the stuff i wanted to work

i pretty much used the Extending the MapPoint ActiveX control guide to understand the concept.
from there, i did my code in C#

these are the class method i used


[DllImport("user32.dll", EntryPoint = "FindWindowA")]
private static extern IntPtr FindWindow(string className, string windowTitle);
[DllImport("user32.dll")]
private static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string className, IntPtr windowTitle);
[DllImport("user32.dll")]
private static extern Boolean PostMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);


i found the map point handle as mentioned in the article (i'm using mappoint 2006)


private const uint WM_COMMAND = 0x111;
IntPtr hwnd;
IntPtr mapPointHwnd ;

hwnd = FindWindow(null, Resources.APP_TITLE);
hwnd = FindWindowEx(hwnd, IntPtr.Zero, "ATL:10024320", IntPtr.Zero);
hwnd = FindWindowEx(hwnd, IntPtr.Zero, "ATL:100240A0", IntPtr.Zero);
mapPointHwnd = FindWindowEx(hwnd, IntPtr.Zero, "AfxFrameOrView70", IntPtr.Zero);


i used spy++ to find the WM_COMMANDs and used PostMessage to invoke the command i wanted in my program


// this invokes the scribble draw tool
PostMessage(mapPointHwnd, WM_COMMAND, 58205, 0);

Wilfried
12-05-2006, 02:35 PM
Hi,

thx for feedback it sure will benefit other user.

faniemeiring
03-07-2007, 08:42 AM
A small change to Kevin's code made it work for me.
If the map control is contained on any other component than the form (or window) itself it did not work for me:


hwnd = FindWindow(null, Resources.APP_TITLE);
This line of code finds the handle to the form your control is contained on and can be replaced by:

hwnd = myForm.Handle;
SO: if your control is on anything other than the form you can use:

hwnd = myPanel.Handle;
or

hwnd = myToolStripContainer1.ContentPanel.Handle; //in my case
Then the rest is as Kev had it before:


hwnd = FindWindowEx(hwnd, IntPtr.Zero, "ATL:10024320", IntPtr.Zero);
hwnd = FindWindowEx(hwnd, IntPtr.Zero, "ATL:100240A0", IntPtr.Zero);
mapPointHwnd = FindWindowEx(hwnd, IntPtr.Zero, "AfxFrameOrView70", IntPtr.Zero);

Thanks for all the posts and code to solve this. It makes life easier...

Kevin_Williams
03-07-2007, 11:54 AM
i found out the other day that using "ATL:10024320" and "ATL:100240A0" might not work for all computers.


hwnd = FindWindowEx(hwnd, IntPtr.Zero, "ATL:10024320", IntPtr.Zero);
hwnd = FindWindowEx(hwnd, IntPtr.Zero, "ATL:100240A0", IntPtr.Zero);
i had my application installed on another computer and it didn't work because "ATL:10024320" was another set of number "ATL:########"

[/URL]the article implemented a FindChildWindow() function to do a partial match on the string "ATL:".
[URL]http://www.mp2kmag.com/downloads/mpvbtest1.zip (http://www.mp2kmag.com/downloads/mpvbtest1.zip)

i was too lazy to implement a string comparison, so i used GetWindow() to just grab the child:


[DllImport("user32.dll")]
private static extern IntPtr GetWindow(IntPtr hWnd, uint uCmd);
private const uint GW_CHILD = 5;

hwnd = GetWindow(hwnd, GW_CHILD); // get the first "ATL:########"
hwnd = GetWindow(hwnd, GW_CHILD); // get the second "ATL:########"
mapPointHwnd = FindWindowEx(hwnd, IntPtr.Zero, "AfxFrameOrView70", IntPtr.Zero);

DrNobody
03-19-2007, 04:50 AM
Thanks WilFried
...but I'm not sure how to FindChildWindow in C#...

Hi.

May be this WIN32 API function will be helpfull:

BOOL EnumChildWindows(
HWND hWndParent,
WNDENUMPROC lpEnumFunc,
LPARAM lParam)

Gianmaria
07-31-2007, 04:56 PM
Hi Kevin,
i'm reading your cod to access the hidden features of MapPoint. Did you find a way to "press" the DrawCircle n the Drawing toolBar?
Can you show me some code in c# to do it?

Regards,
Gianmaria