dcsimg


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Detect and Terminate Word Application

  1. #1
    Serena Guest

    Detect and Terminate Word Application


    David Quick offered great advice in an earlier posting but I've run into a
    snag. The instance of Word, which is launched by another appliaction, has
    had it's close function disabled.

    So the following code.......
    PostMessage hwnd, WM_CLOSE, 0&, 0&
    .......has no effect.

    Can I jump to WM_DESTROY to get rid of this, or perhaps enable the Close
    Function from a lower level.

    I noticed that WM_CLOSE has a hex value of &H10, what does WM_DESTROY map
    to if it's appropriate.

    Also, any explanation to what "OpusApp" represents would be interesting.

    Original code by David is below:

    Const gcClassnameMSWord = "OpusApp"
    Const WM_CLOSE = &H10

    Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA"
    _
    (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, _
    ByVal lpsz2 As String) As Long

    Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" _
    (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam _
    As Long, lParam As Any) As Long


    Private Sub Form_Load()

    Dim hwnd As Long ' window handle
    Do
    ' find the window of Word Class
    hwnd = FindWindowEx(ByVal 0&, ByVal 0&, gcClassnameMSWord & Chr$(0),
    vbNullString)
    ' post the windows close message to the window
    If hwnd > 0 Then PostMessage hwnd, WM_CLOSE, 0&, 0&
    Loop Until hwnd = 0

    End Sub


  2. #2
    David Quick Guest

    Re: Detect and Terminate Word Application


    "Serena" <sfdooley@yahoo.com> wrote in message
    news:3ad4b465$1@news.devx.com...
    >
    > David Quick offered great advice in an earlier posting but I've run into a
    > snag. The instance of Word, which is launched by another appliaction, has
    > had it's close function disabled.
    >
    > So the following code.......
    > PostMessage hwnd, WM_CLOSE, 0&, 0&
    > ......has no effect.
    >
    > Can I jump to WM_DESTROY to get rid of this, or perhaps enable the Close
    > Function from a lower level.
    >
    > I noticed that WM_CLOSE has a hex value of &H10, what does WM_DESTROY map
    > to if it's appropriate.



    Const WM_DESTROY = &H2

    The WM_DESTROY message may work, not sure the only problem with this is the
    WM_DESTROY
    message destroys the window you tell it, it will not destroy any child
    windows of it. As, far as to enable
    the Close function, that I am not sure of.

    >
    > Also, any explanation to what "OpusApp" represents would be interesting.
    >



    All windows are assigned to a Class, that class determines certain
    characteristics of windows in that class
    "OpusApp" is the class that all Word windows are assigned to.... Why OpusApp
    have not idea, but that is
    what the OpusApp is refering to the class for word windows

    > Original code by David is below:
    >
    > Const gcClassnameMSWord = "OpusApp"
    > Const WM_CLOSE = &H10
    >
    > Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA"
    > _
    > (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, _
    > ByVal lpsz2 As String) As Long
    >
    > Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" _
    > (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam _
    > As Long, lParam As Any) As Long
    >
    >
    > Private Sub Form_Load()
    >
    > Dim hwnd As Long ' window handle
    > Do
    > ' find the window of Word Class
    > hwnd = FindWindowEx(ByVal 0&, ByVal 0&, gcClassnameMSWord & Chr$(0),
    > vbNullString)
    > ' post the windows close message to the window
    > If hwnd > 0 Then PostMessage hwnd, WM_CLOSE, 0&, 0&
    > Loop Until hwnd = 0
    >
    > End Sub
    >




  3. #3
    David Quick Guest

    Re: Detect and Terminate Word Application


    "Serena" <sfdooley@yahoo.com> wrote in message
    news:3ad4b465$1@news.devx.com...
    >
    > David Quick offered great advice in an earlier posting but I've run into a
    > snag. The instance of Word, which is launched by another appliaction, has
    > had it's close function disabled.
    >
    > So the following code.......
    > PostMessage hwnd, WM_CLOSE, 0&, 0&
    > ......has no effect.
    >
    > Can I jump to WM_DESTROY to get rid of this, or perhaps enable the Close
    > Function from a lower level.
    >
    > I noticed that WM_CLOSE has a hex value of &H10, what does WM_DESTROY map
    > to if it's appropriate.



    Const WM_DESTROY = &H2

    The WM_DESTROY message may work, not sure the only problem with this is the
    WM_DESTROY
    message destroys the window you tell it, it will not destroy any child
    windows of it. As, far as to enable
    the Close function, that I am not sure of.

    >
    > Also, any explanation to what "OpusApp" represents would be interesting.
    >



    All windows are assigned to a Class, that class determines certain
    characteristics of windows in that class
    "OpusApp" is the class that all Word windows are assigned to.... Why OpusApp
    have not idea, but that is
    what the OpusApp is refering to the class for word windows

    > Original code by David is below:
    >
    > Const gcClassnameMSWord = "OpusApp"
    > Const WM_CLOSE = &H10
    >
    > Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA"
    > _
    > (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, _
    > ByVal lpsz2 As String) As Long
    >
    > Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" _
    > (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam _
    > As Long, lParam As Any) As Long
    >
    >
    > Private Sub Form_Load()
    >
    > Dim hwnd As Long ' window handle
    > Do
    > ' find the window of Word Class
    > hwnd = FindWindowEx(ByVal 0&, ByVal 0&, gcClassnameMSWord & Chr$(0),
    > vbNullString)
    > ' post the windows close message to the window
    > If hwnd > 0 Then PostMessage hwnd, WM_CLOSE, 0&, 0&
    > Loop Until hwnd = 0
    >
    > End Sub
    >




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center