Groups | Blog | Home
all groups > macromedia players flash > may 2007 >

macromedia players flash : How to disable Context Menu of Flash ActiveX control


menno.van.baalen NO[at]SPAM home.nl
5/30/2007 7:22:47 AM
We are developing a PDA application for a wide range of users, varying from
young to quite old. What we experience in several test sessions, is that many
people who are unfamiliar with a pda hold the stylus on the screen too long
when they want to tap an item. The result is, that the context menu of flash
appears. Most people don't know what happens in this case.

So, we want to disable this context menu. We developed a visual studio .NET
2005 application that holds the Flash ActiveX control because of several
reasons. I've tried several 'solutions' found on the internet, but all
unsuccesfull. I also found a way to disable the Context Menu using javascript.
This is no option for us, but when it is possible with Javascript, it should
also be possible from a windows (mobile) application, or am I wrong?

So my question is:
How can I disable the context menu of the Flash ActiveX from a Windows
application?
menno.van.baalen NO[at]SPAM home.nl
6/6/2007 12:00:00 AM
I found the solution to our problem.

This is the c# code, it is based on sample code found here:
http://www.pcreview.co.uk/forums/thread-1298454.php

[DllImport("Coredll.dll", SetLastError = true)]
private static extern bool PeekMessage(
out PeekMsg msg,
IntPtr hWnd,
uint messageFilterMin,
uint messageFilterMax,
uint flags);

[DllImport("Coredll.dll", SetLastError = true)]
private static extern Int32 DispatchMessage(ref PeekMsg lpMsg);

[DllImport("Coredll.dll", SetLastError = true)]
private static extern Int32 TranslateMessage(ref PeekMsg lpMsg);

[DllImport("coredll.dll")]
public static extern int PostMessage(IntPtr hWnd, uint Msg, int wParam, int
lParam);

[DllImport("aygshell.dll")]
static extern uint SHRecognizeGesture(SHRGINFO shrg);

[StructLayout(LayoutKind.Sequential)]
class SHRGINFO
{
public uint cbSize = 0;
public IntPtr hwndClient = IntPtr.Zero;
public int x = 0; // POINT
public int y = 0; // POINT
public uint dwFlags = 0;
}

[StructLayout(LayoutKind.Sequential)]
public struct PeekMsg
{
public IntPtr hwnd;
public Int32 message;
public IntPtr wParam;
public IntPtr lParam;
public uint time;
public System.Drawing.Point pt;
}

internal const int WM_LBUTTONUP = 0x0202,
WM_RBUTTONUP = 0x0205,
WM_LBUTTONDOWN = 0x0201,
MK_LBUTTON = 0x01,
WM_LBUTTONDBLCLK = 0x0203,
WM_CONTEXTMENU = 0x7b;

private const int WM_NOREMOVE = 0x0;
private const uint GN_CONTEXTMENU = 1000;
private const uint SHRG_RETURNCMD = 0x00000001;
private const uint SHRG_NOTIFYPARENT = 0x00000002;
private const uint SHRG_LONGDELAY = 0x00000008;
private const uint SHRG_NOANIMATION = 0x00000010;


/// <summary>
/// The main entry point for the application.
/// </summary>
[MTAThread]
static void Main()
{

//instead of the normal Application.Run(new Form1); we must manually display
the form
Form1 formInstance = new Form1();
formInstance.Visible = true;

PeekMsg msg = new PeekMsg();
while (1 == 1)
{
PeekMessage(out msg, formInstance.Handle, 0, 0, WM_REMOVE);
switch (msg.message)
{
case WM_LBUTTONDOWN:
Debug.WriteLine(string.Format("lbuttondown: msg:{0}, lparam:{1},
wParam:{2}, hwnd:{3}, time:{4}", msg.message, msg.lParam, msg.wParam, msg.hwnd,
msg.time));

SHRGINFO shrginfo = new SHRGINFO();

shrginfo.cbSize = (uint)Marshal.SizeOf(shrginfo);
shrginfo.hwndClient = msg.hwnd;
shrginfo.x = msg.lParam.ToInt32() & 0x0000ffff;
shrginfo.y = (msg.lParam.ToInt32() & 0x0fff0000) >> 16;
shrginfo.dwFlags = SHRG_RETURNCMD;

if (SHRecognizeGesture(shrginfo) == GN_CONTEXTMENU)
{
Debug.WriteLine("in context menu loop");
PostMessage(msg.hwnd, WM_LBUTTONUP, 0, 0);
}

break;
default:
break;
}

TranslateMessage(ref msg);
DispatchMessage(ref msg);
}

derThorstenW
6/19/2007 8:21:56 AM
Hi,

thank you for that piece of code !!!!
I've got one problem if i try out your code:
The name "WM_REMOVE" is not there... only WM_NOREMOVE

WM_NOREMOVE is 0x0
i think WM_REMOVE has to be 0x1

is it correct?

best regards
t
derThorstenW
6/19/2007 8:35:19 AM
AddThis Social Bookmark Button