IonicWind Software

Aurora Compiler => General Discussion => Topic started by: ExMember001 on August 19, 2006, 08:26:09 PM

Title: hit a wall and need help :)
Post by: ExMember001 on August 19, 2006, 08:26:09 PM
Now my head really hurts.. that why i'm asking a bit of help ;)

I've almost get the AutoURLdetect for Richedit control to work under Aurora...
But its seems that the text range is not detect.

Does anyone see what i'm doing wrong?


// Auto URL detection in RichEDIT control

import INT SendMessage alias SendMessageA(INT hWnd,UNSIGNED INT Msg,UNSIGNED INT wParam,INT lParam);

// 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;
    dString lpstrText[1024];
}

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;

CRichEdit *m_Red;
}

global sub main()
{
dlg d1;
d1.Create(0,0,300,202,0x80CB0080,0,"AtoURLdetect test",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);

m_red->SetEventMask(ENM_LINK);
SendMessage(m_red->m_hwnd,EM_AUTOURLDETECT, 1,0);
m_red->settext("\nhttp://www.ionicwind.com");

CenterWindow();
return true;
}

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

INT urlLen;
dstring sText;

select nID
{
case RICHEDIT_1:

    SELECT code
{
Case EN_LINK:

    SELECT *(ENLINK)pnmhdr.msg
{
case WM_LBUTTONDBLCLK:

    //Set up out TEXTRANGE struct
                            eText.chrg.cpMin = eLINK.chrg.cpMin;
                            eText.chrg.cpMax = eLINK.chrg.cpMax;

                            //Tell the RTB to fill out our TEXTRANGE with the text
                            urlLen = SendMessage(m_red->m_hwnd,EM_GETTEXTRANGE,null,&eText);
                            messagebox(0,numtostr(urlLen),"Text Lenght");

                            //Trim the text
                            sText = Left$(eText.lpstrText, urlLen);
                            messagebox(0,sText,"Url");

                            //Launch the browser
                            //ShellExecuteA(0,"open",sText,null,0,1);
}

}
}
return true;
}


Title: Re: hit a wall and need help :)
Post by: Ionic Wind Support Team on August 19, 2006, 08:36:04 PM
Your TEXTRANGE structure is wrong.  lpstrText is a pointer that must contain the address of a buffer that you provide.  It is not an array (string) member as you have defined.

struct TEXTRANGE
{
    CHARRANGE chrg;
    byte *lpstrText;
}
...other changes...


                           //Tell the RTB to fill out our TEXTRANGE with the text
                            eText.lpstrText = &sText;
                            urlLen = SendMessage(m_red->m_hwnd,EM_GETTEXTRANGE,null,&eText);
                            messagebox(0,numtostr(urlLen),"Text Lenght");

                            //Trim the text
                            sText = Left$(sText, urlLen);
                            messagebox(0,sText,"Url");


Title: Re: hit a wall and need help :)
Post by: ExMember001 on August 19, 2006, 09:22:08 PM
interresting, but still getting 0 for text lenght

also, why you doing this :
eText.lpstrText = &sText;

and what does the & does exactly?
Title: Re: hit a wall and need help :)
Post by: kryton9 on August 19, 2006, 09:30:21 PM
eText.lpstrText = &sText;

& in this case is like reading it as: The Address of sText

A pointer stores the address of some information. To put a value where the pointer is pointing to you use the * in front of the pointer.

*lpstrText = "Test String";
But lpstrText itself contains the address of the string in memory where "Test String" is stored.
Title: Re: hit a wall and need help :)
Post by: ExMember001 on August 19, 2006, 09:40:22 PM
thanx Kryton9
nicely explained ;)
Title: Re: hit a wall and need help :)
Post by: Ionic Wind Support Team on August 19, 2006, 09:40:56 PM
Your getting 0 for the text length because your filling in the structure with random data.


dlg::OnNotify(INT code,INT nID,NMHDR *pnmhdr),INT
{
ENLINK eLINK;  //LOCAL variable never initialized by you.
...
                            //What did you expect to happen here?
                            //your assigning two integers from eLink that were never set.
                           // eText.chrg.cpMin = eLINK.chrg.cpMin;
                           // eText.chrg.cpMax = eLINK.chrg.cpMax;
                           //                  TRY THIS:
                           eText.chrg.cpMin = *(ENLINK)pnmhdr.chrg.cpMin;
                           eText.chrg.cpMax = *(ENLINK)pnmhdr.chrg.cpMax;
}


You have a habit of just throwing in local variables randomly when you can't get something to work.  A local variable in a subroutine isn't going to be 'magically' initialized by the compiler to aything useful.
Title: Re: hit a wall and need help :)
Post by: kryton9 on August 19, 2006, 09:58:30 PM
Glad it helped, I still refer to my notes constantly when working with pointers. It is not in my memory yet :)
Title: Re: hit a wall and need help :)
Post by: ExMember001 on August 19, 2006, 10:48:23 PM
Quote from: Paul Turley on August 19, 2006, 09:40:56 PM
Your getting 0 for the text length because your filling in the structure with random data.


dlg::OnNotify(INT code,INT nID,NMHDR *pnmhdr),INT
{
ENLINK eLINK;  //LOCAL variable never initialized by you.
...
                            //What did you expect to happen here?
                            //your assigning two integers from eLink that were never set.
                           // eText.chrg.cpMin = eLINK.chrg.cpMin;
                           // eText.chrg.cpMax = eLINK.chrg.cpMax;
                           //                  TRY THIS:
                           eText.chrg.cpMin = *(ENLINK)pnmhdr.chrg.cpMin;
                           eText.chrg.cpMax = *(ENLINK)pnmhdr.chrg.cpMax;
}


You have a habit of just throwing in local variables randomly when you can't get something to work.  A local variable in a subroutine isn't going to be 'magically' initialized by the compiler to aything useful.

lol  :D don't be mad at me ;)
well, i'm not throwing anything ;) i was just not understanding how to get it working .. so i try different way until i got it ...
i learn by my mistakes and when i know what it was , normaly i never repeat it :P
if i repeat it its because i don't understand it yet!
also with nothing to refer on .. its very hard to learn a new language (very different than Ibasic ;) )
just to give you a hint, i was very impressed just to get what was already working only by myself !

when the help file will be completed it will be easyer for me to understand how the language work
Ibasic was the first language i've ever use on windows to program something, and i never had to use pointer.
Now this is totaly different so i'm starting from the beginning again, well almost ;)

Thanx for showing me this, this will help a lots for other things i want to do!




Title: Re: hit a wall and need help :)
Post by: Ionic Wind Support Team on August 19, 2006, 11:18:30 PM
Not mad ;)   Just glad I can help a learning programmer.
Title: Re: hit a wall and need help :)
Post by: J B Wood (Zumwalt) on August 20, 2006, 08:48:50 AM
I learned a while back, this is Pauls personality :)
He comes across wierd sometimes.
Title: Re: hit a wall and need help :)
Post by: ExMember001 on August 20, 2006, 08:42:03 PM
yes i know, was joking a bit :P