?
Solved

How to disable winword.exe(v2000) some menus,e .g. SaveAs,Save

Posted on 2003-02-20
19
Medium Priority
?
1,144 Views
Last Modified: 2012-08-13
currently, i have a process to launch winword.exe to view or edit document, but i want to some document cannot be used for some function, e.g. SaveAs, Print etc. However, i use hooking technology to implement, but always not found the message regarding the SaveAs, Print functions.

Thanks
Regards
0
Comment
Question by:aimsye
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
  • 5
  • +2
19 Comments
 
LVL 49

Expert Comment

by:DanRollins
ID: 7992422
I think you should make a WORD macro that will disable these commands when you open your document.

Please explain what you are trying to accomplish.

-- Dan
0
 
LVL 12

Expert Comment

by:Salte
ID: 7992800
I would believe word already had that capability built in, just provide word with the proper parameter options at startup line.

It's possible I am wrong and if I am you can - and should - make a word macro to disable those commands.

How are you going to intercept the commands to word anyway? If user select File|Save As... he will send a message to winword.exe process and not to your process. Your process will never see that message. To make matters worse, that message isn't standard in any meaning of the word, it is a user message that has it's own application specific meaning and it is next to impossible for another application to identify which command has which meaning. There might even be several commands which shares the meaning or one command is implemented by a sequence of several messages being sent in sequence etc.. Messing with another application's menu messages is not only bad design but it is a plain bad idea.

The suggestion of making a word macro to disable them sounds like the way to go if word doesn't have an option to make the file unsavable.

In any event you must make very sure you don't cause troubles to the user then. If I have word up and running and happily editing my CV or some other document and then you come running with your program and start word and end up taking my instance and turn it into a version that refuses to save my document I will get severly upset about that and you will find more than one dissatisfied customer.

Alf
0
 
LVL 12

Expert Comment

by:Salte
ID: 7992805
Btw, if you use word only to display text and not to print, save edit etc, why use word in the first place? Why not just use a viewer? If I am not mistaken, MS has a lightweight wordview.exe program available that does exactly that. I believe it is even free and can be downloaded. I haven't checked recently but it used to be somewhere a couple of years ago.

Alf
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Expert Comment

by:J0ker
ID: 7993971
Private Sub Document_Open()
    CommandBars("File").Controls("Save As...").Visible = False
End Sub

Private Sub Document_Close()
    CommandBars("File").Controls("Save As...").Visible = True
End Sub
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7994719
I think j0ker and Salte have hit upon an interesting and novel approach... use a WORD macro to disable menu items.  That idea would never have occurred to me.
-- Dan
0
 

Author Comment

by:aimsye
ID: 8031978
Thank all,
Firstly, in client PC, I am not sure allowed WORD macro running when open the WinWord application. maybe virus problem. and i try to WORD macro to disable menu functiona and button of toolbar. even that, user still use CTRL+S shortcut to do save action after you disable or invisible Save and Save button. Also how to disable the drag-drop function using the WORD macro. So I think the WORD macro maybe not a good solution.
Secondly, Sample for WORD Save funciton, I can using Hooking technica to intercept all messages of WinWord application, i don't know why not found similar message like "Save". This is problem. Thirdly if I using WORD viewer to open document, I don't know, the Viewer maybe whether use some command line parameters to control more functions. This solution maybe exist much limitation.

I don't know, whether Microsoft expert in "www.experts-exchange.com".
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 8032280
Use Spy++ and see what messages get sent to what windows when you use the various commands.  

But I don't think you have any chance of complete success.  Consider that the user could write his own macro so that for instacne, Ctrl+Shift+I will execute a macro that does Save command.  You could never stop that and would never know that it occured.

Perhaps your best bet would be to host Word in your own program, using its ActiveX interface.  You could possibly exert more control over it then.

-- Dan
0
 

Author Comment

by:aimsye
ID: 8032332
Thank you DanRollins, as you know, I had used spy++ to get all message of WinWord Process. but cannot found some message for Save function. there are limitation if you use ActiveX interface. you cannot include all WinWord functions into your ActiveX. I think there are common entry for the Save function, however user click menu, button or make a macro to implement Save funcion. how to know the common entry of Save?
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 8032725
I think you can write a macro that replaces the Save function == whether invoked from keyboard, mouse menu, or macro.  I seem to recall that being a technique that would allow one to pre-set some defaults, etc.

-- Dan
0
 

Author Comment

by:aimsye
ID: 8038979
I still think for the WORD macro cannot be a good solution, maybe a more low level solution for the WORD core, my purpose how to found the general action of WORD entry message, so that intercept it to control WORD.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 8039076
This looks promising.  You can write an interface to sinf ApplicationEvents and here is a smple that discusses the tiopic, suing Microsoft Word as the target program!

   ATLEventHandling: Demonstrates Using IDispEventImpl and IDispEventSimpleImpl to Handle Word Events
    http://msdn.microsoft.com/library/en-us/vcsample98/html/vcrefatleventhandlingsample.asp

It's not gunna happen by magic.  You'll need to study up on ATL and all that.  Use a search string of "ApplicationEvents" on MSDN for more examples.

-- Dan
 

0
 

Author Comment

by:aimsye
ID: 8039918
Thank you Dan,

I found the ATL solution only control the folloing events for word appliation event.

DocumentBeforeClose
DocumentBeforePrint
DocumentBeforeSave
DocumentChange
DocumentOpen
NewDocument
Quit
WindowActivate
WindowBeforeDoubleClick
WindowBeforeRightClick
WindowDeactivate
WindowSelectionChange

, how to contorl other event. e.g. SaveAs, SendTo, Drag-Drop .......

Would you have more solution in it. Thank you again.
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 1000 total points
ID: 8040108
SaveAs can be controlled by canceling the DocumentSave event.  I think that if you don't want to allow the user to use SendTo, you should disable the menu item.  I think that if you don't want the user to be able to drag and drop anything, you should use the Word Viewer rather than Word itself.

That is what I think.  What do you think?

-- Dan
0
 
LVL 12

Expert Comment

by:Salte
ID: 8056088
First off dan,

Not sure why you said that was a novel idea that you never thought of..I believe it was you who first suggested the idea of a word macro in this discussion. No, sarcasm not taken, I never intended to present it as a novel idea, I believe I even referred to your posting when I mentioned the possibility.

Secondly Aimsye,
It very much appear to me that aimsye do NOT want to disable word or use word at all. He wants a viewer that can display word documents without editing them or saving them. Drop Word from your mind, forget word. Go for a viewer instead. As I said before, if you mess around with a word instance that the user uses to happily edit documents that do not concern your application, he or she will be very upset that you suddenly disable his or her ability to save the edited document. Use a viewer if you want to allow people to read word documents without modifying them.

Third, yes, there are several ways to save a file, menu commands, keyboard shortcuts etc etc. If you want to disable them using a word macro you have to disable ALL of them. Saying you can't use word macro because it is possible to save using a different method is non-sense. It just implies that intercepting menu selection only is not enough, you must also intercept keyboard short cuts drag and drop etc etc. A word macro still works you just have to place commands that intercept more than just the menu choices. I still think that you really want a viewer and not word itself and if you mess with word make very sure you only mess with the instance you have created for the purpose of showing your file and not some other instance of word which the user happened to use. Be aware that many MS programs tries to be "smart" and if you want to launch word and the user already have a word instance running it might attempt to use that instance and load your file or whatever into it. You must not allow that to happen, you must make sure that it launches a new instance which you can mess around with.

Alf
0
 

Author Comment

by:aimsye
ID: 8056390
Thank you Alf,
For you last problem, I will use "CreateProcess" API to keep my launched word instance(Process ID), not affect other running word instance even though user launch new WORD instance. In other words, I want to control all of menu function, and Drag & drop function. according to other authority table to determine which function enable/disable for specified user.

For detail:
Save action.

Save menu
Short Cut(Ctrl+S)
Save Button

However, Assume there are three ways to do saving action. I think existing common entry for three ways. If possible, I will intercept the action in the common entry.
0
 
LVL 12

Expert Comment

by:Salte
ID: 8056596
The problem for you is that there most likely IS a common entry but as you are not in the application you might not have access to it.

Using a macro however, means that you are IN the program and  should be able to access that common entry.

I don't know in detail what those various things does in word but I would guess that they all called a common function to do the actual saving and I would also believe that that common function would have a hook or something that allowed a macro to intercept the saving.

However, you need to read the documentation of word in detail to find out exactly which function that would be.

Unless someone here already knows it your best bet is to just search through the word documentation (especially the part for VBA programming and macros) until you find those macros. The hook is most likely implemented as some form of macro or procedure which is called when you do a save and it might have an Boolean return value or a ByRef Argument that is set to false(true) to disable(enable) saving etc. so setting that argument or returning either true or false you can control if the file can be saved or not.

Similarly you have to intercept the drag and drop feature.

Alf
0
 

Author Comment

by:aimsye
ID: 8056703
Thank you Salte,

I know you said hook technology, the core question is how to find out the function common entry. however,I use spy++ to monitoring, but i cannot found any messages like those function. and no WM_COMMAND message found when click save menu, button, Ctrl+S. how should i do?
would someone give me some WORD core technique resource. thanks advance.
0
 
LVL 12

Assisted Solution

by:Salte
Salte earned 1000 total points
ID: 8057319
It is most likely NOT done by messaging.

The common function is implemented by simply having all those different places call the same function. I.e. a common function call.

Then using spy++ or any other message inspection tool won't help you.

You must read the documentation, if the documentation says something like "The VBA function BeforeSave(.....) return bool is called, if this function return true the save will continue, if the function return false the save operation will be aborted" Then you simply define that subroutine in VBA and have it return false. If the documentation says something completely different you follow whatever the documentation says and intercept it through that means.

However, I doubt that intercepting messages will help you. The messages comes into play in the following situations:

1. The user click on a menu option, press a short cut key or by some other means causes window to send a message to the application about the event that user caused. This will most likely be different messages for the different cases, so CTRL + S will have a different message than 'selecting menu and clicking on the Save As menu' which again might be a different message (although also possibly the same) as a pop up menu 'Save As...' entry.

2. Some other application send a message to the application in order to pretend that user or windows caused that message to be sent.

3. The application sends itself a message in order to streamline some handling. For example you COULD implement the short cut CTRL+S to send a message to yourself pretending the user selected the save menu item or you could implement the save menu item to send a WM_CHAR with CTRL_S so that the save would be handled by that message. HOwever, most likely they are both implemented by having a function DoTheSave() (probably not that exact name) and then have both the short cut handle and the menu select handle and also a button click handler call that common function by a simple function call.

Spy++ and similar tools will only detect when you send/receive messages, not function calls.

Function calls can in principle not be detected at all but most likely word has a 'hook' in the function to do the save so that do the save is programmed something along these lines:

void DoTheSave()
{
   if (BeforeSave(filename)) {
      ...continue the saving...
   }
}

So if BeforeSave returned false the save won't take place. Here's the magic: BeforeSave is a call to a VBA function - if that function is not defined it will probably just return 'true' indicating that saving should take place - but if defined word will at this point call and execute the word VBA code and the VBA function's return will be returned from BeforeSave. And so if that VBA function is defined to return 'false' always the saving will never take place.

Another way would simply be to disable the shortcut, short cuts can be disabled just like menues and buttons. However, all that is done by VBA code. VBA is the programmable interface to office applications. Use it.

I still don't understand why you don't want to use a viewer and want to use a full word for this.

Alf
0
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 9443201
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Split points between Dan and Salte

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Ged
EE Cleanup Volunteer
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question