• 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

    • Generally, Earth never initiated that animals lay straight
    • Several UI improvements masquerading as a major update. I'm truly hating this trend.
    • OpenAI to use Google Cloud despite rivalry, diversifying beyond Microsoft by Paul Hill To help it meet its massive computing demands for training and deploying AI models, OpenAI is looking into a surprising partnership with Google Cloud to use its services. It was widely seen that OpenAI was Google’s biggest threat, but this deal puts an end to the idea that the pair are purely competing. The two companies haven’t made any public announcement about the deal but a source speaking to Reuters claimed that talks had been ongoing for a few months before a deal was finalized in May. Notably, such a deal would see OpenAI expand its compute sources beyond Microsoft Azure. Microsoft had arrangements in place with OpenAI since 2019 that gave it the exclusive right to build new computing infrastructure for the startup. This limitation was loosened earlier this year with the announcement of Project Stargate. OpenAI is now allowed to look elsewhere for compute if Microsoft is unable to meet the demand. A win for Google Cloud, a challenge for Google's AI strategy The deal will see Google Cloud supply computing capacity for OpenAI’s AI model training and inference. This is a big win for Google’s Cloud unit because OpenAI is a massive name in AI and it lends credence to Google’s cloud offering. It also justifies Google Cloud’s expansion of its Tensor Processing Units (TPUs) for external use. On the back of the news, Alphabet’s stock price rose 2.1%, while Microsoft’s sank 0.6%, showing investors think it’s a good move for Google too. While many end users don’t interact with Google Cloud the same way they do with something like Android or Chrome, Cloud is actually a huge part of Google’s business. In 2024, it comprised $43 billion (12%) of Alphabet’s total revenue. With OpenAI as a customer, this figure could rise even more given the massive amounts of compute OpenAI needs. By leveraging Google’s services, it will also give OpenAI access to the search giant’s Tensor Processing Units (TPUs). Unlike GPUs, these chips are specifically designed to handle the kinds of calculations that are most common in AI and machine learning, leading to greater efficiency. Google’s expansion of these chips to external customers has already helped it attract business from Anthropic and Safe Superintelligence. While Google will happily take OpenAI’s money, it needs to tread carefully giving compute power to a rival, which will only make OpenAI more of a threat to Google’s search business. Specifically, it’ll need to manage how resources are allocated between Google’s own AI projects and its cloud customers. Another issue is that Google has been struggling to keep up with the overall demand for cloud computing, even with its own TPUs, according to its Chief Financial Officer in April. By giving access to OpenAI, it means even more pressure. Hopefully, this will be short lived as companies compete to build out capacity to attract customers. OpenAI's push for compute independence Back in 2019 when Microsoft became OpenAI’s exclusive cloud partner in exchange for $1 billion, the AI landscape was much different. End users wouldn’t have access to ChatGPT for another 3 years and the rate of development of new models was less ferocious than it is today. As OpenAI’s compute needs evolve, its relationship with Microsoft has had to evolve too, including this deal with Google and the Stargate infrastructure program. Reuters said that OpenAI’s annualized run rate (the amount they’ll earn in one year at its current pace) had surged to $10 billion, which highlights its explosive growth and need for more resources than Microsoft alone can offer. To make itself more independent, OpenAI has also signed deals worth billions of dollars with CoreWeave, another cloud compute provider, and it is nearing the finalization of the design of its first in-house chip, which could reduce its dependency on external hardware providers altogether. Source: Reuters
    • I don't think that means what you think it means
    • The Google Home app gets video forwarding support and many more features by Aman Kumar Along with releasing the Android 16 update for supported Pixel devices, Google has also showcased a number of features coming to its Home app. First up is PiP, also known as picture-in-picture mode, which will be available for Nest Cams on any Google TV device you own. It’ll be similar to YouTube’s PiP, with which you must be familiar with. A small window will appear in a corner of the TV screen, allowing you to view your Nest Cams without interrupting your viewing experience. The feature is currently in public preview, and you can enroll to try it out before its public release. Another YouTube feature that Google is adding to its Home app is the ability to jump 10 seconds forward or backward in recorded videos. This feature ensures that you don't have to go through the entire footage to locate the moment you’re looking for. Google mentioned in its blog post that it is adding more controls to the Google Home web app. Currently, the web app offers limited functionality, such as setting automations and viewing cameras, but soon you’ll be able to manage more things through it, such as adjusting lighting, controlling temperature, and locking or unlocking the door. Google’s AI model, Gemini, is also getting more controls in the Home app. You can use natural language in the Gemini app to search for specific footage in the camera history. Furthermore, the fallback assistant experience that broadcast commands use is also being updated. You’ll now be able to use your voice to broadcast messages through the connected speakers in your home. The Google blog post also mentions that you are no longer required to use the standalone Nest app to receive smoke and other critical alerts. You can now view the Nest Protect smoke and carbon monoxide (CO) status directly in the Home app. You’ll also be able to run safety checkups and hush alarms through the Home app. In addition to all these features, Google is also making the automation creation process much quicker, will allow you to add more tiles to the Home app Favorites section, and will let you create different Favorites for any other device you use, such as your smartwatch. The Home app will now also support third-party Matter locks. Similar to the Nest x Yale lock, you’ll be able to control various settings of these third-party locks, like managing household access, creating guest profiles, and more.
  • Recent Achievements

    • Enthusiast
      computerdave91111 went up a rank
      Enthusiast
    • Week One Done
      Falisha Manpower earned a badge
      Week One Done
    • One Month Later
      elsa777 earned a badge
      One Month Later
    • Week One Done
      elsa777 earned a badge
      Week One Done
    • First Post
      K Dorman earned a badge
      First Post
  • Popular Contributors

    1. 1
      +primortal
      535
    2. 2
      ATLien_0
      272
    3. 3
      +FloatingFatMan
      201
    4. 4
      +Edouard
      200
    5. 5
      snowy owl
      138
  • Tell a friend

    Love Neowin? Tell a friend!