Garmin Fleet Management Controller  2.19.0
CStaticLink.cpp
Go to the documentation of this file.
1 // CStaticLink 1997 Microsoft Systems Journal.
3 // If this program works, it was written by Paul DiLascia.
4 // If not, I don't know who wrote it.
5 // CStaticLink implements a static control that's a hyperlink
6 // to any file on your desktop or web. You can use it in dialog boxes
7 // to create hyperlinks to web sites. When clicked, opens the file/URL
8 //
9 #include "stdafx.h"
10 #include "CStaticLink.h"
11 
12 IMPLEMENT_DYNAMIC( CStaticLink, CStatic )
13 
14 BEGIN_MESSAGE_MAP( CStaticLink, CStatic )
15  ON_WM_CTLCOLOR_REFLECT()
16  ON_CONTROL_REFLECT( STN_CLICKED, OnClicked )
17 END_MESSAGE_MAP()
18 
19 //----------------------------------------------------------------------
23 //----------------------------------------------------------------------
24 CStaticLink::CStaticLink()
25 {
26  mUnvisitedColor = RGB( 0, 0, 255 ); // blue
27  mVisitedColor = RGB( 128, 0, 128 ); // purple
28  mIsVisited = FALSE; // not visited yet
29 }
30 
31 //----------------------------------------------------------------------
43 //----------------------------------------------------------------------
44 afx_msg HBRUSH CStaticLink::CtlColor
45  (
46  CDC * aDC,
47  UINT aCtlColor
48  )
49 {
50  ASSERT( aCtlColor == CTLCOLOR_STATIC );
51 
52  DWORD dwStyle = GetStyle();
53  if( !( dwStyle & SS_NOTIFY ) )
54  {
55  // Turn on notify flag to get mouse messages and STN_CLICKED.
56  // Otherwise, I'll never get any mouse clicks!
57  ::SetWindowLong( m_hWnd, GWL_STYLE, dwStyle | SS_NOTIFY ) ;
58  }
59 
60  HBRUSH hbr = NULL;
61  if( ( dwStyle & 0xFF ) <= SS_RIGHT )
62  {
63  // this is a text control: set up font and colors
64  if( !(HFONT)mFont )
65  {
66  // first time init: create font
67  LOGFONT lf;
68  GetFont()->GetObject( sizeof( lf ), &lf );
69  lf.lfUnderline = TRUE;
70  mFont.CreateFontIndirect( &lf );
71  }
72 
73  // use underline font and visited/unvisited colors
74  aDC->SelectObject( &mFont );
75  aDC->SetTextColor( mIsVisited ? mVisitedColor : mUnvisitedColor );
76  aDC->SetBkMode( TRANSPARENT );
77 
78  // return hollow brush to preserve parent background color
79  hbr = (HBRUSH)::GetStockObject( HOLLOW_BRUSH );
80  }
81  return hbr;
82 }
83 
84 //----------------------------------------------------------------------
86 //----------------------------------------------------------------------
88 {
89  if( mLinkText.IsEmpty() ) // if URL/filename not set..
90  {
91  GetWindowText( mLinkText ); // ..get it from window text
92  }
93 
94  // Call ShellExecute to run the file.
95  // For an URL, this means opening it in the browser.
96  ShellExecute( NULL, _T("open"), mLinkText, NULL, NULL, SW_SHOWNORMAL );
97 
98  mIsVisited = TRUE; // (not really--might not have found link)
99 
100  Invalidate(); // repaint to show visited color
101 }
#define FALSE
Definition: garmin_types.h:46
#define TRUE
Definition: garmin_types.h:45