Click to See Complete Forum and Search --> : MSFlexGrid


Andrew Truckle
May 21st, 1999, 06:44 AM
I have a 3 column ms flex grid which has an "open area" to the right of the last column.

Therefore when I right-click the mouse to bring up a cut/copy/paste popup menu it thinks it is on column 3.

True, the mouse is still within the activex controls focus, but not actually over the column itself.

SoI need to be able to force the popup menu only to display if it falls within the last column.

I've tried GetMouseCol but it still returns the last column.

I hope you can help!

Stu
May 21st, 1999, 08:19 AM
Yeh, I've done a lot of work with MSFlexGrid and its methods leave a lot to be desired ;-)

You have two options:

1) Get rid of the free space by resizing the grid to the extent of the columns/rows.

2) Intepret the mouse co-ordinates provided in OnGridMouseDown() and check if they actually clicked inside the last column.

However both are tricker than they seem:

You will need to know the total width in pixels of all your columns so you can test if the mouse has been clicked inside the actual grid 'boundary' or to resize the control.

_BUT_, the width of a column in MSFlexGrid is measured and specified in twips, not pixels, so you will have to convert between them. AND the ratio of twips to pixels varies with different screen resolutions and font sizes...

Anyway, to save you the grief ;-) here are the functions I use with the control to convert either way:


// CONSTANTS
// Display metrics for PixelsToTwips()
const int TWIPS_PER_INCH = 1440;




/////////////////////////////////////////////////////////////////////////////
// Converts Twips to Pixels
//
// nDirection specifies either Horizontal (0) or Vertical (1) measurement.
//
long CAUIServiceSchedulePage::TwipsToPixels(const long lTwips, const short nDirection /* =0 */)
{
int nPixelsPerInch;
CClientDC dc(this);

if (nDirection == 0)
{
//
// Horizontal measurement
//
nPixelsPerInch = dc.GetDeviceCaps(LOGPIXELSX);
}
else
{
//
// Vertical measurement
//
nPixelsPerInch = dc.GetDeviceCaps(LOGPIXELSY);
}

return (long) (lTwips*nPixelsPerInch) / TWIPS_PER_INCH;
}

/////////////////////////////////////////////////////////////////////////////
// Converts Pixels to Twips
//
// nDirection specifies either Horizontal (0) or Vertical (1) measurement.
//

long CAUIServiceSchedulePage::PixelsToTwips(const long lPixels, const short nDirection /* =0 */)
{
int nPixelsPerInch;
CClientDC dc(this);

if (nDirection == 0)
{
//
// Horizontal measurement
//
nPixelsPerInch = dc.GetDeviceCaps(LOGPIXELSX);
}
else
{
//
// Vertical measurement
//
nPixelsPerInch = dc.GetDeviceCaps(LOGPIXELSY);
}

return (long) (lPixels * TWIPS_PER_INCH) / nPixelsPerInch;
}




Mail me if you need any more help,
Stuart

Andrew Truckle
May 24th, 1999, 07:10 AM
Hi Stu

Thanks for the code which I am trying to use.

I have a problem in that my popup menu is handled by OnContextMenu which is passed a CPoint as the coordinate. This coordinate isn't the same as the x/y passed to OnMouseGridDown.

How do I overcome this problem?

Regards

Stu
May 24th, 1999, 07:39 AM
I haven't used OnContextMenu(), but is sounds like the CPoint is just an encapsulation of the x/y passed to OnMouseDown().

>> This coordinate isn't the same as the x/y passed to OnMouseGridDown.

Do you mean the CPoint.x and CPoint.y values are different than the ones returned in OnMouseGridDown()?

If so, the CPoint may be representing a point on your _Screen_ (relative to the top left of your desktop). If this is the case, you will have to convert it to coordinates relative to your application window. See CWnd:ScreenToClient().

Or it could be the other way round (OnGridMouseDown() returns screen coordinates) , can't remember ;-) You should be able to tell quite easily though by moving your application window around - assuming you click in the same place on your grid, the x/y value from the handler returning Screen coordinates will change radically...

Make sense? ;-)
Stuart

Andrew Truckle
May 24th, 1999, 10:53 AM
Hi Stu

Yes, I needed to use ScreenToClient and all is well! However, my "Grid" actually starts 7 pixels in from the left of the dialog box, so I suppose I need to add this offset and also check the left border too.

I have another problem with the same symptoms. It is the double-click handler. I was hopeing to use the same functions but this handler doesn't have any parameters, so I don't know the mouse position.

What can I do here?

Andrew Truckle
May 24th, 1999, 11:31 AM
Stuart

How aboiut this as a workaround to it all....

add a private member variable:


bool bValidCheck;




Then add the OnGridMouseDown message handler.
In there, check to see if the mouse was pressed within the grid boundary.
If yes, set bValidCheck to true, if not, set it to false.

Then, in my Doubleclick and contextmenu handlers, just check whether bValidCheck is set to true!

It occurred to me that mousedown is handled before the other messages.

What do you think of this work around?

I also have a question about printing too.

Stu
May 24th, 1999, 12:44 PM
Yeh, sounds good!...

BTW, I know nothing about printing the grid ;-)