Tap and hold doesn't popup ContextMenu in ListView?

D

Drasko

Contextmenu in my listview doesn't popup when I tap-and-hold. Circle appears
but nothing else! I work on device with WinCE 4.20. Any idea?

Thanks

Drasko
 
D

Daniel Moth

As far as I know, you cannot get the automatic appearing of a contextmenu on
non-PPC devices with the CF.

For some scenarios you can simulate it manually with ContextMenu.Show

To remove the appearance of the dotted circle, you have to swap aygshell for
the normal one in your image (if memory serves me well)

Cheers
Daniel
 
D

Drasko

System.Envirovnment.Version reports 1.0.3316.0., so I think that it is SP2!?

ContextMenu.Show() brings menu, but I cannot simulate what I need.

Thanks

Drasko
 
D

Drasko

Thanks Daniel.
Is there a way to catch "tap-and-hold" (may be using ApplicationEx ar
something)?

Drasko
 
D

Daniel Moth

Sorry, I know of no way to achieving it given that MouseDown event is not
supported.

Maybe you should consider a workaround (putting the menu up on a double
click OR substituting the contextmenu menuitems for toolbar buttons)...

I haven't used ApplicationEx myself but there might be something
there..openetcf might even have a listview replacement that does what you
want.. worth a look...

Cheers
Daniel
 
C

Chris Tacke, eMVP

Yes, ApplicationEx will work for this. Basically you can capture the
WM_MOUSEDOWN and WM_MOUSEUP. From there you need to determine if the up and
down happen within your timeframe, which could be done with a timer.
 
D

Drasko

Thanks Chris.
Using ApplicationEx I added MouseUp, MouseDown and MouseMove events to my
listview control (it's great!). Also I add TapAndHold event. Problem is to
distinguish "tap" from "tapandhold" because after single "tap" MouseDown
event fires but MouseUp not (I cannot catch WM_LBUTTONUP?). So when
"tap-and-hold" timer expires, I have to detect if button is still pressed
and I tried to use Control.Capture property, but it sometimes work sometimes
not. Obviously I am missing something. Can you help!?

Thanks

Drasko
 
P

Peter Foot [MVP]

If your platform uses the aygshell component, which is probably does if it
uses the tap-n-hold circle, then you can use SHRecognizeGesture from your
LBUTTONDOWN handler which you can P/Invoke using:-

[DllImport("aygshell.dll", SetLastError=true)]

public static extern int SHRecognizeGesture(ref SHRGINFO shrgi);

public const int GN_CONTEXTMENU = 1000;

public struct SHRGINFO

{

public int cbSize;

public IntPtr hwndClient;

public int ptDownX;

public int ptDownY;

public SHRGFlags dwFlags;

}

public enum SHRGFlags: int

{

RETURNCMD =0x00000001,

NOTIFYPARENT =0x00000002,

LONGDELAY =0x00000008,

NOANIMATION =0x00000010,

}



Then use something like this within your WM_LBUTTONDOWN handler:-

//get screen co-ordinates

Point p = new Point(m.LParam.ToInt32() & 0x0000ffff, (m.LParam.ToInt32() &
0x0fff0000) >> 16);

SHRGINFO inf = new SHRGINFO();

inf.cbSize = Marshal.SizeOf(inf);

inf.hwndClient = mhwnd;


inf.ptDownX = p.X;

inf.ptDownY = p.Y;

inf.dwFlags = SHRGFlags.RETURNCMD;

if(SHRecognizeGesture(ref inf)==GN_CONTEXTMENU)

{

contextMenu1.Show(this, Control.MousePosition);

}



I don't have an applicable device to test on but I tried it on Pocket PC as
an alternative to setting a ContextMenu directly and it appears to work.
Used in this way SHRecognizeGesture will block until either the tap-n-hold
completes in which case it returns GN_CONTEXTMENU or if interrupted it will
return 0. By changing the flags you can instead opt to have the method send
a WM_NOTIFY to your window containing the GN_CONTEXTMENU value which you can
catch separately.

Peter
 
D

Drasko

Thanks Peter! It works perfect! But dotted circle appears twice (first one I
can catch on "Peter's way", and then once more!?). It doesen't border me at
all, but I am interested why.

Thank you all

Drasko




Peter Foot said:
If your platform uses the aygshell component, which is probably does if it
uses the tap-n-hold circle, then you can use SHRecognizeGesture from your
LBUTTONDOWN handler which you can P/Invoke using:-

[DllImport("aygshell.dll", SetLastError=true)]

public static extern int SHRecognizeGesture(ref SHRGINFO shrgi);

public const int GN_CONTEXTMENU = 1000;

public struct SHRGINFO

{

public int cbSize;

public IntPtr hwndClient;

public int ptDownX;

public int ptDownY;

public SHRGFlags dwFlags;

}

public enum SHRGFlags: int

{

RETURNCMD =0x00000001,

NOTIFYPARENT =0x00000002,

LONGDELAY =0x00000008,

NOANIMATION =0x00000010,

}



Then use something like this within your WM_LBUTTONDOWN handler:-

//get screen co-ordinates

Point p = new Point(m.LParam.ToInt32() & 0x0000ffff, (m.LParam.ToInt32() &
0x0fff0000) >> 16);

SHRGINFO inf = new SHRGINFO();

inf.cbSize = Marshal.SizeOf(inf);

inf.hwndClient = mhwnd;


inf.ptDownX = p.X;

inf.ptDownY = p.Y;

inf.dwFlags = SHRGFlags.RETURNCMD;

if(SHRecognizeGesture(ref inf)==GN_CONTEXTMENU)

{

contextMenu1.Show(this, Control.MousePosition);

}



I don't have an applicable device to test on but I tried it on Pocket PC as
an alternative to setting a ContextMenu directly and it appears to work.
Used in this way SHRecognizeGesture will block until either the tap-n-hold
completes in which case it returns GN_CONTEXTMENU or if interrupted it will
return 0. By changing the flags you can instead opt to have the method send
a WM_NOTIFY to your window containing the GN_CONTEXTMENU value which you can
catch separately.

Peter


--
Peter Foot
Windows Embedded MVP
www.inthehand.com | www.opennetcf.org

Drasko said:
Thanks Chris.
Using ApplicationEx I added MouseUp, MouseDown and MouseMove events to my
listview control (it's great!). Also I add TapAndHold event. Problem is to
distinguish "tap" from "tapandhold" because after single "tap" MouseDown
event fires but MouseUp not (I cannot catch WM_LBUTTONUP?). So when
"tap-and-hold" timer expires, I have to detect if button is still pressed
and I tried to use Control.Capture property, but it sometimes work
sometimes
not. Obviously I am missing something. Can you help!?

Thanks

Drasko


up
and
 
A

Alex Feinman [MVP]

I suppose internally the Control class still invokes SHRecognizeGesture, but
then ignores the result since the platform is wrong

--
Alex Feinman
---
Visit http://www.opennetcf.org
Drasko said:
Thanks Peter! It works perfect! But dotted circle appears twice (first one
I
can catch on "Peter's way", and then once more!?). It doesen't border me
at
all, but I am interested why.

Thank you all

Drasko




Peter Foot said:
If your platform uses the aygshell component, which is probably does if
it
uses the tap-n-hold circle, then you can use SHRecognizeGesture from your
LBUTTONDOWN handler which you can P/Invoke using:-

[DllImport("aygshell.dll", SetLastError=true)]

public static extern int SHRecognizeGesture(ref SHRGINFO shrgi);

public const int GN_CONTEXTMENU = 1000;

public struct SHRGINFO

{

public int cbSize;

public IntPtr hwndClient;

public int ptDownX;

public int ptDownY;

public SHRGFlags dwFlags;

}

public enum SHRGFlags: int

{

RETURNCMD =0x00000001,

NOTIFYPARENT =0x00000002,

LONGDELAY =0x00000008,

NOANIMATION =0x00000010,

}



Then use something like this within your WM_LBUTTONDOWN handler:-

//get screen co-ordinates

Point p = new Point(m.LParam.ToInt32() & 0x0000ffff, (m.LParam.ToInt32()
&
0x0fff0000) >> 16);

SHRGINFO inf = new SHRGINFO();

inf.cbSize = Marshal.SizeOf(inf);

inf.hwndClient = mhwnd;


inf.ptDownX = p.X;

inf.ptDownY = p.Y;

inf.dwFlags = SHRGFlags.RETURNCMD;

if(SHRecognizeGesture(ref inf)==GN_CONTEXTMENU)

{

contextMenu1.Show(this, Control.MousePosition);

}



I don't have an applicable device to test on but I tried it on Pocket PC as
an alternative to setting a ContextMenu directly and it appears to work.
Used in this way SHRecognizeGesture will block until either the
tap-n-hold
completes in which case it returns GN_CONTEXTMENU or if interrupted it will
return 0. By changing the flags you can instead opt to have the method send
a WM_NOTIFY to your window containing the GN_CONTEXTMENU value which you can
catch separately.

Peter


--
Peter Foot
Windows Embedded MVP
www.inthehand.com | www.opennetcf.org

Drasko said:
Thanks Chris.
Using ApplicationEx I added MouseUp, MouseDown and MouseMove events to my
listview control (it's great!). Also I add TapAndHold event. Problem is to
distinguish "tap" from "tapandhold" because after single "tap"
MouseDown
event fires but MouseUp not (I cannot catch WM_LBUTTONUP?). So when
"tap-and-hold" timer expires, I have to detect if button is still pressed
and I tried to use Control.Capture property, but it sometimes work
sometimes
not. Obviously I am missing something. Can you help!?

Thanks

Drasko


Yes, ApplicationEx will work for this. Basically you can capture the
WM_MOUSEDOWN and WM_MOUSEUP. From there you need to determine if the up
and
down happen within your timeframe, which could be done with a timer.

--
<ctacke/>
www.OpenNETCF.org
Your CF searches start and end here


Thanks Daniel.
Is there a way to catch "tap-and-hold" (may be using ApplicationEx
ar
something)?

Drasko

As far as I know, you cannot get the automatic appearing of a
contextmenu
on non-PPC devices with the CF.

For some scenarios you can simulate it manually with ContextMenu.Show

To remove the appearance of the dotted circle, you have to swap
aygshell
for the normal one in your image (if memory serves me well)

Cheers
Daniel

Contextmenu in my listview doesn't popup when I tap-and-hold. Circle
appears
but nothing else! I work on device with WinCE 4.20. Any idea?

Thanks

Drasko
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top