What’s the deal with that alternate form for menu item template separators?

We saw last time that you can specify a separator in a menu item template by specifying zero for everything, even though technically you're supposed to pass MFT_SEPARATOR for the flags. What's the deal with that alternate form for menu item template separators?

This goes back to the early days of the InsertMenu function (and its friends like AppendMenu and ModifyMenu). In the Before Time, the way you specified a separator was to add a null pointer. Not a null string (a string with no characters, consisting only of the null terminator), but an actual null pointer.

AppendMenu(hmenu, MF_STRING, 0, NULL);

The recommended way of adding a separator is, of course, to use MF_SEPARATOR, but this old-fashioned method is still supported for backward compatibility. The alternate form of the menu item template for separators is just a throwback to the days when this "old style" of adding a separator was in fact the only style.

Comments (7)
  1. Boris says:

    Raymond’s television habits appear to be correct.

  2. Otto N. T. Wickelaer says:

    Thanks for the insight in Windows history.

    I’m looking for a way to draw a bitmap on the side of a menu, like classic menu start. But although I found some source code, it used MFC. Also I didn’t see any mention of an rtl mode. Should the bitmap be drawn on the right side in rtl mode? Does anyone have any hints/clues/pointers on how to do this in plain win32/win64?

  3. JamesNT says:

    Interestingly enough, I was working on a program 2 months ago that had both the NULL pointer and that MF_SEPARATOR in use in different areas of the program.

    This comes as no surprise as I was probably the 4th or 5th person over the past 8 years hired on a contract basis to modify this program for its owner.


  4. Miral says:

    Wasn’t there something where a single minus character ("-") was also treated as a separator?  Or was that purely a resource designer translation?  Or am I just getting confused?

  5. some body says:

    IIRC the resource designer automatically sets the MF_SEPARATOR flag when you enter "-" as caption.

    There are other GUI libraries (e.g., Borland’s VCL) that do not want to bother the poor programmer with menu flags at all, and where using "-" as caption is the only way to get a separator.

  6. SRS says:

    The Wine menu code takes care of the null string ptr resulting in MF_SEPARATOR, but doesn’t do the same for "-", so (assuming Wine is an accurate re-implementation) I guess as "some body" said, either the resource editor does the mapping, or you’re using a custom menu control that does’t come from user32.

    Wine code here: http://source.winehq.org/source/dlls/user32/menu.c#L1995

  7. Bringing 16-bit classic menus into the 32-bit world.

Comments are closed.

Skip to main content