Finding active window & kick the button

Finding active window & kick the button

Anonymous
Not applicable
330 Views
6 Replies
Message 1 of 7

Finding active window & kick the button

Anonymous
Not applicable
Does anyone have any sample code on how to find through VB, an active window or message box with a button hightlighted from one application? what's the activeX module for doing that? I need to use VB program to press the "cancel" button on the active window to cancel the process rather than kill the whole applicaiton. Thanks, Thomas
0 Likes
331 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable
I don't know if it will help your situation but i use Push The Freakin Button.
http://www.bobos.demon.co.uk/par/PTFB.htm
Regards - Nathan
0 Likes
Message 3 of 7

Anonymous
Not applicable
It helps anyway. But I need to customize the code in order to control the timing when I need to puch the button. Regards, Thomas "Nathan Taylor" wrote in message news:7471744.1075786906240.JavaMail.javamailuser@localhost... > I don't know if it will help your situation but i use Push The Freakin Button. > http://www.bobos.demon.co.uk/par/PTFB.htm > Regards - Nathan
0 Likes
Message 4 of 7

Anonymous
Not applicable
Do a google for 'push the button'. Somewhere I ran across free source code to do it - it might have been at http://www.planet-source-code.com I will also look and see if I downloaded it. ___________________________ Mike Tuersley CADalyst's AutoCAD Clinic Rand IMAGINiT Technologies
0 Likes
Message 5 of 7

Anonymous
Not applicable
Hi Mike, Maybe I didn't locate the correct category. I can't find a useful code for this issue. If you happen to find the code, let me know. Many thanks, Thomas "Mike Tuersley" wrote in message news:MPG.1a8a35546645657f9896bb@discussion.autodesk.com... > Do a google for 'push the button'. Somewhere I ran across free source > code to do it - it might have been at http://www.planet-source-code.com > I will also look and see if I downloaded it. > ___________________________ > Mike Tuersley > CADalyst's AutoCAD Clinic > Rand IMAGINiT Technologies
0 Likes
Message 6 of 7

Anonymous
Not applicable
If you still have this issue have a look at this.
http://www.tlhouse.co.uk/forums/index.php?board=3;action=display;threadid=57
It won't solve the issue right now but may at a later stage.

Regards - Nathan
0 Likes
Message 7 of 7

Anonymous
Not applicable
Wrote this code to hit the button if a message box "Non perpendicular UCS" turns up. Maybe you coud modify it for your needs.

P.S. Its VB6 Code not VBA

Put this in a module

Option Explicit

Private Declare Function FindWindow Lib "User32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetClassName Lib "User32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Public Declare Function ShowWindow Lib "User32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Public Declare Function GetParent Lib "User32" (ByVal hwnd As Long) As Long

Public Sub CheckForTargetAutoCADWindow()
Dim hwnd As Long
Dim lpClassName As String
Dim nMaxCount As Long
Dim lresult As Long
Dim delayCount As Long

'Look to see if the target window is---------------------
'on the desktop '
nMaxCount = 256 '
lpClassName = Space(nMaxCount) '
hwnd = FindWindow(vbNullString, "AutoCAD Message") '
'<
lresult = GetClassName(hwnd, lpClassName, nMaxCount) '
hwnd = FindWindow(lpClassName, vbNullString) '
'--------------------------------------------------------
If hwnd <> 0 Then
'if target window found ------------------------------
'Update form caption '
frmSpy.Caption = "ACAD UCS (Hit Enter) Found" '
'Wait a short while for AutoCAD screen to '
'complete loading '
For delayCount = 1 To 10000 '
DoEvents '
Next '
'Focus to the AutoCAD parent. Sending enter to the '
'actual AutoCAD message does not seem to be reliable '
Call ShowWindow(GetParent(hwnd), 5) '
'Wait a shorter while '
For delayCount = 1 To 1000 '
DoEvents '
Next '
'Send enter to clear the message '
SendKeys ("~") '
'Wait a short while for the hit to register '
'to ensure that we do not double hit '
For delayCount = 1 To 10000 '
DoEvents '
Next '
'End if target window found --------------------------
Else
'Update caption if target window not visible--------------
If frmSpy.Caption <> "ACAD UCS (Hit Enter) Not Found" _
Then frmSpy.Caption = _
"ACAD UCS (Hit Enter) Not Found"
'---------------------------------------------------------
End If
End Sub

Add a timer to the form, call the form frmSpy (name property) and add the code

Private Sub Form_Load()
'Make the form title visible but to bottom ---------------
'right of screen '
Me.Height = 0 '
Me.Top = Screen.Height - Me.Height '
Me.Left = Screen.Width - Me.Width '
'---------------------------------------------------------
'Initiate Timer ------------------------------------------
Timer1.Interval = 100 '
Timer1.Enabled = True '
'---------------------------------------------------------
End Sub

Private Sub Timer1_Timer()
'Stop Timer----------------------------------------------
Timer1.Enabled = False '
'--------------------------------------------------------
'Look for a target window to sen a click to--------------
CheckForTargetAutoCADWindow '
'--------------------------------------------------------
'Restart Timer-------------------------------------------
Timer1.Enabled = True '
'--------------------------------------------------------
End Sub

'You may need to mess around with the delay code.
0 Likes