From: jp2msft on
What is the best way to activate menu items like Cut, Copy, Paste, Undo, and
Redo?

Should each of my textbox controls have an event that looks for some text
being selected? That seems cumbersome, especially if I get into my MDI
application that is going to have multiple forms.

I'd like to learn that there is some way that I can receive a notice from
the Clipboard telling me that data is there (activate the Paste items) or
that something has been detected that can be acted upon (activate the Cut and
Copy items), but I don't know what to look for.

Could someone give me advice on this?

Regards,
~Joe
From: MikeD on

"jp2msft" <jp2msft(a)discussions.microsoft.com> wrote in message
news:69097B82-FD8D-4A02-9CDC-269FC2B63789(a)microsoft.com...
> What is the best way to activate menu items like Cut, Copy, Paste, Undo,
> and
> Redo?
>
> Should each of my textbox controls have an event that looks for some text
> being selected? That seems cumbersome, especially if I get into my MDI
> application that is going to have multiple forms.

That's probably the easiest. If these textboxes are all on the same form, a
control array for all the textboxes would simplify things quite a bit.

>
> I'd like to learn that there is some way that I can receive a notice from
> the Clipboard telling me that data is there (activate the Paste items) or
> that something has been detected that can be acted upon (activate the Cut
> and
> Copy items), but I don't know what to look for.
>

I don't think there's any way to receive such messages unless you make your
app part of the clipboard viewer chain. And even then, I don't think that'd
be too helpful. If your app is part of this chain, it will receive a
WM_DRAWCLIPBOARD message whenever the contents of the clipboard changes.
That's really only going to be helpful for your Paste command because Cut
and Copy depend on what, if anything, is selected within your app.

--
Mike
Microsoft MVP Visual Basic


From: MikeD on

"jp2msft" <jp2msft(a)discussions.microsoft.com> wrote in message
news:69097B82-FD8D-4A02-9CDC-269FC2B63789(a)microsoft.com...
> What is the best way to activate menu items like Cut, Copy, Paste, Undo,
> and
> Redo?

I kinda glossed right over the Undo and Redo. But, there's really nothing
there either. I'm not aware of any messages Windows will send to your app or
a textbox for this. The only thing there really is is the EM_CANUNDO, but
that's a message you must explicitly send and check the return value.
There's also an EM_CANREDO message but that is only applicable to a
RichTextBox (and again, you must explicitly send it and check the return
value).

--
Mike
Microsoft MVP Visual Basic


From: Jeff Johnson on
"jp2msft" <jp2msft(a)discussions.microsoft.com> wrote in message
news:69097B82-FD8D-4A02-9CDC-269FC2B63789(a)microsoft.com...

> What is the best way to activate menu items like Cut, Copy, Paste, Undo,
> and
> Redo?
>
> Should each of my textbox controls have an event that looks for some text
> being selected? That seems cumbersome, especially if I get into my MDI
> application that is going to have multiple forms.
>
> I'd like to learn that there is some way that I can receive a notice from
> the Clipboard telling me that data is there (activate the Paste items) or
> that something has been detected that can be acted upon (activate the Cut
> and
> Copy items), but I don't know what to look for.
>
> Could someone give me advice on this?

The rich edit control (known as the Rich Text Box in VB) has a notification
message called EN_SELCHANGE, but it doesn't appear that the regular text box
has this. Because of that you'd probably have to set up a timer to
constantly check whether your regular text boxes have selections or not.

What you're looking to do seems like a basic thing, doesn't it? But it looks
like it's actually a pain to implement.


From: Mike Williams on
"jp2msft" <jp2msft(a)discussions.microsoft.com> wrote in message
news:69097B82-FD8D-4A02-9CDC-269FC2B63789(a)microsoft.com...

> What is the best way to activate menu items like
> Cut, Copy, Paste, Undo, and Redo?

The individual TextBoxes themselves already know about such things and will
activate or deactivate their own "right click" menu items accordingly, so I
presume you must be talking about how to similarly activate or deactivate
your own Form menu items (Edit / Copy, Edit / Paste, etc).

> Should each of my textbox controls have an event that
> looks for some text being selected? That seems
> cumbersome . . .

I don't think an event for each TextBox is a good idea, nor even an array of
TextBoxes. I think it needs to be more "general" than that. As far as I can
see, you're going to need to detect when the user has activated a specific
menu on a Form, such as your Edit menu, and have your code activate or
deactivate the sub menu items (Cut, Copy, Paste, etc) as the list of sub
menus drops down. I don't know much about menus, other than the standard VB
menu editor stuff, and I cannot actually see an event that occurs when a
menu list drops down or is about to drop down, but I'm sure there must be
one, perhaps a window message of some kind? If you can get a hold of that
event then you can write just one block of code to determine the currently
selected control (Me.ActiveControl) and activate or deactivate the sub menu
items of the currently active control according to the current condition of
that specific control. If the control is a TextBox then Cut and Copy, for
example, could be activated if its SelLength is something other than zero.
Paste can similarly be activated or deactivated depending on whether there
is currently some text on the Windows clipboard, which you can check using
the Clipboard GetText method, and Undo can be activated or deactivated
depending on the return value from an EM_CANUNDO message.

All of the above of course relies on you being able to detect when a list of
sub menus is rolling down, which is something I don't yet know how to do,
but I think there must be a way of detecting it? Perhaps even somehting very
simple that I just happen to have missed? Once you can detect that event
then you only need one block of code which, in conjunction with
Me.ActiveControl, will enable you to do all the things you want.

Mike


 |  Next  |  Last
Pages: 1 2 3
Prev: Read Cannot
Next: saving all data on form