It’s been a while that I actually coded something in this particular Visual Studio project of mine (“Virus Total Download Checker”), but once I got into it again, I was hooked.
For a start, here’s a quick summary of my somewhere between half-finished and complete application:
- Runs on Windows
- Run in the background and only interact with the user when necessary
- Hide from ALT-TAB when running in the tray
- Configure a download folder where all your downloads from your browser(s) end up
- Set up a FileSystemWatcher to monitor that folder
- Whenever a new file is downloaded, send this to the VirusTotal API
- Display a warning in the Windows Notifications when there are antivirus tools that indicate malicious software in your download
So basically, this all works more or less (there are some glitches…), but what didn’t work were the maximize and minimize buttons on the form itself (which is shown when you double-click the tray icon):
Despite the internet I couldn’t find out why the two buttons weren’t shown, and the usual suggestions like
- Set the correct FormBorderStyle
- Make sure that MaximizeBox/MinimizeBox are set to True
didn’t apply to me, as they were set to the correct values:
So after some more digging and going through the code, I finally found out why the buttons didn’t show up:
In my former attempts (see above, I hadn’t been working on the code for a while) I somehow seem to have had the idea of overriding CreateParams and setting the Params.ExStyle to 0x80 (WS_EX_TOOLWINDOW). This is documented as follows:
The window is intended to be used as a floating toolbar. A tool window has a title bar that is shorter than a normal title bar, and the window title is drawn using a smaller font. A tool window does not appear in the taskbar or in the dialog that appears when the user presses ALT+TAB. If a tool window has a system menu, its icon is not displayed on the title bar. However, you can display the system menu by right-clicking or by typing ALT+SPACE.
So I must have read what I wanted to read back then and the window also didn’t show up during ALT-TAB when running minimised in the tray. But if I’d read to the end I would also have seen that this hides the buttons I was missing.
So after removing this code and just setting the ShowInTaskbar property to false, the form behaves as expected. To support others that might run into the same issue, I also posted an answer on stackoverflow.com. Happy coding!