Rotated CEdit Control - Programmer

This is a discussion on Rotated CEdit Control - Programmer ; Hi All, Is there anyway I can rotate a CEdit control located on a CDialog? so that user can view CEdit correctly when he/she rotaes the monitor 90 degrees? Thanks in advance for your help....

+ Reply to Thread
Results 1 to 3 of 3

Thread: Rotated CEdit Control

  1. Rotated CEdit Control

    Hi All,

    Is there anyway I can rotate a CEdit control located on a CDialog?
    so that user can view CEdit correctly when he/she rotaes the monitor 90
    degrees?

    Thanks in advance for your help.


  2. Re: Rotated CEdit Control

    What do you mean by the rotate monitor 90 degrees

    Thanks
    Shabbir Bhimani
    Programming Forums - www.go4expert.com


  3. Re: Rotated CEdit Control

    Here is one I developed for use on a Pocket PC.
    Hope this helps.


    #pragma once


    // CVEdit

    class CVEdit : public CWnd
    {
    DECLARE_DYNAMIC(CVEdit)

    public:
    CVEdit();
    virtual ~CVEdit();

    CString GetWindowText() { return m_Text; }
    void SetWindowText(LPCTSTR lpszString);
    protected:
    afx_msg BOOL OnEraseBkgnd(CDC* pDC);
    afx_msg void OnPaint();
    afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
    afx_msg void OnSetFocus(CWnd* pOldWnd);
    afx_msg void OnKillFocus(CWnd* pNewWnd);
    afx_msg UINT OnGetDlgCode();
    afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
    afx_msg void OnTimer(UINT nIDEvent);
    afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
    DECLARE_MESSAGE_MAP()
    private:
    CString m_Text;
    UINT m_CurPos;
    BOOL m_CursorOn;
    long m_Offset;
    CFont m_Font;
    int m_TextHeight;

    void DrawCursor(BOOL Erase=FALSE);
    int GetPosFromPoint(const CPoint &Point);
    };



    // VEdit.cpp : implementation file
    //

    #include "stdafx.h"
    #include "VEdit.h"
    #include


    // CVEdit

    IMPLEMENT_DYNAMIC(CVEdit, CWnd)
    CVEdit::CVEdit()
    : m_Text(_T(""))
    , m_CurPos(0)
    , m_CursorOn(FALSE)
    , m_Offset(0)
    {

    m_Font.CreateFont((int)(14),0,2700,2700,FW_BOLD,FA LSE,FALSE,FALSE,ANSI_CHARS
    ET,OUT_DEFAULT_PRECIS,CLIP_CHARACTER_PRECIS,DEFAUL T_QUALITY,DEFAULT_PITCH,_T
    ("Arial"));
    }

    CVEdit::~CVEdit()
    {
    }


    BEGIN_MESSAGE_MAP(CVEdit, CWnd)
    ON_WM_ERASEBKGND()
    ON_WM_PAINT()
    ON_WM_CHAR()
    ON_WM_SETFOCUS()
    ON_WM_KILLFOCUS()
    ON_WM_GETDLGCODE()
    ON_WM_LBUTTONDOWN()
    ON_WM_TIMER()
    ON_WM_KEYDOWN()
    END_MESSAGE_MAP()



    // CVEdit message handlers


    BOOL CVEdit::OnEraseBkgnd(CDC* pDC)
    {
    // TODO: Add your message handler code here and/or call default

    return CWnd::OnEraseBkgnd(pDC);
    }

    void CVEdit::OnPaint()
    {
    CPaintDC dc(this); // device context for painting

    CFont *oldFont = dc.SelectObject(&m_Font);

    dc.SetTextColor(RGB(0,0,0));
    dc.SetBkMode(OPAQUE);
    dc.SetBkColor(RGB(255,255,255));

    CRect Rect;
    GetClientRect(&Rect);

    CBrush Brush(RGB(255,255,255));
    dc.FillRect(&Rect,&Brush);
    dc.ExtTextOut(Rect.Width(),3,0,Rect,m_Text, NULL);

    dc.SelectObject(oldFont);
    if (m_CursorOn)
    {
    DrawCursor();
    }
    }

    void CVEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
    {
    if (isprint(nChar))
    {
    m_Text.Insert(m_CurPos,nChar);
    m_CurPos++;
    Invalidate();

    GetParent()->SendMessage(WM_COMMAND,MAKEWPARAM(GetDlgCtrlID(),E N_CHANGE),(LP
    ARAM)m_hWnd);
    }
    else if (nChar == VK_BACK)
    {
    if (m_CurPos > 0)
    {
    CString Right = m_Text.Right(m_Text.GetLength()-m_CurPos);
    m_Text = m_Text.Left(m_CurPos-1);
    m_Text += Right;
    m_CurPos--;
    m_CursorOn = TRUE;
    Invalidate();

    GetParent()->SendMessage(WM_COMMAND,MAKEWPARAM(GetDlgCtrlID(),E N_CHANGE),(LP
    ARAM)m_hWnd);
    }
    }
    else if (nChar == VK_TAB)
    {
    CWnd *pParent = GetParent();
    ASSERT(pParent);
    SHORT State = GetKeyState(VK_SHIFT);
    if (State < 0)
    {
    pParent->SendMessage(WM_NEXTDLGCTL,1,0);
    }
    else
    {
    pParent->SendMessage(WM_NEXTDLGCTL,0,0);
    }
    }
    else if (nChar == VK_RETURN)
    {
    ASSERT(GetParent());
    CWnd *pParent = GetParent()->GetParent();;
    ASSERT(pParent);
    LRESULT DefID = pParent->SendMessage(DM_GETDEFID);
    if (HIWORD(DefID) == DC_HASDEFID)
    {
    HWND DefWnd = ::GetDlgItem(*pParent,LOWORD(DefID));
    if (DefWnd)
    {

    pParent->SendMessage(WM_COMMAND,MAKEWPARAM(LOWORD(DefID),BN _CLICKED),(LPARAM
    )DefWnd);
    }
    }
    }

    CWnd::OnChar(nChar, nRepCnt, nFlags);
    }

    void CVEdit::OnSetFocus(CWnd* pOldWnd)
    {
    CWnd::OnSetFocus(pOldWnd);

    m_CursorOn = TRUE;
    KillTimer(100);
    SetTimer(100,GetCaretBlinkTime(),NULL);
    }

    void CVEdit::OnKillFocus(CWnd* pNewWnd)
    {
    CWnd::OnKillFocus(pNewWnd);
    KillTimer(100);
    m_CursorOn = FALSE;
    DrawCursor(TRUE);
    }

    UINT CVEdit::OnGetDlgCode()
    {
    return CWnd::OnGetDlgCode() | DLGC_WANTALLKEYS;
    }

    void CVEdit::OnLButtonDown(UINT nFlags, CPoint point)
    {
    DrawCursor(TRUE);

    m_CurPos = GetPosFromPoint(point);

    SetFocus();

    Default();
    }

    void CVEdit::OnTimer(UINT nIDEvent)
    {
    DrawCursor();
    m_CursorOn = !m_CursorOn;
    CWnd::OnTimer(nIDEvent);
    }

    void CVEdit:rawCursor(BOOL Erase)
    {
    CDC *pDC = GetDC();

    CFont *pOldFont = pDC->SelectObject(&m_Font);

    CRect Rect;
    GetClientRect(&Rect);

    CString Text = m_Text.Left(m_CurPos);
    CSize TextSize = pDC->GetTextExtent(Text);
    TextSize.cy = TextSize.cy <= 0 ? 13 : TextSize.cy;

    CPen Pen(PS_SOLID,1,(Erase || !m_CursorOn) ? RGB(255,255,255) :
    RGB(0,0,0));

    CPen *pOldPen = pDC->SelectObject(&Pen);
    pDC->MoveTo(Rect.Width() - TextSize.cy,2+TextSize.cx);
    pDC->LineTo(Rect.Width()-2,2+TextSize.cx);

    pDC->SelectObject(pOldPen);
    pDC->SelectObject(pOldFont);
    ReleaseDC(pDC);
    }

    void CVEdit::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
    {
    if (nChar == VK_LEFT)
    {
    if (m_CurPos > 0)
    {
    DrawCursor(TRUE);
    m_CurPos--;
    }
    }
    else if (nChar == VK_RIGHT)
    {
    if (m_CurPos < m_Text.GetLength())
    {
    DrawCursor(TRUE);
    m_CurPos++;
    }
    }
    else if (nChar == VK_DELETE)
    {
    if (m_CurPos < m_Text.GetLength())
    {
    CString Left = m_Text.Left(m_CurPos);
    m_Text = Left + m_Text.Right((m_Text.GetLength()-m_CurPos)-1);
    // m_CurPos--;
    m_CursorOn = TRUE;
    Invalidate();

    GetParent()->SendMessage(WM_COMMAND,MAKEWPARAM(GetDlgCtrlID(),E N_CHANGE),(LP
    ARAM)m_hWnd);
    }
    }

    m_CursorOn = TRUE;
    DrawCursor();

    CWnd::OnKeyDown(nChar, nRepCnt, nFlags);
    }

    int CVEdit::GetPosFromPoint(const CPoint &Point)
    {
    CDC *pDC = GetDC();

    CFont *pOldFont = pDC->SelectObject(&m_Font);


    for (int i = 0; i < m_Text.GetLength();i++)
    {
    CString Text = m_Text.Left(i);
    CSize TextSize = pDC->GetTextExtent(Text);
    if (TextSize.cx > Point.y)
    {
    return i-1;
    }
    }
    return m_Text.GetLength();
    }

    void CVEdit::SetWindowText(LPCTSTR lpszString)
    {
    m_Text = lpszString;
    m_CurPos = m_Text.GetLength();
    Invalidate();
    }


    AliR.


    wrote in message
    news:1120441965.879818.230940@g43g2000cwa.googlegr oups.com...
    > Hi All,
    >
    > Is there anyway I can rotate a CEdit control located on a CDialog?
    > so that user can view CEdit correctly when he/she rotaes the monitor 90
    > degrees?
    >
    > Thanks in advance for your help.
    >
    >




+ Reply to Thread