A1VBCode Forums

Some API code used in VB2005


http://www.a1vbcode.com/vbforums/Topic27247.aspx

By jamesnguyen_anewtech - 3/15/2009

Dear all,

These API function I tried with VB2005 and it worked fine. You can write vb application to open , close and move , resize another window application as word, excell. You also can use trasparent API to make color of window application fade away , until it disappear

'move

<DllImport("user32.dll", EntryPoint:="MoveWindow", CharSet:=CharSet.Auto)> _

Public Shared Function MoveWindow(ByVal hWnd As IntPtr, _

ByVal X As Int32, _

ByVal Y As Int32, _

ByVal nWidth As Int32, _

ByVal nHeight As Int32, _

ByVal bRepaint As Boolean _

) As Boolean

End Function

'transparence

Const LWA_COLORKEY As Int32 = 1

Const LWA_ALPHA As Int32 = 2

Const GWL_EXSTYLE As Int32 = (-20)

Const WS_EX_LAYERED As Int32 = 524288

Private Declare Function apiGetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Int32, ByVal nIndex As Int32) As Int32

Private Declare Function apiSetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Int32, ByVal nIndex As Int32, ByVal dwNewLong As Int32) As Int32

Private Declare Function apiSetLayeredWindowAttributes Lib "user32" Alias "SetLayeredWindowAttributes" (ByVal hWnd As Int32, ByVal crKey As Int32, ByVal bAlpha As Byte, ByVal dwFlags As Int32) As Int32

Private nhwnd1, nhwnd2, nhwnd3, nhwnd4, nhwnd5, nhwnd6 As Int32

'maximize minimize

Public sbl As String = ""

Private Const SW_SHOWMINIMIZED As Int32 = 2 'Minimize constant

Private Const SW_SHOWMAXIMIZED As Int32 = 3 'Minimize constant

Private Const sw_shownomal As Int32 = 1 'Minimize constant

<DllImport("user32.dll", EntryPoint:="ShowWindow", CharSet:=CharSet.Auto)> _

Private Shared Function ShowWindow(ByVal hwnd As Int32, ByVal nCmdShow As Int32) As Int32

End Function 'ShowWindow API

'lock

<DllImport("user32.dll", ExactSpelling:=True, CharSet:=CharSet.Auto)> _

Private Shared Function SetWindowPos( _

ByVal hWnd As IntPtr, ByVal hWndInsertAfter As IntPtr, _

ByVal x As Integer, ByVal y As Integer, _

ByVal cx As Integer, ByVal cy As Integer, _

ByVal flags As Integer) As Boolean

End Function

Private Const SWP_NOSIZE As Integer = &H1

Private Const SWP_NOMOVE As Integer = &H2

Private Const SWP_NOZORDER As Integer = &H4

Private Const SWP_NOREDRAW As Integer = &H8

Private Const SWP_NOACTIVATE As Integer = &H10

Private Const SWP_FRAMECHANGED As Integer = &H20

Private Const SWP_SHOWWINDOW As Integer = &H40

Private Const SWP_HIDEWINDOW As Integer = &H80

Private Const SWP_NOCOPYBITS As Integer = &H100

Private Const SWP_NOOWNERZORDER As Integer = &H200

Private Const SWP_NOSENDCHANGING As Integer = &H400

Private Const SWP_DRAWFRAME As Integer = &H20

Private Const SWP_NOREPOSITION As Integer = &H200

Private Const SWP_DEFERERASE As Integer = &H2000

Private Const SWP_ASYNCWINDOWPOS As Integer = &H4000

'lock