Microsoft KB Archive/249291

= The shell taskbar displays a blank button with no icon and no text in Visual C++ when you create and run an MFC dialog box-based application with no title bar =

Article ID: 249291

Article Last Modified on 4/28/2005

-

APPLIES TO


 * Microsoft Visual C++ 5.0 Enterprise Edition
 * Microsoft Visual C++ 6.0 Enterprise Edition
 * Microsoft Visual C++ 5.0 Professional Edition
 * Microsoft Visual C++ 6.0 Professional Edition
 * Microsoft Visual C++ 6.0 Standard Edition

-



This article was previously published under Q249291



SYMPTOMS
It is possible to create an MFC dialog box-based application with no title bar by turning off the dialog box's standard Title bar style. However, when the application runs, the shell taskbar displays a blank button with no icon and no text, even though the icon resource exists.



CAUSE
For the shell's taskbar to display an icon, the dialog template needs the System menu style WS_SYSMENU. The resource editor automatically disables that style and others if the Title bar style is not turned on.



RESOLUTION
Manually add the WS_SYSMENU style by editing the resource as text. If you will be editing any resources afterwards, you will also need to move the dialog resource to the res\ .rc2 file. This prevents the resource editor from overwriting your change, but it also prevents you from being able to edit the dialog box with the resource editor.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



MORE INFORMATION
For some applications, a dialog box functions conveniently as a main window. Visual C++ provides a dialog-based option in the MFC AppWizard (exe) for that purpose. If you want a main dialog window without a standard title bar in such an application, you must edit the dialog properties in ResourceView. To do this, follow these steps in your open project:
 * 1) From the File menu, select New. Select the MFC AppWizard (exe). Name it NoTitle and click OK.
 * 2) In Step 1 of the AppWizard, select Dialog-based. Click Finish, then click OK on the confirmation dialog box.
 * 3) In ResourceView, expand the Dialog resources. Double-click IDD_NOTITLE_DIALOG.
 * 4) Right-click an unused area of the dialog box, and select Properties.
 * 5) In the Properties editor, click the Styles tab, and clear the Title bar check box.

If you build and run the project at this point, you will notice that the button that the shell normally displays in the taskbar for your running application is completely blank. There is no icon, and there is no text.

If you go back to the Properties editor for the main dialog box at this point, you will notice that various items in the Styles tab are disabled. One of those items is the System menu check box. That check box controls adding the WS_SYSMENU style to the dialog resource. The dialog needs this style in order for the application icon to appear in the taskbar.

For more information on how to display an icon in the title bar, click the following article number to view the article in the Microsoft Knowledge Base:

179582 How To Set the Title Bar Icon in a Dialog Box

Though the resource editor prevents adding the WS_SYSMENU style to a dialog box with no title, the combination is possible. You can manually edit the .rc file to put the WS_SYSMENU style in and verify that it causes an icon to appear in the taskbar button:  In the open project created earlier, from the File menu, select Open. In the Open as dropdown list, select Text. Type NoTitle.rc in the File name edit box, then click Open. If the ResourceView is open for the project, you will see a warning dialog box that the resource editor will be closed. Click OK to allow that. Move down to the Dialog section of the .rc file. Locate the IDD_NOTITLE_DIALOG DIALOGEX resource.  On the line labeled STYLE following the dialog name, append: | WS_SYSMENU </li> Now, select the lines defining the dialog resource, starting with the resource name down to and including the END tag. Using the standard editor, select by dragging the mouse over those lines.</li> From the Edit menu, select Cut. The selected resource disappears.</li> Open the NoTitle.rc2 resource file. On the workspace pane, click the FileView tab. Expand the project's Resource Files folder, and double-click the NoTitle.rc2 file.</li> Position the cursor at the end of any text in the NoTitle.rc2 file (or at another convenient location), then from the Edit menu, click Paste. The dialog resource has now been transferred to the manually edited resource file.</li> Press CTRL+F5 to build and run the project. Note that an icon now appears on the taskbar button associated with your application.</li></ol>

Clearing the Title bar check box also disables the Caption field in the dialog resource General properties. If you add a CAPTION entry in the resource with or without a WS_CAPTION style, you will get a title bar anyway. To display text in the taskbar button, you must call SetWindowText in the OnCreate handler or some other appropriate place: <ol> From the View menu, select ClassWizard.</li> On the Message Maps tab, select the main dialog class from the Class name drop down list.</li> In the Messages list, double-click the WM_CREATE message. Click the Edit code button.</li>  Under the TODO line, just before the return from the function, add: SetWindowText("MyTitle"); </li> Press CTRL+F5 to build and run the project. Notice that the application has no title bar, but an icon and the text you entered in the SetWindowText call appear on the taskbar button.</li></ol>

Keywords: kbbug kbide KB249291

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.