Hello. I am attempting to add a command button to the title bar of an external application. From my research it appears that I should be able to use the CreateWindowEx function provided by user32.dll, but so far I am having absolutely no luck. I have done extensive research online, and I can't find anything helpful. Nothings seems amiss in my code, but when I try to add the command button to the external app, I receive an OverflowException (Arithmetic operation resulted in an overflow) from the CreateWindowEx function. Any help would be greatly appreciated!
See the below code.
Thank you.
What I have tried:
I try use this code:
Public Class Form1
Private Const WS_CHILD = &H40000000
Private Const WS_VISIBLE = &H10000000
Private Structure CREATESTRUCT
Dim lpCreateParams As Long
Dim hInstance As Long
Dim hMenu As Long
Dim hWndParent As Long
Dim cy As Long
Dim cx As Long
Dim y As Long
Dim x As Long
Dim style As Long
Dim lpszName As String
Dim lpszClass As String
Dim ExStyle As Long
End Structure
Declare Function CreateWindowEx Lib "user32" Alias "CreateWindowExA" (ByVal dwExStyle As Integer,
ByVal lpClassName As String,
ByVal lpWindowName As String, ByVal dwStyle As Integer, ByVal x As Integer,
ByVal y As Integer,
ByVal nWidth As Integer,
ByVal nHeight As Integer,
ByVal hWndParent As Integer,
ByVal hMenu As Integer,
ByVal hInstance As Integer,
ByRef lpParam As Object) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String,ByVal lpWindowName As String) As Long
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim lhWnd As Long, fw As Long, CS As CREATESTRUCT
Dim rhWnd As Long = System.Runtime.InteropServices.Marshal.GetHINSTANCE(System.Reflection.Assembly.GetExecutingAssembly.GetModules()(0)).ToInt32()
fw = FindWindow(vbNullString, "External App Name")
lhWnd = CreateWindowEx(0, "BUTTON", "ButtonText", WS_VISIBLE Or WS_CHILD,
10, 10, 70, 25, fw, 0, rhWnd, CS)
End Sub
End Class