08-03-17 10:07 PM
09-03-17 01:34 PM
21-04-20 02:23 PM
Sorry to dig up this old thread, but I came across the same requirement as Bart some time ago, and I solved it using BP 6.6 and a StringBuilder object.
I thought to post my solution here, so everyone who comes across this thread might benefit:
Global Code:
'Gets the current active (foreground) window Declare Function GetForegroundWindow Lib "user32.dll" As IntPtr 'Gets the currrent active window's title Declare Function GetWindowTextA Lib "user32.dll" _ (ByVal hWnd As IntPtr, _ ByVal lpString As StringBuilder, _ ByVal cch As Integer) As Integer
Code Step: Get Active Window
Inputs: -
Outputs: Active_Window (Number)
Active_Window = GetForegroundWindow()
Code Step: Get Active Window Title
Inputs: hWnd (Number) <-- This is the Active_Window from the previous step
Outputs: Window_Title (Text), Window_Title_Length (Number)
'Declare a sting builder object in order to build the title string Dim caption As New System.Text.StringBuilder(256) 'Get the window title length by calling the imported function Window_Title_Length = GetWindowTextA(hWnd, caption, caption.Capacity) 'Retrieve the window title from the string builder Window_Title = caption.ToString()
Hope this helps 🙂