123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446 |
- #include "stdafx.h"
- #include "HyperLink.h"
- #include "ylgl.h"
- #include "PreviewDlg.h"
- #include <strsafe.h>
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- #define TOOLTIP_ID 1
- CHyperLink::CHyperLink()
- {
- m_hLinkCursor = NULL;
- m_crLinkColour = RGB(161, 161, 161);
- m_crHoverColour = RGB(222, 222, 222);
- m_bOverControl = FALSE;
- m_bVisited = FALSE;
- m_bUnderline = TRUE;
- m_bAdjustToFit = TRUE;
- m_strURL.Empty();
- m_fontsize = 90;
- m_bDisable = 0;
- m_nParent = -1;
- m_bBlackBk = 0;
- }
- CHyperLink::~CHyperLink()
- {
- m_Font.DeleteObject();
- }
- BEGIN_MESSAGE_MAP(CHyperLink, CStatic)
-
- ON_WM_CTLCOLOR_REFLECT()
- ON_WM_SETCURSOR()
- ON_WM_MOUSEMOVE()
- ON_CONTROL_REFLECT(STN_CLICKED, OnClicked)
- ON_WM_CREATE()
-
- END_MESSAGE_MAP()
- BOOL CHyperLink::PreTranslateMessage(MSG* pMsg)
- {
-
- return CStatic::PreTranslateMessage(pMsg);
- }
- void CHyperLink::OnClicked()
- {
- CString strWndText;
- GetWindowText(strWndText);
- if (m_bBlackBk == 0)
- g_pMainWnd->LinkClick(strWndText, m_nParent);
- else
- ((PreviewDlg*)GetParent())->LinkClick(strWndText);
-
-
- }
- HBRUSH CHyperLink::CtlColor(CDC* pDC, UINT nCtlColor)
- {
- ASSERT(nCtlColor == CTLCOLOR_STATIC);
- if (m_bOverControl)
- pDC->SetTextColor(m_crHoverColour);
-
-
- else
- pDC->SetTextColor(m_crLinkColour);
-
- if (m_bBlackBk)
- pDC->SetBkColor(RGB(0, 0, 0));
- else
- pDC->SetBkMode(TRANSPARENT);
- return (HBRUSH)GetStockObject(NULL_BRUSH);
- }
- void CHyperLink::OnMouseMove(UINT nFlags, CPoint point)
- {
- CStatic::OnMouseMove(nFlags, point);
- if (m_bDisable)return;
- if (m_bOverControl)
- {
- CRect rect;
- GetClientRect(rect);
- if (!rect.PtInRect(point))
- {
- m_bOverControl = FALSE;
- ReleaseCapture();
- RedrawWindow();
- return;
- }
- }
- else
- {
- m_bOverControl = TRUE;
- RedrawWindow();
- SetCapture();
- }
- }
- BOOL CHyperLink::OnSetCursor(CWnd* , UINT , UINT )
- {
- if (m_bDisable)return false;
- if (m_hLinkCursor)
- {
- ::SetCursor(m_hLinkCursor);
- return TRUE;
- }
- return FALSE;
- }
- void CHyperLink::PreSubclassWindow()
- {
-
- DWORD dwStyle = GetStyle();
- ::SetWindowLong(GetSafeHwnd(), GWL_STYLE, dwStyle | SS_NOTIFY);
- CStatic::PreSubclassWindow();
- }
- void CHyperLink::SetURL(CString strURL)
- {
- m_strURL = strURL;
- if (::IsWindow(GetSafeHwnd())) {
- PositionWindow();
-
- }
- }
- CString CHyperLink::GetURL() const
- {
- return m_strURL;
- }
- void CHyperLink::SetColours(COLORREF crLinkColour, COLORREF crVisitedColour,
- COLORREF crHoverColour )
- {
- m_crLinkColour = crLinkColour;
- m_crVisitedColour = crVisitedColour;
- if (crHoverColour == -1)
- m_crHoverColour = ::GetSysColor(COLOR_HIGHLIGHT);
- else
- m_crHoverColour = crHoverColour;
- if (::IsWindow(m_hWnd))
- Invalidate();
- }
- COLORREF CHyperLink::GetLinkColour() const
- {
- return m_crLinkColour;
- }
- COLORREF CHyperLink::GetVisitedColour() const
- {
- return m_crVisitedColour;
- }
- COLORREF CHyperLink::GetHoverColour() const
- {
- return m_crHoverColour;
- }
- void CHyperLink::SetVisited(BOOL bVisited )
- {
-
- }
- BOOL CHyperLink::GetVisited() const
- {
- return m_bVisited;
- }
- void CHyperLink::SetLinkCursor(HCURSOR hCursor)
- {
- m_hLinkCursor = hCursor;
- if (m_hLinkCursor == NULL)
- SetDefaultCursor();
- }
- HCURSOR CHyperLink::GetLinkCursor() const
- {
- return m_hLinkCursor;
- }
- void CHyperLink::SetUnderline(BOOL bUnderline )
- {
- m_bUnderline = bUnderline;
- if (::IsWindow(GetSafeHwnd()))
- {
- LOGFONT lf;
- GetFont()->GetLogFont(&lf);
- lf.lfUnderline = m_bUnderline;
- m_Font.DeleteObject();
- m_Font.CreateFontIndirect(&lf);
- SetFont(&m_Font);
- Invalidate();
- }
- }
- BOOL CHyperLink::GetUnderline() const
- {
- return m_bUnderline;
- }
- void CHyperLink::SetAutoSize(BOOL bAutoSize )
- {
- m_bAdjustToFit = bAutoSize;
- if (::IsWindow(GetSafeHwnd()))
- PositionWindow();
- }
- BOOL CHyperLink::GetAutoSize() const
- {
- return m_bAdjustToFit;
- }
- void CHyperLink::PositionWindow()
- {
- if (!::IsWindow(GetSafeHwnd()) || !m_bAdjustToFit)
- return;
-
- CRect rect;
- GetWindowRect(rect);
- CWnd* pParent = GetParent();
- if (pParent)
- pParent->ScreenToClient(rect);
-
- CString strWndText;
- GetWindowText(strWndText);
- CDC* pDC = GetDC();
- CFont* pOldFont = pDC->SelectObject(&m_Font);
- CSize Extent = pDC->GetTextExtent(strWndText);
- pDC->SelectObject(pOldFont);
- ReleaseDC(pDC);
-
- DWORD dwStyle = GetStyle();
-
- if (dwStyle & SS_CENTERIMAGE)
- rect.DeflateRect(0, (rect.Height() - Extent.cy) / 2);
- else
- rect.bottom = rect.top + Extent.cy;
- if (dwStyle & SS_CENTER)
- rect.DeflateRect((rect.Width() - Extent.cx) / 2, 0);
- else if (dwStyle & SS_RIGHT)
- rect.left = rect.right - Extent.cx;
- else
- rect.right = rect.left + Extent.cx;
-
- SetWindowPos(NULL, rect.left, rect.top, rect.Width(), rect.Height(), SWP_NOZORDER);
- }
- extern HCURSOR g_cursorhand;
- void CHyperLink::SetDefaultCursor()
- {
- m_hLinkCursor = g_cursorhand; return;
- if (m_hLinkCursor == NULL)
- {
-
- CString strWndDir;
- GetWindowsDirectory(strWndDir.GetBuffer(MAX_PATH), MAX_PATH);
- strWndDir.ReleaseBuffer();
- strWndDir += _T("\\winhlp32.exe");
-
- HMODULE hModule = LoadLibrary(strWndDir);
- if (hModule) {
- HCURSOR hHandCursor = ::LoadCursor(hModule, MAKEINTRESOURCE(106));
- if (hHandCursor)
- m_hLinkCursor = CopyCursor(hHandCursor);
- }
- FreeLibrary(hModule);
- }
- }
- LONG CHyperLink::GetRegKey(HKEY key, LPCTSTR subkey, LPTSTR retdata)
- {
- HKEY hkey;
- LONG retval = RegOpenKeyEx(key, subkey, 0, KEY_QUERY_VALUE, &hkey);
- if (retval == ERROR_SUCCESS) {
- long datasize = MAX_PATH;
- TCHAR data[MAX_PATH];
- RegQueryValue(hkey, NULL, data, &datasize);
- #if JEFF_TEST_ON
- StringCchCopy(retdata,MAX_PATH,data);
- #else
- lstrcpy(retdata, data);
- #endif
- RegCloseKey(hkey);
- }
- return retval;
- }
- void CHyperLink::ReportError(int nError)
- {
-
- }
- HINSTANCE CHyperLink::GotoURL(LPCTSTR url, int showcmd)
- {
-
-
-
-
-
- return 0;
- }
- int CHyperLink::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CStatic::OnCreate(lpCreateStruct) == -1)
- return -1;
-
-
- if (m_strURL.IsEmpty())
- GetWindowText(m_strURL);
-
-
- m_Font.CreatePointFont(m_fontsize, "ºÚÌå", NULL);
- SetFont(&m_Font);
- PositionWindow();
- SetDefaultCursor();
-
-
- return 0;
- }
|