GIDForums  

Go Back   GIDForums > Computer Programming Forums > MS Visual C++ / MFC Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 26-May-2004, 02:09
Max Payne's Avatar
Max Payne Max Payne is offline
Regular Member
 
Join Date: Apr 2004
Location: 3° 08 North 101° 42 East
Posts: 332
Max Payne is a jewel in the roughMax Payne is a jewel in the roughMax Payne is a jewel in the rough

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.

CPP / 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.

CPP / 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
  #2  
Old 26-May-2004, 20:08
Max Payne's Avatar
Max Payne Max Payne is offline
Regular Member
 
Join Date: Apr 2004
Location: 3° 08 North 101° 42 East
Posts: 332
Max Payne is a jewel in the roughMax Payne is a jewel in the roughMax Payne is a jewel in the rough
Here is the projects zip file:
Attached Files
File Type: zip RichEditDemo.zip (81.3 KB, 515 views)
__________________
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
  #3  
Old 04-Oct-2004, 09:31
Ralph Shnelvar Ralph Shnelvar is offline
New Member
 
Join Date: Oct 2004
Posts: 1
Ralph Shnelvar is on a distinguished road

Lots of bugs in the downloaded code


I have downloaded this code and found that it has at least three bugs.

1) The pointer m_ctlRichEdit is uninitialized on first use. It should be initialized to 0 in the constructor and then tested for zero in (at least) OnSize.

2) The number of fonts is hard coded to 1000. My XP SP2 system has more than 1000 fonts by default. This oversight causes a subscript out of range condition.

3) Once those two bugs are cleared we still get an addressing exception. I'll let the author fix that one.
  #4  
Old 06-Oct-2004, 08:19
LuciWiz's Avatar
LuciWiz LuciWiz is offline
Moderator
 
Join Date: Jul 2004
Location: Cluj-Napoca (Romania)
Posts: 960
LuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the rough
I just want to say thanks for your remarks on Max Payne's code submittal.
Unfortunatelly, Max hasn't been active on this forum for a while - so he might not have any idea about your (very good) observations.
I am actually surprised he didn't see these problems in this program - I guess it worked fine on his machine and he didn't bother to check it through.
Thanks again and welcome to the GID Forums!

Kind regards,
Luci
__________________
Please read these Guidelines before posting on the forum

"A person who never made a mistake never tried anything new."
Einstein
 
 

Recent GIDBlogStupid Management Policies by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Ultra-fast hosting with free setup and a Real 24/7 Support, $5/Mo, Control Panel Demo hostorange Web Hosting Advertisements & Offers 0 23-May-2003 08:32

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 01:49.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.