 |
|
 |
For my case I don't see the Hand cursor
I had to change the ressource ID for 32649 and changed cursor name for IDC_HAND in the ressource
So, it look like now:
m_hHyperCursor = ::LoadCursor(NULL, MAKEINTRESOURCE(32649));
Guillaume
|
|
|
|
 |
|
 |
I run this program on windosw 7,the cursor is disappear when I move the it to the hyperlink,need I add a cursor resource to the project?
|
|
|
|
 |
|
 |
Here is a UNICODE compatible code.
Dima
www.mmexplorer.com
// MyHyperLink.cpp : implementation file
//
// Written By : Renjith.R
// Email : renji12renji@m2comsys.com
// Details :Derived from MFC CStatic
// Date :Nov 25 2002
#include "stdafx.h"
#include "MyHyperLink.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMyHyperLink
CMyHyperLink::CMyHyperLink()
{
m_sLinkColor = RGB(0, 0 ,255);
m_sHoverColor = RGB(255, 0, 0);
m_sVisitedColor = RGB(5, 34, 143);
m_bFireChild = false;
m_bMouseOver = false;
m_bEnableToolTip = false;
m_bVisited = false;
//Create Tooltip
}
CMyHyperLink::~CMyHyperLink()
{
}
BEGIN_MESSAGE_MAP(CMyHyperLink, CStatic)
//{{AFX_MSG_MAP(CMyHyperLink)
ON_WM_MOUSEMOVE()
ON_WM_SETCURSOR()
ON_CONTROL_REFLECT(BN_CLICKED, OnClicked)
ON_WM_CTLCOLOR_REFLECT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyHyperLink message handlers
//Sets the Link Color
void CMyHyperLink::SetLinkColor(COLORREF sLinkColor)
{
m_sLinkColor = sLinkColor;
}
//open the URL by Windows ShellExecute()
bool CMyHyperLink::GoToLinkUrl(CString csLink)
{
HINSTANCE hInstance = (HINSTANCE)ShellExecute(NULL, _T("open"), csLink.operator LPCTSTR(), NULL, NULL, 2);
if ((UINT)hInstance < HINSTANCE_ERROR){
return false;
}else
return true;
}
//User can Active/Inactive the Tooltip already they set
void CMyHyperLink::ActiveToolTip(int nFlag)
{
if (nFlag)
m_bEnableToolTip = true;
else
m_bEnableToolTip = false;
}
//change The Tooltip text
void CMyHyperLink::SetTootTipText(LPCTSTR szToolTip)
{
if (m_bEnableToolTip )
{
m_ToolTip.UpdateTipText(szToolTip,this,1001);
}
}
//The Mouse Move Message
void CMyHyperLink::OnMouseMove(UINT nFlags, CPoint point)
{
CStatic::OnMouseMove(nFlags, point);
if (m_bMouseOver)
{
CRect oRect;
GetClientRect(&oRect);
//check if the mouse is in the rect
if (oRect.PtInRect(point) == false)
{
m_bMouseOver = false;
//Release the Mouse capture previously take
ReleaseCapture();
RedrawWindow();
return;
}
}else
{
m_bMouseOver = true;
RedrawWindow();
//capture the mouse
SetCapture();
}
}
//before Subclassing
void CMyHyperLink::PreSubclassWindow()
{
//Enable the Static to send the Window Messages To its parent
DWORD dwStyle = GetStyle();
SetWindowLong(GetSafeHwnd() ,GWL_STYLE ,dwStyle | SS_NOTIFY);
TCHAR szCurretText[MAX_PATH];
GetWindowText(szCurretText, MAX_PATH);
if ((szCurretText) == NULL){
SetWindowText(m_csLinkText.operator LPCTSTR());
}
LOGFONT sLogFont;
GetFont()->GetLogFont(&sLogFont);
//Set the Link UnderLined
sLogFont.lfUnderline = true;
//Set the Font to the Control
m_oTextFont.CreateFontIndirect(&sLogFont);
this->SetFont(&m_oTextFont, true);
//Adjust the window
//IsValidURL();
//Set the Cursor Hand
//WinHlp32.exe in windows folder ResourceID 106
//is a standard window HAND cursor
//courtesy www.codeguru.com
//you can use a custom Hand cursor resourse also
// i added that as a resourse in this project with
// ID - IDC_CURSOR_HAND
TCHAR szWindowsDir[MAX_PATH*2];
GetWindowsDirectory(szWindowsDir ,MAX_PATH*2);
_tcscat(szWindowsDir, _T("\\Winhlp32.exe"));
HMODULE hModule = LoadLibrary(szWindowsDir);
if (hModule){
m_hHyperCursor = ::LoadCursor(hModule, MAKEINTRESOURCE(106));
}
this->SetCursor(m_hHyperCursor);
//free the module
if (hModule)
FreeLibrary(hModule);
CStatic::PreSubclassWindow();
this->SetCursor(m_hHyperCursor);
m_ToolTip.Create(this,TTS_ALWAYSTIP);
CRect oRect;
GetClientRect(&oRect);
m_ToolTip.AddTool(this, _T(""),oRect,1001);
m_ToolTip.ShowWindow(SW_HIDE);
}
void CMyHyperLink::SetLinkText(CString csLinkText)
{
m_csLinkText = csLinkText;
this->SetWindowText(csLinkText.operator LPCTSTR());
}
BOOL CMyHyperLink::PreTranslateMessage(MSG* pMsg)
{
m_ToolTip.RelayEvent(pMsg);
return CStatic::PreTranslateMessage(pMsg);
}
BOOL CMyHyperLink::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
::SetCursor(m_hHyperCursor);
return true;
//return CStatic::OnSetCursor(pWnd, nHitTest, message);
}
//////////////////EVENT WILL GET HERE //////////////////////
void CMyHyperLink::OnClicked()
{
if (m_bFireChild){
//Fire the Event to Parent Window
CWnd *pParent;
pParent = GetParent();
int nCtrlID = GetDlgCtrlID();
::SendMessage(pParent->m_hWnd, _HYPERLINK_EVENT, (WPARAM)nCtrlID, 0);
//::PostMessage(pParent->m_hWnd, __EVENT_ID_, (WPARAM)nCtrlID, 0);
}else
{
GoToLinkUrl(m_csUrl);
}
m_bVisited = true;
//reddraw the control
this->Invalidate(true);
}
HBRUSH CMyHyperLink::CtlColor(CDC* pDC, UINT nCtlColor)
{
if (m_bMouseOver){
if (m_bVisited)
pDC->SetTextColor(m_sVisitedColor);
else
pDC->SetTextColor(m_sHoverColor);
}else {
if (m_bVisited)
pDC->SetTextColor(m_sVisitedColor);
else
pDC->SetTextColor(m_sLinkColor);
}
pDC->SetBkMode(TRANSPARENT);
return((HBRUSH)GetStockObject(NULL_BRUSH));
}
void CMyHyperLink::SetToolTipTextColor(COLORREF sToolTipText) {
m_ToolTip.SetTipTextColor(sToolTipText);
}
void CMyHyperLink::SetToolTipBgColor(COLORREF sToolTipBgColor)
{
m_ToolTip.SetTipBkColor(sToolTipBgColor);
}
CString CMyHyperLink::GetLinkText() {
if (m_csLinkText.IsEmpty())
return CString("");
return m_csLinkText;
}
void CMyHyperLink::SetLinkUrl(CString csUrl) {
m_csUrl= csUrl;
}
CString CMyHyperLink::GetLinkUrl() {
return m_csUrl;
}
void CMyHyperLink::SetVisitedColor(COLORREF sVisitedColor) {
m_sVisitedColor = sVisitedColor ;
}
void CMyHyperLink::SetHoverColor(COLORREF cHoverColor) {
m_sHoverColor = cHoverColor;
}
void CMyHyperLink::SetFireChild(int nFlag) {
if (nFlag)
m_bFireChild = true;
else
m_bFireChild = false;
}
BOOL CMyHyperLink::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
NMHDR* pMsgHdr;
pMsgHdr = (NMHDR*) lParam;
switch (pMsgHdr->code){
case NM_RCLICK:
break;
default:
;
}
return CStatic::OnNotify(wParam, lParam, pResult);
}
////////////////////////////////////////////////////////
// Class Name : CMyHyperLink
// Written By : Renjith.R
// Email : renjith_sree@hotmail.com
// Details :Derived from MFC CStatic
// Date :Nov 25 2002
// This can be used as a Hyperlink
//Feel free to use this class in your project
///////////////////////////////////////////////////////////
#if !defined(AFX_MYHYPERLINK_H__699B2FB4_0C03_4B12_B117_210A97860E0D__INCLUDED_)
#define AFX_MYHYPERLINK_H__699B2FB4_0C03_4B12_B117_210A97860E0D__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// MyHyperLink.h : header file
//
//This is the EventID , Which Will send to the Parent
//by the hyperlink control
# define _HYPERLINK_EVENT WM_USER + 101
/////////////////////////////////////////////////////////////////////////////
// CMyHyperLink window
class CMyHyperLink : public CStatic
{
// Construction
public:
CMyHyperLink();
// Attributes
public:
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMyHyperLink)
public:
virtual BOOL PreTranslateMessage(MSG* pMsg);
protected:
virtual void PreSubclassWindow();
virtual BOOL OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult);
//}}AFX_VIRTUAL
// Implementation
public:
void SetFireChild(int nFlag);
CString GetLinkText();
CString GetLinkUrl();
bool GoToLinkUrl(CString csLink);
void SetHoverColor(COLORREF cHoverColor);
void SetVisitedColor(COLORREF sVisitedColor);
void SetLinkUrl(CString csUrl);
void SetToolTipBgColor(COLORREF sToolTipBgColor);
void SetToolTipTextColor(COLORREF sToolTipText);
void SetLinkText(CString csLinkText);
void SetTootTipText(LPCTSTR szToolTip);
void ActiveToolTip(int nFlag);
void SetLinkColor(COLORREF sLinkColor);
virtual ~CMyHyperLink();
// Generated message map functions
protected:
bool m_bFireChild;
HCURSOR m_hHyperCursor;
bool m_bEnableToolTip;
bool m_bMouseOver;
bool m_bVisited;
CFont m_oTextFont;
CToolTipCtrl m_ToolTip;
CString m_csToolTipText;
CString m_csLinkText;
CString m_csUrl;
COLORREF m_sHoverColor;
COLORREF m_sLinkColor;
COLORREF m_sVisitedColor;
//{{AFX_MSG(CMyHyperLink)
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
afx_msg void OnClicked();
afx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_MYHYPERLINK_H__699B2FB4_0C03_4B12_B117_210A97860E0D__INCLUDED_)
|
|
|
|
 |
|
 |
1) It doesn't support unicode builds
2) Where did you learn that strings should be transferred into function by value (not by reference) ?
It is evident that someone who want to use this code should be fully confident that code quality is at least not worse than itself's project code quality.
But anyway this class saves a lot of time for me.
Thank you.
|
|
|
|
 |
|
 |
Thx for your commments, btw there is no point in saying that the codeproject articles should comply with your project's quality..
['Loka Samastha Sukhino Bhavanthu' - May all beings be happy and free]
|
|
|
|
 |
|
 |
Hi,
Eda Nee Eppozhum Jeevichirippundo. I heard You Jumped From M2.
You Became Gold Member Me Too.
Mail Me baijumax@yahoo.com With Updates
Regards
BAIJUMAX
|
|
|
|
 |
|
 |
hi
how can i create without using mfc??
|
|
|
|
 |
|
 |
Hi,
I don't know what's wrong, but when used in dialog boxes under XP themes, the hyperlink is always black in color, even if you try to SetLinkColor() it. When used in property sheets, the colors are ok. Any ideas?
TIA
|
|
|
|
 |
|
 |
He shouldn't be hardcoding the link colours except as a last resort. Try to look up default colours from the IE settings in the registry:
HKEY_CURRENT_USER\
Software\
Microsoft\
Internet Explorer\
Settings\
|
|
|
|
 |
|
 |
Hi! Great work! Thanks for that. Although I needed to make a little change to your code to make it working under XP. TRANSPARENT background settings do not erase text's background and therefore two default colors (blue and red) overlap with very unpleasant look So instead of HBRUSH CHyperLink::CtlColor(CDC* pDC, UINT nCtlColor) { ... pDC->SetBkMode(TRANSPARENT); return((HBRUSH)GetStockObject(NULL_BRUSH)); } use this HBRUSH CHyperLink::CtlColor(CDC* pDC, UINT nCtlColor) { ... return NULL; } according to MSDN (TN062: Message Reflection for Windows Controls) if you return (NULL) parent window will create a brush itself. This is required when using XP Themes or ClearType smoothing, and of course should work in other systems...
Have a good day. Sergey
|
|
|
|
 |
|
 |
great buddy! i'll update it soon.thanks for your comments.
Ninety-eight percent of the thrill comes from knowing that the thing you designed works, and works almost the way you expected it would. If that happens, part of you is in that machine.
|
|
|
|
 |
|
 |
SetLinkText() works only one time. You mast override OnEraseBkgnd function, something like this:
BOOL CMyHyperLink::OnEraseBkgnd(CDC* pDC)
{
CRect rect;
GetClientRect(rect);
pDC->FillSolidRect(rect, ::GetSysColor(COLOR_3DFACE));
return TRUE;
}
|
|
|
|
 |
|
 |
Hi!
I would like to use this control on the first page of a wizard, in which the background is white.
I can't find the way to turn the background into white, or at least, put the background transparency.
How to do this?
Thks in advance!
Appstmd
http://www.appstmd.com
|
|
|
|
 |
|
 |
CMyHyperLink *pCMy=new CMyHyperLink;
CString strTest="where r u?";
CRect rect(50,20,100,50);
pCMy->Create(strTest,WS_VISIBLE|SS_CENTER|WS_CHILD,rect,this,80);
pCMy->SetLinkUrl("www.sina.com.cn");
pCMy->ActiveToolTip(1);
pCMy->SetTootTipText("Click Here to go sina come");
|
|
|
|
 |
|
 |
i will fix that bug ASAP
[ It is possible to represent everything in this universe by using 0 and 1 ]
|
|
|
|
 |
|
 |
This bug still exists.
Any ideas?
|
|
|
|
 |
|
 |
This bug still exist!!!!!!!!!!!!!!!
|
|
|
|
 |
|
 |
Your work is wonderful,but you should fix a big bug!!
your wrapper class:CMyHyperLink cannt support dynamicly creating a object!!!
i.e.
class CControlContainerDlg : public CDialog
{
// Construction
public:
void OnChildFire(WPARAM wparam,LPARAM lparam);
CControlContainerDlg(CWnd* pParent = NULL); // standard constructor
>//added by itanynj@msn.com
public:
// here is the testing codes of how dynamicly create hyperlink control
CMyHyperLink *m_TestDynHyperLink;
//end of testing codes
....
};
BOOL CControlContainerDlg::OnInitDialog()
{
....
if(this->m_TestDynHyperLink==NULL)
{
this->m_TestDynHyperLink=new CMyHyperLink();
if(this->m_TestDynHyperLink!=NULL)
{
this->m_TestDynHyperLink->Create(
"click here",
WS_CHILD|WS_VISIBLE|SS_CENTER,
CRect(100,100,200,130),
this,
ID_DYN_HYPERLINK);
this->m_TestDynHyperLink->ShowWindow(SW_SHOW);
}
}
.....
}
I debug these codes,and finally found the error occurs in thevoid CMyHyperLink::PreSubclassWindow()
{
....
LOGFONT sLogFont;
//error in here!!!
GetFont()->GetLogFont(&sLogFont) //Set the Link UnderLined
sLogFont.lfUnderline = true;
//Set the Font to the Control
m_oTextFont.CreateFontIndirect(&sLogFont);
this->SetFont(&m_oTextFont, true);
....
}
my project is very emergency!!!!!
thank you!!
I love www.codeproject.com deeply and inside!
I am from China
|
|
|
|
 |
|
 |
To avoid this bug, you need to make sure you delete the m_oTextFont object before dynamically creating a new one.
m_oTextFont.DeleteObject();
|
|
|
|
 |
|
 |
saved me some days, really great,
I've added it to my toolbox
ciao Andy
|
|
|
|
 |
|
 |
asrx wrote:
saved me some days
thankyou.
it is nice to hear that that really helped you..
~CodeTheDreams~
|
|
|
|
 |
|
 |
It's actually very easy to get it:
AfxGetApp()->LoadStandardCursor(MAKEINTRESOURCE(IDC_HAND));
This works unless the user has a really old IE (like 3 or 4).
|
|
|
|
 |
|
 |
OOOOOOOOPs.......
i tried that many times...i hav IE 6.0..
the Error is IDC_HAND - undeclared identifier..
~~~~Code the Dreams~~~~~
|
|
|
|
 |
|
 |
That means that you have either an old Platform SDK or that your WINVER is below 0x0500. IDC_HAND is defined as follows:
#if(WINVER >= 0x0500)
#define IDC_HAND MAKEINTRESOURCE(32649)
#endif /* WINVER >= 0x0500 */
Even if this indicates that IDC_HAND is only available in Win2k and above, I'm quite certain that it works with any Windows with a newer IE.
|
|
|
|
 |
|
 |
here i using VC++ 6.0 and Win 2000
~~~~Code the Dreams~~~~~
|
|
|
|
 |