Results 1 to 12 of 12

Thread: Get all the active windows

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2001
    Location
    I thought you knew!!
    Posts
    38

    Angry Get all the active windows

    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!
    Last edited by PunK; Aug 26th, 2001 at 01:18 PM.

  2. #2
    Frenzied Member
    Join Date
    Aug 2001
    Posts
    1,075
    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
    Free VB Add-In - The Reference Librarian
    Click Here for screen shot and download link.

  3. #3

    Thread Starter
    Member
    Join Date
    Jan 2001
    Location
    I thought you knew!!
    Posts
    38

    Post asdf

    Ok Mr.Therapist

    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)

  4. #4
    Megatron
    Guest
    I would suggest you use a WH_SHELL hook, and take action when the HSHELL_WINDOWCREATED code is recieved.

  5. #5

    Thread Starter
    Member
    Join Date
    Jan 2001
    Location
    I thought you knew!!
    Posts
    38

    Smile .

    rrrrrrright.. Sorry, I'm not that good at VB

  6. #6
    Megatron
    Guest
    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.
    Code:
    #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);
    }

  7. #7
    Megatron
    Guest
    Now create a new VB project, and add the following code to it.
    VB Code:
    1. Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
    2. Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, ByVal lpProcName As String) As Long
    3. 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
    4. Private Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
    5. Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
    6. Private Const WH_SHELL = 10
    7. Private hHook As Long
    8. Private hModule As Long
    9.  
    10. Private Sub Form_Load()
    11.        
    12.     Dim lpfn As Long
    13.    
    14.     'Change path to path of the ShellProc Dll.
    15.     hModule = LoadLibrary("C:\Windows\Desktop\ShellProcDll")
    16.     If hModule <> 0 Then
    17.         lpfn = GetProcAddress(hModule, "_ShellProc@12")
    18.         If lpfn <> 0 Then hHook = SetWindowsHookEx(WH_SHELL, lpfn, hModule, 0)
    19.     End If
    20.    
    21. End Sub
    22.  
    23. Private Sub Form_Unload(Cancel As Integer)
    24.     If hHook <> 0 Then UnhookWindowsHookEx (hHook)
    25. End Sub

  8. #8

    Thread Starter
    Member
    Join Date
    Jan 2001
    Location
    I thought you knew!!
    Posts
    38

    Unhappy asdf

    I dont mean to be rude or anything..but.........WHAT THE ****!?

  9. #9
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    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.

  10. #10
    Megatron
    Guest

    Re: asdf

    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)

  11. #11

    Thread Starter
    Member
    Join Date
    Jan 2001
    Location
    I thought you knew!!
    Posts
    38

    Post asdf

    Sure, just send the project files to this email address

  12. #12
    Megatron
    Guest
    Ok.

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width