// Textview. CPP: Implementation of the ctextview class // # include "stdafx. H "# include" text. H "# include" textdoc. H "# include" textview. H "# ifdef _ debug # define new debug_new # UNDEF this_filestatic char this_file [] = _ file __; # endif ////////////////////////////////////// //////////////////////////////////////// /ctextviewimplement_dyncreate (ctextview, cview) begin_message_map (ctextview, cview) // {afx_msg_map (Ctextview) on_wm_create () on_wm_char () returns () //} afx_msg_map // standard printing commandson_command (id_file_print, cview: onfileprint) on_command (outputs, cview :: onfileprint) on_command (id_file_print_preview, cview: onfileprintpreview) end_message_map () //////////////////////////////////////// /// // ctextview construction/destruct Ionctextview: ctextview () {// todo: Add Construction Code herem_strline = ""; m_ptstart = cpoint (0, 0); m_iwidth = 0;} ctextview ::~ Ctextview () {} bool ctextview: precreatewindow (createstruct & CS) {// todo: Modify the window class or styles here by modifying // The createstruct csreturn cview :: precreatewindow (CS );} //////////////////////////////////////// /// // ctextview drawingvoid ctextview:: ondraw (CDC * PDC) {ctextdoc * pdoc = getdocument (); assert_valid (pdoc); cstring STR ("Wu xxabc Hello World"); PDC-> textout (0,200, str );} //////////////////////////////////////// /// // ctextview printingbool ctextview:: onprepareprinting (cprintinfo * pinfo) {// default preparationreturn doprepareprinting (pinfo);} void ctextview: onbeginprinting (CDC */* PDC */, cprintinfo */* pinfo */) {// todo: add extra initialization before printing} void ctextview: onendprinting (CDC */* PDC */, cprintinfo */* pinfo */) {// todo: add cleanup after printing }/////////////////////////////////// //////////////////////////////////////// /// ctextview diagnostics # ifdef _ debugvoid ctextview:: assertvalid () const {cview: assertvalid ();} void ctextview: dump (cdumpcontext & DC) const {cview: dump (DC);} ctextdoc * ctextview :: getdocument () // non-debug version is inline {assert (m_pdocument-> iskindof (runtime_class (ctextdoc); Return (ctextdoc *) m_pdocument ;} # endif/_ debug ////////////////////////////////// //////////////////////////////////////// //// ctextview message handlersint ctextview:: oncreate (maid) {If (cview: oncreate (maid) =-1) Return-1; cclientdc (this); textmetric metric; DC. gettextmetrics (& metric); // createsolidcaret (metric. tmavecharwidth, metric. tmheight); m_bmpcaret.loadbitmap (idb_wu); createcaret (& m_bmpcaret); showcaret (); settimer (1,100, null); Return 0;} void ctextview: onchar (uint nchar, uint nrepcnt, uint nflags) {cfont font; font. createpointfont (300, "文 ", null); cclientdc DC (this); cfont * poldfont = dc. selectObject (& font); If (0x0d = nchar) {// entertextmetric MT; DC. gettextmetrics (& mt); m_ptstart.y + = Mt. tmheight; m_strline.empty ();} else if (0x08 = nchar) {// backspacecolorref colorold = dc. settextcolor (DC. getbkcolor (); DC. textout (m_ptstart.x, m_ptstart.y, m_strline); m_strline = m_strline.left (m_strline.getlength ()-1); DC. settextcolor (colorold);} else {m_strline + = nchar;} DC. textout (m_ptstart.x, m_ptstart.y, m_strline); csize SZ = dc. gettextextent (m_strline); setcaretpos (cpoint (m_ptstart.x + Sz. CX, m_ptstart.y); DC. selectObject (poldfont); cview: onchar (nchar, nrepcnt, nflags);} void ctextview: callback (uint nflags, cpoint point) {setcaretpos (m_ptstart = point ); m_strline.empty (); cview: onlbuttondblclk (nflags, point);} void ctextview: ontimer (uint nidevent) {If (nidevent = 1) {m_iwidth + = 5; cclientdc DC (this); cstring STR ("Wu xxabc Hello World"); csize SZ = dc. gettextextent (STR); crect rect (0,200, m_iwidth, 200 + Sz. cy); DC. settextcolor (RGB (0xff, 0, 0); DC. drawtext (STR, & rect, dt_left);} cview: ontimer (nidevent );}