Solved

How to edit MSFlexGrid in VC++

Posted on 1999-01-28
3
331 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
Comment Utility
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
Comment Utility
Many thanks to sjc2099.
0
 

Expert Comment

by:sjc2099
Comment Utility
"There are 1440 pixels per inch so the conversion is simple:"

Make that 1440 twips per inch.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now