 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Vladimir Stefanovic Guest
|
Posted: Wed Jun 22, 2005 4:10 pm Post subject: How to add a context menu item to IE when some text is selec |
|
|
Hi,
How can I add a new context menu item to the IE when some
text is selected?
Further I want my program to be executed after choosing that
item with selected text as argument.
--
Best regards,
Vladimir Stefanovic
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Wed Jun 22, 2005 8:25 pm Post subject: Re: How to add a context menu item to IE when some text is s |
|
|
"Vladimir Stefanovic" <antivari (AT) po (DOT) sbb.co.yu> wrote
| Quote: | How can I add a new context menu item to the IE when
some text is selected?
|
Adding Entries to the Standard Context Menu
http://msdn.microsoft.com/workshop/browser/ext/tutorials/context.asp
Gambit
|
|
| Back to top |
|
 |
Vladimir Stefanovic Guest
|
Posted: Wed Jun 22, 2005 8:31 pm Post subject: Re: How to add a context menu item to IE when some text is s |
|
|
Gambit wrote:
Thank you, that's it!
--
Best regards,
Vladimir Stefanovic
|
|
| Back to top |
|
 |
Vladimir Stefanovic Guest
|
Posted: Fri Jun 24, 2005 3:33 pm Post subject: Re: How to add a context menu item to IE when some text is s |
|
|
Hi Remy,
I succeded to add my custom menu item to IE context menu,
(in fact InnoSetup procedure did) and I defined my menu item
to appear only when some text is actually selected.
I also prepared my application to receive such text via
arguments of my executable. I have tested that scenario
by making a shortcut with parameters, and that works for now.
The problem I have faced now is about wiring MenuItem & EXE.
According to MSDN I must have a script (may be JavaScript),
to which the Registry entry of my context menu item points.
OK, I also did that, but I do not know anything about Java
Script :(
I know that this is *not* VCL question, but can you point me
to the right place to ask. Maybe one of jborland.
Anyway, if you know that by chance, this is the example code
from msdn:
<SCRIPT LANGUAGE = "JavaScript">
// Get the window object where the context menu was opened.
var oWindow = window.external.menuArguments;
// Get the document object exposed through oWindow.
var oDocument = oWindow.document;
// Get the selection from oDocument.
// in oDocument.
var oSelect = oDocument.selection;
// Create a TextRange from oSelect.
var oSelectRange = oSelect.createRange();
// Get the text of the selection.
var sNewText = oSelectRange.text;
// If nothing was selected, insert some text.
if (sNewText.length == 0){
oSelectRange.text = "INSERT TEXT";
}
// Otherwise, convert the selection to uppercase.
else{
oSelectRange.text = sNewText.toUpperCase();
}
</SCRIPT>
I Googled more and I have found that there is (well known)
ShellExecute() at Java Script , but I couldn't get it to work.
Can you please help me?
--
Best regards,
Vladimir Stefanovic
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Fri Jun 24, 2005 5:51 pm Post subject: Re: How to add a context menu item to IE when some text is s |
|
|
"Vladimir Stefanovic" <antivari (AT) po (DOT) sbb.co.yu> wrote
| Quote: | OK, I also did that, but I do not know anything about Java Script
|
It doesn't have to be Javascript specifically. It can be any language that
is currently installed on the machine that the Windows Scripting Host
recognizes, such as Javascript, VBScript, PerlScript, etc.
| Quote: | I Googled more and I have found that there is (well known)
ShellExecute() at Java Script , but I couldn't get it to work.
|
Just saying it doesn't work says nothing about the actual problem you are
having. You need to be more specific.
In any case, I don't think ShellExecute() is the way to go, though it might
work ok. You would probably be better off adding an ActiveX Automation
object to your main EXE and then have the script instantiate that object via
the CreateObject() function. It is much more effort on your part, though,
but it will provide a tigher integration between your script and your EXE.
Gambit
|
|
| Back to top |
|
 |
Vladimir Stefanovic Guest
|
Posted: Fri Jun 24, 2005 8:13 pm Post subject: Re: How to add a context menu item to IE when some text is s |
|
|
| Quote: | You would probably be better off adding an ActiveX
Automation object to your main EXE and then have the
script instantiate that object via the CreateObject() function.
It is much more effort on your part, though, but it will provide
a tigher integration between your script and your EXE.
|
Yes, I see... Many JScripts I saw today when Googling use
CreateObject() for similar purposes.
I never used ActiveX Automation, so I hope that BCB books
I have in my archive has something with which I can start with.
--
Best regards,
Vladimir Stefanovic
|
|
| Back to top |
|
 |
Vladimir Stefanovic Guest
|
Posted: Sun Jun 26, 2005 5:03 pm Post subject: Re: How to add a context menu item to IE when some text is s |
|
|
Hi Remy,
For start I'm investigating the ShellExecute method of wiring
my application & context IE menu. The ActiveX solution are
still in my plans, but when I collect more knowledge on that.
This is the Java Script that *works* with ShellExecute:
(may be not all olines f the script are necessary)
<SCRIPT language="JScript">
try
{
// Get the window object where the context menu was opened.
var oWindow = window.external.menuArguments;
// Get the document object exposed through oWindow.
var oDocument = oWindow.document;
// Get the selection from oDocument.
// in oDocument.
var oSelect = oDocument.selection;
// Create a TextRange from oSelect.
var oSelectRange = oSelect.createRange();
// Get the text of the selection.
var sNewText = oSelectRange.text;
var oShell = new ActiveXObject("Shell.Application");
oShell.ShellExecute("C:\Program Files\Di recnik\di.exe", sNewText);
}
catch(e)
{
alert("Error - " + e.description);
}
</SCRIPT>
The problem is in passing arguments (selected text) to my app.
THIS WORKS:
a) if my program is closed, the app starts, detects the arguments,
and everything is OK.
THIS DOES NOT WORK:
b) but if my program is opened, my *only one instance* mechanism
do not allow me to pass the *new* arguments, and it works with old
once. And I understand that is normal. But how can I get through it?
#define WM_START_VIA_IE (WM_USER + 1004)
#define WM_START_NORMAL (WM_USER + 1003)
bool StartNewInstance()
{
::CreateMutex( NULL, NULL, "Still in love with BCB" );
if ( GetLastError() )
{
HWND FirstWnd;
FirstWnd = ::FindWindow( "TDiMainForm", NULL );
if ( ParamCount() > 0 )
// Yes, I know that's the FIRST instance which has it's own
arguments
// But how can I collect new arguments and then escape?
PostMessage( FirstWnd, WM_START_VIA_IE, 0, 0 );
else
PostMessage( FirstWnd, WM_START_NORMAL, 0, 0 );
return ( false );
}
return ( true );
}
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
try
{
if ( ! StartNewInstance() )
return 0;
--
Best regards,
Vladimir Stefanovic
|
|
| Back to top |
|
 |
Vladimir Stefanovic Guest
|
Posted: Sun Jun 26, 2005 5:13 pm Post subject: Re: How to add a context menu item to IE when some text is s |
|
|
| Quote: | But how can I get through it?
|
If I must have a shared memory segment for that again
I'm going to retire immediatelly ;)
--
Best regards,
Vladimir Stefanovic
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Mon Jun 27, 2005 7:28 am Post subject: Re: How to add a context menu item to IE when some text is s |
|
|
"Vladimir Stefanovic" <antivari (AT) po (DOT) sbb.co.yu> wrote
| Quote: | b) but if my program is opened, my *only one instance* mechanism
do not allow me to pass the *new* arguments, and it works with old
once. And I understand that is normal. But how can I get through it?
|
Your "only one instance" code is wrong in general, let alone not designed to
handle sending command-line arguments to other instances at all. Use the
following code instead:
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR lpCmdLine, int)
{
HANDLE hMutex = ::CreateMutex(NULL, TRUE, "TDiMainFormMutex");
if( hMutex )
{
if( GetLastError() == ERROR_ALREADY_EXISTS )
{
HWND FirstWnd = ::FindWindow("TDiMainForm", NULL);
if( FirstWnd )
{
COPYDATASTRUCT cds = {0};
cds.dwData = 0x564C4144; // "VLAD"
cds.cbData = strlen(lpCmdLine);
cds.lpData = lpCmdLine;
::SendMessage(FirstWnd, WM_COPYDATA, 0,
reinterpret_cast<LPARAM>(&cds));
}
}
else
{
try
{
Application->Initialize();
Application->Title = "...";
Application->CreateForm(__classid(TDiMainForm),
&MainForm);
Application->Run();
}
catch(Exception &E)
{
Application->ShowException(&E);
}
}
CloseHandle(hMutex);
}
else
{
// real error creating the mutex, do something else...
}
return 0;
}
void __fastcall TDiMainForm::WndProc(TMessage &Message)
{
if( Message.Msg == WM_COPYDATA )
{
LPCOPYDATASTRUCT lpcds =
reinterpret_cast<LPCOPYDATASTRUCT>(Message.LParam);
if( (lpcds) && (lpcds->dwData == 0x564C4144) ) // "VLAD"
{
AnsiString CmdLine((char*) lpcds->lpData, lpcds->cbData);
// parse CmdLine as needed...
Message.Result = TRUE;
return;
}
}
TForm::WndProc(Message);
}
Gambit
|
|
| Back to top |
|
 |
Vladimir Stefanovic Guest
|
Posted: Mon Jun 27, 2005 1:36 pm Post subject: Re: How to add a context menu item to IE when some text is s |
|
|
| Quote: | Your "only one instance" code is wrong in general, let alone not designed
to
handle sending command-line arguments to other instances at all. Use the
following code instead:
|
Thank you very much...
I'll implement the code as soon as possible.
--
Best regards,
Vladimir Stefanovic
|
|
| Back to top |
|
 |
|
|
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 vote in polls in this forum
|
|