Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

superbovine

macrumors 68030
Original poster
Nov 7, 2003
2,872
0
Yeah, yeah I know this is macrumors, but the standard vb forums aren't helping with this one.

OK, Here is the deal. I am calling Spell check from MS Word 2003 programmatically already, and it works great. My problem is that after spell check is complete you get this OK spell check is complete window. My problem is this pops up several times and it gets annoying. I want to press the button programmatically, but I having problems.

I have used FindWindow to get the window, but I am having trouble to know what effect I should use to "Press the button actually". I am running Spy++, but it I can not even sure how what to do. I'll post What I have so far. Am I barking up the right tree? So I have tried WM_CLOSE and WM_DESTORY, whatever BM event that Spy++ caught. Nothing has worked.



Code:
Public Class Form1

    Private Const WM_QUIT As Integer = &H12
    Private Const WM_GETDLGCODE As Integer = &H87
    Private Const BM_SETSTATE As Integer = &HF3
    Private Const WM_DESTROY As Integer = &H2

    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
    (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Short, ByVal lParam As Integer) As Integer


    Private Declare Auto Function FindWindow Lib "user32" ( _
  ByVal lpClassName As String, _
  ByVal lpWindowName As String) As IntPtr
    Private Declare Auto Function GetWindowText Lib "user32" ( _
       ByVal hwnd As IntPtr, _
       ByVal lpString As String, _
       ByVal cch As Integer) As Integer

    Private Const lpClassName = "Microsoft Office Word"


    Private Function GetOK() As String
        Dim hwnd As IntPtr = FindWindow(vbNullString, lpClassName)

        Dim lpText As String = ""

        If hwnd.Equals(IntPtr.Zero) Then
            MsgBox("not running")
            Return "Not running"
        Else
            MsgBox("running")
            SendMessage(hwnd, WM_DESTROY, 0, 0)
            Return "running"

        End If



        Return ""
    End Function



    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        GetOK()
    End Sub
End Class
 

neoserver

macrumors 6502
Apr 24, 2003
335
0
superbovine said:
Yeah, yeah I know this is macrumors, but the standard vb forums aren't helping with this one.

OK, Here is the deal. I am calling Spell check from MS Word 2003 programmatically already, and it works great. My problem is that after spell check is complete you get this OK spell check is complete window. My problem is this pops up several times and it gets annoying. I want to press the button programmatically, but I having problems.

I have used FindWindow to get the window, but I am having trouble to know what effect I should use to "Press the button actually". I am running Spy++, but it I can not even sure how what to do. I'll post What I have so far. Am I barking up the right tree? So I have tried WM_CLOSE and WM_DESTORY, whatever BM event that Spy++ caught. Nothing has worked.



Code:
Public Class Form1

    Private Const WM_QUIT As Integer = &H12
    Private Const WM_GETDLGCODE As Integer = &H87
    Private Const BM_SETSTATE As Integer = &HF3
    Private Const WM_DESTROY As Integer = &H2

    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
    (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Short, ByVal lParam As Integer) As Integer


    Private Declare Auto Function FindWindow Lib "user32" ( _
  ByVal lpClassName As String, _
  ByVal lpWindowName As String) As IntPtr
    Private Declare Auto Function GetWindowText Lib "user32" ( _
       ByVal hwnd As IntPtr, _
       ByVal lpString As String, _
       ByVal cch As Integer) As Integer

    Private Const lpClassName = "Microsoft Office Word"


    Private Function GetOK() As String
        Dim hwnd As IntPtr = FindWindow(vbNullString, lpClassName)

        Dim lpText As String = ""

        If hwnd.Equals(IntPtr.Zero) Then
            MsgBox("not running")
            Return "Not running"
        Else
            MsgBox("running")
            SendMessage(hwnd, WM_DESTROY, 0, 0)
            Return "running"

        End If



        Return ""
    End Function



    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        GetOK()
    End Sub
End Class

I don't have VB.NET handy at this point in time but use Win32 API to bring your target app into focus. Then use
Code:
Sendkeys.Send("{ENTER}")
which is in the System.Windows.Forms namespace.

I'm not sure if this is what you want, but thats how I would have attempted to do it.
 

superbovine

macrumors 68030
Original poster
Nov 7, 2003
2,872
0
neoserver said:
I don't have VB.NET handy at this point in time but use Win32 API to bring your target app into focus. Then use
Code:
Sendkeys.Send("{ENTER}")
which is in the System.Windows.Forms namespace.

I'm not sure if this is what you want, but thats how I would have attempted to do it.

I'll give that a try later.
 

superbovine

macrumors 68030
Original poster
Nov 7, 2003
2,872
0
works like a charm. sort of funny, I asked this question on major vb forums and you are the one that replied and actually had the solution.

In the end through the window in question had focus() set, so I had to do was send the enter before I grab focus back to the calling instance and it worked great. I didn't even have to use Windows API. Thanks.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.