• 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

    • For a moment there I thought it speeds up Windows installation, but alas...
    • PNY's DUO LINK V3 promises truly incredible speed for a USB flash drive by Sayan Sen PNY today announced a new USB flash drive that blends modern design with high performance. The new DUO LINK™ V3 supports USB 3.2 Gen 2 and offers both Type-C and Type-A connectors. Housed in a metal shell with a matte black finish, the device is built for users who need reliable results when transferring and storing files. The drive is available in multiple storage sizes ranging from 256GB, all the way up to 2TB. According to PNY, the DUO LINK V3 is engineered to deliver read speeds of up to 1,000 MB/s and write speeds of up to 800 MB/s. These speeds are significantly higher than those achieved by standard USB 2.0 flash drives, allowing users to move large files. The product reminds us of the "Poxiao" flash memory we recently covered, which promises even more incredible speeds. The DUO LINK V3 flash drive’s design uses the common swivel mechanism with dual connectors. One side of the device features a USB Type-C connector, while the other side has a USB Type-A connector. This dual-connector system is intended to maximize compatibility, making the DUO LINK V3 useful across a broad range of devices, including smartphones, tablets, laptops, and desktop computers. Thus, in practical terms, users can easily manage files between newer mobile devices and traditional computers without needing extra adapters. Durability and ease of use are emphasized by the metal housing, which is designed to protect the drive during everyday handling. A built-in key loop further supports portability, an important factor for professionals who need to carry important data with them. The device also maintains backward compatibility with older USB standards such as USB 3.2 Gen 1, USB 3.0, and USB 2.0, ensuring that users will find it adaptable to many existing systems. The DUO LINK V3 flash drive is now available directly from PNY and through selected online marketplaces like Amazon. The pricing starts at $34.99 for the 256GB version and reaches $159.99 for the 2TB version. This release provides users with a tool that meets the growing demands of data-intensive work while remaining accessible to those needing a reliable and versatile storage solution. This article was generated with some help from AI and reviewed by an editor. As an Amazon Associate we earn from qualifying purchases.
    • Message from Campbell Wilson, MD & CEO, Air India: https://www.instagram.com/airindia/reel/DKzZQUPhafx/
    • I mean they have been proven to be safer than human drivers in many cases so at the end of the day they will be allowed on the road, the fact that you don't trust them doesn't mean that policy has to be changed to make you more comfortable I am afraid.
    • This 4TB Gen4 2280 NVMe SSD is selling for just $200 with promo coupon by Sayan Sen We reported yesterday about the WD_BLACK SN8100 (PCIe Gen5) and SN7100 (PCIe Gen4) deals as they are both priced the lowest. There is also a free VPN on offer. You can check those deals out here. If you do not quite have the budget for those drives but still want a relatively fast drive in 4TB, then Team Group is offering its T-FORCE G50 model at a great price of just $200 with a coupon code (purchase link down below). Like the SN8100 and SN7100 WD SKUs, the Team Group G50 is also a TLC (triple level cell) NAND flash SSD, and thus the endurance on the T-FORCE SSD is quite good, as it is rated for 2600 TBW (terabytes written). Its MTBF, or Mean Time Between Failure, is claimed at 3,000,000 hours. However, unlike the WD_BLACK models, the G50 does not have a dedicated DRAM cache (only the G50 Pro SKUs have it) but it is based on NVMe version 1.4 which supports HMB (host memory buffer) technology; thus, the drive can use system memory for caching. In terms of performance, Team Group promises sequential read and write speeds of up to 5000 MB/s and 4500 MB/s, respectively. However, the firm does not disclose random throughput metrics. Essentially, compared to the WD_BLACK SN7100 linked above, you miss out on faster speeds, but you are also paying less with this. Either of these drives can be a great choice depending on your budget. Get the Team Group SSD at the link below: Team Group T-FORCE G50 M.2 2280 4TB PCIe 4.0 x4 - TM8FFE004T0C129: $219.99 + $20 off with promo code SUMET9324, limited offer => $199.99 (Shipped and Sold by Newegg US) This Amazon deal is US-specific and not available in other regions unless specified. If you don't like it or want to look at more options, check out the Amazon US deals page here. Get Prime (SNAP), Prime Video, Audible Plus or Kindle / Music Unlimited. Free for 30 days. As an Amazon Associate, we earn from qualifying purchases.
  • Recent Achievements

    • Week One Done
      fashionuae earned a badge
      Week One Done
    • One Month Later
      fashionuae earned a badge
      One Month Later
    • Week One Done
      elsafaacompany earned a badge
      Week One Done
    • Week One Done
      Yianis earned a badge
      Week One Done
    • Veteran
      Travesty went up a rank
      Veteran
  • Popular Contributors

    1. 1
      +primortal
      508
    2. 2
      ATLien_0
      263
    3. 3
      +FloatingFatMan
      193
    4. 4
      +Edouard
      174
    5. 5
      snowy owl
      125
  • Tell a friend

    Love Neowin? Tell a friend!