I went and opened my old project for you, i was testing some stuff out so there might be a bit of unused code / commented out lines. But this is 99% done for you...hopefully 😉
This code will get the check in window and click the button when it pops up. Given that you only want to pre-fill out the comments, you will need to use something like Spy++ to get the text area id and define the correct "user32.dll API Function" for the text area object. and remove the section where i have it clicking the button.
When / if you get it working. please post the final code here for everyone, as i know it has been asked a bunch of times in the forums.
Notes, this is for an add-in / vb.net code
Usage Instructions
The following code needs to be copied into the module StandardAddInServer.vb - assuming you are using the Inventor / visual studio template
Imports - add this at the very top of the module
Imports System.Windows.Automation ' this is for the check in window handler
Imports System.Runtime.InteropServices ' Can't remember if this is required
Imports Microsoft.Win32
This will be copied into the standardaddinserver class, just below the first line of the class where it says Implements Inventor.applicationaddinserver
' ** GET WINDOW CODE (USE SPY++ DEBUG TOOL WITHIN VISUAL STUDIO TO LOCATE DIALOG INFO)
'This Is the intercepting form windows api code
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
Private Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" (ByVal hWndParent As Integer, ByVal hWndChildAfter As Integer, ByVal lpszClass As String, ByVal lpszWindow As String) As Integer
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Private Declare Function GetDlgItem Lib "user32" (ByVal hDlg As IntPtr, nIDDlgItem As Integer) As IntPtr
Private Const BM_CLICK As Integer = &HF5&
Private Const BM_SETCHECK As Integer = &HF1&
Private Const WM_SETFOCUS As Integer = &H7
This needs to be added into the "Activate" sub
' ** GET WINDOW CODE
System.Windows.Automation.Automation.AddAutomationEventHandler(WindowPattern.WindowOpenedEvent, AutomationElement.RootElement, TreeScope.Subtree, AddressOf OnWindowOpened)
This sub can be added anywhere in the class, I just added it right below the "activate" sub
'This Is what captures the name of the check in window And automatically accepts
'comments are pre-filled from vault check-out menu
Private Sub OnWindowOpened(sender As Object, oAutomationEventArgs As AutomationEventArgs)
' Check if is currently enabled
'If My.Settings.bAutoCloseCheckInForm = False Then Return
Try
Dim element As AutomationElement = sender
If element Is Nothing Then Return
ThisApplication.StatusBarText = element.Current.Name
If element.Current.Name.Count < 11 Then Return ' Needs to have enough characters to check length
If Left(element.Current.Name, 10) <> "Check In '" Then Return
' wait for form to load (closing too early causes problems / skipping)
sharedFunctions.IsInventorAvailable(ThisApplication, 2)
Dim h1 = element.Current.NativeWindowHandle
ThisApplication.StatusBarText = h1
'Dim H2 = FindWindowEx(h1, IntPtr.Zero, "OK", "")
Dim h2 = GetDlgItem(h1, "00000001") ' OK button is ID "00000001", Cancel button is "00000002"
If h2 <> 0 Then
'SendMessage(h2, WM_SETFOCUS, IntPtr.Zero, IntPtr.Zero) 'trying without set focus
SendMessage(h2, BM_CLICK, IntPtr.Zero, IntPtr.Zero)
'SendMessage(H2, BM_SETCHECK, False, 0)
' this removes the event handler if it was a once only operation
'System.Windows.Automation.Automation.RemoveAutomationEventHandler(WindowPattern.WindowOpenedEvent, AutomationElement.RootElement, AddressOf OnWindowOpened)
Else
MessageBox.Show("Didnt get it")
End If
Catch
End Try
End Sub