I am trying to get the position of the cursor in a richedit with the
CHARFROMPOS message (see below button2click) but it always return 0???
whats wrong?
thanks
philippe
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----
procedure GetPosition(Sender: TRichEdit);
var
aX, aY: Integer;
TheRichEdit : TRichEdit;
begin
aX := 0; aY := 0;
TheRichEdit := TRichEdit(Sender);
aY := SendMessage(TheRichEdit.Handle, EM_LINEFROMCHAR,
TheRichEdit.SelStart, 0);
aX := TheRichEdit.SelStart - SendMessage(TheRichEdit.Handle, EM_LINEINDEX,
aY, 0);
xx:=ax; // <-- global variable
yy:=ay;// <-- global variable
form1.label1.Caption := IntToStr(aY + 1) + ':' + IntToStr(aX + 1) ;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
P: TPoint;
begin
getposition(richedit1);
P := Point(XX, YY);
showmessage(inttostr(SendMessage(RichEdit1.Handle, EM_CHARFROMPOS, 0,
longint(@P))));
end;
You are lucky to not end up with access violations. This message (together
with EM_POSFROMCHAR) is a really stoke of genius by MS, it uses different
parameters for edit/memo controls and TRichedit. Of course the help documents
only one of them, which one depends on the version of win32.hlp you have.
Var
pt: TPoint;
charindex, row, col: Integer;
GetCursorPos( pt );
pt := richedit.screentoclient(pt);
charindex := richedit1.perform( EM_CHARFROMPOS, 0, integer(@pt));
Row := richedit1.PerForm(EM_EXLINEFROMCHAR,0, charindex);
Col := charindex - richedit1.Perform(EM_LINEINDEX,Row,0);
Peter Below (TeamB) 10011...@compuserve.com)
No e-mail responses, please, unless explicitly requested!
Thanks Peter but I want to use SENDMESSAGE and not PERFORM. In fact I
monitor mouse event from other apps and then when I get the control, I want
to know the word under the cursor. So i need to sendmessages(...) to that
app.
Also I don't know where the mouse click happened: in a tedit, trichedit,
etc...
so some sample code taking that into account would help a lot !!
thanks
regards
philippe
Peter Below (TeamB) <10011...@compuXXserve.com> wrote in message ...
------------------------------------------------------q1--------------------
--------------------------------
Hi
I have a delphi program that is monitoring system wide mouse messages. my
program gets the control when the shift-right click is clicked.
I need to check if that click happened in a MS-word application (in fact I
need to know if the app is Word, Excel, Netscape...). For that I need to
know if the current app is word (or excel ).
How can I do that? (the next step is to get the current word under the
cursor).
Also I would like to know if somebody know how to add an option to the right
click menu (of Word).
ps: some sample code would be appreciated
thanks
philippe
------------------------------------------------------q2--------------------
--------------------------------
Hi
Can anyone give some sample code showing how to get the current word of
another application using delphi. (not the selected word, the current
word ->>containing the cursor.)
Thanks
philippe
Start with GetWindowfromPoint, using the current cursor position
(GetCursorPos). You get a window handle back. If <> 0 walk up the parent chain
using wnd:= GetWIndow( wnd, GW_PARENT ) until you find a window without parent
(result of GetWindow is 0). That is the top level window the click landed in.
Using Windows.GetClassname on it yields the window classname, which you can
then compare with a set of known classnames to indentfy the application you
are after. Getting to the application filename from outside the process is
difficult, but if you do it from inside a hook proc inside a DLL you are
inside the process and can use ParamStr(0) to get the module filename.
> (the next step is to get the current word under the cursor).
Abandon hope, all ye enter here <g>. It cannot be done in a generic fashion
unless you resort to scraping the pixels from the screen around the mouse
position and then do OCR on the bitmap image. Faking a Ctrl-C via keybd_event
works in many cases, if you do it from a hook DLL you can use GetFocus to find
the window with focus in the process, then you can send the Ctrl-C to this
window directly. It is not quite straightforward since a modifier key
combination is involved, go to http://www.deja.com,
http://www.mers.com/searchsite.html or http://www.tamaracka.com/search.htm and
search the newsgroups for PostKeyEx, that should turn up a suitable routine.
> Also I would like to know if somebody know how to add an option to the right
> click menu (of Word).
Which one? There are any number of these in Word, depending on where you
click. And even if you succeeded, how to you propose to become aware that the
menu item has been used? I'm sorry, but this is another rather impractical
proposition, resulting from lack of knowledge on how Win32 and Win32
applications work internally. Study the VBA documentation for Word, perhaps
there is a way to modify the menus via OLE automation.
What can I do for that sendmessage ?. I cannot get this thing to work and I
am getting mad...
I want to use SENDMESSAGE and not PERFORM. In fact I
monitor mouse event from other apps and then when I get the control, I want
to know the word under the cursor. So i need to sendmessages(...) to that
app.
Also I don't know where the mouse click happened: in a tedit, trichedit,
etc...
Could you give some sample code (for both cases), I have tried everything
without success (delphi 5, win98)
thanks
regards
philippe
so it does not help.
I am sure there is a way to do it since I have a program (babylon from
www.babylon.com) that allow me to right click system wide on anything (in
explorer, word, IE5,e tc) and it select the current word!
regards
philippe
Peter Below (TeamB) <10011...@compuXXserve.com> wrote in message ...
Believe me, there is no *generic* mechanism to do this. But most applications
handling text will select the word under the mouse cursor on a left
doubleclick on that position. Babylon translator may use that, fake a
doubleclick on the right-click position.