Solved

Twips to pixels...

Posted on 1998-04-23
7
522 Views
Last Modified: 2013-11-19
I'm using an ActiveX Control (MSFlexGrid) which returns a location in twips.  Unfortunately, I need to convert this to for graphical purposes.  I've had the hardest time doing what should be really simple. Can someone help me out?
0
Comment
Question by:MatthewHertz
7 Comments
 
LVL 8

Expert Comment

by:gelbert
ID: 1301718
Twip is screen-independent unit used to ensure that placement and proportion of screen elements in your screen application are the same on all display systems. A twip is a unit of screen measurement equal to 1/20 of a printer's point. There are approximately 1440 twips to a logical inch or 567 twips to a logical centimeter (the length of a screen item measuring one inch or one centimeter when printed).

0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1301719
Get a dc (CDC) for your window.

Then do this..

int logpixelsx = dc.GetDeviceCaps(LOGPIXELSX);
int pixelx = MulDiv(x,pogpixels,1440)

This gives the answer in pixels.

You can use DPtoLP to convert to logical units if you are using something other than pixels.

0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1301720
I assume you want to know how to convert, rather than what a twip is.  If so, let me answer with the above.

BTW: pogpixels should have been logpixelsx (darn my chubby fingers).

Also do the same for the y direction.

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:MatthewHertz
ID: 1301721
Thanks, I know what twips are, I need to know how to convert them...
0
 
LVL 1

Accepted Solution

by:
guruprasad031298 earned 100 total points
ID: 1301722
This is the 2nd time I am posting an answer to MSFlexGrid problem. The measurements given by gelbert are perfectly right. I wrote a generalized conversion routine to use for MSFlexGrid. Unfortunately, it doesn't work very fine with MSFlexGrid. There is something that is fishy about MSFlexGrid.

So, I wrote my own conversion routine which works fine with MSFlexGrid. My requirement is to embed an edit control as the user clicks on a cell in the Grid at run time. I get it perfect. Here's the source code for this purpose. If you want to know the location, please let me know of your exact requirement and a sample code of what you have done. If your requirement is similar to what I have done already, you are free to use the following piece of code

// Embed editable CEdit Control

// Construct my own overridden edit control
pEdit = new CStdEqpEdit(&m_StdGrid, row);


Hope this helps .....
/*
 * Conversion from Twips to Pixel scale. Divisor values are specific to this
 * grid and may not work for others. Generic conversion routine couldn't be
 * written for this purpose. Make sure not to change this
 */

long lLeft = (long) (m_StdGrid.GetCellLeft () / 15);
long lTop = (long) (m_StdGrid.GetCellTop () / 15);
long lHeight = (long) (m_StdGrid.GetCellHeight() / 15);
long lWidth = (long) (m_StdGrid.GetCellWidth() / 14.3);

CRect rect (lLeft, lTop, lLeft + lWidth, lTop + lHeight);
            
// Create the edit control on the fly
pEdit->Create (WS_CHILD | WS_VISIBLE | WS_BORDER, rect, this, IDC_SEQ_NUM_EDIT);

pEdit->SetWindowText (m_StdGrid.GetText());

// Change the font of the edit control to that of the grid cell for consistency
CString sFontName = m_StdGrid.GetCellFontName();
int iFontSize = (int) (m_StdGrid.GetCellFontSize() * FONT_SCALE);
CFont *pFontEdit = new CFont();
pFontEdit->CreatePointFont (iFontSize, sFontName);
pEdit->SetFont (pFontEdit);

// Set the focus to the edit control
pEdit->SetFocus();
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1301723
I told you how to convert twips to pixels .. obviously that's NOT what you wanted.

0
 

Author Comment

by:MatthewHertz
ID: 1301724
Actually, RONSLOW that was what I wanted.  Your solution worked fine.  I couldn't figure out how to give you (and not gelbert, to whom the comment was directed) the points though.  Thanks a bunch!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Creating Labels and Frequency list style reports in SAS code 9 110
lucky13 challenge 11 158
abstract class with all non abstract mentods 6 84
wordappend challenge 8 220
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 …
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…
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.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

685 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