Solved

How to edit MSFlexGrid in VC++

Posted on 1999-01-28
3
335 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
  • 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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to create frequencies of a variable from SAS dataset? 10 133
iSeries DB2 Query 2 97
modThree challenge 4 99
scoreUp challenge 14 64
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

821 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