|
RichEdit Demo
--------------------------------------------------------------------------------
GID Forums C/C++ Forums
Name/Brief Description:
RichEdit Demo - MFC
Date of Original Submission:
May 26, 2004
Submitted by:
MaxPayne
License:
None.
Brief Description:
This a demo program showing how to use Rich Edit Control in a MFC application. The following is a list of features and MFC methods that is used in the program. They shows some basic and advanced methods of programming MFC.
1. MFC controls usage, Extended ComboBox and Normal ComboBox, Check Box, Radio Button and Rich Edit.
2. Shows how to change a static control to a rich edit control using subclassing technique.
3. Creating a SDI application and using a FormView.
4. How to update controls in a formview as usually done with controls toolbar.
5. How to use the CRichEditCtrl class and its member functions to make text formating in the control.
Detail :
This project is a SDI application which uses the FormView as its view object.The CFormView class is the base class used for form views. A form view act like dialog and you can place controls in it as you would with a dialog.
There are 5 different controls used in the project and all of them is placed in the FormView. Lets go one by one of this controls:
Normal ComboBox :
This controls is used in the project to store font size. and the base class is CComboBox, which has the funtionality of a list box and also a edit control.
Extended ComboBox :
This control is used to display all the fonts installed in the user's system.
The CComboBoxEx class is the base class for Extended ComboBox and it extends the combo box control by providing support for image lists.It can be used to access images in the Image List.CImageList is the base class that provides support for image list.
C / C++ Code:
//declare a new Image List
CImageList m_imageList;
//create the image list
m_imageList.Create(16,16,ILC_MASK,12,4);
//Init a HICON object to hold the icons
HICON hIcon[2];
int n;
//Now let's insert some color icons
hIcon[0] = AfxGetApp()->LoadIcon(IDI_TRUETYPE);
hIcon[1] = AfxGetApp()->LoadIcon(IDI_EMPTY);
for (n = 0; n < 2; n++) {
//insert the icons into the image list
m_imageList.Add(hIcon[n]);
}
//Set the imagelist to the comboboxEx
m_ctlFontFace.SetImageList(&m_imageList);
//Contains information about an item in a ComboBoxEx control.
COMBOBOXEXITEM cbi;
// which feature should be activated
cbi.mask = CBEIF_IMAGE|CBEIF_TEXT|CBEIF_OVERLAY|
CBEIF_SELECTEDIMAGE;
//put the values of each in the struct
cbi.iImage = 0;
cbi.iSelectedImage = 0;
cbi.iOverlay = 0;
//insert the item to the comboboxex
m_ctlFontFace.InsertItem(&cbi);
Check Box:
The check box used here is the three button ('B','I' and 'U') which properties is set to 'pushlike' so it looks like a button but behaves like a check box. The check box used to set the text formating effects to Bold,Italic and Undeline.
Radio Button:
This control also used to look like buttons but behave like a radio button. This buuton are used in the project to set paragraph alignment 'L' for left Align, 'C' for center and 'R' for right align.
Rich Edit:
Actually, the control used is a Static control, and it was subclassed to the base class CRichEditCtrl to behave and acts like a rich edit control.
The CMyRichEditCtrl is the new class created to derive from CRichEditCtrl base class. The static controls ID is used to subclass it to the Rich Edit.
C / C++ Code:
//declare a new instatance of the CMyRichEditCtrl class
CMyRichEditCtrl *m_ctlRichEdit;
//create new and set properties of the desired richedit
//IDC_RICHEDIT is the ID of the static control
m_ctlRichEdit = new CMyRichEditCtrl;
m_ctlRichEdit->Create (WS_VISIBLE | WS_CHILD |WS_BORDER | WS_HSCROLL | WS_CLIPCHILDREN | WS_VSCROLL | ES_MULTILINE | ES_AUTOVSCROLL |ES_LEFT | ES_WANTRETURN, rc, this, IDC_RICHEDIT);
As the rich Edit control is created, its ready for use.
__________________
When you say "I wrote a program that crashed Windows," people just stare at you blankly and say "Hey, I got those with the system, for free." Linus Torvalds
utime.김성하 님이 쓰신 글 :
: 안녕하세요 utime.김성하 입니다.
: 네이트온이나 Msn 메신저의 에디터 기능을 구현하려 합니다.
:
: 지난번 이 관련되어 질문을 드렸는데 어느 분께서 TWebBrowser Compnent를 이용해서 html로 처리하는게 편하다고 하시더군요
:
: 그런데 살펴 보니 TWebBrowser 는 M$ IE를 이용해서 그냥 뷰어 정도 가능한 것 같은데 TWebBrowser에서 메신져 처럼 에디팅이 가능 한가요?
:
: 참고로 네이트 온은 SoftWeb_Control이란 클래스를, Msn은 RichEdit20W 라는 클래스를 쓰던데 이 클래스에 관련된 참고할 만한 자료가 있는지요...
:
: 답변 부탁 드립니다~ ^^;
|