VB.NET and Windows API Calls 
Author Message
 VB.NET and Windows API Calls

Hi,

i have a newbie question:

I try to make a Windows.Form hostet by another (old) Win32 Window. In "old
times" i had three windows Calls
FindWindow, SetWindowLong, and SetParent, that did the job and "included" my
VBA-Form into the other window.

However allthough i have imported the Functions with dllimport-Attribute and
the functions work without any error message, the VB.NET Form simply
"refuses" to be but into the other window - simply nothing happens.
Does anybody know why ? Is this possible at all that another window (in this
case it is a Visio custom window) is a parent to a Windows.Form window and
form ?
Any ideas would be appreciated.

--

Regards
Senaj Lelic
MVP Visio



Mon, 31 Jan 2005 02:07:56 GMT  
 VB.NET and Windows API Calls
you could do something like in the following code. Notice the parameter
types for the Windows API declares are Integer instead of Long (as in VB6).
Maybe this was the problem you ran into ?

The following code worked for us after we brought up a notepad window with
"notepad temp.txt".

Module Module1
    Public Declare Function FindWindow Lib "user32" Alias "FindWindowA"
(ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
    Public Declare Function SetWindowLong Lib "user32" Alias
"SetWindowIntegerA" (ByVal hwnd As Integer, ByVal nIndex As Integer, ByVal
dwNewInteger As Integer) As Integer
    Public Declare Function SetParent Lib "user32" Alias "SetParent" (ByVal
hWndChild As Integer, ByVal hWndNewParent As Integer) As Integer

    Sub HostInWin32Window()
        Dim winHandleParent As Integer = FindWindow(Nothing, "temp.txt -
Notepad")
        Dim winHandleChild As Integer = FindWindow(Nothing, "Form1")

        SetParent(winHandleChild, winHandleParent)

        AppActivate("temp.txt - Notepad")
    End Sub

    Dim Form As New Form1()
    Sub Main()
        Form.Show()

        HostInWin32Window()

        Windows.Forms.Application.Run()
    End Sub
End Module

thanks,
VB Team

--
This posting is provided "AS IS" with no warranties, and confers no rights.



Quote:
> Hi,

> i have a newbie question:

> I try to make a Windows.Form hostet by another (old) Win32 Window. In "old
> times" i had three windows Calls
> FindWindow, SetWindowLong, and SetParent, that did the job and "included"
my
> VBA-Form into the other window.

> However allthough i have imported the Functions with dllimport-Attribute
and
> the functions work without any error message, the VB.NET Form simply
> "refuses" to be but into the other window - simply nothing happens.
> Does anybody know why ? Is this possible at all that another window (in
this
> case it is a Visio custom window) is a parent to a Windows.Form window and
> form ?
> Any ideas would be appreciated.

> --

> Regards
> Senaj Lelic
> MVP Visio




Mon, 31 Jan 2005 04:07:51 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. VB.Net Namespace equivalents for Windows API calls

2. API Calls When VB becomes VB.Net

3. Problem in converting this api call from c# to vb.net

4. API calls in VB.NET

5. MCI win32 API call from VB.NET

6. NullReferenceException calling APIs from VB.NET

7. Unmanaged API calls in VB.NET

8. Calling a API function from VB.NET

9. Win API Call not working in vb.net app distributed to WIn 98

10. API calls to MSI file from VB.NET

11. Beta 2 - Calling API's in VB.Net

12. VB.NET and Win32 API Function Calls

 

 
Powered by phpBB® Forum Software