_Shortcutmenu Fix for ctl32_gripper

Update 09/10/2007: Per Carlos’s comment below, please note this fix is no longer needed.

In developing some of my Foxpro apps, I discovered that there is no built-in way of putting a gripper in the lower right-hand corner of my forms. Luckily, the wonderful foxpro community has a fix for this. In fact, there are several fixes, but the one I like the most is Carlos Alloatti’s ctl32_gripper.

Carlos’s control works very well, and his attention to detail make this custom control work and look just as if it were an original Foxpro control. I did, however, come across a little problem in my forms with my own custom controls not behaving correctly when I used the gripper control.

As many Foxpro developers do, I like to subclass the native Foxpro controls and create my own. Makes things easier when I want to make an app-wide change and I also like to add a few enhancements. For example, on the textbox control, I like a right click menu for cut, copy, and paste. In the “RightClick” event of the textbox, using the “_menu.vcx” Foxpro Foundation Class, I use some code to dynamically generate a popup menu. Unfortunately, herein lies the problem with the gripper control.

When I compile and run my app everything seems to work just fine, except when you go to invoke the right-click menu, it doesn’t always show up on the first click. It usually takes a few clicks before it comes up. When I run the program within the Foxpro IDE I get a similar behavior and I also get an error. The program errors out and the error routine shows the problem is on this line ” lnMRow=MAX(MROW(),0) ” in the “activatemenu” method of the “_shortcutmenu” class.

I know from looking at the code that the gripper class is intercepting the “WM_NCHITTEST” message of the form, so I know it has something to do with the code in the event handler for this message somehow interfering with the MROW() and MCOL() functions. While I’m not sure why this is happening, I have found a way around it that seems to work rather well.

I modified the code in the “activatemenu” method of the “_shortcutmenu” class as follows:

Original _shortcutmenu code:

lnMRow=MAX(MROW(),0)
lnMCol=MAX(MCOL(),0)

Modified _shortcutmenu code:

Local laMouseInfo(4)
AMouseObj(laMouseInfo,1)
lnMRow=MAX(laMouseInfo(4)/FONTMETRIC(1),0)
lnMCol=MAX(laMouseInfo(3)/FONTMETRIC(6),0)

If you know of a better solution or have more information on this please leave a comment.

One Comment

  1. Posted September 2, 2007 at 10:15 am | Permalink

    Another user (Anton) sent me a suggestion for improving the class.

    Now WM_NCHITTEST is not intercepted anymore, instead, a WM_LBUTTONDOWN message with the bottom right coordinates of the form is sent to the window when the mouse is down on the gripper.

    This work great and has none of the problems of the previous method.

    Carlos

Post a Comment

Your email is never shared. Required fields are marked *

*
*