Window State

hitechoutlaw

Well-known member
Joined
Mar 22, 2003
Messages
77
Location
USA
is there a way to run through the processes every so often and check to see if a program has been minimized and if it is then maximize it? if so, how?

i was thinking along the lines of:
[VB]
Dim processes(), p As Process

processes = Process.GetProcesses()
For Each p In processes
If Not (p.MainModule Is Nothing) Then
If System.IO.Path.GetFileName(p.MainModule.FileName).ToLower() = "game.exe" Then
(sumthang)
End If
End If
Next
[/VB]
 
The windows style will have WS_MINIMIZE style applied to it if the window is minimized. Use the Win32 API function [api]GetWindowLong[/api] to determine if this style is present.

Code:
Const GWL_STYLE As Integer = (-16)
Const WS_MINIMIZE As Integer = &H20000000


Dim pStyle As IntPtr = GetWindowLong(p.MainWindowHandle, GWL_STYLE)


If (pStyle And WS_MINIMIZE) <> False Then
    Window is minimized
End If

Youll need to declare GetWindowLong of course.
 
if im not mastaken (which i might be) that will only work on the app its run in, i want it to check to see if an app is being run and if it is, then if it is minimized or not.

thats why i was looking through the processes for "game.exe"

what do u or anyone else think?
 
i get two error messages and have no clue where to take it from here

Name p is not declared
&
Operator And is not defined for types System.IntPtr and Integer.
 
thanks for ur help

now if gives me an error:

Value of System.IntPtr cannot be converted into long.


i know some people on the internet would give up after the first answer, this form has the nicest people u can find on the net, im glad i found it.

thanks
 
Change the "Long" value types in the GetWindowLong declaration to "Integer". Longs in Visual Basic .NET are 64-bit, while in Visual Basic 6 they were 32-bit. This makes a huge difference when calling a Win32 API function.
 
my program brings up an exception that has never come up before:
---------------------------------------------
An unhandled exception of type System.ComponentModel.Win32Exception occurred in system.dll

Additional information: Access is denied
---------------------------------------------
at this line:

Code:
If Not (p.MainModule Is Nothing) Then

it has always worked before in other programs but now it wont work in any of my programs.
 
Back
Top