Tema: StartUp
View Single Post
Staro 03.07.2006., 17:26   #5
NeTmAsTeR
Registered User
 
NeTmAsTeR's Avatar
 
Datum registracije: Jul 2006
Lokacija: Serbia
Postovi: 5
Quote:
PrivateDeclareFunction CloseHandle Lib"kernel32" (ByVal hObject AsLong) AsLong
PrivateDeclareFunction CreateToolhelp32Snapshot Lib"kernel32" (ByVal dwFlags AsLong, ByVal dwProcessId AsLong) AsLong
PrivateDeclareFunction FindWindow Lib"user32"Alias"FindWindowA" (ByVal lpClassName AsString, ByVal lpWindowName AsString) AsLong
PrivateDeclareFunction GetClassName Lib"user32"Alias"GetClassNameA" (ByVal hWnd AsLong, ByVal lpClassName AsString, ByVal nMaxCount AsLong) AsLong
PrivateDeclareFunction GetMenu Lib"user32" (ByVal hWnd AsLong) AsLong
PrivateDeclareFunction GetWindowText Lib"user32"Alias"GetWindowTextA" (ByVal hWnd AsLong, ByVal lpString AsString, ByVal cch AsLong) AsLong
PrivateDeclareFunction GetWindowTextLength Lib"user32"Alias"GetWindowTextLengthA" (ByVal hWnd AsLong) AsLong
PrivateDeclareFunction GetWindowThreadProcessId Lib"user32" (ByVal hWnd AsLong, ByVal lpdwProcessID AsLong) AsLong
PrivateDeclareFunction OpenProcess Lib"kernel32" (ByVal dwDesiredAccess AsLong, ByVal bInheritHandle AsLong, ByVal dwProcessId AsLong) AsLong
PrivateDeclareFunction SendMessageLong& Lib"user32"Alias"SendMessageA" (ByVal hwnd AsLong, ByVal wMsg AsLong, ByVal wParam AsLong, ByVal lParam AsLong)
PrivateDeclareFunction TerminateProcess Lib"kernel32" (ByVal hProcess AsLong, ByVal uExitCode AsLong) AsLong

Const PROCESS_ALL_ACCESS = (&H439)
Const WM_CLOSE = (&H10)
Dim hProcess, hWnd, Tl, i AsLong

PublicFunction GetHandleByClass(ByVal lpClass AsString) AsLong
GetHandleByClass = FindWindow(lpClass, vbNullString)
EndFunction

PublicFunction GetHandleByCaption(ByVal lpCaption AsString) AsLong
GetHandleByCaption = FindWindow(vbNullString, lpCaption)
EndFunction

PublicFunction GetClassByHandle(ByVal hWnd AsLong) AsString
Tl = 256
GetClassByHandle = Space(Tl - 1)
Tl = GetClassName(hWnd, GetClassByHandle, Tl)
GetClassByHandle = Left(GetClassByHandle, Tl)
EndFunction

PublicFunction GetClassByCaption(ByVal lpCaption AsString) AsString
Tl = 256
GetClassByCaption = Space(Tl - 1)
Tl = GetClassName(GetHandleByCaption(lpCaption), GetClassByCaption, Tl)
GetClassByCaption = Left(GetClassByCaption, Tl)
EndFunction

PublicFunction GetCaptionByHandle(ByVal hWnd AsLong) AsString
Tl = GetWindowTextLength(hWnd)
GetCaptionByHandle = Space(Tl)
Call GetWindowText(hWnd, GetCaptionByHandle, Tl + 1)
EndFunction

PublicFunction GetCaptionByClass(ByVal lpClass AsString) AsString
Tl = GetWindowTextLength(FindWindow(lpClass, vbNullString))
GetCaptionByClass = Space(Tl)
Call GetWindowText(FindWindow(lpClass, vbNullString), GetCaptionByClass, Tl + 1)
EndFunction

PublicFunction GetPIDByHandle(ByVal hWnd AsLong) AsLong
Call GetWindowThreadProcessId(hWnd, GetPIDByHandle)
EndFunction

PublicFunction GetPIDByClass(ByVal lpClass AsString) AsLong
Call GetWindowThreadProcessId(GetHandleByClass(lpClass) , GetPIDByClass)
EndFunction

PublicFunction GetPIDByCaption(ByVal lpCaption AsString) AsLong
Call GetWindowThreadProcessId(GetHandleByCaption(lpCapt ion), GetPIDByCaption)
EndFunction

PublicFunction GethProcessByHandle(ByVal hWnd AsLong) AsLong
GethProcessByHandle = OpenProcess(PROCESS_ALL_ACCESS, False, GetPIDByHandle(hWnd))
'CloseHandle GethProcessByHandle 'This was for debugging only
EndFunction

PublicFunction GethProcessByClass(ByVal lpClass AsString) AsLong
GethProcessByClass = OpenProcess(PROCESS_ALL_ACCESS, False, GetPIDByClass(lpClass))
'CloseHandle GethProcessByClass 'This was for debugging only
EndFunction

PublicFunction GethProcessByCaption(ByVal lpCaption AsString) AsLong
GethProcessByCaption = OpenProcess(PROCESS_ALL_ACCESS, False, GetPIDByCaption(lpCaption))
'CloseHandle GethProcessByCaption 'This was for debugging only
EndFunction

PublicFunction GethProcessByPID(ByVal pID AsLong) AsLong
GethProcessByPID = OpenProcess(PROCESS_ALL_ACCESS, False, pID)
'CloseHandle GethProcessByPID 'This was for debugging only
EndFunction

PublicFunction GetMenuByHandle(ByVal hWnd AsLong) AsLong
GetMenuByHandle = GetMenu(hWnd)
EndFunction

PublicFunction GetMenuByClass(ByVal lpClass AsString) AsLong
GetMenuByClass = GetMenu(GetHandleByClass(lpClass))
EndFunction

PublicFunction GetMenuByCaption(ByVal lpCaption AsString) AsLong
GetMenuByCaption = GetMenu(GetHandleByCaption(lpCaption))
EndFunction

PublicFunction KillProcessByHandle(ByVal hWnd AsLong) AsLong
hProcess = GethProcessByHandle(hWnd)
KillProcessByHandle = TerminateProcess(hProcess, 0)
CloseHandle(hProcess)
EndFunction

PublicFunction KillProcessByClass(ByVal lpClass AsString) AsLong
hProcess = GethProcessByClass(lpClass)
KillProcessByClass = TerminateProcess(hProcess, 0)
CloseHandle(hProcess)
EndFunction

PublicFunction KillProcessByCaption(ByVal lpCaption AsString) AsLong
hProcess = GethProcessByCaption(lpCaption)
KillProcessByCaption = TerminateProcess(hProcess, 0)
CloseHandle(hProcess)
EndFunction

PublicFunction KillProcessByPID(ByVal pID AsLong) AsLong
hProcess = GethProcessByPID(pID)
KillProcessByPID = TerminateProcess(hProcess, 0)
CloseHandle(hProcess)
EndFunction
NeTmAsTeR je offline   Reply With Quote