• 0

How to make an open windows list VB 2010 express


Question

Hello all

Basically this has stumped us. We are making a program that depends on being able to choose which window of all open windows is the one to use. However, we cant find which command to use to get the windows to make the list. The window will most likely be firefox. This is 2010 express so there isn't .net commands.

Any ideas here whould be most appreciated.

Thanks

14 answers to this question

Recommended Posts

  • 0

If it will always be firefox you can use System.Diagnostics.Process.GetProcessByName. If the user must choose then I recommend you reference managed winapi and use code such as (C# but very similar and still .NET, should give you the idea. This example fills a treeview named treeView1)

foreach (SystemWindow m in SystemWindow.AllToplevelWindows.Where<SystemWindow>;
                ((SystemWindow g) =&gt; {
            if (g.Visible) treeView1.Nodes.Add(g.Title + "[" + g.HWnd.ToString() + "]").Tag = g.HWnd; return false;
                })) { }

  • 0
  On 01/12/2010 at 22:09, omnicoder said:

If it will always be firefox you can use System.Diagnostics.Process.GetProcessByName. If the user must choose then I recommend you reference managed winapi and use code such as (C# but very similar and still .NET, should give you the idea. This example fills a treeview named treeView1)

foreach (SystemWindow m in SystemWindow.AllToplevelWindows.Where<SystemWindow>;
                ((SystemWindow g) =&gt; {
            if (g.Visible) treeView1.Nodes.Add(g.Title + "[" + g.HWnd.ToString() + "]").Tag = g.HWnd; return false;
                })) { }

Thanks, but as we don't have .net extensions it won't run. We need a solution for VB 2010 express without using .net

  • 0

All express versions of any of the .NET languages fully support '.net extensions' so I'm not sure what you think is missing. Everything in omnicoders response is possible with VB.NET 2010 Express .

  • 0

Unless he was referring to my use of Where<T>, which I don't think is avaliable in .NET2.0 (in which case he should upgrade to 3.5/4.0) but that would be trivial to convert into a loop for use in 2.0 anyway.

VB 2010 uses .net exclusively, there is no way around that.

  • 0
  On 02/12/2010 at 00:27, Getwin said:

Thanks, but as we don't have .net extensions it won't run. We need a solution for VB 2010 express without using .net

You must have the .NET Framework to use any software written in VB or C#. The "old" style of VB doesn't exist anymore.

  • 0

Hi and thank you to everybody esp. Omnicoder

However, we still cannot use that code. It doesnt compile because the functions are unrecognised by the interpreter.

What we want to do is display a dialogbox to the user, which lists all open windows on the computer, so that he can select one to use. Our code will then interact with that window. That is the objective.

We have tried many samples of code we have found from online tutorials, but none of them will work in our computer because all of them use .net functions. We have the Visual Basic 2010 Express application, which errors over anything with .net code. It will not run it or compile it. This is the free application from MS which specifically has all .net functionality removed.

We need code to do this without using .net extensions. We know it is possible because we have seen someone's application do exactly this kind of window on this computer.

Maybe his code was not vb ? It could have been C#.

Any ideas would be appreciated.

Thanx

  • 0

As I said, if you don't want to use the .NET Framework you'll have to either buy a copy of Visual Basic 6 if you can find it. Visual Basic and C# have been .NET for almost ten years now.

Visual Studio Express doesn't have any .NET stuff removed: it is .NET. smile.gif

The framework is included with all modern versions of Windows. Out of curiosity, why don't you want to use it?

Just to be clear, this is the Visual Studio Express family. Is that what you are using?

  • 0

Module Module1

	Public Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As IntPtr) As Boolean
	Private Declare Function BringWindowToTop Lib "user32" (ByVal hwnd As IntPtr) As Boolean

	Sub Main()
 	For Each p As Process In Process.GetProcesses
 	If Not IsWindowVisible(p.MainWindowHandle) Then Continue For
 	Console.WriteLine(p.ProcessName) ' Just an example - You would want to add this to your program's window list.
 	BringWindowToTop(p.MainWindowHandle) ' This will bring the process's window to the top.
 	Next
	End Sub

End Module

Try that. It complies and runs fine in VBE2010. There doesn't seem to be any around using at least one or two P/Invoke commands.

Obviously you won't want to use it "as-is" since it simply loops through all the non-hidden process windows and brings them to the front, but you get the idea. :)

  • 0

thank you Grey Wolf for your code,

but it produces nothing on our computer.

we have modifed the code to make it display what it finds and it still finds nothing.

Module Module1

Public Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As IntPtr) As Boolean

Private Declare Function BringWindowToTop Lib "user32" (ByVal hwnd As IntPtr) As Boolean

Sub Main()

For Each p As Process In Process.GetProcesses

MsgBox(p)

'If Not IsWindowVisible(p.MainWindowHandle) Then Continue For

'Console.WriteLine(p.ProcessName) ' Just an example - You would want to add this to your program's window list.

'BringWindowToTop(p.MainWindowHandle) ' This will bring the process's window to the top.

Next

End Sub

End Module

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Main()

End Sub

End Class

the interpreter likes it, runs it but there is no result. just an empty window.

we cannot figure out what is wrong here. Technically the code is correct. but it doesnt work on our system.

Any ideas ?

  • 0

Public Class Form1

	Public Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As IntPtr) As Boolean
	Public Declare Function BringWindowToTop Lib "user32" (ByVal hwnd As IntPtr) As Boolean
	Dim visibleWindows As New List(Of Process)
	Dim list As New ListBox

	Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 	Me.Controls.Add(list)
 	list.Dock = DockStyle.Fill
 	AddHandler list.DoubleClick, AddressOf List_DoubleClick

 	For Each p As Process In Process.GetProcesses
 	If Not IsWindowVisible(p.MainWindowHandle) Then Continue For
 	list.Items.Add(p.MainWindowTitle)
 	visibleWindows.Add(p)
 	Next
	End Sub

	Private Sub List_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs)
 	BringWindowToTop(visibleWindows(list.SelectedIndex).MainWindowHandle)
	End Sub
End Class

Try that. I coded the listbox control into the Form_Load so you don't have to create it on the designer. Double-clicking on a window title will bring that window to the front.

  • 0

Thanx guys

Omnicoder you were right about that string thing. It should be p.ProcessName. And it correctly shows processes.

And GreyWolf we tried that new bit of code and it works exactly like u said it should. It finds all windows and can bring forward the one chosen. That was a novel strategy to find all processes and ignore processes without windows. Clever :D

Thank you all very much.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • When are MS going to learn. Traditional home users who email, watch cat videos and perform basic tasks don't care if W11 is slightly faster...assuming it's true. Few home users care about faster speed and more secure claims.
    • They have. https://www.xda-developers.com...-25h2-update-kind-of-small/
    • Microsoft shares detailed performance benchmarks for Windows 11 vs 10 to show the faster PC by Sayan Sen In the past, Microsoft has always made big claims regarding Windows 11 performance and how it is faster and better than Windows 10. For example, back in 2021, the company stated how the former was designed to get the best out of your system hardware. Later in 2023, Microsoft shared detailed Windows 11 performance improvements and upgrades it achieved on the new OS. While the claims were not substantiated with data, they were certainly quite interesting. Then, in 2024, Microsoft highlighted the differences in performance, citing a paid study, to show Windows 11 was way faster. As with most commissioned studies, the data was not represented fairly. This week, Microsoft has shared new numbers based on its December 2024 testing in a new support document. Here are the performance claims Microsoft made: Top Windows 11 PCs have up to 2.7 more hours of battery life than Windows 10 PCs Windows 11 PCs are up to 2.3x faster than Windows 10 PCs Windows 11 PCs offer up to 3.2x faster web browsing than Windows 10 PCs Windows 11 PCs offer up to 2x faster Microsoft Office productivity than Windows 10 PCs Thus, if you ask Microsoft, it will say that Windows 11 is better than Windows 10 in everything there is, be it web browsing, Office use, battery life, and overall performance in general. The company notes that the results are "based on a 95% confidence interval" for each OS across multiple tests. Microsoft also accounted for outliers. To reach such numbers, Microsoft used the following test metrics: For battery life, a local 1080p 24 fps MP4 video file playback was tested till 90% battery discharge on the Windows Media Player app. During the test, all settings were default except that screen brightness was set to 150 nits and Auto-brightness was disabled. Wi-Fi was connected to a network. For the "2.3x faster" claim, Geekbench 6 results have been cited. For web browsing, Speedometer was used, though Microsoft does not mention the version. And finally, for Office, Procyon Office productivity was used. Interestingly, Microsoft only used Intel CPUs (the company also recently recommended Intel chips for Windows 11 Pro PCs). The company has played it a smarter this time as it has "tested performance, battery life and application capabilities of a selection of Windows 11 PCs in comparison to a selection of Windows 10 PCs", where the Windows 10 PCs feature Intel Core 6th, 8th, and 10th gen chips and Windows 11 PCs pack Intel Core 12th and 13th gen. Thus, this is Microsoft essentially acknowledging that the underlying hardware itself actually plays a big role in the claims it has made. But to be fair to the company, there is also no way to run Windows 11, at least officially, on unsupported PCs, such that a direct comparison can be made. You can find the support document with full battery results in this article here on Microsoft's website.
    • So, do nothing basically, as long as you deploy Windows Updates? Pretty much yeah. Some Linux distros distribute update the secureboot certs as well, assuming you do use SecureBoot.
    • On one hand, YouTube videos are filled with so much fillers and the Youtubers intentionally speak slowly to increase video time and "engagement" metrics. On the other, Google's asking you to not stay on their site for longer. That's a win-win for viewers. So, I think it'll be axed or de-emphasised in the near future.
  • Recent Achievements

    • Week One Done
      Marites earned a badge
      Week One Done
    • One Year In
      runge100 earned a badge
      One Year In
    • One Month Later
      runge100 earned a badge
      One Month Later
    • One Month Later
      jfam earned a badge
      One Month Later
    • First Post
      TheRingmaster earned a badge
      First Post
  • Popular Contributors

    1. 1
      +primortal
      560
    2. 2
      +FloatingFatMan
      177
    3. 3
      ATLien_0
      169
    4. 4
      Michael Scrip
      126
    5. 5
      Xenon
      118
  • Tell a friend

    Love Neowin? Tell a friend!