Solved

Twips to pixels...

Posted on 1998-04-23
7
520 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Expand to include initial dialog with two choices. 9 78
Complete beginner needs help making a cron job 9 117
fizzArray  challenge 1 85
JQuery serialize and unserialize 8 89
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
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.

821 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