Solved

Twips to pixels...

Posted on 1998-04-23
7
526 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Suggested Courses

626 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