Why do my program crash using getseltext() ?
this should return the text selected in the richedit control, right?
write some text in the box, select it , rightclick and choose the search option to crash.
import INT ShellExecuteA(INT hwnd, POINTER *lpOperation, POINTER *lpFile, POINTER *lpParameters, POINTER *lpDirectory, INT nShowCmd);
import INT GetCursorPos(POINT *lpPoint);
import INT ScreenToClient(INT hWnd,POINT *lpPoint);
//richedit mouse event mask
#define EN_MSGFILTER 0x700
#define ENM_MOUSEEVENTS 0x20000
#define WM_RBUTTONDOWN 0x204
#define RICHEDIT_1 1
struct MSGFILTER
{
NMHDR nmhdr;
UNSIGNED INT msg;
UNSIGNED INT wParam;
INT lParam;
}
MSGFILTER MF;
POINT pt;
// Richedit UDT
class dlg:CDialog
{
declare OnInitDialog(),int;
declare OnClose(),int;
declare OnNotify(INT code,INT nID,NMHDR *pnmhdr),INT;
declare OnMenuPick(INT nID),INT;
//Pointer to Menu Class
CMenu m;
//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_MOUSEEVENTS);
CenterWindow();
return true;
}
dlg::OnNotify(INT code,INT nID,NMHDR *pnmhdr),INT
{
//which control get notifications
select nID
{
//the richedit in this case
case RICHEDIT_1:
//look at code to get the notification message
SELECT code
{
// An input message from mouse or keyboard is sent
Case EN_MSGFILTER:
//Look at MSGFILTER UDT for the received message
SELECT *(MSGFILTER)pnmhdr.msg
{
//Mouse right button clicked
Case WM_RBUTTONDOWN:
m.BeginContextMenu();
m.MenuItem( "search on WikipÃÆ'Ã,©dia",0,1);
m.EndMenu();
//use API to get mouse position in Richedit
GetCursorPos(Pt);
ScreenToClient(m_hWnd,Pt);
//Show the context menu at current mouse location
ShowContextMenu(m.m_hMenu,pt.x,pt.y);
}
}
}
return;
}
dlg::OnMenuPick(INT nID),INT
{
string text,url;
select nID
{
Case 1:
text = m_Red->GetSelText();
url = "http://fr.wikipedia.org/wiki/Special:Search?search=" + text + "&fulltext=Rechercher";
//Launch the browser
ShellExecuteA(0,"open",url,null,0,1);
}
return true;
}
It's a bug in my RichEdit code. Will be fixed in beta1.
For now you can use this:
import INT ShellExecuteA(INT hwnd, POINTER *lpOperation, POINTER *lpFile, POINTER *lpParameters, POINTER *lpDirectory, INT nShowCmd);
import INT GetCursorPos(POINT *lpPoint);
import INT ScreenToClient(INT hWnd,POINT *lpPoint);
declare import,SendMessageA(unsigned int hwnd,unsigned int uMsg,unsigned int wParam,unsigned int lParam),unsigned int;
//richedit mouse event mask
#define EN_MSGFILTER 0x700
#define ENM_MOUSEEVENTS 0x20000
#define WM_RBUTTONDOWN 0x204
#define EM_GETSELTEXT (0x400 + 62)
#define RICHEDIT_1 1
struct MSGFILTER
{
NMHDR nmhdr;
UNSIGNED INT msg;
UNSIGNED INT wParam;
INT lParam;
}
MSGFILTER MF;
POINT pt;
// Richedit UDT
class dlg:CDialog
{
declare OnInitDialog(),int;
declare OnClose(),int;
declare OnNotify(INT code,INT nID,NMHDR *pnmhdr),INT;
declare OnMenuPick(INT nID),INT;
//Pointer to Menu Class
CMenu m;
//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_MOUSEEVENTS);
CenterWindow();
return true;
}
dlg::OnNotify(INT code,INT nID,NMHDR *pnmhdr),INT
{
//which control get notifications
select nID
{
//the richedit in this case
case RICHEDIT_1:
//look at code to get the notification message
SELECT code
{
// An input message from mouse or keyboard is sent
Case EN_MSGFILTER:
//Look at MSGFILTER UDT for the received message
SELECT *(MSGFILTER)pnmhdr.msg
{
//Mouse right button clicked
Case WM_RBUTTONDOWN:
m.BeginContextMenu();
m.MenuItem( "search on WikipÃÆ'Ã,©dia",0,1);
m.EndMenu();
//use API to get mouse position in Richedit
GetCursorPos(Pt);
ScreenToClient(m_hWnd,Pt);
//Show the context menu at current mouse location
ShowContextMenu(m.m_hMenu,pt.x,pt.y);
}
}
}
return;
}
dlg::OnMenuPick(INT nID),INT
{
string text,url;
select nID
{
Case 1:
SendMessageA(m_Red->m_hWnd,EM_GETSELTEXT,0,&text);
//text = m_Red->GetSelText();
url = "http://fr.wikipedia.org/wiki/Special:Search?search=" + text + "&fulltext=Rechercher";
//Launch the browser
ShellExecuteA(0,"open",url,null,0,1);
}
return true;
}
Thanks Paul ;)
I have same problem with this but on Cbasic
my question is :How translate this code to CBasic
if is posible?
sure it is possible ;)
you got all that you need to translate from this code...
i've not do any coding in cbasic for about 4 years ;) but ill give it a try tonight if i have the time
Thanks advance becose i'm do everithing other in interpreter that look ok,
and editor dont have contextmenu for cut,copy,paste such problem!!!
bye i hope that you find time...