Results 1 to 14 of 14

Thread: Detecting if a window from an external app is open or not?

  1. #1

    Thread Starter
    Addicted Member Fat_N_Furry's Avatar
    Join Date
    Oct 2002
    Posts
    171

    Detecting if a window from an external app is open or not?

    Hey peeps! Been a while, huh? Haven't been doing much VB.NET for lack of projects lately, but I'm getting back into it a little.

    Anyway, my question:

    How do you detect if a window from an external application is open or not? (like how do you detect if an IE window is open, for example)

    Did a search but didn't really find anything. Don't really know what to search for (detecting windows is what i searched for)


    Gracias por su tiempo! <-----Español
    Rick
    Eat long and prosper!
    If someone helps you, find someone you can help.
    If you still have time, click on the darn banner up there and help the forum!

  2. #2
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    This is a C# source. compile it as a dll and see if it helps you.
    Attached Files Attached Files
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  3. #3

    Thread Starter
    Addicted Member Fat_N_Furry's Avatar
    Join Date
    Oct 2002
    Posts
    171
    Thankyou for your response.

    I don't think I quite understand you. I don't know how to compile it as a DLL file, and what do I do with it after I've done that?


    Thanks again,
    Rick
    Eat long and prosper!
    If someone helps you, find someone you can help.
    If you still have time, click on the darn banner up there and help the forum!

  4. #4
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    Open New Project>C# Projects>Class Library
    Then add this source code as an existing item. You can remove the automatically added class (class1). Add the required references, in this case they are System.Windows.Forms and System.Drawing and also in this case let it be compiled with Unsafe code (you can set it in the project build properties). Then build the project. Depending on you have chosen to build as debug or realse you will find a dll in the project\bin\release or \debug folder.
    Now you have the dll.
    Open your VB.NET project and add a refernce and select Browse from .NET tab and point to the dll just created. and choose select, and ok.
    Now in your Imports section of your form add:
    Imports Win32Utils
    This should be the name you will see, or something like that. And then use it.

    Alternatively you can add that C# project to the Soloution you are working on and the rest is the same.
    If you still have problem let me know to sendyou the compiled dll.
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  5. #5

    Thread Starter
    Addicted Member Fat_N_Furry's Avatar
    Join Date
    Oct 2002
    Posts
    171
    Alright I got one question so far:

    How do I get to the project buld properties?
    Eat long and prosper!
    If someone helps you, find someone you can help.
    If you still have time, click on the darn banner up there and help the forum!

  6. #6
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    Right click on the project in the Solution Explorer, choose properties>Configuration Properties>Bilud>Allow Unsafe Code Blocks=True
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  7. #7

    Thread Starter
    Addicted Member Fat_N_Furry's Avatar
    Join Date
    Oct 2002
    Posts
    171
    Hmm I don't seem to have the Build tab on the Configuration Properties dialogue box.

    Maybe you should just send me the DLL file. I'm quite perplexed as to why in the heck I don't have that option.
    Eat long and prosper!
    If someone helps you, find someone you can help.
    If you still have time, click on the darn banner up there and help the forum!

  8. #8
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    Here is the dll.
    Attached Files Attached Files
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  9. #9

    Thread Starter
    Addicted Member Fat_N_Furry's Avatar
    Join Date
    Oct 2002
    Posts
    171
    Cool. Thankyou very much for your help. P.S. for all you newbies out there it's Imports Win32Util (no S)

    Anyway, how does it work? What do we do now that we have the DLL?


    Thanks again
    Rick
    Eat long and prosper!
    If someone helps you, find someone you can help.
    If you still have time, click on the darn banner up there and help the forum!

  10. #10
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    What property of the external window you gonna refer to? its name?
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  11. #11

    Thread Starter
    Addicted Member Fat_N_Furry's Avatar
    Join Date
    Oct 2002
    Posts
    171
    Yeah. For a window like Internet Explorer, would I use IE6 or something like that or would I use the actual title (in this case it's "VBForums.com - Reply to Topic - Microsoft Internet Explorer")


    Thanks again,
    Rick
    Eat long and prosper!
    If someone helps you, find someone you can help.
    If you still have time, click on the darn banner up there and help the forum!

  12. #12
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    For some applications for example Iexplorer each open window is representative of one process so you can simply check for their existence as follows:
    VB Code:
    1. Dim pr As Process
    2. For Each pr In Process.GetProcesses
    3.       If pr.MainWindowTitle = "somthing" Then
    4.           MessageBox.Show("That window exists")
    5.       End If
    6. Next
    But the problem is when the application has some child windows and you are looking to see if the child window is open or not. By the above example you will get the main window title. So you may use this code:
    VB Code:
    1. Dim pr As Process
    2. For Each pr In Process.GetProcesses
    3.       If pr.MainWindowTitle = "Somthing" Then
    4.          Dim winds As New Win32Util.Win32Window(pr.MainWindowHandle)
    5.          Dim child As Win32Util.Win32Window
    6.          For Each child In winds.GetThreadWindows(winds.ThreadId)
    7.             MessageBox.Show(child.Text)
    8.          Next
    9.     End If
    10. Next
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  13. #13

    Thread Starter
    Addicted Member Fat_N_Furry's Avatar
    Join Date
    Oct 2002
    Posts
    171
    Ah I see. Seems like these functions are quite dynamic. Since this is something you created (I think) I must ask the question is there documentation for this somewhere?


    Thankyou for your time!
    Eat long and prosper!
    If someone helps you, find someone you can help.
    If you still have time, click on the darn banner up there and help the forum!

  14. #14
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    Since this is something you created (I think)..
    No, I ddint write that code. If i can find the link where i downloaded it, would send you.
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

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