
10-26-2003, 12:28 AM
|
|
Newcomer
|
|
Join Date: Oct 2003
Location: Italy
Posts: 9
|
|
Translation of twips to pixels in WIndows NT
|
Translation of twips to pixels in WIndows NT.
This is a problem midway between Visual Basic and Visual C++.
I wanto to use a MSFlexGrid in Visual C++ applications, but adding a TextBox (or a CEdit, as you prefer) covering the active cell of the grid that is not directly editable.
To do so I need position and dimension of the cell, that the inside code of MSFlexGrid gives in TWIPS, while Windows understands only pixels.
The code here below sticks strictly to the Windows API's, and works properly in Windows '95 and '98.
BUT, in Windows NT or XP, my TextBox results IRREGULARLY misplaced, on the left and higher that it should be. Irregularly means that the misplacement depends somehow from the row or the col, but apparently it doesn't follow a rule. So it is of no avail the applications of an empiric correction factor.
Anybody can see where is my mistake? Great thanks.
GetCellRect
************************************************************
CRect CRbDLLApp::GetCellRect(CMSFlexGrid *pGrid)
{
// this function returns, in pixels, the inside (client) dimensions
// of the Grid's active cell
// The parent window of the CEdit to be set over the active cell is the same Grid
HWND hDesktop = GetDesktopWindow();
HDC hdc = GetDC(hDesktop);
long ScreenHeightInTwips = GetDeviceCaps(hdc, VERTSIZE) *567 /10;
long ScreenHeightInPixels = GetDeviceCaps(hdc, VERTRES);
long ScreenWidthInTwips = GetDeviceCaps(hdc,HORZSIZE) *567 /10 ;
long ScreenWidthInPixels = GetDeviceCaps(hdc, HORZRES);
ReleaseDC(hDesktop, hdc); // NEVER forget this ! ! !
CRect ControlRect;
ControlRect.left = (long) ( pGrid->GetColPos(pGrid->GetCol())* ScreenWidthInPixels
/ ScreenWidthInTwips);
ControlRect.top = (long) (pGrid->GetRowPos(pGrid->GetRow()) * ScreenHeightInPixels
/ ScreenHeightInTwips);
ControlRect.right = ControlRect.left + (long) ( pGrid->GetCellWidth() * ScreenWidthInPixels
/ ScreenWidthInTwips);
ControlRect.bottom = ControlRect.top + (long)( pGrid->GetCellHeight() * ScreenHeightInPixels
/ ScreenHeightInTwips);
return ControlRect;
}
|
|