Go Back   TX Text Control Community > TX Text Control Discussion and Support Forums > TX Text Control ActiveX

TX Text Control ActiveX Please use this forum for TX Text Control ActiveX support only. If you need support for a different product, please use the appropriate forum.

Reply
 
Thread Tools Display Modes
  #1  
Old December 4, 2009
burmair burmair is offline
Registered User
 
Join Date: Jun 2008
Posts: 3
Lightbulb Converting between TWIPS and pixels (C++/MFC)

Most of you probably already know how to do this, but I just figured it out. If you're using MFC, the following C++ code can be used to convert between TWIPS and pixels.

Code:
(afxwin.h is the required header)

const int    TWIPS_PER_INCH       = 1440;
[...]
    inline int TwipsToPixels(int twips) { return (twips * m_devicePixelsPerInch / TWIPS_PER_INCH); }
    inline int PixelsToTwips(int pixels) { return (pixels * TWIPS_PER_INCH / m_devicePixelsPerInch); }
[...]
    int m_devicePixelsPerInch;
[...]
    // this code goes in the constructor
    CClientDC dc(this);  // 'this' is any CWnd-derived object
    m_devicePixelsPerInch = dc.GetDeviceCaps( LOGPIXELSY );

Last edited by Gunnar Giffey; December 4, 2009 at 16:00:10. Reason: Please use [CODE][/CODE] tags when posting source code. Thanks!
Reply With Quote
  #2  
Old December 4, 2009
Reallyethical's Avatar
Reallyethical Reallyethical is offline
TX Text Control MVP
 
Join Date: Sep 2008
Location: Derby, England
Posts: 230
Send a message via Skype™ to Reallyethical
Re: Converting between TWIPS and pixels (C++/MFC)

but as your using fixed measurements you could just use constants like:

TwipsPerInch = 1440; {Same as minutes per day}
TwipsPerPixel = 15;
TwipsPerMil = 56.7;
Reply With Quote
Reply

Bookmarks

Tags
c++ , convert , mfc , pixels , twips

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Autosize & Twips --> Pixel question xyzabc1010 TX Text Control .NET 1 November 19, 2008 09:42:23


All times are GMT +1. The time now is 06:26:27.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
© 1991 - 2010 The Imaging Source Europe GmbH