I am interested in making my own Hide to Tray program that will hide any program i choose to the tray. I already know how I'm going to do it.. all i need is to know how to hide another window.

In Visual C++ you do this->Visible = false; telling the main form's window to not be visible. I want to be able to do this to another window on your screen.

Any ideas?

Dani AI

Generated

As noted, hiding a window in your own VC++ form with a Visible property only affects windows you own. To hide arbitrary windows you need to work with the Win32 API: locate the target window handle (HWND) and hide or show it with the system calls. Use [FindWindow]/[EnumWindows] to get an HWND (or match windows to a PID with [GetWindowThreadProcessId]) and call [ShowWindow] with SW_HIDE / SW_SHOW. Add a tray icon for restore using [Shell_NotifyIcon].

A minimal workflow and example (your app must run a message loop to handle tray clicks):

HWND hTarget = FindWindow(NULL, L"Target Window Title");
if (hTarget)
{
    ShowWindow(hTarget, SW_HIDE);

    NOTIFYICONDATAW nid = {};
    nid.cbSize = sizeof(nid);
    nid.hWnd = hMyWindow;           // your window to receive clicks
    nid.uID = 1;
    nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
    nid.uCallbackMessage = WM_APP + 1;
    nid.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON));
    wcscpy_s(nid.szTip, L"Hidden: Target Window");
    Shell_NotifyIconW(NIM_ADD, &nid);

    // To restore later: Shell_NotifyIconW(NIM_DELETE,&nid); ShowWindow(hTarget, SW_SHOW);
}

Notes and cautions: s suggestion of process.h is not the right tool—use the Win32 API. Some applications (elevated processes, services, or apps that manage their own visibility) may resist being hidden or will re-show themselves; in those cases you may need elevated privileges or a different approach. Changing another process window style or injecting code can break behavior and is risky. See the API docs for details: ShowWindow, EnumWindows, Shell_NotifyIcon.

Recommended Answers

All 2 Replies

You can use the functions in process.h try taking a look at them

Couldn't Find much there :/

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.