Files
NeoandClaude 904d32cbbf Win16: add OLE controls (COleControl and the control container) (#147)
Build the OLE control sources for 16-bit Windows: COleControl,
COlePropertyPage, the stock property pages, CWnd::CreateControl and
COleControlSite. Add the OLE control interfaces, IIDs and CLSIDs to the
Win16 headers. Add src/win16olepro.cpp with the OLEPRO32 functions that
16-bit Windows does not have: the stock font and picture objects, the
property frame and OleTranslateColor.

Parse and write 16-bit dialog templates in the control container and
the property pages. Use OLESTR and CStringOle for OLE strings, and
64-bit arithmetic for the HIMETRIC conversions.

16-bit Windows has no OLE DB, so data binding causes a
CNotSupportedException. Add tests/win16ctl.cpp and the docs.


Claude-Session: https://claude.ai/code/session_01B82eRV6wfb9PKGryxuRrjF

Co-authored-by: Claude <noreply@anthropic.com>
2026-11-27 06:29:07 -08:00

28 KiB

16-bit Windows

The library builds for 16-bit Windows (Windows 3.0 and later) with clang-retro's i8086-pc-win16 target and the win16-sdk sysroot. It gives the core classes and the window classes of MFC 2.5, in the large memory model, ANSI only.

What is there

The core classes:

  • CObject, CRuntimeClass, DECLARE_DYNAMIC, DECLARE_DYNCREATE and DECLARE_SERIAL
  • CString (CStringA), and CStringW for text that you convert
  • the collections of afxcoll.h and afxtempl.h
  • CFile, CStdioFile, CMemFile, CFileFind and CFileStatus
  • CArchive and serialization
  • CTime and CTimeSpan
  • the exceptions, with C++ try and catch, and with TRY and CATCH
  • the memory diagnostics: DEBUG_NEW, CMemoryState, AfxCheckMemory and AfxDumpMemoryLeaks

The window classes:

  • CWinApp, CWinThread (the main thread only) and CCmdTarget
  • message maps, ON_COMMAND, ON_UPDATE_COMMAND_UI, the ON_WM_ macros, the control notifications and message reflection
  • CWnd, CFrameWnd, CMDIFrameWnd, CMDIChildWnd, CMiniFrameWnd and CSplitterWnd
  • CDialog, dialog data exchange (DDX_ and DDV_), and the common dialogs of commdlg.dll (CFileDialog, CColorDialog, CFontDialog, CPrintDialog and CFindReplaceDialog)
  • the controls: CButton, CEdit, CStatic, CListBox, CCheckListBox, CComboBox and CScrollBar
  • CDC, CPaintDC, CClientDC, CWindowDC, CMetaFileDC, the GDI objects and CMenu
  • document/view: CDocument, CView, CScrollView, CFormView, CEditView, CSingleDocTemplate, CMultiDocTemplate, printing and print preview
  • the profile functions of CWinApp, with the INI file of the program
  • CToolBar, CStatusBar and CDialogBar, with docking, floating and the idle update of the buttons and panes
  • all the common controls of afxcmn.h, and CReBar. 16-bit Windows does not have comctl32.dll, so the library draws them itself (see "The other common controls")

OLE automation (afxdisp.h):

  • dispatch maps (DISP_PROPERTY, DISP_FUNCTION and the others), and the IDispatch of a CCmdTarget (EnableAutomation and GetIDispatch)
  • interface maps, connection maps and connection points, and event sink maps
  • COleDispatchDriver, COleVariant, COleDateTime, COleCurrency and COleSafeArray
  • type libraries: AfxOleRegisterTypeLib and AfxOleUnregisterTypeLib

Strings in OLE 2 for 16-bit Windows are ANSI. A BSTR and an OLECHAR are char. CStringOle is CStringA on 16-bit Windows and CStringW on the other targets. Use it and OLESTR for OLE strings in code for both.

16-bit OLE 2 does not have the OLE control interfaces (connection points, IProvideClassInfo, IClassFactory2, IOleControl, IPropertyPage and the others). include/win16/ocidl.h declares them with the IIDs of Win32. MFC objects use them between each other in one program.

16-bit TYPELIB has no UnRegisterTypeLib. On 16-bit Windows, MFC deletes the registry key of the version (src/win16ole.cpp).

OLE controls (afxctl.h and afxocc.h):

  • controls: COleControl, with the stock properties, methods and events, the verbs, property exchange (PX_ functions), the persistence interfaces and the licence functions (AfxVerifyLicFile)
  • property pages: COlePropertyPage, the DDP_ functions, and the stock pages for fonts, colours and pictures
  • containers: AfxEnableControlContainer, CWnd::CreateControl, COleControlSite and controls in dialog templates (RT_DLGINIT)
  • CFontHolder and CPictureHolder

16-bit Windows has no OLEPRO32.DLL. src/win16olepro.cpp has its functions:

  • OleCreateFontIndirect: a font object with IFont, IFontDisp, IPersistStream and the property notifications
  • OleCreatePictureIndirect and OleLoadPicture: a picture object for bitmaps, icons and metafiles, with IPicture, IPictureDisp and IPersistStream. The stream format is the format of Win32.
  • OleCreatePropertyFrame and OleCreatePropertyFrameIndirect: a dialog with a tab for each page, and OK, Cancel and Apply
  • OleTranslateColor

These limits apply:

  • Controls are in the program (EXE) that uses them. The library does not build 16-bit DLLs, thus there are no .ocx files.
  • There is no data binding. 16-bit Windows has no OLE DB. CWnd::BindDefaultProperty and CWnd::BindProperty cause a CNotSupportedException.
  • A 16-bit dialog template has no extended styles. The property pages and the stock pages use 16-bit templates in "MS Sans Serif".
  • int and UINT properties are VT_I2 and VT_UI2.

Wine's 16-bit OLE2DISP does not have VariantClear, VariantCopy and VariantChangeType. Thus the Wine test does not call IDispatch::Invoke. It checks the names, the dispatch interface and the connection points (tests/win16auto.cpp).

OLE documents (afxole.h):

  • containers: COleDocument, COleClientItem, COleLinkingDoc, in-place activation of items, and CRectTracker
  • servers: COleServerDoc, COleServerItem, COleIPFrameWnd, COleResizeBar, COleTemplateServer, COleObjectFactory and the registry functions
  • data transfer: COleDataSource, COleDataObject, the clipboard, COleDropSource, COleDropTarget and the drag and drop of CView
  • compound files: COleStreamFile and the storage of COleDocument
  • COleMessageFilter, the monikers of CMonikerFile, and document objects (CDocObjectServer)

16-bit OLE 2 has no OLE dialog DLL. The OLE 2 SDK gave the dialogs as sample source (OLE2UI). src/win16oleui.cpp has these functions:

  • the verb menu of an item (OleUIAddVerbMenu) and the update of links (OleUIUpdateLinks)
  • Insert Object (OleUIInsertObject). The list has the classes that have an Insertable key in the registration database. The dialog makes the object with OleCreate, OleCreateFromFile or OleCreateLinkToFile when the flags tell it to.
  • Paste Special (OleUIPasteSpecial). The list has the formats of the caller that the data object has. Without a data object, the dialog uses the data on the clipboard.
  • Links (OleUIEditLinks): Update Now, Open Source and Break Link.
  • Server Busy (OleUIBusy): Switch To, Retry and Cancel. Switch To activates the first visible window of the busy task.

The dialogs are templates in memory. They do not use the template or the resource of the caller. They call the hook of the caller for each message. These dialogs are not there: Change Icon, Convert, Change Source and Object Properties. Their DoModal gives IDABORT. "Display As Icon" sets the flag, but the dialogs do not make an icon picture (hMetaPict). The Server Busy dialog does not close itself when the call is no longer blocked.

16-bit Windows has no enhanced metafiles. TYMED_ENHMF is 0, and CF_ENHMETAFILE is a format that no 16-bit program gives.

Wine's 16-bit OLE2.DLL is mostly stubs. Thus the Wine test of the OLE document classes is a link check: tests/win16oledoc.cpp makes containers, servers, drop targets and in-place frames in a function that does not run. The part that runs caches data in a COleDataSource and finds its format with COleDataObject. The OLE dialogs run with a hook that closes them. These classes need a real 16-bit Windows with OLE 2 to run.

The Wine test of the OLE controls is a link check too: tests/win16ctl.cpp makes a control and a property page, hosts the control with CWnd::CreateControl and shows its property frame in a function that does not run. The part that runs makes fonts and pictures, saves and loads them through a stream, and calls OleTranslateColor.

What is not there

  • OLE control DLLs (.ocx) and data binding of controls (see "OLE controls").
  • The Change Icon, Convert, Change Source and Object Properties dialogs (see "OLE documents").
  • CWnd::EnableToolTips. It does nothing on any target of the library. Use a CToolTipCtrl (see "The other common controls").
  • The shell file dialog (IFileDialog). CFileDialog always shows the classic dialog.
  • Threads. CWinThread::CreateThread fails with ERROR_NOT_SUPPORTED.
  • The medium and small models, and Unicode.

Build the library

make TARGET=i8086-pc-win16 BIN=/path/to/llvm/bin SYSROOT=/path/to/sysroot static

The library is build/i8086-pc-win16/libmfc.a. WIN16_FLAGS gives the flags of the model. The default is -mcmodel=large -fexceptions.

make install TARGET=i8086-pc-win16 copies the headers to include/mfc, include/mfc/win16 and include/mfc/winport of the sysroot, and the library to lib.

Build a program

Use these flags:

clang++ --target=i8086-pc-win16 -mcmodel=large -fexceptions -frtti \
  --sysroot=/path/to/sysroot \
  -Ipath/to/mfc/include -Ipath/to/mfc/include/win16 \
  -idirafter path/to/mfc/port/include \
  app.cpp app.res -Lpath/to/mfc/build/i8086-pc-win16 -lmfc -o app.exe
  • include/win16 must come before the other MFC headers. Its OLE headers send the OLE names to the OLE 2 headers of the 16-bit SDK.
  • -idirafter port/include must come last. The SDK has no common control headers. The headers of the portable layer give their types.
  • The guard of a function-local static object calls __atomic_load_1. The compiler-rt builtins of the sysroot have this function (compiler-rt/lib/builtins/i8086/atomic.c). A sysroot that does not have it is too old: build its builtins again. A task has one thread, so -fno-threadsafe-statics is safe, and it makes the program smaller.
  • Compile the resources with llvm-rc -win16.

A program with main() and the core classes only can use -mquickwin, which shows its standard output and input in a window.

How it works

  • afx.h sets _AFX_WIN16 and STRICT, and includes afxwin16.h. That header gives the Win32 types and the KERNEL32 functions that the core classes call. src/win16.cpp does those functions.
  • afxwin.h includes afxwin16u.h. That header gives the Win32 USER, GDI and KERNEL types, values and functions that the window classes use. src/win16u.cpp does those functions. Each function does its work with the nearest 16-bit function (SetBrushOrg for SetBrushOrgEx, TrackPopupMenu for TrackPopupMenuEx), or fails as Win32 fails when the system cannot do the call (paths, world transforms, enhanced metafiles).
  • INT_PTR, UINT_PTR and WPARAM are 16 bits. DWORD_PTR, LONG_PTR and LPARAM are 32 bits and hold a far pointer.
  • The functions of the library (AFXAPI) use the pascal calling convention, as in MFC 2.5.

Messages

16-bit Windows packs some messages in a different way from Win32, because WPARAM has 16 bits. The library reads each one in the 16-bit way:

Message 16-bit packing
WM_COMMAND ID in wParam; control in the low word and code in the high word of lParam
WM_ACTIVATE state in wParam; window in the low word and minimized flag in the high word of lParam
WM_HSCROLL, WM_VSCROLL code in wParam; position in the low word and scroll bar in the high word of lParam
WM_MENUSELECT, WM_MENUCHAR item or character in wParam; flags in the low word and menu in the high word of lParam
WM_VKEYTOITEM, WM_CHARTOITEM key in wParam; list box in the low word and caret in the high word of lParam
WM_MDIACTIVATE activation flag in wParam; activated window in the low word and deactivated window in the high word of lParam
WM_CTLCOLOR one message; control in the low word and CTLCOLOR_ code in the high word of lParam
  • tools/gen-msgmap.py writes a 16-bit form of each ON_WM_ macro for these messages (include/afxmsg_wm_.h).
  • CWnd::OnCommand and the notification reflection use GET_WM_COMMAND_ID, GET_WM_COMMAND_HWND and GET_WM_COMMAND_CMD. To send a notification, use GET_WM_COMMAND_MPS. afxwin.h defines these macros for each target.
  • CWnd::OnWndMsg changes WM_CTLCOLOR to the Win32 message of its CTLCOLOR_ code. Thus ON_WM_CTLCOLOR and ON_WM_CTLCOLOR_REFLECT work as on Win32. Default() sends the message that came.
  • CMDIFrameWnd sends WM_MDISETMENU with both menus in lParam, and reads WM_MDIGETACTIVE from the two words of the result. In place of WM_MDIREFRESHMENU, it sends WM_MDISETMENU with wParam TRUE.

Dialog templates

CAfxDlgTemplate (src/dlgtmpl.cpp) writes the 16-bit template form. The header has a byte for the item count. The strings are ANSI. The class of each item is one byte. There is no alignment. DialogBoxIndirect needs the template in a global memory block. The library copies the template into one.

The registry

16-bit Windows has one registry tree, HKEY_CLASSES_ROOT. Each key has one value, the value without a name.

  • RegOpenKeyEx, RegCreateKeyEx, RegQueryValueEx and RegSetValueEx use the 16-bit calls of shell.dll for that tree and for string values.
  • A call for another tree, or for a value with a name, fails with ERROR_BADKEY. This value is the same as ERROR_FILE_NOT_FOUND of Win32.
  • Thus a program that calls SetRegistryKey keeps its settings in its INI file. The document types that RegisterShellFileTypes records go to the registry.

The task

A 16-bit task has one thread.

  • GetCurrentThreadId gives the task handle.
  • PostThreadMessage uses PostAppMessage.
  • GetCommandLine gives the path of the program and the command tail of its program segment prefix.
  • Events, mutexes and semaphores are objects of the task. A wait for an object that is not signaled cannot end, because no other thread can signal it. The wait gives WAIT_TIMEOUT when the time is up. An INFINITE wait fails with ERROR_POSSIBLE_DEADLOCK. MsgWaitForMultipleObjects also ends when a message comes.

The toolbar and the status bar

src/win16bar.cpp registers two window classes, AfxToolbar16 and AfxStatusBar16, and the class of the toolbar's tooltips. afxwin16u.h sets TOOLBARCLASSNAME and STATUSCLASSNAME to these names. Wine can also have the 32-bit classes of comctl32.dll, which do not read the 16-bit structures. Thus the names are not the names of the common controls.

  • The windows do the messages that CToolBar and CStatusBar send (TB_ADDBUTTONS, TB_SETSTATE, TB_GETITEMRECT, SB_SETPARTS, SB_SETTEXT, SB_GETRECT and others). Other messages go to DefWindowProc.
  • A toolbar button has a raised edge. A pressed or checked button has a sunken edge, and a checked button has a dithered face. A disabled button shows its image in the highlight and shadow colors. With TBSTYLE_FLAT, only a pressed or checked button has an edge.
  • A click sends WM_COMMAND with BN_CLICKED to the owner of the toolbar, in the 16-bit packing.
  • The toolbar keeps the text of a button (SetButtonText), but it does not draw it.
  • 16-bit Windows has no tooltip control of its own. A toolbar with CBRS_TOOLTIPS (TBSTYLE_TOOLTIPS) shows the tip of a button itself. When the mouse stays on a button for half a second, the toolbar sends TTN_NEEDTEXTA to its owner, and shows the text below the mouse in a window of the class AfxW16ToolTip. CFrameWnd gives the part of the command's string after the newline. A timer finds when the mouse leaves the button, because 16-bit Windows does not tell the window. CBRS_FLYBY also works: the status bar shows the prompt of the button.
  • A status bar pane has a sunken edge, a raised edge (SBPS_POPOUT) or no edge (SBPS_NOBORDERS). An owner-drawn pane sends WM_DRAWITEM to the parent.
  • A press on the size grip of the status bar sizes the frame from its lower-right corner.
  • A UINT has 16 bits. Thus a button style of CToolBar has the TBSTYLE_ bits in its low byte and the TBSTATE_ bits in its high byte, as in MFC 2.5. SBPS_DISABLED is 0x4000, and SBPS_STRETCH is 0x8000.

The other common controls

src/win16ctl.cpp, src/win16lv.cpp, src/win16tv.cpp, src/win16tt.cpp, src/win16misc.cpp, src/win16cbex.cpp, src/win16date.cpp, src/win16rebar.cpp and src/win16anim.cpp register seventeen more window classes. afxwin16u.h sets the class names to the names of the library, as for the toolbar:

Class Name MFC class
progress bar AfxProgress16 CProgressCtrl
trackbar AfxTrackbar16 CSliderCtrl
up-down control AfxUpDown16 CSpinButtonCtrl
tab control AfxTabControl16 CTabCtrl
header control AfxHeader16 CHeaderCtrl
list view AfxListView16 CListCtrl
tree view AfxTreeView16 CTreeCtrl
tooltip AfxToolTip16 CToolTipCtrl
hot key AfxHotKey16 CHotKeyCtrl
IP address AfxIPAddress16 CIPAddressCtrl
pager AfxPager16 CPagerCtrl
link SysLink CLinkCtrl
extended combo box AfxComboBoxEx16 CComboBoxEx
month calendar AfxMonthCal16 CMonthCalCtrl
date and time picker AfxDateTime16 CDateTimeCtrl
rebar AfxReBar16 CReBarCtrl, CReBar
animation AfxAnimate16 CAnimateCtrl

The files also register each class with the name of comctl32.dll (msctls_progress32, msctls_trackbar32, msctls_updown32, SysTabControl32, SysHeader32, SysListView32, SysTreeView32, tooltips_class32, msctls_hotkey32, SysIPAddress32, SysPager ComboBoxEx32, SysMonthCal32, SysDateTimePick32, ReBarWindow32 and SysAnimate32). CLinkCtrl always uses the name SysLink. Thus a dialog template can use these names.

  • The windows do the messages of the common controls in ANSI. They send WM_HSCROLL and WM_VSCROLL in the 16-bit packing: the code in wParam, the position in the low word and the control in the high word of lParam. They send WM_NOTIFY to the parent.
  • The progress bar draws blocks, or one bar with PBS_SMOOTH. PBS_VERTICAL and PBS_MARQUEE work.
  • The trackbar has the keys, a drag of the thumb, and a click in the channel that pages and repeats. It draws the ticks (TBS_AUTOTICKS, TBM_SETTIC), the selection (TBS_ENABLESELRANGE) and a thumb that points to the ticks. It has no buddy windows and no tooltips.
  • The up-down control has the acceleration (UDM_SETACCEL), the buddy (UDS_AUTOBUDDY, UDS_ALIGNRIGHT, UDS_ALIGNLEFT), the number in the buddy (UDS_SETBUDDYINT, with a comma between each 3 digits) and the arrow keys of the buddy (UDS_ARROWKEYS). The default range is 100 to 0, as in comctl32.dll.
  • The tab control has one row of tabs, a click and the left and right keys (TCN_SELCHANGING, TCN_SELCHANGE), TCS_BUTTONS and TCS_FIXEDWIDTH. It has no images, no tooltips and no TCS_MULTILINE.
  • The header control has the drag of a divider (HDN_BEGINTRACK, HDN_TRACK, HDN_ENDTRACK), the click of a button (HDS_BUTTONS), HDM_LAYOUT, the order of the items, the sort arrows, owner draw and an image list. It has no filters and no drag of an item.
  • The list view has the four views, virtual lists (LVS_OWNERDATA), the text and image callbacks (LVN_GETDISPINFO), label editing, check boxes, full row selection, grid lines, custom draw, sorting (LVM_SORTITEMS, LVM_SORTITEMSEX), LVM_FINDITEM, and the keys and the mouse of comctl32.dll. The report view uses a header control. The icon views always arrange the items in rows. The list view has no groups, no tiles, no work areas and no tooltips.
  • The tree view has the lines, the buttons, the check boxes (TVS_CHECKBOXES), the normal and state image lists, the text, image and children callbacks (TVN_GETDISPINFO), label editing, custom draw, sorting (TVM_SORTCHILDREN, TVM_SORTCHILDRENCB), the drop highlight, the insert mark, TVN_BEGINDRAG, the incremental search, and the keys and the mouse of comctl32.dll. It has no tooltips and no hot tracking (TVS_TRACKSELECT).
  • The tooltip has window tools (TTF_IDISHWND) and rectangle tools, TTM_RELAYEVENT and TTF_SUBCLASS, the text callback (TTN_GETDISPINFO), string resources, TTN_SHOW and TTN_POP, tracking tips (TTF_TRACK), TTF_CENTERTIP, a title, the delay times, the colors, the margins and word wrap (TTM_SETMAXTIPWIDTH). 16-bit Windows has no WM_MOUSELEAVE, so a timer finds the mouse when it leaves a tool. There are no balloon tips. A 16-bit wParam cannot hold a COLORREF, so TTM_SETTIPBKCOLOR and TTM_SETTIPTEXTCOLOR take the color from lParam when lParam is not 0.
  • The hot key control shows the modifiers and the name of the key (GetKeyNameText), and sends EN_CHANGE. HKM_SETRULES works. Backspace, Delete, Esc and Space with no modifier clear the key.
  • The IP address control has four edit controls. Three digits, a dot or a space go to the next field, and the arrow keys and Backspace cross the fields. A field that loses the focus sends IPN_FIELDCHANGED and goes into its range (IPM_SETRANGE).
  • The pager asks the parent for the size of the child (PGN_CALCSIZE). Its buttons show only when the child can scroll in that direction. A pressed button repeats PGN_SCROLL. The notifications of the child go to the parent of the pager.
  • The link control reads the <a href="..." id="..."> markup, breaks the lines at spaces, and sends NM_CLICK (or NM_RETURN with LWS_IGNORERETURN) with an NMLINK. The links are blue, and purple when visited. The IDs and URLs of an LITEM are Unicode: the window changes each character to one byte. 16-bit Windows has no hand cursor, so the cursor stays an arrow.
  • The extended combo box holds an owner-drawn combo box and draws the indent, the image and the text of each item. It sends CBEN_INSERTITEM, CBEN_DELETEITEM, CBEN_GETDISPINFO, CBEN_BEGINEDIT and CBEN_ENDEDIT, and gives the CB_ messages to the combo box. The edit control of CBS_DROPDOWN shows no image.
  • The month calendar shows as many months as its size holds. It has the arrows and the scroll of the months (MCM_SETMONTHDELTA), the keys, a drag of the selection (MCS_MULTISELECT), the range, today (MCS_NOTODAY, MCS_NOTODAYCIRCLE), the week numbers (MCS_WEEKNUMBERS), the bold days (MCS_DAYSTATE, MCN_GETDAYSTATE) and the colors. It sends MCN_SELCHANGE and MCN_SELECT. A click on the month or the year in the title does not open a menu.
  • The date and time picker reads its formats from the [intl] section of WIN.INI (sShortDate, sLongDate, sTime, iTime, iTLZero, s1159 and s2359). DTM_SETFORMAT sets a custom format, with the callback fields (DTN_FORMAT, DTN_FORMATQUERY and DTN_WMKEYDOWN). It has the keys, typed digits, the up-down button (DTS_UPDOWN), the drop-down calendar, the check box (DTS_SHOWNONE) and the edit control of DTS_APPCANPARSE (DTN_USERSTRING). It sends DTN_DATETIMECHANGE, DTN_DROPDOWN and DTN_CLOSEUP. WM_GETTEXT gives the text that the picker shows.
  • The rebar puts its bands in rows. A band starts a new row with RBBS_BREAK, or when the row does not have the space for it. The last band of a row gets the space that is left. A band has a gripper, an image from the image list of RB_SETBARINFO, a text, a background bitmap or color, and a chevron (RBBS_USECHEVRON, RBN_CHEVRONPUSHED). The user drags a gripper to change the width of a band or to move it to another row (RBN_BEGINDRAG, RBN_ENDDRAG, RBN_LAYOUTCHANGED). A click on a gripper, or a double-click with RBS_DBLCLKTOGGLE, makes the band as large or as small as it can be. The rebar sends RBN_HEIGHTCHANGE, RBN_CHILDSIZE, RBN_DELETINGBAND, RBN_DELETEDBAND and RBN_AUTOSIZE, and gives the notifications and commands of the child windows to its parent. CCS_VERT works. The rebar shows no tooltips: RB_SETTOOLTIPS only keeps the window. It has no drop target (RBS_REGISTERDROP) and no custom draw.
  • The animation control plays the first video stream of an AVI clip from an AVI resource or from a file. The frames are uncompressed (1, 4, 8 or 24 bits) or BI_RLE8. The control reads each frame from the file when it shows it, so a clip can be larger than 64 KB, but one frame must fit in a segment. 16-bit Windows has no threads, so a timer moves the clip on, as ACS_TIMER does. ACS_CENTER, ACS_AUTOPLAY and ACS_TRANSPARENT (for frames of 8 bits or less) work. The parent gets ACN_START and ACN_STOP in WM_COMMAND.
  • The MCHT_ hit-test codes of comctl32.dll use the high word, but the uHit of MCHITTESTINFO is a 16-bit UINT. Thus afxwin16u.h moves MCHT_TITLE, MCHT_CALENDAR and MCHT_TODAYLINK to 0x1000, 0x2000 and 0x3000, and MCHT_NEXT and MCHT_PREV to 0x0100 and 0x0200. Code that uses the names of the codes works.
  • The CB_ messages of 16-bit Windows are WM_USER + 0 to WM_USER + 24: the numbers of the CBEM_ messages of comctl32.dll. Thus afxwin16u.h moves the CBEM_ messages to WM_USER + 0x101 and above. CBEM_DELETEITEM stays CB_DELETESTRING. Code that sends a CBEM_ message by its number, not by its name, does not work.
  • The toolbar does not use this tooltip. It shows its own tips (see "The toolbar and the status bar").
  • An HTREEITEM has 16 bits. TVI_ROOT, TVI_FIRST, TVI_LAST and TVI_SORT become 0, 1, 2 and 3, so the handles of the items start at 4.
  • LVM_SORTITEMS gives lParamSort in wParam. A 16-bit wParam holds only 16 bits, so the comparison function gets only the low word.
  • UDM_GETRANGE32 gets two pointers. A 16-bit wParam holds only an offset, so the window uses the segment of lParam for it.

Handle maps

A 16-bit handle is a near pointer. The handle maps of the library use the handle as a word key (CMapWordToPtr).

Differences from Win32

  • FormatMessage takes the message from a string only (FORMAT_MESSAGE_FROM_STRING). 16-bit Windows has no message tables.
  • DOS keeps only the time of the last write of a file. GetFileTime gives that time for all three times.
  • LockFile and UnlockFile do nothing.
  • GetTimeZoneInformation gives the bias from the TZ variable, without daylight saving dates.
  • CFile and CArchive count in 16-bit values where MFC 2.5 did. An archive holds at most 65,535 objects and classes.
  • CBitmap::LoadMappedBitmap and CToolBar::LoadBitmap do not change the colors of the bitmap to the system colors.
  • LoadImage loads a bitmap, an icon or a cursor from the resources only. It does not load from a file.
  • CPrintDialogEx and CPageSetupDialog are not there.
  • A scroll bar has no page size. GetScrollInfo gives nPage 0.
  • ExtCreatePen makes a cosmetic pen of one color only.
  • IDC_SIZEALL is IDC_SIZE, and DEFAULT_GUI_FONT is ANSI_VAR_FONT.

Test

make check TARGET=i8086-pc-win16 BIN=... SYSROOT=... runs tests/run-win16-tests.sh. The script builds these tests at -O0, -Os and -O2 and runs them in Wine:

Test What it does
core the core classes
memtest the memory diagnostics
win16wnd CWinApp, CFrameWnd, a menu command, a button notification, WM_CTLCOLOR, a modal CDialog with DDX, and the INI profile
win16doc CSingleDocTemplate, File New, OnDraw, OnUpdate, and the command routing to the view and the document
win16mdi CMultiDocTemplate, two MDI children, the MDI menus, and MDIGetActive, MDINext and MDIActivate
win16bar CToolBar and CStatusBar: the button layout, a click, the idle update, the message pane, docking at the left edge, floating, the tooltip of a button, and ShowControlBar
win16cmn CImageList, CProgressCtrl, CSliderCtrl, CSpinButtonCtrl, CTabCtrl, CListCtrl, CTreeCtrl, CToolTipCtrl, CHotKeyCtrl, CIPAddressCtrl, CPagerCtrl, CLinkCtrl, CComboBoxEx, CMonthCalCtrl, CDateTimeCtrl, CReBarCtrl, CReBar and CAnimateCtrl: the images and masks, the ranges and positions, the keys, the buddy of the up-down control, a click on a tab, the columns, items, find and sort of a report view, the links, expansion, selection and sort of a tree, the tools, text, hit test, show and pop of a tooltip, a hot key and its rules, the fields and ranges of an IP address, the buttons and position of a pager, the links of a link control, the items of an extended combo box, the selection, today, range and hit test of a month calendar, the format, keys, range and check box of a date and time picker, the bands, rows, hit test, drag and smallest width of a rebar, a CReBar in the frame, the frames of an RLE8 clip, play and stop of an animation, and the notifications

The window tests need an X display. Without one, the script starts itself under xvfb-run.

Wine puts a 16-bit MDI child that has the position CW_USEDEFAULT outside the client area. The MDI test thus gives its children a position.