|
|
 | | From: | Heinz Kesting | | Subject: | How to determine if text is highlighted in an editor control | | Date: | Wed, 19 Jan 2005 21:19:56 +0100 |
|
|
 | Hi everybody, for a context menu attached to an editor I'd like to set the menu items "COPY" and "CUT" enabled, if there is text highlighted resp. disabled if no text is selected. In a thread some months ago Marco Mihorko (please forgive misspelling of the name) helped with a code that works for entryfields, unfortunately not for editors. Here's the code ...
#define EM_GETSELTEXT 0x00B0 .... extern cLong SendMessageN(CHANDLE, CUINT, CUINT, CLONG) User32 from "SendMessageA" if SendMessageN(form.editor1.hwnd, EM_GETSELTEXT, null, null) = 0 form.entryfield1.value = "No text highlighted in form.editor1" else form.entryfield1.value = "There IS text highlighted in form.editor1!" endif
The problem is that the dbase editor object is apparently no "rich edit control", as an excerpt from the WinAPI help is saying the following: "The EM_GETSELTEXT message retrieves the currently selected text in a rich edit control."
Does anyone around here see another way of determining wether there is text highlighted or not?
Thanks very much for helping! Heinz
|
|
 | | From: | Ivar B. Jessen | | Subject: | Re: How to determine if text is highlighted in an editor control | | Date: | Wed, 19 Jan 2005 22:01:45 +0100 |
|
|
 | Wed, 19 Jan 2005 21:19:56 +0100 chr(10) dbase.programming chr(10)How to determine if text is highlighted in an editor control chr(10) "Heinz Kesting" chr(10)
> >Does anyone around here see another way of determining wether there is text >highlighted or not?
See the following message in dBaseTalk programming group:
Message-ID:
Ivar B. Jessen
|
|
 | | From: | Heinz Kesting | | Subject: | Re: How to determine if text is highlighted in an editor control | | Date: | Wed, 19 Jan 2005 22:20:07 +0100 |
|
|
 | Hi Ivar
> See the following message in dBaseTalk programming group: > > Message-ID: > Maybe I'm too stupid, but I can't find the message you pointed at. Perhaps you can give a date or an author who started this thread ...
Thanks for helping, Heinz
|
|
 | | From: | Ivar B. Jessen | | Subject: | Re: How to determine if text is highlighted in an editor control | | Date: | Thu, 20 Jan 2005 09:56:50 +0100 |
|
|
 | Wed, 19 Jan 2005 22:20:07 +0100 chr(10) dbase.programming chr(10)Re: How to determine if text is highlighted in an editor control chr(10) "Heinz Kesting" chr(10)
>> See the following message in dBaseTalk programming group: >> >> Message-ID: >> >Maybe I'm too stupid, but I can't find the message you pointed at. Perhaps >you can give a date or an author who started this thread ...
There are two messages by Ronnie MacGregor of October 9, 2004,
Re: How to determine if text is highlighted - TextSelEd.zip [0/1] Re: How to determine if text is highlighted - TextSelEd.zip [1/1]
Ivar B. Jessen
|
|
 | | From: | Ronnie MacGregor | | Subject: | Re: How to determine if text is highlighted in an editor control | | Date: | Thu, 20 Jan 2005 18:16:57 -0000 |
|
|
 | In article <3hsuu0h7s2hmdb35kmrm8apm4qgsujtjgg@4ax.com>, bergishagen@it.notthis.dk says...
> >Maybe I'm too stupid, but I can't find the message you pointed at. Perhaps > >you can give a date or an author who started this thread ... > > There are two messages by Ronnie MacGregor of October 9, 2004,
..... and the most amazing thing is Heinz, that your name appears in the header for this cc. It was written for _you_ !!
-- Ronnie MacGregor Scotland
|
|
 | | From: | Heinz Kesting | | Subject: | Re: How to determine if text is highlighted in an editor control | | Date: | Thu, 20 Jan 2005 19:41:36 +0100 |
|
|
 | Hi Ronnie > .... and the most amazing thing is Heinz, that your name appears in the > header for this cc. It was written for _you_ !!
You probably can imagine the looks on my face when I finally found that post (I had to re-load the old threads, that's why I didn't see it last night). Actually I had the zip you had posted already on my hard disk, but there it had remained untouched until now. I proceeded last October without using it, to get ahead with that project, the popups worked so far, except for that blemish, that's the way it was and then I forgot about it completely. I had promised to ...
> ... It will take some time for testing, so I'll drop you a line later this week.
but that never happened, but after more than 3 months - here I am, at last .... Sorry for that, really, I am ...
But I've tested it just now, and it works great, of course. I'm working with wheel editors by Marc Van den Berghen and I asked him if he could add this feature to it.
Thank you once more for this! Best regards, Heinz
|
|
 | | From: | Heinz Kesting | | Subject: | Re: How to determine if text is highlighted in an editor control | | Date: | Thu, 20 Jan 2005 23:57:58 +0100 |
|
|
 | Hi Ronnie, After some testing and working with your code, some questions came up. First, I had some strange display behaviour of the form - certain objects were not visible. This was corrected after I commented out the line // form.metric := 6 // Pixels Without this line in the .cc the form is displayed as before.
Another question is about the last line in the following block, just trying to understand your code. // Copy anything selected in ED this.copy() this.ED2.paste() sel = this.ED2.value The variable sel is never used again, as far as I can see (which might be not too far ...), but what is it good for?
Then, at last a problem with the PASTE menu option came up. In the function that opens the popup I check if there is text in the clipboard to determine wether this option is enabled or not. Here's the code for this.
function Show_Popup(flags, col, row) local cbv1, cbv2, cbv3 extern clogical IsClipboardFormatAvailable(cuint) user32 cbv1 = IsClipboardFormatAvailable(1) // CF-Text cbv2 = IsClipboardFormatAvailable(7) // CF_OEMTEXT cbv3 = IsClipboardFormatAvailable(13) // CF_UNICODETEXT if cbv1 = true or cbv2 = true or cbv3 = true // there IS Text in the clipboard form.edit_pop.m_paste.enabled = true else form.edit_pop.m_paste.enabled = false endif
if empty(this.value) form.edit_pop.m_cut.enabled = false form.edit_pop.m_copy.enabled = false form.edit_pop.m_select_all.enabled = false else if form.nb.edit_body.IsTextSelected(true) form.edit_pop.m_cut.enabled = true form.edit_pop.m_copy.enabled = true else form.edit_pop.m_cut.enabled = false form.edit_pop.m_copy.enabled = false endif form.edit_pop.m_select_all.enabled = true endif
Now if the popup is opened for the first time and there is no text in the clipboard, it's ok. Later in this function when form.nb.edit_body.IsTextSelected(true) is called, then there IS text in the clipboard, naturally. And thus the PASTE option is enabled when the popup is opened up again, which is, in a way correct, on the other hand it's wrong, as this value in the clipboard came from IsTextSelected() and not from the user who does not understand if he then chooses actually to PASTE and finds some XXX inserted. Is there a way to clear the clipboard in this case?
Best regards, Heinz
|
|
|