473,387 Members | 1,530 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How do I get a window to the forground? .NET

IonutZ
7
VB.NET 2008-FORM: Getting a window to forground while only knowing its partial name.


Hi guys :)

I have the name of an application, it starts with ACI and I want to set it to my forground in order to sendkeys some stuff to it. Now I've read a BUNCH of stuff and could not come up with a solution on my own. This is the code I have for now, a bunch of stuff compiled together [most of the code I've seen out there and help, was provided by someone named Herfried - so 95% credits of what I have here should go to him] :]


[[[On the side if you could point me in the right direction, how do I send text to a textbox who's HWND I know?]]]


Thanks in advance,

Love this forum, I've gotten so many solutions just from other people's posts, however, everything concerning this user32.dll and its api seems to vague for me so I had to ask for help once and for all!

~IonutZ



Expand|Select|Wrap|Line Numbers
  1. Public Class Form1
  2.     Public Const GW_HWNDPREV = 3
  3.     Private Const SW_SHOW = 5
  4.     Private Const SW_RESTORE = 9
  5.  
  6.     Public Shared Function SetForegroundWindow(ByVal handle As IntPtr) As Boolean
  7.         ' Leave function empty
  8.     End Function
  9.  
  10.     Private Shared Function ShowWindow(ByVal handle As IntPtr, ByVal nCmd As Int32) As Boolean
  11.         ' Leave function empty
  12.     End Function
  13.  
  14.     Private Shared Function IsIconic(ByVal hWnd As IntPtr) As Boolean
  15.         ' Leave function empty
  16.     End Function
  17.  
  18.     Private Shared Function IsZoomed(ByVal hWnd As IntPtr) As Boolean
  19.         ' Leave function empty
  20.     End Function
  21.  
  22.     Public Shared Sub SetToForGround(ByVal hwnd As IntPtr)
  23.         Dim strStatus As String
  24.         'Dim hwnd As IntPtr
  25.         'hwnd = p.MainWindowHandle
  26.  
  27.         If IntPtr.Zero.Equals(hwnd) Then
  28.             strStatus = ""
  29.             Exit Sub
  30.         End If
  31.         If IsIconic(hwnd) Then
  32.             strStatus = "MIN"
  33.         End If
  34.         'If IsZoomed(hwnd) Then
  35.         ' IsNormal = True
  36.         'End If
  37.         'If IsIconic(hwnd) And IsZoomed(hwnd) Then
  38.         ' IsNormal = True
  39.         'End If
  40.  
  41.         If strStatus = "MIN" Then
  42.             'mimized
  43.             ShowWindow(hwnd, SW_RESTORE)
  44.             SetForegroundWindow(hwnd)
  45.         Else
  46.             'maximzed or restored
  47.             SetForegroundWindow(hwnd)
  48.         End If
  49.     End Sub
  50.  
  51.  
  52.     Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
  53.         Dim strPartialTitle As String = "ACI"
  54.  
  55.         ' enumerate all processes 
  56.         For Each pProcess As Process In Process.GetProcesses()
  57.             ' check process' main window title 
  58.             If pProcess.MainWindowTitle.StartsWith(strPartialTitle) Then
  59.                 ' it's a match 
  60.                 Dim strMsg As String = [String].Format("{0}", pProcess.MainWindowTitle)
  61.                 'MessageBox.Show(pProcess.MainWindowHandle.ToString)
  62.                 SetToForGround(pProcess.MainWindowHandle)
  63.  
  64.             End If
  65.         Next
  66.     End Sub
  67. End Class
Mar 1 '08 #1
0 983

Sign in to post your reply or Sign up for a free account.

Similar topics

18
by: D Witherspoon | last post by:
I developed this module, examples on the internet seem to be much longer.. Can someone explain to me why my solution doesn't work? Module modAPI Declare Function SetForegroundWindow Lib...
6
by: David Hayes | last post by:
juglesh <juglesh@nospamRadioKDUG.com> wrote in "Re: how to maximize the browser window that fits the monitor size?" (Saturday, January 01, 2005 3:12 AM): > > >I want to maximize the browser...
19
by: Darren | last post by:
I have a page that opens a popup window and within the window, some databse info is submitted and the window closes. It then refreshes the original window using window.opener.location.reload(). ...
14
by: D. Alvarado | last post by:
Hello, I am trying to open a window containing an image and I would like the image to be flush against the window -- i.e. have no padding or border. Can I make this happen with a single call to a...
1
by: Lex | last post by:
I want to write an app in C# that keeps track of when the foreground window in the OS changes. Is there an event that I can "susbscribe" to for this? Or am I stuck polling using the...
1
by: Earl Teigrob | last post by:
I did a ton of searching to try and find a simple solution to this issue and finally wrote my own, which I am sharing with everyone. In my searching, I did find a very complete and robust solution at...
26
by: yb | last post by:
Hi, Is there a standard for the global 'window' object in browsers? For example, it supports methods such as setInterval and clearInterval, and several others. I know that w3c standardized...
4
by: alexandre.brisebois | last post by:
Hi, I am using access 2003, I would like to know if there is an option to reorganize the tables in a maner that is readable, as we can do in sql sever 2000 or 2005. I have been given a database...
10
by: Gary | last post by:
I'm trying to find a way to determin which window Within-Another-Program currently has the focus. THE SITUATION: (Skip down to "My Question" if you don't want the background...) * This is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.