hi,
Can anybody help me in solving this,
if user opens a notepad window,it should be notified to my application, and i should get the hwnd of that.
thanx
Printable View
hi,
Can anybody help me in solving this,
if user opens a notepad window,it should be notified to my application, and i should get the hwnd of that.
thanx
Now, this is just an idea, and you will have to work to set it.
From api-guide I extracted an example about enumwindowproc.
Add a timer to a form
and a module (.bas) to the project
add this code to form:
'----------------------------------------------------
Private Sub Timer1_Timer()
'call the Enumwindows-function
Me.Cls
EnumWindows AddressOf EnumWindowsProc, ByVal 0&
End Sub
'----------------------------------------------------
'add this code to module:
Option Explicit
Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Boolean
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Public Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean
Dim sSave As String, Ret As Long
Dim foundpos As Integer
Ret = GetWindowTextLength(hwnd)
sSave = Space(Ret)
GetWindowText hwnd, sSave, Ret + 1
'for make you see, print all to the form
'rem this if not needed
Form1.AutoRedraw = True
Form1.Print Str$(hwnd) + " " + sSave
''hwnd is window handle; sSave, the title, if any
'now, if you find a title, look if you already added it to form
'caption. For your purpouse, you should add this to an array
'from where to search if a desiderd program is opened
'you may furter look for Notepad inside a cell
string of your array (remember whole string would be:
'title of file opened and notepad
'ie: mydoc1 - notepad)
If Trim(sSave) <> "" Then
foundpos = InStr(1, Form1.Caption, sSave, vbTextCompare)
If foundpos = 0 Then
Form1.Caption = Form1.Caption & " " & sSave
End If
End If
'continue enumeration
EnumWindowsProc = True
End Function
Hope this may give a hint
Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.
... timer interval is ok over 5000 ms
Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.