Windows Mobile Developer Network Forum

Windows Mobile Developer Network Forum
It is currently Wed Sep 08, 2010 3:10 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 2 posts ] 

Rate this article
1 0%  0%  [ 0 ]
2 0%  0%  [ 0 ]
3 0%  0%  [ 0 ]
4 0%  0%  [ 0 ]
5 0%  0%  [ 0 ]
Total votes : 0
Author Message
 Post subject: How to add a hyperlink to my dialog?
PostPosted: Thu Oct 28, 2004 11:06 am 
Offline
PPCDN Team

Joined: Tue Apr 01, 2003 6:28 pm
Posts: 229
Location: Saint-Petersburg, Russia
<h2>Question</h2> I need to place a hyperlink to my dialog and to handle clicks on this link in my application code. How can I do it?
<h2>Answer</h2> You can simulate a link in dialog by a number of ways. First of all you can draw a link text on screen in <i>WM_PAINT</i> handler. You should select desired (most probably underlined) font into dialog device context, and draw link text to dialog. Your OnPaint method should contain code like this:
Code:
CFont* pOldFont = dc.SelectObject(&m_fontUnderlined);
dc.SetTextColor(rgbLinkColor);
dc.DrawText(strFirstLinkText, m_rtFirstLink, 0);
dc.SelectObject(pOldFont);

Also don't forget to check does stylus pressed inside link text. This could be done in <i>WM_LBUTTONDOWN</i> handler:
Code:
if (m_rtFirstLink.PtInRect(point)) {
    //link activated
}

Link rectangle should be calculated in advance:
Code:
CFont* pOldFont = dc.SelectObject(&m_fontUnderlined);
CSize szFirstLinkSize = dc.GetTextExtent(strFirstLinkText);
m_rtFirstLink = CRect(
   CPoint(rectClient.left+(rectClient.Width()-szFirstLinkSize.cx)/2,
      rectClient.top+50), szFirstLinkSize);

The other way is to use custom drawn static control. You should set underlined font in this static:
Code:
GetDlgItem(IDC_LINK_2)->SetFont(&m_fontUnderlined);

For font color changing you should handle WM_CTLCOLOR message and update color in provided device context:
Code:
HBRUSH CTestHyperlinkDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
   HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

   if (pWnd->GetDlgCtrlID()==IDC_LINK_2) {
      pDC->SetTextColor(rgbLinkColor);
   }
   
   return hbr;
}

Link activation is received through <i>BN_CLICKED</i> notification in dialog. Ensure that <i>Notify</i> check box is set in link static styles. It is responsible for <i>SS_NOTIFY</i> style.
Also you can use controls that supports links, such as <i>RichInk</i> or <i>HTML Viewer</i> controls. RichInk supports <i>EM_INSERTLINKS</i> message for link insertion and <i>HTML Viewer</i> could be fed with html code. Please, look at related resources section of this article for mere information.
You can download a <a href="samples/TestHyperlink.zip">sample program</a> that uses a number of approaches discussed in this article. This is a eVC4 MFC dialog based application. In case of pure WinAPI application implementation details will change but these approaches still apply.
<h2>Related resources:</h2>
<img src="http://www.pocketpcdn.com/images/bullet.gif" width="22" height="15"><a href="/sections/ui.html">Section: User Interface</a>
<img src="http://www.pocketpcdn.com/images/bullet.gif" width="22" height="15"><a href="/sections/html.html">Section: HTML in Programs</a>
<img src="http://www.pocketpcdn.com/images/bullet.gif" width="22" height="15"><a href="/articles/buttoncolor.html">QA: How to create a colored button?</a>
<img src="http://www.pocketpcdn.com/images/bullet.gif" width="22" height="15"><a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnppc2k/html/ppc_viewer.asp">Article: Developing in C++ with the HTML Viewer Control</a>
<img src="http://www.pocketpcdn.com/images/bullet.gif" width="22" height="15"><a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/guide_ppc/htm/_rapier_ref_em_insertlinks.asp">Article: EM_INSERTLINKS message</a>
<img src="http://www.pocketpcdn.com/images/bullet.gif" width="22" height="15"><a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnce30/html/richink.asp">Article: Using Rich Ink Technology in Microsoft Windows CE 3.0</a>

_________________
Andrey Yatsyk


Top
 Profile  
 
 Post subject: Re: How to add a hyperlink to my dialog?
PostPosted: Tue Jun 15, 2010 10:42 am 
Offline

Joined: Thu Jun 10, 2010 8:03 am
Posts: 0
How to upload file on my domain using hyperlink? I have created multiple files. I want to add these on my domain. How do I link these files to their related hyperlink? If you need additional information, please send me message.
_____________________
keyword research ~ keyword tool ~ keyword tracking ~ affiliate elite


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group