Few years back I wrote a program in C language using Windows API that displays the list of all "Windows" opened on my PC (Windows) and I can make any of them visible/invisible.
I decided to share the part of code which Enumerate windows, find a window and make them visible/invisible.
Enumerating Windows
Windows API provide a function EnumWindows which takes a pointer to Callback function which it calls for each window found. Second parameter is a LPARAM which you can use to pass any argument you want, this LPARAM will be passed to our callback function.
Here is how to use EnumWindows
Finding a Window by its Title
My app lists all the windows in a listbox showing title of each window found. To hide/unhide a window I first find its Handle using FindWindow method provided by Windows API. FindWindow function takes Classname and Title of window and return the HWND(handle) to that window or NULL on error.
Show/Hide a Window
To show/hide a window we will use ShowWindow function. It takes Handle to a window and style (SW_SHOW / SW_HIDE).
To show window
To determine if Window is already visible or not
To check if Window is already visible or not we can use IsWindowVisible function. It takes window handle as input parameter and return TRUE (non zero) if window visible otherwise FALSE (zero).
I decided to share the part of code which Enumerate windows, find a window and make them visible/invisible.
Enumerating Windows
Windows API provide a function EnumWindows which takes a pointer to Callback function which it calls for each window found. Second parameter is a LPARAM which you can use to pass any argument you want, this LPARAM will be passed to our callback function.
Here is how to use EnumWindows
BOOL isSuccess=EnumWindows(OurAppCallback,(LPARAM)userDefinedVariable);Syntax of callback (OurAppCallback) will be like this
BOOL CALLBACK OurAppCallback(HWND h,LPARAM l)Important Remarks about EnumWindows from MSDN:
The EnumWindows function does not enumerate child windows, with the exception of a few top-level windows owned by the system that have the WS_CHILD style.
Finding a Window by its Title
My app lists all the windows in a listbox showing title of each window found. To hide/unhide a window I first find its Handle using FindWindow method provided by Windows API. FindWindow function takes Classname and Title of window and return the HWND(handle) to that window or NULL on error.
HWND wHandle=FindWindow(NULL,title);
Show/Hide a Window
To show/hide a window we will use ShowWindow function. It takes Handle to a window and style (SW_SHOW / SW_HIDE).
To show window
BOOL isSuccess=ShowWindow(wHandle,SW_SHOW);To hide window
BOOL isSuccess=ShowWindow(wHandle,SW_HIDE);
To determine if Window is already visible or not
To check if Window is already visible or not we can use IsWindowVisible function. It takes window handle as input parameter and return TRUE (non zero) if window visible otherwise FALSE (zero).
Comments
Post a Comment
Share your wisdom