January 26, 2023, 10:12:21 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


AutoURL Detection in Richedit control

Started by ExMember001, August 21, 2006, 02:46:41 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ExMember001

Thanx to Paul For helping with this one ;)


// Auto URL detection in RichEDIT control

import INT SendMessage alias SendMessageA(INT hWnd,UNSIGNED INT Msg,UNSIGNED INT wParam,INT lParam);
import INT ShellExecuteA(INT hwnd, POINTER *lpOperation, POINTER *lpFile, POINTER *lpParameters, POINTER *lpDirectory, INT nShowCmd);

// AutoURL Detect
#define EN_LINK          0x70B
#define ENM_LINK         0x4000000
#define WM_LBUTTONDBLCLK 0x0203
#define WM_USER          0x0400
#define EM_GETTEXTRANGE  (WM_USER + 75)
#define EM_AUTOURLDETECT (WM_USER + 91)

#define RICHEDIT_1 1

// Richedit UDT
struct CHARRANGE
{
    INT cpMin;
    INT cpMax;
}

struct TEXTRANGE
{
    CHARRANGE chrg;
    pointer *lpstrText;
}

struct ENLINK
{
    NMHDR nmhdr;
    UNSIGNED INT msg;
    UNSIGNED INT wParam;
    INT lParam;
    CHARRANGE chrg;
}

class dlg:CDialog
{
declare OnInitDialog(),int;
declare OnClose(),int;
declare OnNotify(INT code,INT nID,NMHDR *pnmhdr),INT;

//create pointer to Richedit class
CRichEdit *m_Red;
}

global sub main()
{
dlg d1;
d1.Create(0,0,300,202,0x80CB0080,0,"AutoURLdetect",0);
d1.AddControl(CTRICHEDIT,"",30,24,241,155,0x50B01045,0x200,RICHEDIT_1);

d1.DoModal();

return 0;
}

dlg::OnClose(),int
{
CloseDialog(1);
return true;
}

dlg::OnInitDialog(),int
{
m_red = GetControl(RICHEDIT_1);

//set the eventmask to receive notification to the control
m_red->SetEventMask(ENM_LINK);
//send the auto url detection message, change true to false to deactivate
SendMessage(m_red->m_hwnd,EM_AUTOURLDETECT, true,0);
//write url text in the control
m_red->settext("Double click to Open Browser!\n\nhttp://www.ionicwind.com");

CenterWindow();

return true;
}

dlg::OnNotify(INT code,INT nID,NMHDR *pnmhdr),INT
{
ENLINK eLINK;
TEXTRANGE eText;
CHARRANGE chrg;

INT urlLen;
string url;

//which control get notifications
select nID
{
//the richedit in this case
case RICHEDIT_1:
   
//look at code to get the notification message
    SELECT code
{
//if we got a link in the text
Case EN_LINK:
   
//Check the message sent by the url in ENLINK structure
    SELECT *(ENLINK)pnmhdr.msg
{
//someone doubleclick on it
case WM_LBUTTONDBLCLK:

//Set up out TEXTRANGE struct
                            eText.chrg.cpMin = *(ENLINK)pnmhdr.chrg.cpMin;
                            eText.chrg.cpMax = *(ENLINK)pnmhdr.chrg.cpMax;

                            //Tell the RTB to fill out TEXTRANGE with the text
                            eText.lpstrText = &url;
                            urlLen = SendMessage(m_red->m_hwnd,EM_GETTEXTRANGE,null,&eText);

                            //Trim the text
                            url = Left$(url,urlLen);

                            //Launch the default browser
                            ShellExecuteA(0,"open",url,null,0,1);
}
}
}
return;
}

Jerry Muelver

Hmmm.... Seems like you could grab the url, and use it to open another file in the RichEdit control. Hypertext with no browser....  ::)