473,692 Members | 2,230 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is it possible to handle the events for MSWord ?

lkr
hi
is there is anyway to capture the document events of a MSWord?eg:I have to
handle the event awhen WM_KEYUP or anyother events will occur.
give me a solution....... .....
thanks in advance
lkr

Nov 17 '05 #1
7 2057
If you want to consume MS Word events within an existing VS.NET C# Project use Automation:

Add a reference to the Word interop assembly in your Project. If it is not available in the .NET tab of the Add Reference dialog,
then click "Browse..." and locate the MS Word executable and add a reference to it instead.

Research if there is a Word Primary Interop Assembly, which should be referenced if avialable instead of the above solution. I'm
not sure if it's available, or for what versions of Word, at this time.

VS.NET will wrap it as a .NET assembly unless you choose one from the .NET tab, or reference a PIA (Primary Interop Assembly)
provided by MS. Once referenced, you can code against MS Word as you would any other .NET assembly, subscribing to events, etc.

To get an instance Word (running or new):

Declare a method:

/// <summary>Retrie ves a reference to a running COM object with the specified ProgID or creates a new one.</summary>
public static object GetRunningObjec t(string ProgID)
{
try
{
// First, check the running object table (ROT)
return Marshal.GetActi veObject(ProgID );
}
catch {}

object instance = null;

try
{
// Create a new instance
Type type = Type.GetTypeFro mProgID(ProgID, false);
instance = Activator.Creat eInstance(type) ;
}
catch {}

return instance;
}
Invoke the method:

Word._Applicati on word = GetRunningObjec t("Word.Applica tion") as Word._Applicati on

Subscribe to an event:

word.Applicatio n.DocumentOpen+ =
new Word.Applicatio nEvents2_Docume ntOpenEventHand ler(Application _DocumentOpen);
--
Dave Sexton
dave@www..jwaon line..com
-----------------------------------------------------------------------
"lkr" <lk*@discussion s.microsoft.com > wrote in message news:11******** *************** ***********@mic rosoft.com...
hi
is there is anyway to capture the document events of a MSWord?eg:I have to
handle the event awhen WM_KEYUP or anyother events will occur.
give me a solution....... .....
thanks in advance
lkr

Nov 17 '05 #2
Hi,

Actually there is a simpler way , just call the Win32API FindWindow and get
the handle of your word app (you can use Spy++ to get the name) and then you
can PeekMessages of that handle, you can trap WM_KEYUP or any other message
and perform your actions. Remember, everything in windows are windows :)
including the Start button, give it a try .

Cheers
Salva
"lkr" wrote:
hi
is there is anyway to capture the document events of a MSWord?eg:I have to
handle the event awhen WM_KEYUP or anyother events will occur.
give me a solution....... .....
thanks in advance
lkr

Nov 17 '05 #3
lkr
hi Salva
Thanks for u reply.........
By using the the Win32API FindWindow i got the handle to MSWord ,But It is
the main window handle ,Again i tried to get the handle of child window ,i
used EnumChildWindow s Win32API i got the hadle of ScrollBar window.i checked
it wit sp++ FinWindow.Handl e returned r same........... .
But my problem is that i was not able to subclass this scrollbar...... .......
Is it possible ?
"Salvador" wrote:
Hi,

Actually there is a simpler way , just call the Win32API FindWindow and get
the handle of your word app (you can use Spy++ to get the name) and then you
can PeekMessages of that handle, you can trap WM_KEYUP or any other message
and perform your actions. Remember, everything in windows are windows :)
including the Start button, give it a try .

Cheers
Salva
"lkr" wrote:
hi
is there is anyway to capture the document events of a MSWord?eg:I have to
handle the event awhen WM_KEYUP or anyother events will occur.
give me a solution....... .....
thanks in advance
lkr

Nov 17 '05 #4
Using FindWindow won't necessarily work with all versions of Word since your using Spy++ to obtain a window name for a particular
version. Using automation will be more robust in that Microsoft can now change the names of their windows, even remove them
completely, and your event hookups will remain in-tact given that they do not remove the events in successive versions.

--
Dave Sexton
dave@www..jwaon line..com
-----------------------------------------------------------------------
"lkr" <lk*@discussion s.microsoft.com > wrote in message news:26******** *************** ***********@mic rosoft.com...
hi Salva
Thanks for u reply.........
By using the the Win32API FindWindow i got the handle to MSWord ,But It is
the main window handle ,Again i tried to get the handle of child window ,i
used EnumChildWindow s Win32API i got the hadle of ScrollBar window.i checked
it wit sp++ FinWindow.Handl e returned r same........... .
But my problem is that i was not able to subclass this scrollbar...... .......
Is it possible ?
"Salvador" wrote:
Hi,

Actually there is a simpler way , just call the Win32API FindWindow and get
the handle of your word app (you can use Spy++ to get the name) and then you
can PeekMessages of that handle, you can trap WM_KEYUP or any other message
and perform your actions. Remember, everything in windows are windows :)
including the Start button, give it a try .

Cheers
Salva
"lkr" wrote:
> hi
> is there is anyway to capture the document events of a MSWord?eg:I have to
> handle the event awhen WM_KEYUP or anyother events will occur.
> give me a solution....... .....
> thanks in advance
> lkr
>

Nov 17 '05 #5
lkr

Hi Dave
Thanks for ur reply.......... .....
I already done automation of MSWord.But i want to handle the document
window and ScrollBar window seperatly,There is no solution for this one in
automation.
Is there is any way for this, plse help me.......?

thanks in advance
lkr
"Dave" wrote:
Using FindWindow won't necessarily work with all versions of Word since your using Spy++ to obtain a window name for a particular
version. Using automation will be more robust in that Microsoft can now change the names of their windows, even remove them
completely, and your event hookups will remain in-tact given that they do not remove the events in successive versions.

--
Dave Sexton
dave@www..jwaon line..com
-----------------------------------------------------------------------
"lkr" <lk*@discussion s.microsoft.com > wrote in message news:26******** *************** ***********@mic rosoft.com...
hi Salva
Thanks for u reply.........
By using the the Win32API FindWindow i got the handle to MSWord ,But It is
the main window handle ,Again i tried to get the handle of child window ,i
used EnumChildWindow s Win32API i got the hadle of ScrollBar window.i checked
it wit sp++ FinWindow.Handl e returned r same........... .
But my problem is that i was not able to subclass this scrollbar...... .......
Is it possible ?
"Salvador" wrote:
Hi,

Actually there is a simpler way , just call the Win32API FindWindow and get
the handle of your word app (you can use Spy++ to get the name) and then you
can PeekMessages of that handle, you can trap WM_KEYUP or any other message
and perform your actions. Remember, everything in windows are windows :)
including the Start button, give it a try .

Cheers
Salva
"lkr" wrote:

> hi
> is there is anyway to capture the document events of a MSWord?eg:I have to
> handle the event awhen WM_KEYUP or anyother events will occur.
> give me a solution....... .....
> thanks in advance
> lkr
>


Nov 17 '05 #6
If Word doesn't supply the events you need, then you'll have to use a "hack" such as FindWindowEx, but use it with caution.

--
Dave Sexton
dave@www..jwaon line..com
-----------------------------------------------------------------------
"lkr" <lk*@discussion s.microsoft.com > wrote in message news:1D******** *************** ***********@mic rosoft.com...

Hi Dave
Thanks for ur reply.......... .....
I already done automation of MSWord.But i want to handle the document
window and ScrollBar window seperatly,There is no solution for this one in
automation.
Is there is any way for this, plse help me.......?

thanks in advance
lkr
"Dave" wrote:
Using FindWindow won't necessarily work with all versions of Word since your using Spy++ to obtain a window name for a particular
version. Using automation will be more robust in that Microsoft can now change the names of their windows, even remove them
completely, and your event hookups will remain in-tact given that they do not remove the events in successive versions.

--
Dave Sexton
dave@www..jwaon line..com
-----------------------------------------------------------------------
"lkr" <lk*@discussion s.microsoft.com > wrote in message news:26******** *************** ***********@mic rosoft.com...
> hi Salva
> Thanks for u reply.........
> By using the the Win32API FindWindow i got the handle to MSWord ,But It is
> the main window handle ,Again i tried to get the handle of child window ,i
> used EnumChildWindow s Win32API i got the hadle of ScrollBar window.i checked
> it wit sp++ FinWindow.Handl e returned r same........... .
> But my problem is that i was not able to subclass this scrollbar...... .......
> Is it possible ?
>
>
> "Salvador" wrote:
>
>> Hi,
>>
>> Actually there is a simpler way , just call the Win32API FindWindow and get
>> the handle of your word app (you can use Spy++ to get the name) and then you
>> can PeekMessages of that handle, you can trap WM_KEYUP or any other message
>> and perform your actions. Remember, everything in windows are windows :)
>> including the Start button, give it a try .
>>
>> Cheers
>> Salva
>>
>>
>> "lkr" wrote:
>>
>> > hi
>> > is there is anyway to capture the document events of a MSWord?eg:I have to
>> > handle the event awhen WM_KEYUP or anyother events will occur.
>> > give me a solution....... .....
>> > thanks in advance
>> > lkr
>> >


Nov 17 '05 #7
lkr

Hi Dave
i also tried to get the event by using FindWindowEx(), But i didnt get the
handle to the childwindow using FindWindowEx ().But i got child window handle
by EnumChildWindow but i was not able to subclass and handle the
events.........
How can i subclass this child window?
lkr
"Dave" wrote:
If Word doesn't supply the events you need, then you'll have to use a "hack" such as FindWindowEx, but use it with caution.

--
Dave Sexton
dave@www..jwaon line..com
-----------------------------------------------------------------------
"lkr" <lk*@discussion s.microsoft.com > wrote in message news:1D******** *************** ***********@mic rosoft.com...

Hi Dave
Thanks for ur reply.......... .....
I already done automation of MSWord.But i want to handle the document
window and ScrollBar window seperatly,There is no solution for this one in
automation.
Is there is any way for this, plse help me.......?

thanks in advance
lkr
"Dave" wrote:
Using FindWindow won't necessarily work with all versions of Word since your using Spy++ to obtain a window name for a particular
version. Using automation will be more robust in that Microsoft can now change the names of their windows, even remove them
completely, and your event hookups will remain in-tact given that they do not remove the events in successive versions.

--
Dave Sexton
dave@www..jwaon line..com
-----------------------------------------------------------------------
"lkr" <lk*@discussion s.microsoft.com > wrote in message news:26******** *************** ***********@mic rosoft.com...
> hi Salva
> Thanks for u reply.........
> By using the the Win32API FindWindow i got the handle to MSWord ,But It is
> the main window handle ,Again i tried to get the handle of child window ,i
> used EnumChildWindow s Win32API i got the hadle of ScrollBar window.i checked
> it wit sp++ FinWindow.Handl e returned r same........... .
> But my problem is that i was not able to subclass this scrollbar...... .......
> Is it possible ?
>
>
> "Salvador" wrote:
>
>> Hi,
>>
>> Actually there is a simpler way , just call the Win32API FindWindow and get
>> the handle of your word app (you can use Spy++ to get the name) and then you
>> can PeekMessages of that handle, you can trap WM_KEYUP or any other message
>> and perform your actions. Remember, everything in windows are windows :)
>> including the Start button, give it a try .
>>
>> Cheers
>> Salva
>>
>>
>> "lkr" wrote:
>>
>> > hi
>> > is there is anyway to capture the document events of a MSWord?eg:I have to
>> > handle the event awhen WM_KEYUP or anyother events will occur.
>> > give me a solution....... .....
>> > thanks in advance
>> > lkr
>> >


Nov 17 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2137
by: allyn44 | last post by:
HI--what I am trying to do is 2 things: 1. Open a form in either data entry mode or edit mode depending on what task the user is performing 2. Cancel events tied to fields on the form if I am in edit mode. The reason I want to do this is becasue when entering a new record the form is entered in data entry mode and I have lots of stuff happening upon entering and leaving fields. In edit mode I do not want the events to fire.
3
2273
by: mrhicks | last post by:
Hello all, I have a question regarding efficeny and how to find the best approach when trying to find flag with in a structure of bit fields. I have several structures which look similar to typedef unsigned long int uint32; /* 32 bits */ // Up to 36 request flags, so this will take up to 3
0
1263
by: lkr | last post by:
hi i got the code for handling some of the events in MSWord.But i need ScrollBar events to be handled .i got the handle to the word application window through an API using ForeGroundWindow().By using this handle to thw window can i manage the events in MSWord? and how can i trigger the scroll events in this pplication? if anyone knows ,plse help me .........
15
4040
by: Adam J. Schaff | last post by:
I have noticed that if a user closes a form via pressing return (either while the OK button has focus or if AcceptButton is set to OK for the form) then the "ENTER" keypress event fires ON THE CALLING FORM! This is very bad for me, because in my application, Form1 responds to an ENTER keypress by calling Form2. If the user closes Form2 via an ENTER, then Form1 just reopens it again, kind of trapping the user in Form2 (they can still close...
6
1822
by: Peter | last post by:
I have to write a ASP.NET application that creates MSWord document from a template and populated with data from the webpage. (Templates can reside on the server or client's hard drive.) What is the best way to do this? Is it good idea to have MSWord installed on the server? If it's not a good idea or if MSWord is not installed on the server what are the alternatives? I am using Office 2003. Thank You
11
3018
by: GaryB | last post by:
Hi Guys, I've been battling with this one for hours - I hope that you can help me! My code modifies the <aon a page, from a standard document link into a link with a tailored onclick event. It works perfectly (assigning the correct images and the correct onclick events to the correct <atags):
0
2137
by: Kenneth McDonald | last post by:
Sorry for crossposting to several lists, but from what I can tell, what I want to do may involve several different areas of expertise. (None of which I have :-( ) I'd like to use Gecko as the UI for an application mostly implemented in Python. Ideally, I'd like to somehow come up with a Python module that wraps the Gecko, so that I can: 1) Create windows whose content is drawn by Gecko. 1) Dynamically manipulate what is shown by Gecko.
1
2591
by: Matt Curreri | last post by:
I'm trying to automate the creation of a MSWord document with C#; however, when I start creating the MSWord document, I occassionly have a MSWord dialog box displaying a warning of low memory and asking if I would like to continue (Yes, No, Cancel). Is there a way to send the "Enter" or mouse click to this MSWord Dialog Box to invoke the "Yes" option, which will allow the MS Word to continue? I would appreciate any help... Matt
2
4756
by: adlloyd | last post by:
Hi all, I've developed a small C# DLL to test COM Interop between .net and an older MFC C++ application (Visual Studio 6) - the end goal of which is to integrate an object into a legacy application. I can import the DLL (.tlb), create an object and execute the object's methods. I'm not sure, however, if it's possible to handle events triggered by the object; by means of a callback function or something similar. I've taken a quick look...
0
8540
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9086
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8803
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8806
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7629
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6459
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5820
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4324
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4557
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.