Go Back  Xtreme Visual Basic Talk > Other Languages > Miscellaneous Languages > Translation of twips to pixels in WIndows NT

Thread Tools Display Modes
Old 10-26-2003, 12:28 AM
rbarella rbarella is offline
Join Date: Oct 2003
Location: Italy
Posts: 9
Question 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.


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;

Reply With Quote
Old 11-01-2003, 12:04 AM
rbarella rbarella is offline
Join Date: Oct 2003
Location: Italy
Posts: 9

I've found myself the answer to my problem.

If anybody is interested, here it is:

Build an user control with the MSFlexGrid, and its brave, valiant TextBox on it, but in Visual Basic 6.0

Add the user control to your project in Visual C++.

It will run properly, and solve inside any problem of difference between Windows '98 and NT

Reply With Quote

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Twips or Pixels Seanami General 2 12-10-2002 10:21 AM
Twips, Pixels, and Large Fonts bmw Interface and Graphics 9 08-06-2002 11:03 AM
pixels and twips scott911 General 11 10-26-2001 03:10 AM
Twips to Pixels ChiefRedBull General 2 09-19-2001 11:27 AM
twips to pixels blursea General 1 08-07-2001 06:17 PM


Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..