Link to home
Start Free TrialLog in
Avatar of Thomas Stockbruegger
Thomas StockbrueggerFlag for Germany

asked on

Need some help with mouse over, change color

Hello,
I would like to change the color of a static text (like a hyperlink) when I go with my mouse over the
text.
I already change the cursor to a hand-cursor when my mouse is over the static text.
Please let me know. 500 points
Best regards,
Thomas


BOOL COffenePostenDialog_Detail::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
	BOOL bReturn;
	
	CRect rcBtn;
	CRect rcBtn1;
	CRect rcBtn2;
 
	CPoint ptCursor;
	CPoint ptCursor1;
	CPoint ptCursor2;
 
    // Calculate the current cursor position
	// Change cursor if we are over Internet and Email link
	//-----------------------------------
	CWnd* pBtn  = GetDlgItem(IDC_STATIC_INTERNET);
	CWnd* pBtn1 = GetDlgItem(IDC_STATIC_EMAIL);
	CWnd* pBtn2 = GetDlgItem(IDC_STATIC_TELEFON);
 
	pBtn->GetWindowRect(rcBtn);
    GetCursorPos(&ptCursor);
 
	pBtn1->GetWindowRect(rcBtn1);
	GetCursorPos(&ptCursor1);
 
	pBtn2->GetWindowRect(rcBtn2);
	GetCursorPos(&ptCursor1);
 
 
    //===========================================================================
	if(rcBtn.PtInRect(ptCursor)==TRUE ||rcBtn1.PtInRect(ptCursor1)==TRUE||rcBtn2.PtInRect(ptCursor1)==TRUE)
	{
		CWinApp* pApp = AfxGetApp();
		HCURSOR my_new_cursor = pApp->LoadCursor(IDC_CURSOR2); // load new cursor
		SetCursor(my_new_cursor);
		 bReturn = TRUE;
 
	}
   	else
	{
		bReturn = CDialog::OnSetCursor(pWnd, nHitTest, message);// default cursor
	}
	return bReturn;
   //===========================================================================
 
	return CDialog::OnSetCursor(pWnd, nHitTest, message);
}
 
 
 
 
 
HBRUSH COffenePostenDialog_Detail::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
  {
	   HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
       //--------------------------- Link Color Internet/ Email ------------------------------
	  if((pWnd->GetDlgCtrlID()==IDC_STATIC_INTERNET) ||(pWnd->GetDlgCtrlID()==IDC_STATIC_EMAIL))
      {
		  pDC->SetTextColor(clr_blue); 		   
	  }
      //---------------------------------------------------------------------------------
  
 
 
 
	  return hbr;
  }
  //###############################################################################

Open in new window

Avatar of alb66
alb66
Flag of Italy image

This is a nice sample (it is for a button, but you can apply the same concept to a static control):
http://www.codeproject.com/KB/buttons/hoverbutton.aspx

NOTE: may be you need to change CHoverButton::OnMouseHover from
void CHoverButton::OnMouseHover(WPARAM wparam, LPARAM lparam)
to
LRESULT CHoverButton::OnMouseHover(WPARAM wparam, LPARAM lparam)
and return 0 from it
ASKER CERTIFIED SOLUTION
Avatar of LordOfPorts
LordOfPorts
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Thomas Stockbruegger

ASKER

Thank you. That was easy and the code I was looking for, thanks a lot