Solved

Equivalence between twips and inches or pixels

Posted on 2000-05-13
3
793 Views
Last Modified: 2013-11-20
Hi all..

I have added an ActiveX control to my application.. specifically it is a FlexGrid control. I need to know the height of the row so that I will be able to define the number of rows at run time. The problem is that the FlexGrid RowHeight property returns a value measured in twips, so that I need to convert it into pixels. That way I could use GetClientRect to know how many rows the control need to have when application is initialized.

I use Visual C++ 6.0.

Any advice? suggestion? help?
Thanks a lot in advance

Demarcy
0
Comment
Question by:demarcy
  • 2
3 Comments
 
LVL 2

Accepted Solution

by:
vbk_bgm earned 70 total points
ID: 2807943
Hi,
1440 twips make an inch(=72 points).

To make conversion from pixels to twips,
CClientDC dc(this);
int pixels_per_inchX = dc.GetDeviceCaps(LOGPIXELSX);
int pixels_per_inchY = dc.GetDeviceCaps(LOGPIXELSY);
CRect rect;
GetClientRect(rect);
int client_width_in_twips = rect.Width()*1440/pixels_per_inchX;
int client_height_in_twips = rect.Height()*1440/pixels_per_inchY;

Hope this helps!
0
 

Author Comment

by:demarcy
ID: 2808588
Thanks for your comment...

I saw you used CClientDC... I have used CDC* pDC = GetDC() instead and it worked.. is it right? or should I use CClientDC in that case?

Demarcy
0
 
LVL 2

Expert Comment

by:vbk_bgm
ID: 2809712
You can use either CClientDC or GetDC. If you use GetDC make sure to release the DC using ReleaseDC.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.

831 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