==========Get handle from an application==========
We must get the handle from an application before minimizing it.To get a handle and minimize a program , you use HWND,FindWindow and ShowWindow ( API ).
HWND :(h) handle (Wnd) Window.
Code:
HWND mywindow; FindWindow(NULL,"SRO_Client");
We use the FindWindow function to search windows.
The first parameter NULL defines that it should find any window whose title matches to the second parameter ( ' SRO_Client ' ).
The second parameter is the title of the window we search ( ' SRO_Client ' ).
To search child windows, beginning with a specified child window, use the FindWindowEx function.
==========Check if notepad is opened==========
Code:
#include <windows.h> //imports HWND,FindWindow,ShowWindow #include <iostream> //imports cout and cin using namespace std; int main() { HWND hWnd_my_application; //We declare hWnd_my_application as a HWND hWnd_my_application = FindWindow(NULL,"notepad"); //Searches the window 'notepad' if(hWnd_my_application) // if we find the notepad our application does : { cout << "I have found your window :-)nn" << endl; system("pause"); } else // else our console application does : { cout << "Sorry,I haven't found your window.Maybe it isn't opened...nn" << endl; system("pause"); } }
Our first parameter in FindWindow is NULL.So it will find any window whose title name is 'notepad'.
After that we use a if-else-statement to display if we have found our notepad.
The \n is an escape-sequence.I will make a new thread about escape sequences.
\n stands for newline
==========Minimizing and Maximizing==========
We use the ShowWindow function to change a windows's show state.Code:
HWND window_one; window_one = FindWindow(NULL,SRO_Client); ShowWindow(window_one, SW_MINIMIZE);
The second parameter specifies how the window is to be shown :
Example :Quote:
SW_FORCEMINIMIZE
Windows 2000/XP: Minimizes a window, even if the thread that owns the window is not responding. This flag should only be used when minimizing windows from a different thread.
SW_HIDE
Hides the window and activates another window.
SW_MAXIMIZE
Maximizes the specified window.
SW_MINIMIZE
Minimizes the specified window and activates the next top-level window in the Z order.
SW_RESTORE
Activates and displays the window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when restoring a minimized window.
SW_SHOW
Activates the window and displays it in its current size and position.
SW_SHOWDEFAULT
Sets the show state based on the SW_ value specified in the STARTUPINFO structure passed to the CreateProcess function by the program that started the application.
SW_SHOWMAXIMIZED
Activates the window and displays it as a maximized window.
SW_SHOWMINIMIZED
Activates the window and displays it as a minimized window.
SW_SHOWMINNOACTIVE
Displays the window as a minimized window. This value is similar to SW_SHOWMINIMIZED, except the window is not activated.
SW_SHOWNA
Displays the window in its current size and position. This value is similar to SW_SHOW, except the window is not activated.
SW_SHOWNOACTIVATE
Displays a window in its most recent size and position. This value is similar to SW_SHOWNORMAL, except the window is not actived.
SW_SHOWNORMAL
Activates and displays a window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when displaying the window for the first time.
Code:
#include <windows.h> //imports HWND,FindWindow,ShowWindow #include <iostream> //imports cout and cin using namespace std; int main() { HWND hWnd_my_application; hWnd_my_application = FindWindow(NULL,"SRO_Client"); if(hWnd_my_application) { cout << "I have found your window :-) and minimized it hehenn" << endl; ShowWindow(hWnd_my_application,SW_MINIMIZE); system("pause"); } else { cout << "Sorry,I haven't found your window.Maybe it isn't opened...nn" << endl; system("pause"); } }
link :