Dialog's message map followed by 'OnCtlColor':
BEGIN_MESSAGE_MAP(EditPixelMap1, CDialog)
//{{AFX_MSG_MAP(EditPixelMap1)
ON_EN_CHANGE(IDA_EDITPIXMAP, OnChangeEditpixmap)
ON_BN_CLICKED(IDC_PMSHOWDYN, OnPmshowdyn)
ON_EN_CHANGE(IDC_EDIT1_PIXELS, OnChangeEdit1Pixels)
ON_WM_PAINT()
//}}AFX_MSG_MAP
ON_WM_CTLCOLOR()
END_MESSAGE_MAP()
HBRUSH EditPixelMap1::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
AfxMessageBox("OnCtlColor");
if(nCtlColor == CTLCOLOR_EDIT)
{
UINT nID = pWnd->GetDlgCtrlID();
switch(nID)
{
case IDC_EDIT1_PIXELS:
pDC->SetTextColor( RGB( 255, 0, 0 ) );
break;
default:
pDC->SetTextColor( RGB( 0, 255, 0 ) );
break;
}
}
return hbr;
}
The dialog is created by the code below which is executed by the 'OnCreate' in the MainFrm.cpp for the project:
BOOL CMainFrame::CreatePMEditDialog()
{
if (!m_wndPMEDlgBar.Create(this, IDB_EDITPIXMAP, CBRS_FLYBY, IDB_EDITPIXMAP))
{
TRACE0("Failed to create PixMapEdit dialog bar\n");
return FALSE; // fail to create
}
m_wndPMEDlgBar.SetWindowText(_T("Pixel Map Editor"));//title also used in CSunFlowerApp::PreTranslateMessage
m_wndPMEDlgBar.EnableDocking(0);
// Get previous position of PME toolbar
CPoint pt;
pt.x = AfxGetApp()->GetProfileInt(_T("Settings"), _T("Window7"), -1);
pt.y = AfxGetApp()->GetProfileInt(_T("Settings"), _T("Window8"), -1);
if ( (pt.x<0) || (pt.x>(GetSystemMetrics(SM_CXSCREEN)-50)) )
pt.x = GetSystemMetrics(SM_CXSCREEN) - 300;
if ( (pt.y<0) || (pt.y>(GetSystemMetrics(SM_CYSCREEN)-200)) )
pt.y = 50;
FloatControlBar(&m_wndPMEDlgBar, pt);
CString szEdit;
szEdit.Format("");
SetPixelMapEditText(szEdit);
return TRUE;
}
Creation code for the dialog:
BOOL CMainFrame::CreatePMEditDialog()
{
if (!m_wndPMEDlgBar.Create(this, IDB_EDITPIXMAP, CBRS_FLYBY, IDB_EDITPIXMAP))
{
TRACE0("Failed to create PixMapEdit dialog bar\n");
return FALSE; // fail to create
}
m_wndPMEDlgBar.SetWindowText(_T("Pixel Map Editor"));//title also used in CSunFlowerApp::PreTranslateMessage
m_wndPMEDlgBar.EnableDocking(0);
// Get previous position of PME toolbar
CPoint pt;
pt.x = AfxGetApp()->GetProfileInt(_T("Settings"), _T("Window7"), -1);
pt.y = AfxGetApp()->GetProfileInt(_T("Settings"), _T("Window8"), -1);
if ( (pt.x<0) || (pt.x>(GetSystemMetrics(SM_CXSCREEN)-50)) )
pt.x = GetSystemMetrics(SM_CXSCREEN) - 300;
if ( (pt.y<0) || (pt.y>(GetSystemMetrics(SM_CYSCREEN)-200)) )
pt.y = 50;
FloatControlBar(&m_wndPMEDlgBar, pt);
CString szEdit;
szEdit.Format("");
SetPixelMapEditText(szEdit);
return TRUE;
}
Section of the .rc file for the project:
IDB_EDITPIXMAP DIALOGEX 0, 0, 156, 203
STYLE WS_CHILD
FONT 8, "MS Sans Serif"
BEGIN
EDITTEXT IDA_EDITPIXMAP,7,6,89,190,ES_MULTILINE | ES_UPPERCASE |
ES_AUTOHSCROLL | ES_WANTRETURN | WS_VSCROLL
LTEXT "Show:",IDC_STATIC,103,6,27,8
PUSHBUTTON "Raw",IDC_PMSHOWRAW,102,15,45,12
PUSHBUTTON "Origional PM",IDC_PMSHOWORIG,102,29,45,12
PUSHBUTTON "Current PM",IDC_PMSHOWCURR,102,43,45,12
EDITTEXT IDC_EDIT1_PIXELS,107,122,36,12,ES_AUTOHSCROLL,
WS_EX_TRANSPARENT
LTEXT "Pixels",IDC_STATIC,102,114,30,8
EDITTEXT IDC_EDIT1_ROWS,107,144,35,12,ES_AUTOHSCROLL
LTEXT "Rows",IDC_STATIC,102,136,32,8
EDITTEXT IDC_EDIT1_COLUMNS,107,165,35,12,ES_AUTOHSCROLL
LTEXT "Columns",IDC_STATIC,102,157,33,8
EDITTEXT IDC_EDIT1_LINES,107,184,36,12,ES_AUTOHSCROLL
LTEXT "Lines",IDC_STATIC,103,176,31,8
CONTROL "Dynamic",IDC_PMSHOWDYN,"Button",BS_AUTOCHECKBOX |
WS_TABSTOP,104,100,43,10
PUSHBUTTON "Revt to Orig",IDC_PMREVERT,102,57,45,12
PUSHBUTTON "Save PM",IDC_PMSAVE,102,76,45,12
END
HBRUSH CMainFrame::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CMainFrame::OnCtlColor(pDC, pWnd, nCtlColor);
AfxMessageBox("CMainFrame::OnCtlColor");
return hbr;
}
File EditPixMapDlg1.cpp:
// EditPixMapDlg1.cpp : implementation file
//
#include "stdafx.h"
#include "SunFlower.h"
#include "EditPixMapDlg1.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// EditPixMapDlg1 dialog
//EditPixMapDlg1::EditPixMapDlg1(CWnd* pParent /*=NULL*/)
// : CDialogBar(EditPixMapDlg1::IDD, pParent)
EditPixMapDlg1::EditPixMapDlg1( /*=NULL*/)
: CDialogBar()
{
//{{AFX_DATA_INIT(EditPixMapDlg1)
m_nPixelCount = _T("");
m_nRows = _T("");
m_nColumns = _T("");
m_nLines = _T("");
//}}AFX_DATA_INIT
}
void EditPixMapDlg1::DoDataExchange(CDataExchange* pDX)
{
CDialogBar::DoDataExchange(pDX);
//{{AFX_DATA_MAP(EditPixMapDlg1)
DDX_Text(pDX, IDC_EDIT1_PIXELS, m_nPixelCount);
DDX_Text(pDX, IDC_EDIT1_ROWS, m_nRows);
DDX_Text(pDX, IDC_EDIT1_COLUMNS, m_nColumns);
DDX_Text(pDX, IDC_EDIT1_LINES, m_nLines);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(EditPixMapDlg1, CDialogBar)
//{{AFX_MSG_MAP(EditPixMapDlg1)
ON_WM_CTLCOLOR()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// EditPixMapDlg1 message handlers
HBRUSH EditPixMapDlg1::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialogBar::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
AfxMessageBox("new OnCtlColor");
// TODO: Return a different brush if the default is not desired
return hbr;
}
File EditPixMapDlg1.h:
#if !defined(AFX_EDITPIXMAPDLG1_H__32012004_3D66_4926_B51E_592053790141__INCLUDED_)
#define AFX_EDITPIXMAPDLG1_H__32012004_3D66_4926_B51E_592053790141__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// EditPixMapDlg1.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// EditPixMapDlg1 dialog
class EditPixMapDlg1 : public CDialogBar
{
// Construction
public:
// EditPixMapDlg1(CWnd* pParent = NULL); // standard constructor
EditPixMapDlg1(); // standard constructor
// Dialog Data
//{{AFX_DATA(EditPixMapDlg1)
enum { IDD = IDB_EDITPIXMAP };
CString m_nPixelCount;
CString m_nRows;
CString m_nColumns;
CString m_nLines;
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(EditPixMapDlg1)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(EditPixMapDlg1)
afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_EDITPIXMAPDLG1_H__32012004_3D66_4926_B51E_592053790141__INCLUDED_)
Dialog bar creation code in MainFrm.cpp:
BOOL CMainFrame::CreatePMEditDialog()
{
if (!m_wndPMEDlgBar.Create(this, IDB_EDITPIXMAP, CBRS_FLYBY, IDB_EDITPIXMAP))
{
TRACE0("Failed to create PixMapEdit dialog bar\n");
return FALSE; // fail to create
}
m_wndPMEDlgBar.SetWindowText(_T("Pixel Map Editor"));//title also used in CSunFlowerApp::PreTranslateMessage
m_wndPMEDlgBar.EnableDocking(0);
// Get previous position of PME toolbar
CPoint pt;
pt.x = AfxGetApp()->GetProfileInt(_T("Settings"), _T("Window7"), -1);
pt.y = AfxGetApp()->GetProfileInt(_T("Settings"), _T("Window8"), -1);
if ( (pt.x<0) || (pt.x>(GetSystemMetrics(SM_CXSCREEN)-50)) )
pt.x = GetSystemMetrics(SM_CXSCREEN) - 300;
if ( (pt.y<0) || (pt.y>(GetSystemMetrics(SM_CYSCREEN)-200)) )
pt.y = 50;
FloatControlBar(&m_wndPMEDlgBar, pt);
CString szEdit;
szEdit.Format("");
SetPixelMapEditText(szEdit);
return TRUE;
}
you're right, 'OnCtlColor' is the correct place to handle it. Take a look at the attached code: It causes all edit controls display their text green colored except 'IDC_EDIT_TEST' which displays the text in red.
Hope that helps,
ZOPPO
Open in new window