Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- class CMyEdit : public CEdit
- {
- public:
- CMyEdit()
- : m_HasFocus(false)
- {
- }
- bool m_HasFocus;
- afx_msg void OnSetFocus(CWnd* pOldWnd);
- afx_msg void OnKillFocus(CWnd* pNewWnd);
- DECLARE_MESSAGE_MAP()
- };
- class Cmfc_testDlg : public CDialog
- {
- public:
- Cmfc_testDlg(CWnd* pParent = NULL); // standard constructor
- enum { IDD = IDD_MFC_TEST_DIALOG };
- protected:
- virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
- protected:
- CMyEdit m_Edit;
- CBrush m_RedBrush;
- virtual BOOL OnInitDialog();
- afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
- DECLARE_MESSAGE_MAP()
- };
- #include "stdafx.h"
- #include "mfc_test.h"
- #include "mfc_testDlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #endif
- Cmfc_testDlg::Cmfc_testDlg(CWnd* pParent /*=NULL*/)
- : CDialog(Cmfc_testDlg::IDD, pParent)
- {
- }
- void Cmfc_testDlg::DoDataExchange(CDataExchange* pDX)
- {
- DDX_Control(pDX, IDC_EDIT1, m_Edit);
- CDialog::DoDataExchange(pDX);
- }
- BEGIN_MESSAGE_MAP(CMyEdit, CEdit)
- ON_WM_SETFOCUS()
- ON_WM_KILLFOCUS()
- END_MESSAGE_MAP()
- BEGIN_MESSAGE_MAP(Cmfc_testDlg, CDialog)
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- ON_WM_CTLCOLOR()
- END_MESSAGE_MAP()
- BOOL Cmfc_testDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- m_RedBrush.CreateSolidBrush(RGB(255, 0, 0));
- return TRUE;
- }
- HBRUSH Cmfc_testDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
- {
- if (pWnd->GetSafeHwnd() == m_Edit.GetSafeHwnd() && m_Edit.m_HasFocus) {
- pDC->SetBkColor(RGB(255, 0, 0));
- return m_RedBrush;
- }
- return CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
- }
- void CMyEdit::OnSetFocus(CWnd* pOldWnd)
- {
- m_HasFocus = true;
- CEdit::OnSetFocus(pOldWnd);
- }
- void CMyEdit::OnKillFocus(CWnd* pNewWnd)
- {
- m_HasFocus = false;
- CEdit::OnKillFocus(pNewWnd);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement