GridControl::GetMousePixel

 

Description

Converts the given twips X/Y to screen-coordinates position and returns the 0-offset row/column index under the mouse pointer.

Syntax

bool GetMousePixel( float X, float Y, int & nRow, int & nCol, int & nx, int & ny )

Parameters

X
[input] X coordinate in twips
Y
[input] Y coordinate in twips
nRow
[output] 0-offset row index under the mouse pointer
nCol
[output] 0-offset column index under the mouse pointer
nx
[output] x screen-coordinates
ny
[output] y screen-coordinates

Return

false if the mouse pointer is not at cell area, otherwise true

Examples

Examples

Example codes can be added to GridControl's examples to run

ON_GRID_BEFORE_MOUSE_DOWN(IDC_GRID, OnBeforeMouseDown) //add to class GridCtrlDLG's Message Map 

//add in class GridCtrlDLG
        void OnBeforeMouseDown(Control cntrl, short nButton, short nShift, float X, float Y, BOOL* pCancel)
        {
                if ( MK_RBUTTON != nButton || m_GridCtrl.IsMouseOnHeader() )
                        return;

                int nRow, nCol, nX, nY;
                if ( !m_GridCtrl.GetMousePixel(X, Y, nRow, nCol, nX, nY) )
                        return;
                
                Menu menu;
                menu.Add("Red", 1, MF_STRING);
                menu.Add("Green", 2, MF_STRING);
                menu.Add("Blue", 3, MF_STRING);
                
                int nCmd = 0;
                menu.TrackPopupMenu(0, nX, nY, GetSafeHwnd(), &nCmd);
                out_int("", nCmd);
                if ( nCmd > 0 )
                {
                        vector<uint> vBColor = {COLOR_RED, COLOR_GREEN, COLOR_BLUE};
                        m_GridCtrl.SetRowColor(nRow, -1, vBColor[nCmd-1]);
                }
        }

Remark

See Also

GridControl::GetMouseCell

Header to Included

GridControl.h