disabling ctrl+d shortcut

M

MickMcG

Hi there,

I know this has been covered before but its turning into a real
headache for me... we have an outlook addin which processes the
item_remove message to mark a database row a deleted when a user
deletes an appointment from their calendar. The way we track the item
being deleleted is to build up a vb collection object based on the
currently selected items in the calendar...each time a new selection
is made we store the exchange id of the appointment...

this all works as its imposssible (almost!) to delete a calendar item
wihtout selecting it first. The one execption is deleting appointments
from within the appointment forms themselves. Users could potentially
open up 5 appointment forms and using the delete key on the toolbar or
the delete entry on the file menu delete the appointment. There doesnt
seem to be an easy way to track these deletes so i have disabled and
hidden the Delete entry in the file menu in the appointment form plus
the toolbar.....


the one drawback is that a user can still press ctrl+d from within an
appointment form and delete an appointment ... i dont want this!

any suggestions how i can delete or disable the ctrl+d shortcut in the
appointment form> the outlook addin is written in visual basic 6 using
the outlook model....from outlook 2000...
..
will changing the caption of the Delete entry in the file menu from
&Delete to to say Delete do the trick? i didnt get time to try that
before i had to leave work this evening...

Any help appreciated...

Cheers,
Mick
 
K

Ken Slovak - [MVP - Outlook]

Not with Outlook 2000 except for various workarounds like checking ItemAdd
in Deleted Items and comparing your collection to the Items collection. For
Outlook 2002 and later you can use the BeforeDelete method for items deleted
in an Inspector, it's the only thing it's good for.
 
M

MickMcG

Hi Ken,

Thanks for the reply. I think i have a workaround.. First off for
controlling deleting of items... i've added a selection change event
handler to my addin.. this is fired each time an item is selected in
outlook and i can trap whether its a calendar item etc... using the
selection object i build up a list of currently selected items so when
a user deletes them... by either pressing the delete key/right
clicking on the appointment and clicking delete/pressing shift+delete
etc. i have a collection of the exchange id's associated with each
selected appointment..

where the theory fell down yesterday when i was unit testing it - was
that you can delete appointments from within appointments by either
ctrl+d - the file-delete key or the delete toolbar button...

i had no way to track this as any number of appointments could be
opened up at the same time and the user could randomly delete any of
them..


as i mentioned yesterday the reason i want to track deletes is to be
able to update a row in our sql database that stores extra details
about appointments... we process the delete in the item_remove

so this morning i was in a dilema...

first off i disabled and hide the delete key on the appointment form
toolbar
then i hide and disable the file - delete menu so far so good but the
i was left with the darn ctrl+d shortcut still deleting appointment
items on me!

so after a bit of head scratching i added a hook to my addin which
traps keyboard events - then i search for the ctrl+d key and hey
presto ctrl+d no longer works...

i then asked our users if they were happy with the solution and they
wanted a delete appointment button in the appointment form - this
wasnt to bad... i added a custom button to the toolbar and handle
deleting the appointment in the event handler for the button. this
doesnt cause any headaches because i can get the exchange id for the
appointment inthe on click event so i think i'm nearly there.

Can you see any flaws in my approach ken? i'm making the assumption
that you cant delete appointments any other way....

Any suggestions appreciated..

Cheers,
Mick
 
K

Ken Slovak - [MVP - Outlook]

Well, in an Explorer you can have one or more items selected and still
right-click on a non-selected item and bring up the context menu where you
can delete that item. Selection won't change in that case. There's one
shortcoming.

For cases of one or more items being opened in Inspectors I would use an
Inspector wrapper class and collection. In the class you can declare objects
WithEvents for any types you want to handle:

Private WithEvents m_objAppt As Outlook.AppointmentItem
Private WithEvents m_objContact As Outlook.ContactItem
'etc.

Then you declare public properties for each type of item you want to handle
and use that property to set the class module level object in the
NewInspector event based on Inspector.CurrentItem.Class:

Public Property Let Appt(oAppt As Outlook.AppointmentItem)
Set m_objAppt = oAppt
End Property

That lets each open item field its own events independent of any other open
item. That lets you handle the BeforeDelete event and cancel the deletion
within the class module for Outlook 2002 and later (2000 doesn't have
BeforeDelete).

See http://www.slovaktech.com/code_samples.htm#InspectorWrapper for an
example of an Inspector wrapper. I use those all the time to handle button
clicks when there are more than one item open plus events such as Close and
Send and so on.
 
M

MickMcG

Hi Ken,

Thanks for the reply. I think i have a workaround.. First off for
controlling deleting of items... i've added a selection change event
handler to my addin.. this is fired each time an item is selected in
outlook and i can trap whether its a calendar item etc... using the
selection object i build up a list of currently selected items so when
a user deletes them... by either pressing the delete key/right
clicking on the appointment and clicking delete/pressing shift+delete
etc. i have a collection of the exchange id's associated with each
selected appointment..

where the theory fell down yesterday when i was unit testing it - was
that you can delete appointments from within appointments by either
ctrl+d - the file-delete key or the delete toolbar button...

i had no way to track this as any number of appointments could be
opened up at the same time and the user could randomly delete any of
them..


as i mentioned yesterday the reason i want to track deletes is to be
able to update a row in our sql database that stores extra details
about appointments... we process the delete in the item_remove

so this morning i was in a dilema...

first off i disabled and hide the delete key on the appointment form
toolbar
then i hide and disable the file - delete menu so far so good but the
i was left with the darn ctrl+d shortcut still deleting appointment
items on me!

so after a bit of head scratching i added a hook to my addin which
traps keyboard events - then i search for the ctrl+d key and hey
presto ctrl+d no longer works...

i then asked our users if they were happy with the solution and they
wanted a delete appointment button in the appointment form - this
wasnt to bad... i added a custom button to the toolbar and handle
deleting the appointment in the event handler for the button. this
doesnt cause any headaches because i can get the exchange id for the
appointment inthe on click event so i think i'm nearly there.

Can you see any flaws in my approach ken? i'm making the assumption
that you cant delete appointments any other way....

Any suggestions appreciated..

Cheers,
Mick
 
K

Ken Slovak - [MVP - Outlook]

Did you read my earlier post? Your reply is about the same as the one I
replied to already. As I mentioned, if you select Item A in a folder and
then right-click on Item B the Selection collection will not change but the
user can still delete Item B.

Also, using an Inspector wrapper and a declared item in it that handles
events such as BeforeDelete should let you handle the Ctrl+D shortcut.
 
M

MickMcG

Hi Ken,

I'm posting through google groups so i didnt see your reply before i
last replied... must be a delay on this side or something... i see
what you mean about the selection/delete through the context menu...
is there anyway to remove the delete from the context menu? our users
may be able to live with the solution we have anyway but it would be
nice to box off every angle..

Cheers,
Mick
 
K

Ken Slovak - [MVP - Outlook]

You can try your luck with the code for handling context menus at
outlookcode.com and see if you can remove Delete from the Explorer context
menu but I don't know if it will work.
 
M

MickMcG

Hi Ken,

I tested our solution again and it seems like i cant highlight an item
- then right click on another without selecting it - maybe its because
we have the selection change handler implemented in our addin? i tried
the same thing on a machine which doesnt have our addin and you can do
as you say - hightlight one item then right click on another and
delete it without the selection changing. Any ideas on why it might be
happening? It looks like we might be ok - do you have any other ideas
on where our selection method might be bypassed for deletes? The
solution is in test now and likely to go into production at the
begining of next month all going well

Thanks for your advice
Regards,
Mick
 
M

MickMcG

Hi Ken,

One more question if you dont mind?

When my appointment form loads on the end of the standard tool bar
there a 'More buttons' toolbar button - when you click it it has the
option to 'Add or Remove buttons' We've been requested to hide or
disable this button but i cant find the button in the standard toolbar
commandbar to hide it. Have you any idea on how we might get rid of
it? It seems like the last hurdle facing us.

Cheers,
Mick
 
K

Ken Slovak - [MVP - Outlook]

I'm not sure, I haven't seen your selection handler code. If you are testing
this now you can be sure that some user will find something you or I would
never think of that will show up some problems. It's unavoidable :)

See what happens...
 
K

Ken Slovak - [MVP - Outlook]

I haven't played with this but I'm guessing that setting
CommandBar.AdaptiveMenu = False and then setting the CommandBar.Protection
flags should do that for you. Look up the Protection flags in the Object
Browser, it looks like msoBarNoCustomize is the one you want. According to
the Help in the Object Browser setting that flag prevents access to the
add/remove buttons menu.




MickMcG said:
Hi Ken,

One more question if you dont mind?

When my appointment form loads on the end of the standard tool bar
there a 'More buttons' toolbar button - when you click it it has the
option to 'Add or Remove buttons' We've been requested to hide or
disable this button but i cant find the button in the standard toolbar
commandbar to hide it. Have you any idea on how we might get rid of
it? It seems like the last hurdle facing us.

Cheers,
Mick
"Ken Slovak - [MVP - Outlook]" <[email protected]> wrote in message
You can try your luck with the code for handling context menus at
outlookcode.com and see if you can remove Delete from the Explorer context
menu but I don't know if it will work.
 
M

MickMcG

Hi ken,

Cheers for that i will try it in the morning and let you know how i get on

Thanks,
Mick
Ken Slovak - said:
I haven't played with this but I'm guessing that setting
CommandBar.AdaptiveMenu = False and then setting the CommandBar.Protection
flags should do that for you. Look up the Protection flags in the Object
Browser, it looks like msoBarNoCustomize is the one you want. According to
the Help in the Object Browser setting that flag prevents access to the
add/remove buttons menu.




MickMcG said:
Hi Ken,

One more question if you dont mind?

When my appointment form loads on the end of the standard tool bar
there a 'More buttons' toolbar button - when you click it it has the
option to 'Add or Remove buttons' We've been requested to hide or
disable this button but i cant find the button in the standard toolbar
commandbar to hide it. Have you any idea on how we might get rid of
it? It seems like the last hurdle facing us.

Cheers,
Mick
"Ken Slovak - [MVP - Outlook]" <[email protected]> wrote in message
You can try your luck with the code for handling context menus at
outlookcode.com and see if you can remove Delete from the Explorer context
menu but I don't know if it will work.




Hi Ken,

I'm posting through google groups so i didnt see your reply before i
last replied... must be a delay on this side or something... i see
what you mean about the selection/delete through the context menu...
is there anyway to remove the delete from the context menu? our users
may be able to live with the solution we have anyway but it would be
nice to box off every angle..

Cheers,
Mick
 
M

MickMcG

Hi Ken,

THe first line

CommandBar.AdaptiveMenu = False threw an error but when i used the
Protection line it worked

'hide the 'more buttons' button
colCommandBars.Item("Standard").Protection = msoBarNoCustomize

so again thanks for your help... hopefully i wont have any more
questions!

Cheers,
Mick



Hi ken,

Cheers for that i will try it in the morning and let you know how i get on

Thanks,
Mick
Ken Slovak - said:
I haven't played with this but I'm guessing that setting
CommandBar.AdaptiveMenu = False and then setting the CommandBar.Protection
flags should do that for you. Look up the Protection flags in the Object
Browser, it looks like msoBarNoCustomize is the one you want. According to
the Help in the Object Browser setting that flag prevents access to the
add/remove buttons menu.




MickMcG said:
Hi Ken,

One more question if you dont mind?

When my appointment form loads on the end of the standard tool bar
there a 'More buttons' toolbar button - when you click it it has the
option to 'Add or Remove buttons' We've been requested to hide or
disable this button but i cant find the button in the standard toolbar
commandbar to hide it. Have you any idea on how we might get rid of
it? It seems like the last hurdle facing us.

Cheers,
Mick
"Ken Slovak - [MVP - Outlook]" <[email protected]> wrote in message
You can try your luck with the code for handling context menus at
outlookcode.com and see if you can remove Delete from the Explorer context
menu but I don't know if it will work.




Hi Ken,

I'm posting through google groups so i didnt see your reply before i
last replied... must be a delay on this side or something... i see
what you mean about the selection/delete through the context menu...
is there anyway to remove the delete from the context menu? our users
may be able to live with the solution we have anyway but it would be
nice to box off every angle..

Cheers,
Mick
 
M

MickMcG

Hello again Ken,

I found another problem! To allow the handle of deletes from within an
appointment form i've added a custom delete appointment button to the
standard toolbar

Private Sub colInspectors_NewInspector(ByVal Inspector As
Outlook.Inspector)

.....
If TypeName(Inspector.CurrentItem) = "AppointmentItem" Then

objTrace.LogTrace LOG_DIAGNOSTIC, "", "Adding Delete Appointment
button
to standard toolbar "
Set tbDeleteAppointment = colControls.Add(Type:=msoControlButton,
ID:=1,
Temporary:=False)
tbDeleteAppointment.Caption = "Delete Appointment"
tbDeleteAppointment.FaceId = 478 '2148
tbDeleteAppointment.Style = msoButtonIconAndCaption

End if

The click event for the tbDeleteAppointment button works grand each
time i open an appointment form. If however i open two appointment
forms.. - leave both open then tab back to the first and click on the
'Delete Appointment' button the event does fire.... i guess its some
sort of concurrency issue to do with where i'm binding the event to
the button. Any ideas on how i might get around this?

Cheers,
Mick


Hi Ken,

THe first line

CommandBar.AdaptiveMenu = False threw an error but when i used the
Protection line it worked

'hide the 'more buttons' button
colCommandBars.Item("Standard").Protection = msoBarNoCustomize

so again thanks for your help... hopefully i wont have any more
questions!

Cheers,
Mick



Hi ken,

Cheers for that i will try it in the morning and let you know how i get on

Thanks,
Mick
Ken Slovak - said:
I haven't played with this but I'm guessing that setting
CommandBar.AdaptiveMenu = False and then setting the CommandBar.Protection
flags should do that for you. Look up the Protection flags in the Object
Browser, it looks like msoBarNoCustomize is the one you want. According to
the Help in the Object Browser setting that flag prevents access to the
add/remove buttons menu.




Hi Ken,

One more question if you dont mind?

When my appointment form loads on the end of the standard tool bar
there a 'More buttons' toolbar button - when you click it it has the
option to 'Add or Remove buttons' We've been requested to hide or
disable this button but i cant find the button in the standard toolbar
commandbar to hide it. Have you any idea on how we might get rid of
it? It seems like the last hurdle facing us.

Cheers,
Mick
"Ken Slovak - [MVP - Outlook]" <[email protected]> wrote in message
You can try your luck with the code for handling context menus at
outlookcode.com and see if you can remove Delete from the Explorer context
menu but I don't know if it will work.




Hi Ken,

I'm posting through google groups so i didnt see your reply before i
last replied... must be a delay on this side or something... i see
what you mean about the selection/delete through the context menu...
is there anyway to remove the delete from the context menu? our users
may be able to live with the solution we have anyway but it would be
nice to box off every angle..

Cheers,
Mick
 
K

Ken Slovak - [MVP - Outlook]

You need to use an Inspector wrapper class and collection and assign each
button you create in each new Inspector that is opened a unique Tag
property. That way each class fires only events such as button clicks in
that Inspector and the unique Tag ensures that only that class will fire the
event and not every instantiated Inspector class.

See http://www.slovaktech.com/code_samples.htm#InspectorWrapper for an
example of an Inspector wrapper. It's similar in concept to the Explorer
wrapper used in the MicroEye ItemsCB template.
 
M

MickMcG

Hi Ken,

Thanks for that - i'll give it ago but i think our users may be able
to live with the limitation... at least for now

one final question if you dont mind?

if i wanted to remove the delete entry from the context menu in
outlook 2000 or just disable the conext menu from popping up when i
right click with the mouse in outlook do you know of any handy way to
do this?

Cheers,
Mick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top