Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.Runtime.InteropServices
- Public Class Form1
- 'SendMessage API Declaration:
- Private Declare Auto Function SendMessage Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As IntPtr, ByVal lParam As String) As IntPtr
- Private Declare Function ShowWindow Lib "user32.dll" (ByVal hwnd As IntPtr, ByVal nCmdShow As IntPtr) As IntPtr
- 'FindWindowEx API Declaration:
- Private Const WM_GETTEXT As Integer = &HD
- <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
- Private Shared Function FindWindowEx(ByVal parentHandle As IntPtr, _
- ByVal childAfter As IntPtr, _
- ByVal lclassName As String, _
- ByVal windowTitle As String) As IntPtr
- End Function
- 'FindWindow API Declaration:
- <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
- Private Shared Function FindWindow( _
- ByVal lpClassName As String, _
- ByVal lpWindowName As String) As IntPtr
- End Function
- Const WM_SETTEXT As Long = &HC 'WM_SETTEXT Constant. For setting text to objects in Windows applications.
- Const WS_MINIMIZE As Integer = &H20000000
- Const WM_CLOSE = &H10 'WM_CLOSE Constant. For closing any open Windows applications.
- Private Declare Function GetWindowPlacement Lib "user32" (ByVal hwnd As IntPtr, ByRef lpwndpl As WINDOWPLACEMENT) As Integer
- Private Structure POINTAPI
- Public x As Integer
- Public y As Integer
- End Structure
- Private Structure RECT
- Public Left As Integer
- Public Top As Integer
- Public Right As Integer
- Public Bottom As Integer
- End Structure
- Private Structure WINDOWPLACEMENT
- Public Length As Integer
- Public flags As Integer
- Public showCmd As Integer
- Public ptMinPosition As POINTAPI
- Public ptMaxPosition As POINTAPI
- Public rcNormalPosition As RECT
- End Structure
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
- Dim intRet As Integer
- Dim wpTemp As WINDOWPLACEMENT
- Dim lpszParentClass As String = "MozillaWindowClass" 'The name of the Calc.exe parent class.
- 'IEFrame 'MozillaWindowClass
- Dim lpszParentWindow As String = "Google - Mozilla Firefox" 'The title of the Calc.exe window.
- 'MSN.com - Windows Internet Explorer 'Google - Mozilla Firefox
- Dim ParenthWnd As New IntPtr(0) 'New IntPtr variable.
- Dim hWnd As New IntPtr(0) 'New IntPtr variable.
- ParenthWnd = FindWindow(lpszParentClass, lpszParentWindow)
- wpTemp.Length = System.Runtime.InteropServices.Marshal.SizeOf(wpTemp)
- intRet = GetWindowPlacement(Me.Handle.ToInt32, wpTemp)
- 'Me.Handle.ToInt32
- If wpTemp.showCmd = 1 Then
- ' ActiveForm.WindowState = FormWindowState.Minimized
- ElseIf wpTemp.showCmd = 2 Then
- ' ActiveForm.WindowState = FormWindowState.Maximized
- ElseIf wpTemp.showCmd = 3 Then
- ' ActiveForm.WindowState = FormWindowState.Normal
- End If
- If Not ParenthWnd = (IntPtr.Zero) Then 'Make sure we can find Calc.exe.
- 'Dim NumText As New IntPtr
- 'NumText = SendMessage(ParenthWnd, WM_GETTEXT, 24, 0)
- 'Dim Text As String = (NumText)
- 'Display the string using a label
- 'MessageBox.Show(Text)
- 'SendMessage(ParenthWnd, WM_SETTEXT, 5, "yo sup")
- ShowWindow(ParenthWnd, 3)
- 'System.Threading.Thread.Sleep(50000)
- 'SendMessage(ParenthWnd, &H10, 0, 0) '&H10=WM_CLOSE
- 'SendMessage(ParenthWnd, WM_CLOSE, 0, 0)
- Else
- MessageBox.Show("Application Not Running!!", "Firefox Win API Source Code", MessageBoxButtons.OK, MessageBoxIcon.Error)
- Exit Sub
- End If
- End Sub
- Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
- Dim intRet As Integer
- Dim wpTemp As WINDOWPLACEMENT
- Dim lpszParentClass As String = "MozillaWindowClass" 'The name of the Calc.exe parent class.
- 'IEFrame 'MozillaWindowClass
- Dim lpszParentWindow As String = "Google - Mozilla Firefox" 'The title of the Calc.exe window.
- 'MSN.com - Windows Internet Explorer 'Google - Mozilla Firefox
- Dim ParenthWnd As New IntPtr(0) 'New IntPtr variable.
- Dim hWnd As New IntPtr(0) 'New IntPtr variable.
- ParenthWnd = FindWindow(lpszParentClass, lpszParentWindow)
- wpTemp.Length = System.Runtime.InteropServices.Marshal.SizeOf(wpTemp)
- intRet = GetWindowPlacement(Me.Handle.ToInt32, wpTemp)
- 'Me.Handle.ToInt32
- If wpTemp.showCmd = 1 Then
- ' ActiveForm.WindowState = FormWindowState.Minimized
- ElseIf wpTemp.showCmd = 2 Then
- ' ActiveForm.WindowState = FormWindowState.Maximized
- ElseIf wpTemp.showCmd = 3 Then
- ' ActiveForm.WindowState = FormWindowState.Normal
- End If
- If Not ParenthWnd = (IntPtr.Zero) Then 'Make sure we can find Calc.exe.
- 'SendMessage(ParenthWnd, WM_SETTEXT, 5, "yo sup")
- 'System.Threading.Thread.Sleep(50000)
- 'SendMessage(ParenthWnd, WM_CLOSE, 0, 0)
- ShowWindow(ParenthWnd, 2)
- Else
- MessageBox.Show("Application Not Running!!", "Firefox Win API Source Code", MessageBoxButtons.OK, MessageBoxIcon.Error)
- Exit Sub
- End If
- End Sub
- Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
- Dim intRet As Integer
- Dim wpTemp As WINDOWPLACEMENT
- Dim lpszParentClass As String = "MozillaWindowClass" 'The name of the Calc.exe parent class.
- 'IEFrame 'MozillaWindowClass
- Dim lpszParentWindow As String = "Google - Mozilla Firefox" 'The title of the Calc.exe window.
- 'MSN.com - Windows Internet Explorer 'Google - Mozilla Firefox
- Dim ParenthWnd As New IntPtr(0) 'New IntPtr variable.
- Dim hWnd As New IntPtr(0) 'New IntPtr variable.
- ParenthWnd = FindWindow(lpszParentClass, lpszParentWindow)
- wpTemp.Length = System.Runtime.InteropServices.Marshal.SizeOf(wpTemp)
- intRet = GetWindowPlacement(Me.Handle.ToInt32, wpTemp)
- 'Me.Handle.ToInt32
- If wpTemp.showCmd = 1 Then
- ' ActiveForm.WindowState = FormWindowState.Minimized
- ElseIf wpTemp.showCmd = 2 Then
- ' ActiveForm.WindowState = FormWindowState.Maximized
- ElseIf wpTemp.showCmd = 3 Then
- ' ActiveForm.WindowState = FormWindowState.Normal
- End If
- If Not ParenthWnd = (IntPtr.Zero) Then 'Make sure we can find Calc.exe.
- 'SendMessage(ParenthWnd, WM_SETTEXT, 5, "yo sup")
- 'System.Threading.Thread.Sleep(50000)
- SendMessage(ParenthWnd, WM_CLOSE, 0, 0)
- 'ShowWindow(ParenthWnd, 2)
- Else
- MessageBox.Show("Application Not Running!!", "Firefox Win API Source Code", MessageBoxButtons.OK, MessageBoxIcon.Error)
- Exit Sub
- End If
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement