DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: ... Converting from Twips to Pixels ? ...

  1. #1
    Guest

    ... Converting from Twips to Pixels ? ...

    Hello everybody,

    I'm using the MSFlexGridControl with MFC, and when i click on a cell, i move
    a CEdit box to the position.

    The problem is :

    When i get the position and dimension of the selected Cell (Width,Height), i
    have the values in Twips ...

    -> How to convert that dimension in Pixels ?

    in VB we have :

    Screen.TwipsPerPixelX
    Screen.TwipsPerPixelY

    But in C++ ? Do I have to use the CDC of the control or something like that
    ??

    I'm really lost ... Thank's for any help.

    Driss.



  2. #2
    Brian Preston Guest

    Re: ... Converting from Twips to Pixels ? ...



    CDC::GetDeviceCaps() is what you are looking for.

    It would go something like this if you were moving a CEdit.

    CRect rect;
    CDC* pDC = GetDC();
    int pixelsX = pDC->GetDeviceCaps(LOGPIXELSX);
    int pixelsY = pDC->GetDeviceCaps(LOGPIXELSY);
    m_Grid.GetWindowRect(&rect);
    ScreenToClient(&rect);

    m_Edit.MoveWindow(m_Grid.GetCellLeft()* pixelsY/1440 + rect.left,
    m_Grid.GetCellTop() * pixelsY/1440 + rect.top,
    m_Grid.GetCellWidth() * pixelsY/1440,
    m_Grid.GetCellHeight() * pixelsY/1440, TRUE);
    m_Edit.SetFocus();

    Brian

    <ndriss@club-internet.fr> wrote:
    >Hello everybody,
    >
    >I'm using the MSFlexGridControl with MFC, and when i click on a cell, i

    move
    >a CEdit box to the position.
    >
    >The problem is :
    >
    >When i get the position and dimension of the selected Cell (Width,Height),

    i
    >have the values in Twips ...
    >
    >-> How to convert that dimension in Pixels ?
    >
    >in VB we have :
    >
    >Screen.TwipsPerPixelX
    >Screen.TwipsPerPixelY
    >
    >But in C++ ? Do I have to use the CDC of the control or something like that
    >??
    >
    >I'm really lost ... Thank's for any help.
    >
    >Driss.
    >
    >



  3. #3
    Guest

    Re: ... Converting from Twips to Pixels ? ...

    Thank's a lot, i'm going to try it right now ...

    Driss.

    "Brian Preston" <brian81@yahoo.com> a écrit dans le message news:
    3b17f330$1@news.devx.com...
    >
    >
    > CDC::GetDeviceCaps() is what you are looking for.
    >
    > It would go something like this if you were moving a CEdit.
    >
    > CRect rect;
    > CDC* pDC = GetDC();
    > int pixelsX = pDC->GetDeviceCaps(LOGPIXELSX);
    > int pixelsY = pDC->GetDeviceCaps(LOGPIXELSY);
    > m_Grid.GetWindowRect(&rect);
    > ScreenToClient(&rect);
    >
    > m_Edit.MoveWindow(m_Grid.GetCellLeft()* pixelsY/1440 + rect.left,
    > m_Grid.GetCellTop() * pixelsY/1440 + rect.top,
    > m_Grid.GetCellWidth() * pixelsY/1440,
    > m_Grid.GetCellHeight() * pixelsY/1440, TRUE);
    > m_Edit.SetFocus();
    >
    > Brian
    >
    > <ndriss@club-internet.fr> wrote:
    > >Hello everybody,
    > >
    > >I'm using the MSFlexGridControl with MFC, and when i click on a cell, i

    > move
    > >a CEdit box to the position.
    > >
    > >The problem is :
    > >
    > >When i get the position and dimension of the selected Cell

    (Width,Height),
    > i
    > >have the values in Twips ...
    > >
    > >-> How to convert that dimension in Pixels ?
    > >
    > >in VB we have :
    > >
    > >Screen.TwipsPerPixelX
    > >Screen.TwipsPerPixelY
    > >
    > >But in C++ ? Do I have to use the CDC of the control or something like

    that
    > >??
    > >
    > >I'm really lost ... Thank's for any help.
    > >
    > >Driss.
    > >
    > >

    >




  4. #4
    Guest

    Re: ... Converting from Twips to Pixels ? ...

    Thank's Brian, it works very well !

    I had written so many and complicated codes with no success,
    and yours are 3 times shorter and really more simple !

    Thank's.

    Driss


    "Brian Preston" <brian81@yahoo.com> a écrit dans le message news:
    3b17f330$1@news.devx.com...
    >
    >
    > CDC::GetDeviceCaps() is what you are looking for.
    >
    > It would go something like this if you were moving a CEdit.
    >
    > CRect rect;
    > CDC* pDC = GetDC();
    > int pixelsX = pDC->GetDeviceCaps(LOGPIXELSX);
    > int pixelsY = pDC->GetDeviceCaps(LOGPIXELSY);
    > m_Grid.GetWindowRect(&rect);
    > ScreenToClient(&rect);
    >
    > m_Edit.MoveWindow(m_Grid.GetCellLeft()* pixelsY/1440 + rect.left,
    > m_Grid.GetCellTop() * pixelsY/1440 + rect.top,
    > m_Grid.GetCellWidth() * pixelsY/1440,
    > m_Grid.GetCellHeight() * pixelsY/1440, TRUE);
    > m_Edit.SetFocus();
    >
    > Brian
    >
    > <ndriss@club-internet.fr> wrote:
    > >Hello everybody,
    > >
    > >I'm using the MSFlexGridControl with MFC, and when i click on a cell, i

    > move
    > >a CEdit box to the position.
    > >
    > >The problem is :
    > >
    > >When i get the position and dimension of the selected Cell

    (Width,Height),
    > i
    > >have the values in Twips ...
    > >
    > >-> How to convert that dimension in Pixels ?
    > >
    > >in VB we have :
    > >
    > >Screen.TwipsPerPixelX
    > >Screen.TwipsPerPixelY
    > >
    > >But in C++ ? Do I have to use the CDC of the control or something like

    that
    > >??
    > >
    > >I'm really lost ... Thank's for any help.
    > >
    > >Driss.
    > >
    > >

    >




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center