Solved

Twips to pixels...

Posted on 1998-04-23
7
515 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

Author Comment

by:MatthewHertz
Comment Utility
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
Comment Utility
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
Comment Utility
I told you how to convert twips to pixels .. obviously that's NOT what you wanted.

0
 

Author Comment

by:MatthewHertz
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

762 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now