Simple code to make your C++ Builder or Delphi app use the 'standard' taskbar system menu
When you right-click on C++ Builder/Delphi application's taskbar tab, you
get a system menu that shows three items: Restore, Minimize and Close. A
standard windows app(like Notepad), displays three more: Maximize, Size and Move.
This problem happens because a C++ Builder/Delphi app has a hidden window, and
it is this hidden window that has a tab on the Taskbar.
This code snippet solves the problem by removing the tab of the hidden window
and replacing it with the tab of the main form's window.
Using the code
Insert the following code into your app's main file (where TApplication is
initialized). Specifically, insert the code snippet immediately after the main
form is created. See the code for some more comments.
//The shlobj.h file causes compile-time problems in C++ Builder 5. To
//avoid them, define NO_WIN32_LEAN_AND_MEAN in:
//Project->Options->'Directories/Conditional' tab->'Conditional defines' edit box
#include "Unit1.h" //The main form's include file (important to include!)
if(SUCCEEDED(CoCreateInstance(CLSID_TaskbarList, 0,CLSCTX_INPROC, IID_ITaskbarList, (LPVOID *)&pTaskbarList)) && pTaskbarList)
//Remove tab of hidden window pTaskbarList->DeleteTab() does not seem to work (atleast on Windows 2000),
//so we use an alternative method. A window with the WS_EX_TOOLWINDOW style does not have a taskbar tab:
SetWindowLong(Application->Handle, GWL_EXSTYLE, GetWindowLong(Application->Handle,GWL_EXSTYLE)|WS_EX_TOOLWINDOW);
//Add tab for main form instead
ITaskbarList is available on
- Windows 95 with IE 4 or greater
- Windows 98
- Windows NT 4.0 with IE 4 or greater
- Windows 2000
- Windows XP
Specifically, Version 4.71 or later of Shell32.dll is needed.
- The Taskbar tab does not remain pressed during the duration the system menu is active.