home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 July / CMCD0704.ISO / Software / Freeware / Utilitare / VisualBoyAdvance-1.7.2 / src / win32 / Hyperlink.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2004-05-13  |  2.7 KB  |  119 lines

  1. // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
  2. // Copyright (C) 1999-2003 Forgotten
  3. // Copyright (C) 2004 Forgotten and the VBA development team
  4.  
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation; either version 2, or(at your option)
  8. // any later version.
  9. //
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. // GNU General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program; if not, write to the Free Software Foundation,
  17. // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18.  
  19. // Hyperlink.cpp : implementation file
  20. //
  21.  
  22. #include "stdafx.h"
  23. #include "vba.h"
  24. #include "Hyperlink.h"
  25.  
  26. #ifdef _DEBUG
  27. #define new DEBUG_NEW
  28. #undef THIS_FILE
  29. static char THIS_FILE[] = __FILE__;
  30. #endif
  31.  
  32. /////////////////////////////////////////////////////////////////////////////
  33. // Hyperlink
  34.  
  35. Hyperlink::Hyperlink()
  36. {
  37.   m_over = false;
  38. }
  39.  
  40. Hyperlink::~Hyperlink()
  41. {
  42.   m_underlineFont.DeleteObject();
  43. }
  44.  
  45.  
  46. BEGIN_MESSAGE_MAP(Hyperlink, CStatic)
  47.   //{{AFX_MSG_MAP(Hyperlink)
  48.   ON_WM_CTLCOLOR_REFLECT()
  49.   ON_WM_ERASEBKGND()
  50.   ON_WM_MOUSEMOVE()
  51.   //}}AFX_MSG_MAP
  52.   ON_CONTROL_REFLECT(STN_CLICKED, OnClicked)
  53. END_MESSAGE_MAP()
  54.  
  55.   /////////////////////////////////////////////////////////////////////////////
  56. // Hyperlink message handlers
  57.  
  58. void Hyperlink::PreSubclassWindow() 
  59. {
  60.   DWORD dwStyle = GetStyle();
  61.   ::SetWindowLong(GetSafeHwnd(), GWL_STYLE, dwStyle | SS_NOTIFY);
  62.  
  63.   // 32649 is the hand cursor
  64.   m_cursor = LoadCursor(NULL, MAKEINTRESOURCE(32649));
  65.  
  66.   CFont *font = GetFont();
  67.  
  68.   LOGFONT lg;
  69.   font->GetLogFont(&lg);
  70.  
  71.   lg.lfUnderline = TRUE;
  72.   
  73.   m_underlineFont.CreateFontIndirect(&lg);
  74.   SetFont(&m_underlineFont);
  75.     
  76.   CStatic::PreSubclassWindow();
  77. }
  78.  
  79. void Hyperlink::OnClicked()
  80. {
  81.   CString url;
  82.   GetWindowText(url);
  83.   ::ShellExecute(0, _T("open"), url, 
  84.                  0, 0, SW_SHOWNORMAL);
  85. }
  86.  
  87. HBRUSH Hyperlink::CtlColor(CDC* pDC, UINT nCtlColor) 
  88. {
  89.   pDC->SetTextColor(RGB(0,0,240));
  90.     
  91.   return (HBRUSH)GetStockObject(NULL_BRUSH);
  92. }
  93.  
  94. BOOL Hyperlink::OnEraseBkgnd(CDC* pDC) 
  95. {
  96.   CRect rect;
  97.   GetClientRect(rect);
  98.   pDC->FillSolidRect(rect, ::GetSysColor(COLOR_3DFACE));
  99.  
  100.   return TRUE;
  101. }
  102.  
  103. void Hyperlink::OnMouseMove(UINT nFlags, CPoint point) 
  104. {
  105.   if(!m_over) {
  106.     m_over = true;
  107.     SetCapture();
  108.     ::SetCursor(m_cursor);
  109.   } else {
  110.     CRect r;
  111.     GetClientRect(&r);
  112.  
  113.     if(!r.PtInRect(point)) {
  114.       m_over = false;
  115.       ReleaseCapture();
  116.     }
  117.   }
  118. }
  119.