Advertisement
Guest User

Untitled

a guest
Feb 28th, 2013
486
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.07 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include "lSEdit.h"
  3. #include "lSColors.h"
  4.  
  5. #ifdef _DEBUG
  6. #define new DEBUG_NEW
  7. #undef THIS_FILE
  8. static char THIS_FILE[] = __FILE__;
  9. #endif
  10. BEGIN_MESSAGE_MAP(ClSEdit, CEdit)
  11.     //{{AFX_MSG_MAP(ClSEdit)
  12.     ON_WM_MOUSEMOVE()
  13.     ON_WM_PAINT()
  14.     ON_WM_SETFOCUS()
  15.     ON_WM_KILLFOCUS()
  16.     ON_WM_SYSCOLORCHANGE()
  17.     ON_WM_VSCROLL()
  18.     ON_WM_HSCROLL()
  19.     ON_WM_CTLCOLOR()
  20.     // do not remove
  21.     ON_WM_STYLECHANGING()
  22.     //ON_CONTROL_REFLECT_EX(EN_UPDATE, OnEnUpdate)
  23.     //}}AFX_MSG_MAP
  24. END_MESSAGE_MAP()
  25. ClSEdit::ClSEdit()
  26. {
  27.     CWinApp *pMainApplication;
  28.     pMainApplication = AfxGetApp ();
  29.     m_hInstance = pMainApplication->m_hInstance;
  30.     m_bVScrollPressed           = TRUE;
  31.     m_bHScrollPressed           = TRUE;
  32.     m_bIsActivateSound          = FALSE;
  33.     m_bIsHScrollSound           = FALSE;
  34.     m_bIsVScrollSound           = FALSE;
  35.     m_bMouseOnEdit              = FALSE;
  36.     m_bIsFocused                = FALSE;
  37.     m_iHorizontalScrollWidth    = NULL;
  38.     m_iVerticalScrollWidthLeft  = NULL;
  39.     m_iVerticalScrollWidthRight = NULL;
  40.     m_bHorizontalFrameWidth     = NULL;
  41.     m_bVerticalFrameWidth       = NULL;
  42.     GetSysColors ();
  43. }
  44. ClSEdit::~ClSEdit(){}
  45. void ClSEdit::OnMouseMove(UINT nFlags, CPoint point)
  46. {  
  47.     CEdit::OnMouseMove(nFlags, point);
  48.     if (m_bIsFocused) return;
  49.     if (GetCapture() != this)
  50.     {
  51.         m_bMouseOnEdit = TRUE;
  52.         SetCapture();
  53.         DrawEdit();
  54.         // Play sound
  55.         if (m_bIsActivateSound)
  56.         {
  57.             ::PlaySound ((LPCTSTR)m_StrActivateSound, m_hInstance, SND_ASYNC | SND_RESOURCE);
  58.         }
  59.     }
  60.     else
  61.     {
  62.         CRect RectEditControl;
  63.         GetClientRect(&RectEditControl);
  64.         if (!RectEditControl.PtInRect(point))
  65.         {
  66.             m_bMouseOnEdit = FALSE;
  67.             DrawEdit();
  68.             ReleaseCapture();
  69.         }
  70.     }
  71. }
  72. void ClSEdit::OnPaint()
  73. {
  74.     // Process default (do not remove)
  75.     Default();
  76.     // Process control drawing (main!)
  77.     DrawEdit();
  78. }
  79. BOOL ClSEdit::DrawEdit(VOID)
  80. {
  81.     CPaintDC dc(this);
  82.     CRect RectEditControl;
  83.     GetClientRect(&RectEditControl);
  84.     CDC *pEditControlDC;
  85.     pEditControlDC = GetDC();
  86.     RectEditControl.top    -= m_bHorizontalFrameWidth;
  87.     RectEditControl.bottom += m_iHorizontalScrollWidth;
  88.     RectEditControl.bottom += m_bHorizontalFrameWidth;
  89.     RectEditControl.right  += m_iVerticalScrollWidthRight;
  90.     RectEditControl.right  += m_bVerticalFrameWidth;
  91.     RectEditControl.left   -= m_iVerticalScrollWidthLeft;
  92.     RectEditControl.left   -= m_bVerticalFrameWidth;
  93.     pEditControlDC->SetBkMode(OPAQUE);
  94.     pEditControlDC->SetBkColor(TRANSPARENT);
  95.     pEditControlDC->FillSolidRect(&RectEditControl, COLOR_BLACK);
  96.     if (m_bMouseOnEdit)
  97.     {
  98.         // Mouse on edit
  99.         pEditControlDC->Draw3dRect(&RectEditControl, m_clrShadow, m_clrHiLite);
  100.         RectEditControl.DeflateRect(1,1);
  101.         pEditControlDC->Draw3dRect(&RectEditControl, m_clrDarkShadow, m_clrButton);
  102.     }
  103.     else
  104.     {
  105.         // Mouse is not on edit
  106.         pEditControlDC->Draw3dRect(&RectEditControl, m_clrHiLite, m_clrHiLite);
  107.         RectEditControl.DeflateRect(1,1);
  108.         pEditControlDC->Draw3dRect(&RectEditControl, m_clrHiLite, m_clrHiLite);
  109.     }
  110.     CString str;
  111.     pEditControlDC->SelectObject(GetFont());
  112.     GetWindowText(str);
  113.     pEditControlDC->SetTextColor(COLOR_WHITE);
  114.     //pEditControlDC->SetBkColor(RGB(0, 0, 0));
  115.     GetRect(&RectEditControl);
  116.     int winStyle = GetStyle();
  117.     int style;
  118.     if (winStyle & ES_CENTER)
  119.         style = DT_CENTER;
  120.     else if (winStyle & ES_RIGHT)
  121.         style = DT_RIGHT;
  122.     else
  123.         style = DT_LEFT;
  124.     if (winStyle & ES_PASSWORD)
  125.     {
  126.         style = style |= ES_PASSWORD;
  127.         TRACE(_T("IS %s\n"), "PASSWORD");
  128.         //SetPasswordChar('*');
  129.     }
  130.     pEditControlDC->DrawText(str, &RectEditControl, style);
  131.     UpdateData();
  132.     // Release DC ! do not remove!
  133.     ReleaseDC (pEditControlDC);
  134.     //Invalidate(TRUE);
  135.  
  136.     return (TRUE);
  137. }
  138. BOOL ClSEdit::OnDrawItemValue(CDC& dc, CRect rcValue)
  139. {
  140.     CString str;
  141.     GetWindowText(str);
  142.     CString strPassword = {'*' * str.GetLength()};
  143.     dc.DrawText( strPassword, rcValue,  DT_SINGLELINE|DT_VCENTER);
  144.     return TRUE;
  145. }
  146. HBRUSH ClSEdit::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
  147. {
  148.     //HBRUSH hbr = CEdit::OnCtlColor(pDC, pWnd, nCtlColor);
  149.     //pDC->SetBkMode(TRANSPARENT);
  150.     //pDC->SetTextColor(RGB(255, 0, 0));
  151.     //return hbr;
  152.     TRACE(_T("IS %s\n"), nCtlColor);
  153.     pDC->SetBkMode(TRANSPARENT);
  154.     return (HBRUSH)::GetStockObject(NULL_BRUSH);
  155. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement