class CRichProt : public CDialog
{
DECLARE_DYNAMIC(CRichProt)
public:
CRichProt(CWnd* pParent = NULL); // standard constructor
virtual ~CRichProt();
// Dialog Data
enum { IDD = D_RICH1 };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
DECLARE_MESSAGE_MAP()
public:
CRichEditCtrl m_cRichEdit;
int i;
int err; // код ошибки
CHARFORMAT fmtText;
LOGFONT lf;
int klcr;
CRect rectrich;
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
// My callback procedure that writes the rich edit control contents
// to a file.
static DWORD CALLBACK
MyStreamInCallback(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
{
CFile* pFile = (CFile*) dwCookie;
*pcb = pFile->Read(pbBuff, cb);
return 0;
}
// Установка шрифта выдачи текста
void SetRichEditFont(void);
afx_msg void OnPaint();
void ReadFileProt(void);
void SetWindowProt(void);
afx_msg void OnSize(UINT nType, int cx, int cy);
protected:
virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam);
public:
afx_msg void OnEnChangeRich1E1();
};
CRichProt.cpp
// RichProt.cpp : implementation file
//
#include "stdafx.h"
#include "WK3PRALL.h"
#include "WK3PRALLDlg.h"
#include "RichProt.h"
#include ".\richprot.h"
extern CRect rectText;
// файл тела протокола
extern CFile c_FileProt;
extern CFileException cfeProt;
extern char lpFileNameProt[255];
extern int indFileProt; // индекс начала записи для чтения
// CRichProt dialog
IMPLEMENT_DYNAMIC(CRichProt, CDialog)
CRichProt::CRichProt(CWnd* pParent /*=NULL*/)
: CDialog(CRichProt::IDD, pParent)
{
}
CRichProt::~CRichProt()
{
}
void CRichProt::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, D_RICH1_E1, m_cRichEdit);
}
BEGIN_MESSAGE_MAP(CRichProt, CDialog)
ON_WM_CREATE()
ON_WM_PAINT()
ON_WM_SIZE()
// ON_WM_KEYDOWN()
//ON_EN_SETFOCUS(D_RICH1_E1, OnEnSetfocusRich1E1)
ON_EN_CHANGE(D_RICH1_E1, OnEnChangeRich1E1)
//ON_NOTIFY(EN_CORRECTTEXT, D_RICH1_E1, OnEnCorrecttextRich1E1)
END_MESSAGE_MAP()
int CRichProt::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDialog::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
m_cRichEdit.DestroyWindow();
m_cRichEdit.Create(ES_MULTILINE|ES_AUTOHSCROLL|ES_AUTOVSCROLL|
WS_VSCROLL |WS_HSCROLL | WS_BORDER | WS_VISIBLE,
CRect(0,0,0,0),
this,D_RICH1_E1);
// Установка шрифта выдачи текста
CRichProt::SetRichEditFont();
// m_cRichEdit.SetReadOnly(true);
m_cRichEdit.SetEventMask(m_cRichEdit.GetEventMask() | ENM_CHANGE);
m_cRichEdit.MoveWindow(0,0,0,0,true);
return 0;
}
// Установка шрифта выдачи текста
void CRichProt::SetRichEditFont(void)
{
m_cRichEdit.GetDefaultCharFormat(fmtText);
CString strDefFont;
strDefFont.Format(_T("Courier New"));
ASSERT(fmtText.cbSize == sizeof(CHARFORMAT));
fmtText.dwMask = CFM_BOLD|CFM_ITALIC|CFM_UNDERLINE|CFM_STRIKEOUT|CFM_SIZE|
CFM_COLOR|CFM_OFFSET|CFM_PROTECTED;
fmtText.dwEffects = CFE_AUTOCOLOR;
fmtText.yHeight = 8*20; // высота 10pt - 200
fmtText.yOffset = 0;
fmtText.crTextColor = RGB(0, 0, 0);
fmtText.bCharSet = 0;
fmtText.bPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
ASSERT(strDefFont.GetLength() < LF_FACESIZE);
lstrcpyn(fmtText.szFaceName, strDefFont, LF_FACESIZE);
fmtText.dwMask |= CFM_FACE;
m_cRichEdit.SetDefaultCharFormat(fmtText);
}
void CRichProt::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
// Do not call CDialog::OnPaint() for painting messages
}
void CRichProt::ReadFileProt(void)
{
//MessageBox("ReadFileProt","Отладка",MB_OK);
// Чтение текста протокола из файла
// The file from which to load the contents of the rich edit control.
//CFile cFile(lpFileNameProt, CFile::modeRead);
cfeProt.m_lOsError = 0;
c_FileProt.Open(lpFileNameProt,CFile::modeRead, &cfeProt);
err = cfeProt.m_lOsError;
//itoa(err,ch10,10);
//strrab1.Format(_T("Код закрытия файла - %s"),lpFileNameProt);
//MessageBox(ch10,strrab1,MB_OK);
if ( err == 0)
{
EDITSTREAM es;
es.dwCookie = (DWORD) &c_FileProt;
es.pfnCallback = MyStreamInCallback;
m_cRichEdit.StreamIn(SF_TEXT, es);
c_FileProt.Close();
}
}
// размещение окна с текстом протокола
void CRichProt::SetWindowProt(void)
{
CRichProt::GetClientRect(rectrich);
// TODO: Add your message handler code here
m_cRichEdit.MoveWindow(rectrich,true);
m_cRichEdit.InvalidateRect(rectrich,true);
}
void CRichProt::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
//MessageBox("OnSize","Отладка",MB_OK);
CRichProt::SetWindowProt();
}
BOOL CRichProt::OnCommand(WPARAM wParam, LPARAM lParam)
{
// TODO: Add your specialized code here and/or call the base class
char chcom[10];
ltoa(LOWORD(wParam),chcom,10);
// MessageBox("OnCommand",chcom,MB_OK);
if ( LOWORD(wParam) == WM_RBUTTONDOWN)
{
MessageBox("WM_RBUTTONDOWN","Отладка",MB_OK);
wParam = 0;
return 0;
}
if ( LOWORD(wParam) == 2)
{
MessageBox("Esc - 2",chcom,MB_OK);
wParam = 0;
return 0;
}
if ( LOWORD(wParam) == 13)
{
MessageBox("Enter - 13",chcom,MB_OK);
wParam = 0;
return 0;
}
if ( LOWORD(wParam) == 21)
{
MessageBox("Enter - 21",chcom,MB_OK);
wParam = 0;
return 0;
}
// lParam
// The low-order word specifies the x-coordinate of the cursor. The coordinate
// is relative to the upper-left corner of the client area.
// The high-order word specifies the y-coordinate of the cursor. The coordinate
// is relative to the upper-left corner of the client area.
return CDialog::OnCommand(wParam, lParam);
}
void CRichProt::OnEnChangeRich1E1()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
MessageBox("OnEnChangeRich1E1","Отладка",MB_OK);
}
Поле D_RICH1_E1 - опция VISIBLE - FALSE Avto HScroll - True Avto VScroll - True Multiline - True
В основном диалоге все поле разделено попалам 1 половина - CListCtrl 2 - половина - CRichEditCtrl