VC version super notepad, vc super notepad

Source: Internet
Author: User
Tags getcolor

VC version super notepad, vc super notepad

This is a big job for learning VC. It was a super notebook and suddenly found out. It was uploaded for your reference!

I. Functional requirements:

1. Add more functions based on the original Notepad program:

1). can change the background color.

2). The font color can be changed.

3). The font can be changed.

4). Alignment of paragraphs.

Ii. Overall Design:

The first statement is: this program inherits from CRichEditView.

1. Add the "format (O)" menu item:

(1) Add the "font (F)" sub menu.

(2) Add the "background color (B)" sub menu.

(3) Add the font color sub-menu.

2. Add a new toolbar:

(1) Add the bold button.

(2) Add the Italic button.

(3) Add the underline button.

(4) add the "Left alignment", "center", and "right alignment" buttons.

(5) add the "text color" and "background color" buttons.

3. Status Bar display time:

Displays the system time in real time.

4. Change the application icon:

5. Add a shortcut menu.

Iii. Detailed Design:

1. Add the "format (O)" menu item:

(1) Add the "font (F)" sub menu:

After the menu is added, add the message response function to the View class. In this function, the CFontDialog class of the general dialog box is called to change the font.

The Code is as follows:

Void CMyWordView: OnFormatFont () // set the font

{

// TODO: Add your command handler code here

 

CMyWordDoc * pDoc = GetDocument ();

ASSERT_VALID (pDoc );

CFontDialogcfd (& pDoc-> m_lf, CF_SCREENFONTS | CF_INITTOLOGFONTSTRUCT );

If (cfd. DoModal () = IDOK) // if you click OK, set the font

{

CHARFORMATcf;

Cf. cbSize = sizeof (CHARFORMAT );

Cf. dwMask = CFM_FACE | CFM_SIZE;

: Lstrcpy (cf. szFaceName, cfd. GetFaceName ());

Cf. yHeight = cfd. GetSize () * 2;

SetCharFormat (cf );

}

}

(2) Add the "background color (B)" sub menu:

After the menu is added, add the message response function to the View class. And call the color dialog box to set the color.

Note that:

The background color inherited from CRichEditView does not seem suitable. I saw that I didn't seem to have changed the background color. I could only change the background color of the font.

Because the background color will overwrite the previous text and must be output again

The font size, color, and other information of the previous text must be stored and output.

My code is:

Void CMyWordView: OnBkcolor () // change the background color

{

// TODO: Add your command handler code here

CMyWordDoc * pDoc = GetDocument ();

ASSERT_VALID (pDoc );

CColorDialog dlg;

CRichEditCtrl & EditCtrl = GetRichEditCtrl ();

CHARFORMAT cf;

If (dlg. DoModal () = IDOK)

{

EditCtrl. SetBackgroundColor (FALSE, dlg. GetColor (); // obtain the color selected by the user

Cf. dwMask = CFM_COLOR;

Cf. cbSize = sizeof (CHARFORMAT );

EditCtrl. getdefacharcharformat (cf );

Cf. crTextColor = RGB (0, 0 );

Cf. dwEffects & = ~ CFE_AUTOCOLOR;

EditCtrl. setdefacharcharformat (cf );

}

}

(3) add the "font color (T)" sub menu:

Similar to changing the background color, you must call the general dialog box-color dialog box.

After obtaining the color set by the user, re-design and output the characters.

The Code is as follows:

Void CMyWordView: OnTxtcolor () // change the font color

{

// TODO: Add your command handler code here

CHARFORMATcf;

CMyWordDoc * pDoc = GetDocument ();

ASSERT_VALID (pDoc );

CColorDialogdlg;

If (dlg. DoModal () = IDOK)

{

Cf. crTextColor = dlg. GetColor (); // obtain the selected color.

ZeroMemory (& cf, sizeof (CHARFORMAT ));

Cf. crTextColor = dlg. GetColor ();

Cf. dwMask = CFM_CHARSET | CFM_COLOR;

Cf. dwEffects = cf. dwEffects &~ CFE_AUTOCOLOR; // remove the original color effect and change it to a new color.

SetCharFormat (cf); // set

}

}

2. Add a new toolbar:

A. Create A new toolbar:

First, create a new toolbar resource in the resource view.

Secondly, because the toolbar belongs to the framework class, a new toolbar is displayed in the OnCreate function of the CMainFrame class. The tool bar can be modeled after it is automatically generated.

In the resource view, add the bold, italic, and underline buttons to the new toolbar resources.

B. Use the CHARFORMAT Structure in RichEdit Structure to set bold, italic, and underline.

The Code is as follows:

Void CMyWordView: OnCharBold () // whether the font is bold

{

// TODO: Add your command handler code here

CHARFORMATcf;

Cf = GetCharFormatSelection ();

If (! (Cf. dwMask & CFM_BOLD) |! (Cf. dwEffects & CFE_BOLD) // if it is not in bold, change it to bold.

Cf. dwEffects = CFE_BOLD;

Else // otherwise, change to the original font

Cf. dwEffects = 0;

Cf. dwMask = CFM_BOLD;

SetCharFormat (cf );

}

The other three are similar.

(4) add the "Left alignment", "center", and "right alignment" buttons.

Directly call the member function OnParaAlign () of the CRichEditView class.

Void CMyWordView: OnParaLeft ()

{

// TODO: Add your command handler code here

OnParaAlign (PFA_LEFT); // left-aligned paragraph

}

(5) add the "text color" and "background color" buttons:

The IDS of these two toolbar buttons are the same as those of the Response List menu in the menu item.

3. Status Bar display time:

The system time can be displayed in real time. You must obtain the system time and set the timer to update from time to time.

Obtain the system time and display it on the status bar:

CTimet = CTime: GetCurrentTime ();

CString str = t. Format ("% H: % M: % S"); // set the display time of the status bar

CClientDC dc (this );

CSize sz = dc. GetTextExtent (str );

Int index = 0;

Index = m_wndStatusBar.CommandToIndex (IDS_TIMER );

M_wndStatusBar.SetPaneInfo (index, IDS_TIMER, SBPS_NORMAL, sz. cx );

M_wndStatusBar.SetPaneText (1, str );

SetTimer (, NULL); // sets the timer

When the timer arrives, the following function Update time is called and displayed:

Void CMainFrame: OnTimer (UINT nIDEvent)

{

// TODO: Add your message handler code here and/or call default

CTime t = CTime: GetCurrentTime ();

CString str = t. Format ("% H: % M: % S ");

CClientDC dc (this );

CSize sz = dc. GetTextExtent (str );

M_wndStatusBar.SetPaneInfo (1, IDS_TIMER, SBPS_NORMAL, sz. cx );

M_wndStatusBar.SetPaneText (1, str );

CFrameWnd: OnTimer (nIDEvent );

}

4. Change the application icon:

You only need to erase the original icon and draw a new one.

Note: you must add two icons of different sizes.

5. Add a shortcut menu.

In the right-click message response function, add the design and display the pop-up menu:

VoidCMyWordView: OnRButtonUp (UINT nFlags, CPoint point) // create a pop-up menu

{

HWND hWnd;

POINT p;

GetCursorPos (& p );

: ScreenToClient (hWnd, & p );

CMenu menuPopup;

If (menuPopup. CreatePopupMenu ())

{

MenuPopup. AppendMenu (MF_STRING, ID_EDIT_UNDO, "undo (& U) \ tCtrl + Z ");

MenuPopup. AppendMenu (MF_STRING, ID_EDIT_CUT, "Cut (& C) \ tCtrl + X ");

MenuPopup. AppendMenu (MF_STRING, ID_EDIT_COPY, "Copy (& C) \ tCtrl + C ");

MenuPopup. AppendMenu (MF_STRING, ID_EDIT_PASTE, "paste (& P) \ tCtrl + V ");

MenuPopup. AppendMenu (MF_STRING, ID_EDIT_SELECT_ALL, "select all (& L) \ tCtrl + ");

MenuPopup. AppendMenu (MF_STRING, ID_FORMAT_FONT, "font (& F )");

MenuPopup. AppendMenu (MF_STRING, IDM_BKCOLOR, "background color (& B )");

MenuPopup. AppendMenu (MF_STRING, IDM_TXTCOLOR, "font color (& T )");

MenuPopup. TrackPopupMenu (TPM_LEFTALIGN, p. x, p. y, this );

}

CRichEditView: OnRButtonUp (nFlags, point );

}

Iv. Test and implementation:

V. Summary:

Through the development of this super notepad, I have a better understanding of the framework of MFC, and also feel the ease of use for the rich classes in MFC. I wrote it After inheriting CEditVIew according to my instructor's courseware at the beginning, but I found that although it can implement the notepad function, it is difficult to extend other functions of CEditVIew. As a result, I inherited from CScrollView, which has good scalability, but all its functions had to be compiled by myself, and I felt a little broken at the time. But I still need to check the information, read the books, and implement it myself. From the beginning, only outputs cannot be input, to can be input, but cannot wrap or delete,

The mouse cannot be processed after a line break or deletion occurs. In this process, I learned a lot, not only knowledge, but also programming ideas. Many things are not what we think. For example

The original string takes the total length (n-1), sets the text color as the background color, and then outputs the re-assigned string.

Because it inherits from CscrollView, it takes a long time to write too many files. If you submit a job, you may not be able to perform the most basic operations. I decided to write it over the winter vacation.

Finally, I inherited from the CRichEditView, and implemented functions such as changing the font, font color, and background color. I also learned a lot.

Reprinted please indicate the source: dunni column http://blog.csdn.net/u012027907

Advantages of this program: added the text editing Extension function to enable it to edit rich texts.

Disadvantages of this program: the interface design is still old and has limited functions. Should be aligned with the WordPad or Word, although it cannot be the same, but try to like its interface, and can achieve its 1/5 function is very good.


Questions about how to download the donkey vc and official versions

It depends on the emule version used by the source.
In some versions of emule, the anti-blood-sucking plug-in DLP is available. Currently, the main shielding object in China is thunder. If the source user uses such an emule, you cannot directly download it from thunder. Although VC emule has been blocked by some people, most of them are still unblocked. The emule of the VC version is definitely not blocking thunder. The reason is very simple. For commercial interests, money can make the promotion "go", you will say, I saw thunder in the shield list ...... We can see that thunder is not necessarily thunder. Similarly, we may not necessarily use easymule if we see people uploaded to easymule.
Of course, in the end, the number of sources is also the key. Some people use emule or thunder to do the work in order or do not do the work in order. They can still download the work without the source, all software is useless. Because any emule is not sent to you by the website, but by ordinary users like us.

I don't know if your emule 0.49c is the real official version of emule downloaded from the emule-project Website. If yes, it is quite good and will not block others, it will not be blocked by others. If you download it, you can use it. If you release it in domestic environments, you will not be able to use the official version. If the blood-sucking is so rampant, it will not be available.

Release of release by VC

For static connections, you do not need to copy the attached files to the target machine.
For dynamic connection, copy the dynamic library on the target machine that mfc depends on.
Varies depending on the VC version you are using.
For example, VC6 generally includes mfc42.dll, msvcrt. dll, and MSVCP60.DLL.
For vc71, MFC71.dll, msvcp71.dll, and msvcr71.dll are generally required.
VC2005, VC2010, and other versions can be used directly to Microsoft to download the corresponding runtime environment installation package. After installation, you can.
Bytes
Vcredist2008_x86.exe,vcredist2008sp1_x86.exe

Vs2010.install the runtime environment comparison insurance .vcredist2010_x86.exe or vcredist2010_x64.exe

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.