PDA

View Full Version : By Right-click displaying context menu on map



Banu
02-24-2006, 02:43 PM
Right-click on a pushpin shows up a context menu. I want to display my own context menu by right-click on a pushpin instead of the default context menu. Any help will be appreciated.

Thanks

Wilfried
02-25-2006, 01:28 AM
Hi,

Install an event handler in BeforeClick event. 1 of the arguments is Cancel. If you set this to True the popupmenu will never popup.

If you wants to popup your own menu, then do it outside the event handler. If you do not and a user does not click within 10 seconds you will have the Server Busy popup from mappoint. This is because a popup menu is nothing more than a modal form.

ayla
02-27-2006, 07:20 AM
Hi Wilfried,
I have exactly the same problem as Banu. I followed your suggestion of creating an event handler for Beforeclick mappoint event and forcing the argument Cancel to be TRUE. But unfortunately, the default mappoint context menu appears.
Do you may be know the reason for this behaviour? Or how I can solve it in another way.
Thank you very much,

Wilfried
02-27-2006, 08:35 AM
Hi,

I just tryed the following:


private void MP_BeforeClick_1(object sender, AxMapPoint._IMappointCtrlEvents_BeforeClickEvent e)
{
if (e.button == 2)
e.cancel = true;


I I have no popup if I click right mouse butten. Did you do something different ?

ayla
02-27-2006, 11:01 AM
Hi,
here you have my code, I think I am doing exactly the same, don't I?
I debugged teh routine and every time that I right-clicked on the map, the function is executed the if clause is true but the default mappoint message
still appears.


void CMyAppView::OnBeforeClickMapMp(long Button, long Shift, long X, long Y, BOOL FAR* Cancel)
{
if(Button == MY_MOUSE_RIGHT_CLICK)
{
//mappoint popup menu will never popup
*Cancel = TRUE;

}
}

Thank you for your help!

Wilfried
02-28-2006, 12:39 PM
Hi,

You do indeed exacly the same. Hmm thinking...

Unless there is a bug in the TRUE. "Normally" 0 is false, and antithing that is not 0 is true. I recall my one of the Delphi versions (I think 2) where Borland wrote a bug in such a way that they interpreted -1 as True, 0 as false, but any other number was also false. This was leading to problems interfacing with win32 API and also with other apps (COM/DLL) of course.

So what if there is such a bug ? Is this C ? Then you can try it, because in C you can assign almost anything to anithing:

*Cancel = -1;
*Cancel = (!0);
*Cancel = 0xFFFF;
... or other combinations ...

Banu
03-01-2006, 07:13 AM
Hi Wilfried,

I can successfully hide mappoint's menu, but having problem with showing my menu. The syntax to show a context menu is

Show(Control control, Point pos)

What do I pass for control, MapPoint application is not a control. How do I tell menu to pop up on the mappoint window.

Thanks

Wilfried
03-01-2006, 02:11 PM
Hi,

is this C# ?

Then you have a lots of overload method. Try:


PopupMenu.Show(MousePosition);

Banu
03-06-2006, 09:58 AM
Yes, it is C# 2005. Under my MSDN library I don't see any class by PopupMenu name. Is it a third party tool? By further search I found "DataDynamics.SharpUI.Toolbars.PopupMenu" class. Is this same class you are talking about. If not then can you tell me the name of namespace, PopupMenu class lies under.

Wilfried
03-06-2006, 12:46 PM
Hi,

PopupMenu was the name I given it. Sorry to be confusing :(

No tirth party. I also use VS2005. it is in:
System.Windows.Forms.ContextMenuStrip.

And the ContexMenuStrip is in the toolbox in Menu's and toolbars. I think it is default there as I just upgraded from Beta2 to full version and I see it there.

Banu
03-07-2006, 09:26 AM
Hi Wilfried,

I need to update myself with VS2005 :) . On map's right-click event I can make it to show a messagebox or any modal window by starting new thread. But ContextMenu does not show up. On the same thread it does not paint itself properly, but can see its boundary. Showing it on new thread does not do anything.

Thanks for bearing with me and for your great help.

Wilfried
03-07-2006, 03:29 PM
Hi,

You cannot show a message box in another thread. You have to show it in the same thread context of the main GUI thread.

Be very carefull with thread in dotNet !!!

Banu
03-08-2006, 01:08 PM
Hi Wilfried,

It's working now. Thanks for helping me.

Wilfried
03-09-2006, 02:39 PM
Hi,

Thx for feedback.I'm glad it works for you

skylord5816
10-02-2007, 10:48 PM
How do you prevent the popping up of the context menu on your site and make an alert box if anybody rightclicks anywhere on the document in plain old HTML? I have tried onRightClick, and onContextMenu. The box comes up, but it doesn't stop the context window from coming up. Please help soon.

Wilfried
10-03-2007, 11:49 AM
Hi,

Do you mean with the MP control ? There is a parameter Cancel that can be set to true. About HTML you cannot, you need to use JavaScript.

skylord5816
10-03-2007, 08:11 PM
Can you use JS w/ HTML??? I tried, and it worked. Some JS scripts I tried on HTML:
<html>
<title>
Scripting
</title>
<body>
<fieldset>
<legend>
Scripts
</legend>
<BODY onContextMenu="javascript:alert(...')">
<BODY onLoad="javascript:alert(...')">
<A NAME="top">Welcome to the Top!
<A HREF="#nbop">Click here to go back!</A><br>(2nd time through)<br>
</HEAD>
<BODY BGCOLOR="FFFFFF" TEXT="000000" LINK="0000FF" VLINK="800080" ALINK="FF0000">
<P>&nbsp;<P><P>&nbsp;<P>
<br><br><br><br><br><br><br>
<CENTER>
<FONT SIZE="+2"><A HREF=""onMouseOver="document.bgColor='black'">Black</a>
<A HREF=""onMouseOver="document.bgColor='green'">Green</a>
<A HREF=""onMouseOver="document.bgColor='yellow'">Yellow</a>
<A HREF=""onMouseOver="document.bgColor='red'">Red</a>
<A HREF=""onMouseOver="document.bgColor='brown'">Brown</a>
<A HREF=""onMouseOver="document.bgColor='white'">White</a>
</FONT></CENTER><br>Color onMouseOver<br>
<A HREF="... (http://play.clubpenguin.com/load.swf)" onMouseOver="window.status=
...'; return true">Club Penguin</A>.<br>
<A HREF="... (http://www.runescape.com)" onMouseOver="window.status='...'; return true" onMouseOut="window.status=
'...'; return true">Runescape</A><br>
<A HREF="..."
onMouseOver="parent.location=...";>Dude!</A>o<br>
<A HREF="..."
onMouseOver="alert('...')";>...</A><br>
<A HREF="..."
onClick="alert('...')";>...</A><br>
<FORM>
<INPUT TYPE="button" VALUE="BACK"
onClick="history.go(-1)">
<INPUT TYPE="button" VALUE="FORWARD"
onClick="history.go(1)">
</FORM>OnClick FormBut. Hist<br>
<FORM>
<INPUT TYPE="button"
VALUE="Click To Go To the Bottom Of The Page"
onClick="parent.location='#code'">
</FORM>WIpagel<br>
<FORM>
<INPUT TYPE="button" VALUE="Click Here to Write to Me"
onClick="parent.location='mailto:...'">
</FORM>Mailto<br>
<A NAME="nbop">
<A HREF="#top">Top of Page onClick</A><br>
</fieldset>
<A NAME="code">
</body>
</html>

Of course I used different things instead of ellipses dots.
But can you show me how to altogether eliminate the context bar and display an alert??? This one shows the alert, but doesn't block the context menu (the code for the context menu is near the top).
This is HTML, and the site I learned if off of told me it was also JS. What is going on??? I am just getting into coding, but I am ambitious and want to learn everything. I am working on scripting for now.
Can you give me an example for blocking the context message?
What does MP control mean??? And whats a parameter cancel???

Wilfried
10-04-2007, 03:43 AM
Hi,

I'm not sure I understand the problem. Also please put code into [ code ] tags then it is displayed with the right indent for better readability. Do you display the map, so how? This code does not show enough unless I'm not looking well.

skylord5816
10-09-2007, 06:37 PM
The other stuff is all other stuff. The only thing that I'm asking about is the <BODY onContextMenu="javascript:alert(...')"> line. It says when you rightclick (or context menu) anywhere in the BODY, it will alert you saying whatever is in the parenthesis. It will display the alert, but still allow the context menu. How do you block the context menu AND display an alert??? And as for the code tags, what are they???

Wilfried
10-16-2007, 07:46 AM
Hi,


What does MP control mean??? And whats a parameter cancel

I think you use mappoint webservice right ? This forum is for the mappoint desktop version and also for using it embedded in a custom application. There is another forum for the webservice and virtual earth here also.

For the contextmenu you mean the one generated by the browser? You can prevent this for some browsers but not for all. For IE you find an article at msdn: Adding Entries to the Standard Context Menu (http://msdn2.microsoft.com/en-us/library/Aa753589.aspx) but this will not work with other browsers. Operan and Firefox will display it. I don't think you can even block this with Firefox. And there are a lots other browsers too included custom made that you can't prevent anything.