How to create a Window (or other control) in another application's window
Posted on 2006-11-20
I would like to create a window or control inside another application's window, so that it moves around with the target window. Preferrably, the window created would 'belong' to the target window and disappear when the application window or the application itself is closed. I know that keep the contents of the window updated will be the responsibility of my program. It would be VERY nice if the window I created could have events that communicate with my program as well!
The following creates a window, but at the top left of the screen - not in the target application window. I have tried various combinations of the 1st and 4th parameters but this is the best I have been able to do so far. The hwnd parameter is that of the target window.
Dim retval As Integer = 0
Dim btext As String = buttontext
retval = CreateWindowEx(WS_EX_TOPMOST, "BUTTON", btext, WS_CHILD Or WS_VISIBLE, 5, 10, 50, 100, 0, 0, hwnd, 0&)
SendMessage(retval, WM_PAINT, 0, 0)
I am using Visual Studio 2005, Visual Basic. The target application is unmanaged code.