Click here to Skip to main content
15,868,141 members
Articles / Programming Languages / Visual Basic

ByPass difficult Automation and add applications "as is" in your .NET application

Rate me:
Please Sign up or sign in to vote.
3.40/5 (29 votes)
28 Dec 2004CPOL4 min read 153.6K   2.9K   74  
Fed up with automation? Need to add components as is to your application? Try this out.
Imports System.Reflection
Imports System.Text
Imports System.Runtime.InteropServices
Public Class Win32Functions
    ' Flags of SetWindowPos
    Public Const SWP_FRAMECHANGED As Integer = &H20
    Public Const SWP_NOACTIVATE As Integer = &H10
    Public Const SWP_NOMOVE As Integer = &H2
    Public Const SWP_NOSIZE As Integer = &H1
    Public Const SWP_NOZORDER As Integer = &H4
    Public Const SWP_SHOWWINDOW As Integer = &H40
    Public Const SWP_NOSENDCHANGING As Integer = &H400
    Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As System.IntPtr) As Integer
    Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As System.IntPtr, ByVal nIndex As Integer, ByVal dwNewLong As Integer) As Integer
    Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As System.IntPtr, ByVal nIndex As Integer) As Integer
    Declare Function SetParent Lib "user32" (ByVal hWndChild As System.IntPtr, ByVal hWndNewParent As System.IntPtr) As System.IntPtr
    Declare Function SetWindowPos Lib "user32" (ByVal hwnd As System.IntPtr, ByVal hWndInsertAfter As System.IntPtr, ByVal x As Integer, ByVal y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal wFlags As Integer) As Integer
    Declare Ansi Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hWnd As IntPtr, ByVal lpClassName As StringBuilder, ByVal nMaxCount As Int32) As Int32
    Delegate Function EnumChildProc(ByVal hWnd As IntPtr, ByRef lParam As IntPtr) As Int32
    Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As IntPtr, ByVal lpEnumFunc As EnumChildProc, ByRef lParam As IntPtr) As Int32
    Declare Ansi Function RegisterWindowMessage Lib "user32" Alias "RegisterWindowMessageA" (ByVal lpString As String) As Int32
    Declare Ansi Function SendMessageTimeout Lib "user32" Alias "SendMessageTimeoutA" (ByVal hWnd As IntPtr, ByVal msg As Int32, ByVal wParam As Int32, ByVal lParam As Int32, ByVal fuFlags As Int32, ByVal uTimeout As Int32, ByRef lpdwResult As Int32) As Int32
    Declare Function ShowWindow Lib "user32" (ByVal hWnd As System.IntPtr, ByVal nCmdShow As Integer) As Boolean
    Public Const SMTO_ABORTIFHUNG As Int32 = &H2

    Public Shared Function removeTitleBarAndRescale(ByVal p As IntPtr)
        Dim dwNewLong As Long = GetWindowLong(p, -16)

        dwNewLong = dwNewLong And (Not &H40000) And (Not &H400000)
        Call SetWindowLong(p, -16, dwNewLong)
    End Function
End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
Pakistan Pakistan
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions