Solved

How to edit MSFlexGrid in VC++

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
iSeries FTP Exit Program 8 174
unable to delete all specified values regedit 38 901
substring method in java 1 142
How do I get Window Title of all opened process? 4 61
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.

752 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