Skip to content

Commit

Permalink
Add show/hide argument flags
Browse files Browse the repository at this point in the history
  • Loading branch information
thefowlj committed Mar 3, 2024
1 parent ada409c commit 175c50c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# taskbarhider

Small C++ program to hide/show the Windows Taskbar using the Windows API. It simply toggles between showing the taskbar or not and attempts to work against multiple monitors.
An example of a small C++ program to hide/show the Windows Taskbar using the Windows API. By default it will toggle between showing and hiding the taskbar on monitors each time it is executed

Seemed to work consistently with Windows 7 and 10. Windows 11 seems to try and recover the main monitor taskbar automatically (as of testing March 2024).
To force it to try and show or hide the taskbar, execute with the `-show` or `-hide` flags.

This is likely not the best method to accomplish the task of hiding the taskbar UI elements in most production cases, but it is a simple example of how it can still be forced through the old 32-bit Windows APIs. Previously this was tested with 1-2 monitors on Windows 7 and 10. A workaround was added (March 2024) for Windows 11 as well.
40 changes: 36 additions & 4 deletions taskbarhider.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* @file taskbarhider.cpp
* @brief A program to hide or show the Windows taskbar.
*/

#include <windows.h>
#include <thread>
#include <chrono>
Expand All @@ -10,7 +15,7 @@ using namespace std;
*
* @return true if the taskbar is visible, false otherwise.
*/
boolean isTaskbarVisible() {
bool isTaskbarVisible() {
// Get a handle to the taskbar and secondary taskbar windows
HWND hwnd = FindWindow(TEXT("Shell_traywnd"), NULL);
HWND hwnd2 = FindWindow(TEXT("Shell_SecondaryTrayWnd"), NULL);
Expand All @@ -20,11 +25,11 @@ boolean isTaskbarVisible() {
}

/**
* Hides or shows the taskbar.
* @brief Hides or shows the taskbar.
*
* @param hide - A boolean value indicating whether to hide or show the taskbar.
*/
void hideTaskbar(boolean hide) {
void hideTaskbar(bool hide) {
// Get a handle to the taskbar and secondary taskbar windows
HWND hwnd = FindWindow(TEXT("Shell_traywnd"), NULL);
HWND hwnd2 = FindWindow(TEXT("Shell_SecondaryTrayWnd"), NULL);
Expand All @@ -41,12 +46,39 @@ void hideTaskbar(boolean hide) {
}
}

/**
* @brief The main function of the program.
*
* @param argc The number of command-line arguments.
* @param argv An array of command-line arguments. argv[0] is the program name, argv[1] is the first argument, and so on.
* The following command-line arguments are supported:
* - "-hide": Hides the taskbar.
* - "-show": Shows the taskbar.
* @return The exit status of the program.
*/
int main(int argc, char* argv[]) {
bool hide = false;
bool force = false;

for (int i = 1; i < argc; i++) {
if (strcmp(argv[i], "-hide") == 0) {
force = true;
hide = true;
} else if (strcmp(argv[i], "-show") == 0) {
force = true;
hide = false;
}
}

int main() {
// Get a handle to the taskbar and secondary taskbar windows
HWND hwnd = FindWindow(TEXT("Shell_traywnd"), NULL);
HWND hwnd2 = FindWindow(TEXT("Shell_SecondaryTrayWnd"), NULL);

if (force) {
hideTaskbar(hide);
return 0;
}

// If the taskbar is visible, hide it; otherwise, show it
if (isTaskbarVisible()) {
hideTaskbar(true);
Expand Down

0 comments on commit 175c50c

Please sign in to comment.