Solved

How to edit MSFlexGrid in VC++

Posted on 1999-01-28
3
342 Views
Last Modified: 2013-11-20
I am using the common way used in VB: Put an edit box on the application and move this box to whereever I want to edit.
The problem is I do not know how to unite the unit for the editbox's position. The unit for both editbox and Grid should be same. Because of this problem, I can not move the Editbox to the proper position. Any help is appreciated.
0
Comment
Question by:xiandong
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 

Accepted Solution

by:
sjc2099 earned 100 total points
ID: 1328454
I believe you are speaking of the coordinates that the grid is using versus the coordinates used to place your edit control.  If this is the case then this should fix your problem:

The grid's GetCellHeight(), GetCellWidth(), GetCellTop() and GetCellLeft() functions all return values in a unit called twips.  Since your edit control will most likely be placed (via CWnd::MoveWindow or equivalent) using pixels for a unit.  Your solution is to convert twips to pixels.  There are 1440 pixels per inch so the conversion is simple:

// Get a pointer to the grid
CMSFlexGrid* pGrid = (CMSFlexGrid*)GetDlgItem(IDC_MSFLEXGRID1);
ASSERT(pGrid);

// Get a pointer to the edit control
CEdit* pEdit = (CEdit*)GetDlgItem(IDC_EDIT);
ASSERT(pEdit);

// Get the cell diminesions.
// Grid always returns twips. Convert twips to pixels.
long nTwipsPerPixelX = 1440 / pGrid->GetWindowDC()->GetDeviceCaps(LOGPIXELSX);
long nTwipsPerPixelY = 1440 / pGrid->GetWindowDC()->GetDeviceCaps(LOGPIXELSY);

long nHeight  = pGrid->GetCellHeight() / nTwipsPerPixelY;
long nWidth   = pGrid->GetCellWidth()  / nTwipsPerPixelX;
long nTop     = pGrid->GetCellTop()  / nTwipsPerPixelY;
long nLeft    = pGrid->GetCellLeft() / nTwipsPerPixelX;

// Size and move the edit control over the cell.
CRect rect;
pGrid->GetWindowRect(&rect);
ScreenToClient(&rect);
pEdit->MoveWindow(nLeft + rect.left, nTop + rect.top, nWidth, nHeight, TRUE);

pEdit->ShowWindow( SW_SHOW );
0
 

Author Comment

by:xiandong
ID: 1328455
Many thanks to sjc2099.
0
 

Expert Comment

by:sjc2099
ID: 1328456
"There are 1440 pixels per inch so the conversion is simple:"

Make that 1440 twips per inch.
0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

634 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question