Converts the given twips X/Y to screen-coordinates position and returns the 0-offset row/column index under the mouse pointer.
bool GetMousePixel( float X, float Y, int & nRow, int & nCol, int & nx, int & ny )
false if the mouse pointer is not at cell area, otherwise true
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]); } }
GridControl.h