Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to edit MSFlexGrid in VC++

Posted on 1999-01-28
3
Medium Priority
?
344 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 400 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

722 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