Michael A
Michael A

Reputation: 9930

How to Minimize any open application (AHK example of the desired result)

I'm trying to write a piece of code to minimize an application based on the text displaying in the title bar (any application running on the system, not just my own). I've been able to perform the task in an AHK but the desired result isn't ideal and I'd definitely rather it be an active piece of my application then an external one. The AHK is:

#Persistent
#SingleInstance

SetTimer, NoCashierOrHEM, 300
return

NoCashierOrHEM:
IfWinExist , Cashier
WinClose , Cashier
IfWinExist , Hold’em + Omaha Manager
WinMinimize , Hold’em + Omaha Manager
return

Which will minimize any window that has the title bar "Hold'em + Omaha Manager" and close any window that has the title "Cashier". What direction should I be looking in for solving this problem in C#?

Upvotes: 0

Views: 645

Answers (1)

Nils Magne Lunde
Nils Magne Lunde

Reputation: 1824

You will need to use a combination of Windows API functions, like

GetClassName
GetWindowsText
GetWindow

and write a method that goes through open forms and searches for the text.

An example in vb6 can be found here. I believe that code should be fairly easy to convert to c#.

Upvotes: 1

Related Questions