It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming Visual Basic Forum

PROCESS LISt

Moderator: dafunkymunky

PROCESS LISt

Postby Acer_iwk on Mon Aug 18, 2008 11:37 am

how can we access the active process list like task manager?
please help
:?: :?: :?: :?: :?:
Acer_iwk
 
Posts: 7
Joined: Wed Jul 30, 2008 8:35 pm

Postby atulaga on Tue Aug 19, 2008 4:39 pm

hi.
I have finished one:
You can using API function from user32.dll.

This is my code (using VB2005) to obtain all window has caption which has
first 8 chars is "PSS/E - " and last 4 char is ".sav"


'--------------------------------------------------------------
Public Const StringBufferLength As Integer = 255
Public Function FindPSSEWindows() As Boolean
Dim i As Integer
Dim sPSSE As String
Dim str As String
Dim sCaption As String
Dim sClass As String
Dim SplitChar(0) As String
Dim hWndStart As Integer
Dim hChild As Integer
Dim windowText As New StringBuilder(StringBufferLength)
Dim className As New StringBuilder(StringBufferLength)
'Find deskktop window
hWndStart = GetDesktopWindow()
i = 0 'PSS/E window index
hChild = GetWindow(hWndStart, GW_CHILD)
Do While hChild > 0
Win32API.GetWindowText(hChild, windowText, StringBufferLength)
Win32API.GetClassName(hChild, className, StringBufferLength)
sCaption = windowText.ToString
sClass = className.ToString
sPSSE = Mid(sCaption, 1, 8)
SplitChar(0) = "."
str = Strings.Right(sCaption, 4)

If (sPSSE = "PSS/E - ") And (UCase(str) = ".SAV") Then
i = i + 1
' DO YOUR CODE HERE, EXAMPLE:
'MsgBox("Handle: " + windowHandleAr(i).ToString + vbCrLf _
'+ "Class: " + windowClassAr(i).ToString + vbCrLf _
'+ "Caption: " + windowCaptionAr(i).ToString)
End If
hChild = GetWindow(hChild, GW_HWNDNEXT)
Loop
TotalPSSEWindows = i
If TotalPSSEWindows = 0 Then
Return False
Else
Return True
End If

End Function

'---------------------------------------------
'above code can use with vb6: you can replace functions Win32API.xxx with these declares:

Declare Function EnumChildWindows Lib "user32" Alias "EnumChildWindows" _
(ByVal hWndParent As Integer, ByVal lpEnumFunc As System.Delegate, ByVal lParam As Integer) As Boolean

Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hWnd As Integer, ByVal Msg As Integer, ByVal ByValwParam As Integer, ByVal lParam As String) As Integer

Public Declare Function SendChar Lib "user32" Alias "SendMessageA" _
(ByVal hWnd As Integer, ByVal Msg As Integer, ByVal ByValwParam As Integer, ByVal lParam As Integer) As Integer

Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Integer

Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
(ByVal hWnd1 As Integer, ByVal hWnd2 As Integer, ByVal lpsz1 As String, ByVal lpsz2 As String) As Integer

Public Declare Auto Function GetWindow Lib "user32" _
(ByVal hWnd As Integer, ByVal uCmd As Integer) As Integer

Public Declare Function GetClassName Lib "user32" Alias "GetClassNameA" _
(ByVal hwnd As Integer, ByVal lpClassName As String, ByVal nMaxCount As Integer) As Integer

Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" _
(ByVal hwnd As Integer, ByVal lpString As String, ByVal cch As Integer) As Integer


Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" _
(ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
'UnhookWindowsHookEx
Public Declare Function GetDesktopWindow Lib "user32" () As Integer


Delegate Function EnumChildWindowsCallBack(ByVal hChild As Integer, ByVal lParam As Integer) As Boolean
atulaga
 
Posts: 3
Joined: Tue Aug 19, 2008 3:11 pm

Postby atulaga on Tue Aug 19, 2008 4:52 pm

or You can use this funtion: Enumwindow
VB2005:

Declare Function EnumChildWindows Lib "user32" Alias "EnumChildWindows" _
(ByVal hWndParent As Integer, ByVal lpEnumFunc As System.Delegate, ByVal lParam As Integer) As Boolean

Declare Function EnumWindows Lib "user32" Alias "EnumChildWindows" _
(ByVal lpEnumFunc As System.Delegate, ByVal lParam As Integer) As Boolean

Public Declare Function GetClassName Lib "user32" Alias "GetClassNameA" _
(ByVal hwnd As Integer, ByVal lpClassName As String, ByVal nMaxCount As Integer) As Integer

Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" _
(ByVal hwnd As Integer, ByVal lpString As String, ByVal cch As Integer) As Integer

Delegate Function EnumChildWindowsCallBack(ByVal hChild As Integer, ByVal lParam As Integer) As Boolean
Delegate Function EnumWindowsCallBack(ByVal hChild As Integer, ByVal lParam As Integer) As Boolean



Public Function EnumWindowsProc(ByVal hWnd As Integer, ByVal lParam As Integer) As Boolean
Dim windowText As New StringBuilder(StringBufferLength)
Dim className As New StringBuilder(StringBufferLength)
' Get the Window Caption and Class Name. Notice that the definition of Win32API
' functions in the Win32API class are declared differently than in VB6. All Longs
' have been replaced with Integers, and Strings by StringBuilders.

Win32API.GetWindowText(hWnd, windowText, StringBufferLength)
Win32API.GetClassName(hWnd, className, StringBufferLength)
If windowText.ToString <> "" Then
' your code can be different here
End If
Return True
End Function


sub FindAllWindow()
EnumWindow(new EnumWindowsCallBack(AddressOf EnumWindowProc),0)
' With each window found, enumwindowsproc will be called.
' the "type declared of" delegate enumwindowscallback and enumwindowsproc is same.

' In VB6 you do not have to use delegate and can directly use: AddressOf
end sub
atulaga
 
Posts: 3
Joined: Tue Aug 19, 2008 3:11 pm


Who is online

Users browsing this forum: No registered users and 1 guest