PDA

Click to See Complete Forum and Search --> : Get all the active windows


PunK
Aug 26th, 2001, 12:48 PM
Alright this is making me mad...I've been going into other posts for some time now and they ALL havent answer my question, or didnt work!

How can I get a window's text when its opened?C:\Windows\System\1~guard.txt)

e.g: [8-26-01] -Window opened here-


Thank you!:cool:

gdebacker
Aug 26th, 2001, 01:45 PM
Maybe it is not the replies you get, but the question you ask.

This line is confusing. What is the path at the end of the question for?

How can I get a window's text when its opened?C:\Windows\System\1~guard.txt)


What are you trying to convey here?

e.g: [8-26-01] -Window opened here-


What do these lines mean?
Are you trying to capture the window text JUST as the window is opened?
Is this for every window in the os?
Is it just for windows in your program?
What exactly are you trying to do?

Greg

PunK
Aug 26th, 2001, 02:12 PM
Ok Mr.Therapist:rolleyes: :p

I need to get the window's title right when its opened...and the path was for where it would save the text to...as for the "e.g: [8-26-01] -Window opened here-" part that was supposed to be how I wanted it...


In the text file it would say:

[(Date)] (Window's title)

Megatron
Aug 26th, 2001, 05:38 PM
I would suggest you use a WH_SHELL hook, and take action when the HSHELL_WINDOWCREATED code is recieved.

PunK
Aug 27th, 2001, 03:45 PM
rrrrrrright.. Sorry, I'm not that good at VB :D

Megatron
Aug 27th, 2001, 04:24 PM
Well, since we want it to respond globally, you need to put your procedure in a standard DLL. But since VB cannot create standard DLLs, you need to use C++ or Delphi.

Here is some C++ should that should work.

#include <windows.h>
#include <fstream.h>
HHOOK hHook;

extern "C" __declspec(dllexport) LRESULT CALLBACK ShellProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if( nCode == HSHELL_WINDOWCREATED )
{
LPSTR lpBuff;
if(GetWindowText( (HWND)wParam, lpBuff, GetWindowTextLength((HWND)wParam)+1))
{
ofstream file("C:\\MyLog.txt", ios::app);
file << "'" << lpBuff << "'" << " OPENED AT: " << __DATE__ << endl;
file.close();
}

}

return CallNextHookEx(hHook, nCode, wParam, lParam);
}

Megatron
Aug 27th, 2001, 04:33 PM
Now create a new VB project, and add the following code to it.

Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, ByVal lpProcName As String) As Long
Private 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
Private Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
Private Const WH_SHELL = 10
Private hHook As Long
Private hModule As Long

Private Sub Form_Load()

Dim lpfn As Long

'Change path to path of the ShellProc Dll.
hModule = LoadLibrary("C:\Windows\Desktop\ShellProcDll")
If hModule <> 0 Then
lpfn = GetProcAddress(hModule, "_ShellProc@12")
If lpfn <> 0 Then hHook = SetWindowsHookEx(WH_SHELL, lpfn, hModule, 0)
End If

End Sub

Private Sub Form_Unload(Cancel As Integer)
If hHook <> 0 Then UnhookWindowsHookEx (hHook)
End Sub

PunK
Aug 27th, 2001, 08:05 PM
I dont mean to be rude or anything..but.........WHAT THE ****!?

Nucleus
Aug 27th, 2001, 10:05 PM
The hook is there so that everytime a new window is created, you can respond to it.
VB cannot create such a hook, so he used C++ and then showed you how to implement with VB. :)

Megatron
Aug 28th, 2001, 08:44 AM
Originally posted by PunK
I dont mean to be rude or anything..but.........WHAT THE ****!?
What part don't you get? The C++ part?

Want me to just send you the projects? (and you can modify them where necessary)

PunK
Aug 28th, 2001, 03:56 PM
Sure, just send the project files to this email address (tmpii@hotmail.com)

Megatron
Aug 28th, 2001, 05:02 PM
Ok.

I didn't know whether you had C++ installed, so I sent the source files as well as the compiled DLL.