Removing an icon from Windows headers without clicking the close button or system menu?

I am developing an MFC application, and recently I was looking for a good way to remove an icon from the Windows title bar, but retained the close button. Two obvious candidate solutions are disabling the system menu style or using the tool window style, but I would prefer not to disable the system menu or use the title bar of the shortened tool window. Many MFC applications have this functionality, so I ask myself: is there a lack of a standard way to do this?

+6
c ++ user-interface windows mfc
source share
6 answers

You can use WM_NCRBUTTONDOWN to determine if the user has right-clicked over the header, and then call up the system menu.

+2
source share

Set WS_EX_DLGMODALFRAME extended style.

+4
source share

You can use a fully transparent icon.

+2
source share

how about getting rid of the system menu and then returning it to another place yourseld (say, next to the close button, etc.)?

0
source share

Without an icon, the only way I could imagine so that users could access the system menu was by right-clicking on the title.

If you had that in mind, you can handle WM_RBUTTONDOWN on your main frame, and then calculate whether there was a right-click on the header.

 int clickX = GET_X_LPARAM(lParam); int clickY = GET_Y_LPARAM(lParam); CRect frameRect; mainFrame.GetWindowRect(&frameRect); int titleBarHeight = GetSystemMetrics(SM_CYCAPTION); if (clickX >= frameRect.left && clickX <= frameRect.right && clickY >= frameRect.top && clickY <= frameRect.top + titleBarHeight) { TrackPopupMenu(m_systemMenu); } 
0
source share

Example code in Delphi that removes an icon:

 const WM_ResetIcon = WM_APP - 1; type TForm1 = class(TForm) procedure FormShow(Sender: TObject); protected procedure WMResetIcon(var Message: TMessage); message WM_ResetIcon; end; implementation procedure TForm1.FormShow(Sender: TObject); begin PostMessage(Handle, WM_ResetIcon, 0, 0); end; procedure TForm1.WMResetIcon(var Message: TMessage); const ICON_SMALL = 0; ICON_BIG = 1; begin DestroyIcon(SendMessage(Handle, WM_SETICON, ICON_BIG, 0)); DestroyIcon(SendMessage(Handle, WM_SETICON, ICON_SMALL, 0)); end; 

Similar code should work for MFC. Basically, you just need WM_SETICON to NULL in the right place.

0
source share

All Articles