# If! Defined (success _) # define success _ # If _ msc_ver> 1000 # pragma once # endif // _ msc_ver> 1000 // hyperlinkstatic. h: header file ////////////////////////////////////// //////////////////////////////////////// /// chyperlinkstatic windowclass chyperlinkstatic: public cstatic {// constr Uctionpublic: Role (); // region: // operationspublic: // overrides // classwizard generated virtual function overrides // {afx_virtual (chyperlinkstatic) protected: Virtual void presubclasswindow (); ///} afx_virtual // implementationpublic: Virtual ~ Chyperlinkstatic (); // generated message map functionsprotected: // {afx_msg (chyperlinkstatic) afx_msg void onlbuttondown (uint nflags, cpoint point); afx_msg void onpaint (); afx_msg void ondestroy (); afx_msg void onmousemove (uint nflags, cpoint point); afx_msg int oncreate (empty rows); //} specify lresult values (wparam, lparam ); declare_message_map () Public ://*** **************************************** * ************************/Function: set the super connection //*********************************** * ********************************* void sethyperlink (cstring strurl); //************************************** ****************************** // function: set display text //*********************************** * ********************************* void setcaption (cstring strcaption); //********* **************************************** * ******************* // Function: set the default color //*********************************** * ********************************* void setdefaultcolor (colorref color) {m_crdefault = color; m_crcurrent = color ;} //************************************** ****************************** // function: set the mouse to overwrite the color //********************************** *********************************** void se Tonmousecolor (colorref color) {m_cronmouse = color ;} //************************************** ****************************** // function: modify the font size //*********************************** * ********************************* void setfontsizeincrement (INT nincrement) {m_nfontincrement = nincrement ;} //************************************** ****************************** // function: set whether the underline exists //***************** **************************************** * *********** Void setunderline (bool bunderline) {m_bunderline = bunderline ;} //************************************** ****************************** // function: get text size //*********************************** * ********************************* csize getcaptionsize (); PRIVATE: cstring _ strcaption, _ strhyperlink; cfont _ fontcaption; csize _ sizecaption; bool _ bcreatefont ,_ Bmouseincontrol, _ bgetcaptionsize; partition, _ harrowcursor; void createfont (cfont * pfont, long lfontincrement); void drawtext (CDC * PDC, colorref color); void setcaptionsize (); bool incaptionrange (cpoint & Point ); //************************************** ****************************** // function: set the size of the text in a certain font //***************************** **************************************** csize gettex Tsize (cfont * pfont, const cstring & strtext); Private: int m_nfontincrement; bool m_bunderline; colorref m_crdefault; // default font color: colorref m_cronmouse; // colorref m_crcurrent when the mouse overwrites; // current font }; //////////////////////////////////////// ///////////////////////////////////////{ {afx_insert_location }}// Microsoft Visual C ++ will insert additional declarations immediately before the previous line. # endif //! Defined (afx_hyperlinkstatic_h1_32a71426_1315_407c_9d90_a484c5589d801_encoded _)
// Hyperlinkstatic. CPP: implementation file // # include "stdafx. H "# include" hyperlinkstatic. H "# include" resource. H "# ifdef _ debug # define new debug_new # UNDEF this_filestatic char this_file [] = _ file __; # endif ////////////////////////////////////// //////////////////////////////////////// /chyperlinkstaticchyperlinkstatic:: chyperlinkstatic (): m_nfontincrement (0) {_ strcaption = _ strhyperlink = _ TT (""); _ BM Ouseincontrol = _ bcreatefont = _ bgetcaptionsize = false; _ hhandcursor =: loadcursor (afxgetapp ()-> m_hinstance, makeintresource (outputs); _ harrowcursor =: loadcursor (0, makeintresource (idc_arrow); Assert (_ hhandcursor & _ harrowcursor); // default attribute m_bunderline = true; // underline m_crdefault = RGB (0, 0,255 ); // blue m_cronmouse = m_crdefault; // when the mouse is overwritten, the color will not change m_crcurrent = m_crdefault; // The current font blue} chyperlinkstatic :: ~ Chyperlinkstatic () {} begin_message_map (chyperlinkstatic, cstatic) // {afx_msg_map (chyperlinkstatic) values () on_wm_paint () values () on_wm_mousemove () on_wm_create () //} afx_msg_mapon_message (wm_mouseleave, onmouseleave) end_message_map () //////////////////////////////////////// /// // chyperlinkstatic message handlersvoid chyperlinkstatic:: sethyperlink (cstrin G strhyperlink) {_ strhyperlink = strhyperlink;} void chyperlinkstatic: setcaption (cstring strcaption) {_ strcaption = strcaption; _ blank = false; invalidate (true);} void chyperlinkstatic :: onlbuttondown (uint nflags, cpoint point) {If (! _ Bgetcaptionsize) setcaptionsize (); If (! _ Strhyperlink. isempty () & incaptionrange (point) ShellExecute (0, "open", _ strhyperlink, 0, 0, sw_shownormal); cstatic: onlbuttondown (nflags, point );} void chyperlinkstatic: drawtext (CDC * PDC, colorref color) {If (null = PDC) return; cfont * poldfont = (cfont *) PDC-> SelectObject (& _ fontcaption); int nbkmode = PDC-> setbkmode (transparent); colorref noldcolor = PDC-> settextcolor (color); PDC-> textout (0, 0, _ strca Ption); PDC-> SelectObject (poldfont); PDC-> setbkmode (nbkmode); PDC-> settextcolor (noldcolor);} void chyperlinkstatic: onpaint () {If (! _ Fontcaption. m_hobject) {createfont (& _ fontcaption, m_nfontincrement); _ bcreatefont = true;} cpaintdc DC (this); // crect rctclient; // This-> getclientrect (& rctclient ); /// CDC memdc; // cbitmap membmp; // memdc. createcompatibledc (& DC); // membmp. createcompatiblebitmap (& DC, rctclient. width (), rctclient. height (); // cbitmap * poldbmp = memdc. selectObject (& membmp); // cbrush bgbrush (0 xffffff); // crect rctdraw (0, 0, rctcl Ient. width (), rctclient. height (); // memdc. fillrect (rctdraw, & bgbrush); drawtext (& DC, m_crcurrent); // dc. bitblt (0, 0, rctclient. width (), rctclient. height (), // & memdc, 0, 0, srccopy); // memdc. selectObject (poldbmp);/* If (_ bcreatefont = false) createfont (); cpaintdc DC (this); cfont * poldfont = (cfont *) DC. selectObject (& _ fontcaption); DC. setbkmode (transparent); DC. settextcolor (m_tagfontcolor); DC. textout (0, 0, _ Strcaption); DC. selectObject (poldfont); */} void chyperlinkstatic: ondestroy () {cstatic: ondestroy (); _ fontcaption. deleteobject ();} void chyperlinkstatic: presubclasswindow () {modifystyle (0, ss_policy, true); getwindowtext (_ strcaption); _ bgetcaptionsize = false; cstatic :: presubclasswindow ();} lresult chyperlinkstatic: onmouseleave (wparam, lparam) {_ bmouseincontrol = false; // restore the cursor if (! _ Strhyperlink. isempty (): setcursor (_ harrowcursor); // restore the font color if (m_crcurrent! = M_crdefault) {m_crcurrent = m_crdefault; invalidate (true);} return 0;} void chyperlinkstatic: onmousemove (uint nflags, cpoint point) {If (_ bmouseincontrol = false) {// track the mouse leave eventtrackmouseevent tme; tme. cbsize = sizeof (TME); tme. hwndtrack = getsafehwnd (); tme. dwflags = tme_leave; _ trackmouseevent (& TME); _ bmouseincontrol = true;} else {If (! _ Bgetcaptionsize) setcaptionsize (); // display the hand-shaped cursor if (! _ Strhyperlink. isempty (): setcursor (_ hhandcursor); // (incaptionrange (point ))? _ Hhandcursor: _ harrowcursor); // change the font color if (m_crcurrent! = M_cronmouse) {m_crcurrent = m_cronmouse; invalidate (true) ;}} cstatic: onmousemove (nflags, point);} void chyperlinkstatic: createfont (cfont * pfont, long lfontincrement) {cfont * pfontparent = getparent ()-> getfont (); Assert (pfontparent); logfont lf; pfontparent-> GetObject (sizeof (LF), & lf); LF. lfunderline = m_bunderline; LF. lfheight + = lfontincrement; pfont-> createfontindirect (& lf );} //************************** **************************************** * ** // Function: obtain the size of the specified text in a specific Font //***************************** **************************************** csize chyperlinkstatic:: gettextsize (cfont * pfont, const cstring & strtext) {assert (pfont); cclientdc DC (this); cfont * poldfont = dc. selectObject (pfont); csize size = dc. gettextextent (strtext); DC. selectObject (poldfont); Return size ;}//***************************** **************************************** // Function: set the size of the text in a certain font //***************************** **************************************** void chyperlinkstatic:: setcaptionsize () {If (! _ Bcreatefont) {createfont (& _ fontcaption, m_nfontincrement); _ bcreatefont = true;} If (! _ Bgetcaptionsize) {_ sizecaption = gettextsize (& _ fontcaption, _ strcaption); _ bgetcaptionsize = true ;}} //************************************** ****************************** // function: get text size //*********************************** * ********************************* csize chyperlinkstatic:: getcaptionsize () {If (! _ Bgetcaptionsize) setcaptionsize (); Return _ sizecaption;} bool chyperlinkstatic: incaptionrange (cpoint & Point) {If (_ bgetcaptionsize = false) return false; Return (point. x> = 0) & (point. x <_ sizecaption. CX) & (point. y> = 0) & (point. Y <_ sizecaption. cy);} int chyperlinkstatic: oncreate (maid) {If (cstatic: oncreate (lpcreatestruct) =-1) Return-1; createfont (& _ fontcaption, m_nfontincrement); _ bcreatefont = true; return 0 ;}