Files
NeoandClaude Opus 5.5 114257cce2 Classic look of the portable controls; Win16 OLE dialogs and all the common controls (#141)
* port: finish the classic look of the controls

- Scroll bars: the trough is the checker of the face and highlight
  colors, as DefWindowProc gives it for WM_CTLCOLORSCROLLBAR. A scroll
  bar control asks its parent for the brush. Disabled arrows are
  embossed, and a scroll bar control made with WS_DISABLED draws as
  disabled from the start.
- List boxes: a scroll bar that SetScrollInfo hid shows again when the
  items no longer fit. Before, a list box made empty lost WS_VSCROLL
  and never got its bar back.
- Trackbars: without TBS_BOTH, the thumb has a point toward the ticks.
  A thumb that is dragged or disabled has the checker face.
- Tabs: the two outer corners of each tab are cut.

wintest checks the trough, the list box's bar and the thumb's point.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B82eRV6wfb9PKGryxuRrjF

* urlmon.h: define __WINPORT_EXTERN_C for the 16-bit build

The 16-bit build takes the OLE headers of the win16-sdk, which do not
include the windef.h of the portable layer. Since urlmon.h became C
compatible, afxole.h did not compile for i8086-pc-win16. The library and
the 16-bit tests build again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B82eRV6wfb9PKGryxuRrjF

* win16: show the tooltips of the toolbar

16-bit Windows has no tooltip control, so a toolbar with CBRS_TOOLTIPS
showed no tooltip. The 16-bit toolbar window now shows them itself:
when the mouse stays on a button for half a second, it sends
TTN_NEEDTEXTA to its owner and shows the text below the mouse in a
small window. A timer finds when the mouse leaves the button. win16bar
checks the tip of a button.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B82eRV6wfb9PKGryxuRrjF

* win16: the Insert Object, Paste Special, Links and Server Busy dialogs

16-bit OLE 2 has no OLE dialog DLL. The dialogs are now templates in
memory in src/win16oleui.cpp, with the same rules as the dialogs of the
portable layer. Change Icon, Convert, Change Source and Object
Properties still fail. tests/win16oledoc.cpp runs each dialog with a
hook that closes it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B82eRV6wfb9PKGryxuRrjF

* win16: the progress bar, trackbar, up-down and tab control windows

16-bit Windows has no comctl32.dll. src/win16ctl.cpp registers four
window classes that do the messages of the common controls in ANSI,
with the 16-bit packing of WM_HSCROLL and WM_VSCROLL, and draws them in
the 3D style of the system colors. CProgressCtrl, CSliderCtrl,
CSpinButtonCtrl and CTabCtrl now make their windows. tests/win16cmn.cpp
checks each control and its notifications.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B82eRV6wfb9PKGryxuRrjF

* win16: image lists, and the afxcmn.h class members

src/win16imgl.cpp gives the ImageList_ functions with 16-bit GDI: the
images side by side in one screen bitmap, the masks in one monochrome
bitmap, the draw styles, the overlays, the icons and the drag image.
cmnctls.cpp is now in the 16-bit library, so CImageList and the other
classes of afxcmn.h link. win16ctl.h has what the control windows share.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B82eRV6wfb9PKGryxuRrjF

* Win16: add the header control and the list view

The library draws the header control (AfxHeader16, also SysHeader32) and
the list view (AfxListView16, also SysListView32) on 16-bit Windows. The
list view has the four views, virtual lists, callbacks, label editing,
check boxes, custom draw, sorting and find. The win16cmn test checks a
report view. The Win16 code is built and linked; Wine cannot run it in
this container.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B82eRV6wfb9PKGryxuRrjF

* Win16: add the tree view

The library draws the tree view (AfxTreeView16, also SysTreeView32) on
16-bit Windows: lines, buttons, check boxes, image lists, callbacks,
label editing, custom draw, sorting, the drop highlight, the insert
mark, drag notifications and the incremental search. The win16cmn test
checks the links, the expansion, the selection and the sort of a tree.
The Win16 code is built and linked; Wine cannot run it in this
container.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B82eRV6wfb9PKGryxuRrjF

* Win16: add the tooltip control

The library draws the tooltip (AfxToolTip16, also tooltips_class32) on
16-bit Windows: window and rectangle tools, TTM_RELAYEVENT and
TTF_SUBCLASS, the text callback, string resources, TTN_SHOW and
TTN_POP, tracking tips, titles, delay times, colors, margins and word
wrap. AFX_WNDCOMMCTL_BAR_REG registers it, as ICC_BAR_CLASSES does. The
win16cmn test checks the tools, the text, a hit test, the show and the
pop. The Win16 code is built and linked; Wine cannot run it in this
container.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B82eRV6wfb9PKGryxuRrjF

* Win16: add the hot key, IP address, pager and link controls

The library draws the hot key control, the IP address control, the
pager and the link control (SysLink) on 16-bit Windows, with their
messages and notifications. The win16cmn test checks each of them. The
Win16 code is built and linked; Wine cannot run it in this container.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B82eRV6wfb9PKGryxuRrjF

* Win16: add the extended combo box

The library draws the extended combo box (AfxComboBoxEx16, also
ComboBoxEx32) on 16-bit Windows with an owner-drawn combo box: indents,
images, callbacks and the CBEN_ notifications. The 16-bit CB_ messages
have the numbers of the CBEM_ messages, so afxwin16u.h moves the CBEM_
messages above them. The win16cmn test checks the items, the data and
the notifications. The Win16 code is built and linked; Wine cannot run
it in this container.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B82eRV6wfb9PKGryxuRrjF

* Win16: draw the month calendar and the date and time picker

src/win16date.cpp registers AfxMonthCal16 and AfxDateTime16 (and the
comctl32 names). The calendar does the MCM_ messages, several months,
the selection, the range, today, week numbers and day states. The
picker reads the WIN.INI [intl] formats, does custom formats with
callback fields, the keys, the up-down button, the drop-down calendar,
DTS_SHOWNONE and DTS_APPCANPARSE, and sends the DTN_ notifications.

afxwin16u.h moves the MCHT_ flags into 16 bits. win16cmn tests both
controls. The code is built and linked, but not run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B82eRV6wfb9PKGryxuRrjF

* Win16: draw the rebar, and build CReBar

src/win16rebar.cpp registers AfxReBar16 (and ReBarWindow32). It does
the RB_ messages: bands in rows, grippers, images, text, background
bitmaps, chevrons, drags between rows and along a row, the smallest and
largest width of a band, and CCS_VERT. It sends the RBN_ notifications
and gives the notifications of the child windows to its parent.

rebar.cpp (CReBar) is now in the Win16 library. win16cmn tests the
rebar and a CReBar. The code is built and linked, but not run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B82eRV6wfb9PKGryxuRrjF

* Win16: draw the animation control

src/win16anim.cpp registers AfxAnimate16 (and SysAnimate32). It plays
the first video stream of an AVI clip from an AVI resource or a file,
with uncompressed or BI_RLE8 frames. It reads each frame when it shows
it, so a clip can be larger than a segment. A timer plays the clip, and
the parent gets ACN_START and ACN_STOP. ACS_CENTER, ACS_AUTOPLAY and
ACS_TRANSPARENT work.

Now the library draws all the common controls on Win16. win16cmn writes
a small RLE8 clip and checks its frames. The code is built and linked,
but not run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B82eRV6wfb9PKGryxuRrjF

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-11-26 13:57:32 -08:00

1208 lines
46 KiB
C++

// win16cmn.cpp - the common controls that the library draws on 16-bit
// Windows: CImageList, CProgressCtrl, CSliderCtrl, CSpinButtonCtrl and
// CTabCtrl, CHeaderCtrl, CListCtrl, CTreeCtrl, CToolTipCtrl, CHotKeyCtrl,
// CIPAddressCtrl, CPagerCtrl, CLinkCtrl, CComboBoxEx, CMonthCalCtrl,
// CDateTimeCtrl, CReBarCtrl, CReBar and CAnimateCtrl. The frame makes each control, sends it messages and
// checks the notifications that the frame gets. It prints ALL PASSED when each
// check holds, because Wine gives the exit code 0 whatever a 16-bit
// program returns.
#include <afxwin.h>
#include <afxcmn.h>
#include <afxext.h>
#include <stdio.h>
#include <string.h>
static int g_failures = 0;
static BOOL g_bDone = FALSE; // the test ran to the end
#define CHECK(cond) \
do { \
if (!(cond)) { \
printf("FAIL %s:%d: %s\n", __FILE__, __LINE__, #cond); \
g_failures++; \
} \
} while (0)
enum { IDC_PROGRESS = 100, IDC_SLIDER, IDC_BUDDY, IDC_SPIN, IDC_TAB, IDC_LIST, IDC_TREE, IDC_HOTKEY, IDC_IPADDR, IDC_PAGER,
IDC_PAGERCHILD, IDC_LINK, IDC_COMBOEX, IDC_MONTHCAL,
IDC_DATETIME, IDC_REBAR, IDC_RBEDIT1, IDC_RBEDIT2, IDC_RBEDIT3, IDC_RBEDIT4, IDC_ANIMATE,
IDT_RECT = 500 };
class CMainFrame : public CFrameWnd {
public:
CProgressCtrl m_progress;
CSliderCtrl m_slider;
CEdit m_buddy;
CSpinButtonCtrl m_spin;
CTabCtrl m_tab;
CListCtrl m_list;
CTreeCtrl m_tree;
CToolTipCtrl m_tip;
CHotKeyCtrl m_hotkey;
CIPAddressCtrl m_ipaddr;
CPagerCtrl m_pager;
CLinkCtrl m_link;
CComboBoxEx m_comboEx;
CMonthCalCtrl m_cal;
CDateTimeCtrl m_dtp;
CReBarCtrl m_rebar;
CEdit m_rbEdit1, m_rbEdit2, m_rbEdit3, m_rbEdit4;
CReBar m_wndReBar;
CAnimateCtrl m_anim;
UINT m_nLastHScroll; // the code of the last WM_HSCROLL from the slider
int m_nLastHScrollPos; // its position
int m_nVScrolls; // the WM_VSCROLL messages from the up-down control
int m_nDeltaPos; // the UDN_DELTAPOS notifications
int m_nLastDelta; // the iDelta of the last one
int m_nSelChanging; // the TCN_SELCHANGING notifications
int m_nSelChange; // the TCN_SELCHANGE notifications
BOOL m_bRefuseTab; // TCN_SELCHANGING refuses the change
int m_nItemChanged; // the LVN_ITEMCHANGED notifications
int m_nExpanding; // the TVN_ITEMEXPANDING notifications
int m_nTreeSelChanged; // the TVN_SELCHANGED notifications
int m_nTreeDeleted; // the TVN_DELETEITEM notifications
int m_nTipText; // the TTN_NEEDTEXT notifications of IDT_RECT
int m_nTipShow; // the TTN_SHOW notifications of IDT_RECT
int m_nTipPop; // the TTN_POP notifications of IDT_RECT
int m_nHotKeyChange; // the EN_CHANGE notifications of the hot key
int m_nFieldChanged; // the IPN_FIELDCHANGED notifications
int m_nCalcSize; // the PGN_CALCSIZE notifications
int m_nLinkClick; // the NM_CLICK notifications of the link control
int m_iLastLink; // the link of the last NM_CLICK
int m_nCbInserted; // the CBEN_INSERTITEM notifications
int m_nCbDeleted; // the CBEN_DELETEITEM notifications
int m_nCalSelChange; // the MCN_SELCHANGE notifications
int m_nDtChange; // the DTN_DATETIMECHANGE notifications
int m_nRbHeight; // the RBN_HEIGHTCHANGE notifications
int m_nRbDeleted; // the RBN_DELETEDBAND notifications
int m_nRbBeginDrag; // the RBN_BEGINDRAG notifications
int m_nRbEndDrag; // the RBN_ENDDRAG notifications
int m_nAnStart; // the ACN_START notifications
int m_nAnStop; // the ACN_STOP notifications
/// Starts with no notifications.
CMainFrame()
: m_nLastHScroll(0xFFFF), m_nLastHScrollPos(-1), m_nVScrolls(0), m_nDeltaPos(0),
m_nLastDelta(0), m_nSelChanging(0), m_nSelChange(0), m_bRefuseTab(FALSE),
m_nItemChanged(0), m_nExpanding(0), m_nTreeSelChanged(0), m_nTreeDeleted(0),
m_nTipText(0), m_nTipShow(0), m_nTipPop(0), m_nHotKeyChange(0), m_nFieldChanged(0),
m_nCalcSize(0), m_nLinkClick(0), m_iLastLink(-1), m_nCbInserted(0), m_nCbDeleted(0),
m_nCalSelChange(0), m_nDtChange(0), m_nRbHeight(0), m_nRbDeleted(0),
m_nRbBeginDrag(0), m_nRbEndDrag(0), m_nAnStart(0), m_nAnStop(0) {}
/// Makes the controls and runs the checks.
void RunTests() {
TestImageList();
TestProgress();
TestSlider();
TestSpin();
TestTab();
TestListView();
TestTreeView();
TestToolTip();
TestHotKey();
TestIPAddress();
TestPager();
TestLink();
TestComboBoxEx();
TestMonthCal();
TestDateTime();
TestReBar();
TestAnimate();
g_bDone = TRUE;
}
protected:
/// Checks the images of an image list: two images from a bitmap whose
/// red pixels are transparent, a draw on a white background, and the
/// removal of an image.
void TestImageList() {
CClientDC dcScreen(this);
CDC dc;
dc.CreateCompatibleDC(&dcScreen);
CBitmap bm;
bm.CreateCompatibleBitmap(&dcScreen, 32, 16);
CBitmap* pOld = dc.SelectObject(&bm);
dc.FillSolidRect(0, 0, 32, 16, RGB(255, 0, 0)); // transparent
dc.FillSolidRect(4, 4, 8, 8, RGB(0, 0, 255)); // the first image
dc.FillSolidRect(20, 4, 8, 8, RGB(0, 255, 0)); // the second image
dc.SelectObject(pOld);
CImageList il;
CHECK(il.Create(16, 16, ILC_COLOR | ILC_MASK, 2, 2));
CHECK(il.Add(&bm, RGB(255, 0, 0)) == 0);
CHECK(il.GetImageCount() == 2);
int cx = 0, cy = 0;
CHECK(::ImageList_GetIconSize(il.GetSafeHandle(), &cx, &cy) && cx == 16 && cy == 16);
CBitmap bmDraw;
bmDraw.CreateCompatibleBitmap(&dcScreen, 16, 16);
pOld = dc.SelectObject(&bmDraw);
dc.FillSolidRect(0, 0, 16, 16, RGB(255, 255, 255));
CHECK(il.Draw(&dc, 1, CPoint(0, 0), ILD_TRANSPARENT));
CHECK(dc.GetPixel(0, 0) == RGB(255, 255, 255)); // the red pixels are transparent
CHECK(dc.GetPixel(8, 8) == RGB(0, 255, 0));
dc.SelectObject(pOld);
CHECK(il.Remove(0));
CHECK(il.GetImageCount() == 1);
IMAGEINFO info;
CHECK(il.GetImageInfo(0, &info) && info.rcImage.right == 16);
CHECK(il.DeleteImageList());
}
/// Checks the range, the position and the step of the progress bar.
void TestProgress() {
CHECK(m_progress.Create(WS_CHILD | WS_VISIBLE, CRect(10, 10, 210, 30), this, IDC_PROGRESS));
m_progress.SetRange(0, 50);
int nLower = -1, nUpper = -1;
m_progress.GetRange(nLower, nUpper);
CHECK(nLower == 0 && nUpper == 50);
CHECK(m_progress.SetPos(20) == 0);
CHECK(m_progress.GetPos() == 20);
m_progress.SetStep(5);
CHECK(m_progress.StepIt() == 20);
CHECK(m_progress.GetPos() == 25);
m_progress.SetPos(100); // past the end: the position stops at the end
CHECK(m_progress.GetPos() == 50);
m_progress.UpdateWindow();
}
/// Checks the range and the position of the slider, and the scroll
/// messages that its keys send.
void TestSlider() {
CHECK(m_slider.Create(WS_CHILD | WS_VISIBLE | TBS_AUTOTICKS, CRect(10, 40, 210, 80), this,
IDC_SLIDER));
m_slider.SetRange(0, 10, TRUE);
CHECK(m_slider.GetRangeMin() == 0 && m_slider.GetRangeMax() == 10);
m_slider.SetPos(3);
CHECK(m_slider.GetPos() == 3);
m_slider.SetPos(20);
CHECK(m_slider.GetPos() == 10);
m_slider.SetPos(5);
m_slider.SetPageSize(4);
CHECK(m_slider.GetPageSize() == 4);
m_slider.SendMessage(WM_KEYDOWN, VK_RIGHT, 0);
CHECK(m_slider.GetPos() == 6);
CHECK(m_nLastHScroll == TB_LINEDOWN && m_nLastHScrollPos == 6);
m_slider.SendMessage(WM_KEYDOWN, VK_PRIOR, 0);
CHECK(m_slider.GetPos() == 2);
CHECK(m_nLastHScroll == TB_PAGEUP);
m_slider.SendMessage(WM_KEYUP, VK_PRIOR, 0);
CHECK(m_nLastHScroll == TB_ENDTRACK);
CRect rcThumb;
m_slider.GetThumbRect(&rcThumb);
CHECK(!rcThumb.IsRectEmpty());
m_slider.UpdateWindow();
}
/// Checks the range and the position of the up-down control, the text
/// of its buddy, and the notifications of a click on its up arrow.
void TestSpin() {
CHECK(m_buddy.Create(WS_CHILD | WS_VISIBLE | WS_BORDER, CRect(10, 90, 110, 112), this,
IDC_BUDDY));
CHECK(m_spin.Create(WS_CHILD | WS_VISIBLE | UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_ARROWKEYS,
CRect(0, 0, 16, 22), this, IDC_SPIN));
m_spin.SetBuddy(&m_buddy);
CHECK(m_spin.GetBuddy() == &m_buddy);
CRect rcBuddy, rcSpin;
m_buddy.GetWindowRect(&rcBuddy);
m_spin.GetWindowRect(&rcSpin);
CHECK(rcSpin.left == rcBuddy.right); // UDS_ALIGNRIGHT
m_spin.SetRange(0, 2000);
int nLower = -1, nUpper = -1;
m_spin.GetRange(nLower, nUpper);
CHECK(nLower == 0 && nUpper == 2000);
m_spin.SetPos(1234);
CHECK(m_spin.GetPos() == 1234);
CString strText;
m_buddy.GetWindowText(strText);
CHECK(strText == "1,234");
m_buddy.SetWindowText("7");
CHECK(LOWORD(m_spin.GetPos()) == 7); // the position comes from the buddy
// A click on the up arrow: UDN_DELTAPOS, then WM_VSCROLL, then
// SB_ENDSCROLL when the button goes up.
m_spin.GetClientRect(&rcSpin);
LPARAM lUp = MAKELPARAM(rcSpin.Width() / 2, 2);
m_spin.SendMessage(WM_LBUTTONDOWN, MK_LBUTTON, lUp);
m_spin.SendMessage(WM_LBUTTONUP, 0, lUp);
CHECK(m_nDeltaPos == 1);
CHECK(m_nLastDelta == 1);
CHECK(m_nVScrolls == 2);
CHECK(m_spin.GetPos() == 8);
m_buddy.GetWindowText(strText);
CHECK(strText == "8");
// UDS_ARROWKEYS: the down key of the buddy steps down.
m_buddy.SendMessage(WM_KEYDOWN, VK_DOWN, 0);
CHECK(m_spin.GetPos() == 7);
CHECK(m_nLastDelta == -1);
}
/// Checks the tabs of the tab control, and the notifications of a click
/// on a tab.
void TestTab() {
CHECK(m_tab.Create(WS_CHILD | WS_VISIBLE, CRect(220, 10, 420, 150), this, IDC_TAB));
CHECK(m_tab.InsertItem(0, "One") == 0);
CHECK(m_tab.InsertItem(1, "Two") == 1);
CHECK(m_tab.InsertItem(2, "Three") == 2);
CHECK(m_tab.GetItemCount() == 3);
CHECK(m_tab.GetCurSel() == 0);
char szText[16];
TCITEM item;
memset(&item, 0, sizeof(item));
item.mask = TCIF_TEXT;
item.pszText = szText;
item.cchTextMax = sizeof(szText);
CHECK(m_tab.GetItem(2, &item) && strcmp(szText, "Three") == 0);
CHECK(m_tab.SetCurSel(1) == 0);
CHECK(m_tab.GetCurSel() == 1);
CHECK(m_nSelChange == 0); // SetCurSel does not notify
// A click on the third tab.
CRect rcItem;
CHECK(m_tab.GetItemRect(2, &rcItem));
LPARAM lClick = MAKELPARAM(rcItem.CenterPoint().x, rcItem.CenterPoint().y);
m_tab.SendMessage(WM_LBUTTONDOWN, MK_LBUTTON, lClick);
CHECK(m_nSelChanging == 1 && m_nSelChange == 1);
CHECK(m_tab.GetCurSel() == 2);
// A refused change.
m_bRefuseTab = TRUE;
CHECK(m_tab.GetItemRect(0, &rcItem));
lClick = MAKELPARAM(rcItem.CenterPoint().x, rcItem.CenterPoint().y);
m_tab.SendMessage(WM_LBUTTONDOWN, MK_LBUTTON, lClick);
CHECK(m_nSelChanging == 2 && m_nSelChange == 1);
CHECK(m_tab.GetCurSel() == 2);
// The display area is inside the window.
CRect rcClient, rcDisplay;
m_tab.GetClientRect(&rcClient);
rcDisplay = rcClient;
m_tab.AdjustRect(FALSE, &rcDisplay);
CHECK(rcDisplay.top > rcClient.top && rcDisplay.bottom < rcClient.bottom);
m_tab.AdjustRect(TRUE, &rcDisplay);
CHECK(rcDisplay == rcClient);
CHECK(m_tab.DeleteItem(0));
CHECK(m_tab.GetItemCount() == 2);
CHECK(m_tab.GetCurSel() == 1);
m_tab.UpdateWindow();
}
/// Compares two items by their item data, from the largest to the
/// smallest.
static int CALLBACK CompareDown(LPARAM l1, LPARAM l2, LPARAM lSort) {
(void)lSort;
return l1 < l2 ? 1 : l1 > l2 ? -1 : 0;
}
/// Checks a report view: the columns in its header, the items and their
/// subitems, a find, a sort, a selection by a click and the
/// LVN_ITEMCHANGED notification.
void TestListView() {
CHECK(m_list.Create(WS_CHILD | WS_VISIBLE | LVS_REPORT | LVS_SHOWSELALWAYS,
CRect(10, 160, 410, 300), this, IDC_LIST));
CHECK(m_list.InsertColumn(0, "Name", LVCFMT_LEFT, 120) == 0);
CHECK(m_list.InsertColumn(1, "Size", LVCFMT_RIGHT, 80, 1) == 1);
CHeaderCtrl* pHeader = m_list.GetHeaderCtrl();
CHECK(pHeader != NULL && pHeader->GetItemCount() == 2);
CHECK(m_list.GetColumnWidth(0) == 120);
CHECK(m_list.SetColumnWidth(1, 90) && m_list.GetColumnWidth(1) == 90);
static const char* const names[] = {"alpha", "beta", "gamma"};
for (int i = 0; i < 3; i++) {
CHECK(m_list.InsertItem(i, names[i]) == i);
char szSize[8];
sprintf(szSize, "%d", (i + 1) * 10);
CHECK(m_list.SetItemText(i, 1, szSize));
CHECK(m_list.SetItemData(i, (DWORD_PTR)(i + 1)));
}
CHECK(m_list.GetItemCount() == 3);
CHECK(m_list.GetItemText(1, 0) == "beta");
CHECK(m_list.GetItemText(2, 1) == "30");
LVFINDINFO find;
memset(&find, 0, sizeof(find));
find.flags = LVFI_STRING;
find.psz = "gamma";
CHECK(m_list.FindItem(&find) == 2);
find.flags = LVFI_PARTIAL | LVFI_STRING;
find.psz = "be";
CHECK(m_list.FindItem(&find) == 1);
// Sort by the item data, from the largest to the smallest.
CHECK(m_list.SortItems(CompareDown, 0));
CHECK(m_list.GetItemText(0, 0) == "gamma");
CHECK(m_list.GetItemText(2, 0) == "alpha");
CHECK(m_list.GetItemText(0, 1) == "30");
// A click on the second item selects it.
int nChanged = m_nItemChanged;
CRect rcItem;
CHECK(m_list.GetItemRect(1, &rcItem, LVIR_LABEL));
LPARAM lClick = MAKELPARAM(rcItem.left + 4, rcItem.CenterPoint().y);
m_list.SendMessage(WM_LBUTTONDOWN, MK_LBUTTON, lClick);
m_list.SendMessage(WM_LBUTTONUP, 0, lClick);
CHECK(m_list.GetSelectedCount() == 1);
CHECK(m_list.GetNextItem(-1, LVNI_SELECTED) == 1);
CHECK(m_nItemChanged > nChanged);
CHECK(m_list.SetItemState(0, LVIS_SELECTED, LVIS_SELECTED));
CHECK(m_list.GetSelectedCount() == 2);
CHECK(m_list.DeleteItem(0));
CHECK(m_list.GetItemCount() == 2);
CHECK(m_list.GetSelectedCount() == 1);
CHECK(m_list.DeleteAllItems());
CHECK(m_list.GetItemCount() == 0);
CHECK(m_list.DeleteColumn(1) && pHeader->GetItemCount() == 1);
m_list.UpdateWindow();
}
/// Checks a tree view: the links of the items, a sorted insert, the
/// expansion and its notifications, the selection, the item rectangles,
/// a click on a button, a sort and the deletion of a branch.
void TestTreeView() {
CHECK(m_tree.Create(WS_CHILD | WS_VISIBLE | WS_BORDER | TVS_HASLINES | TVS_HASBUTTONS |
TVS_LINESATROOT | TVS_SHOWSELALWAYS,
CRect(420, 160, 620, 300), this, IDC_TREE));
HTREEITEM hFruit = m_tree.InsertItem("Fruit");
HTREEITEM hVeg = m_tree.InsertItem("Vegetables");
CHECK(hFruit != NULL && hVeg != NULL && hFruit != hVeg);
HTREEITEM hPear = m_tree.InsertItem("pear", hFruit);
HTREEITEM hApple = m_tree.InsertItem("apple", hFruit, TVI_FIRST);
HTREEITEM hFig = m_tree.InsertItem("fig", hFruit, TVI_SORT); // between apple and pear
m_tree.InsertItem("leek", hVeg);
CHECK(m_tree.GetCount() == 6);
CHECK(m_tree.GetRootItem() == hFruit);
CHECK(m_tree.GetNextSiblingItem(hFruit) == hVeg);
CHECK(m_tree.GetChildItem(hFruit) == hApple);
CHECK(m_tree.GetNextSiblingItem(hApple) == hFig);
CHECK(m_tree.GetNextSiblingItem(hFig) == hPear);
CHECK(m_tree.GetParentItem(hPear) == hFruit);
CHECK(m_tree.GetItemText(hFig) == "fig");
CHECK(m_tree.ItemHasChildren(hFruit) && !m_tree.ItemHasChildren(hPear));
CHECK(m_tree.SetItemData(hPear, 3) && m_tree.GetItemData(hPear) == 3);
// A hidden item has no rectangle until its parent is expanded.
CRect rc;
CHECK(!m_tree.GetItemRect(hApple, &rc, TRUE));
CHECK(m_tree.Expand(hFruit, TVE_EXPAND));
CHECK(m_nExpanding == 1);
CHECK(m_tree.GetItemState(hFruit, TVIS_EXPANDED) & TVIS_EXPANDED);
CHECK(m_tree.GetItemRect(hApple, &rc, TRUE));
CRect rcFruit;
CHECK(m_tree.GetItemRect(hFruit, &rcFruit, TRUE));
CHECK(rc.left > rcFruit.left && rc.top > rcFruit.top);
CHECK(m_tree.GetNextVisibleItem(hFruit) == hApple);
// Another TVM_EXPAND does not notify after the first expansion.
CHECK(m_tree.Expand(hFruit, TVE_COLLAPSE) && m_tree.Expand(hFruit, TVE_EXPAND));
CHECK(m_nExpanding == 1);
// The selection.
CHECK(m_tree.SelectItem(hFig));
CHECK(m_tree.GetSelectedItem() == hFig);
CHECK(m_nTreeSelChanged == 1);
CHECK(m_tree.GetItemState(hFig, TVIS_SELECTED) & TVIS_SELECTED);
UINT flags = 0;
CHECK(m_tree.GetItemRect(hFig, &rc, TRUE));
CHECK(m_tree.HitTest(rc.CenterPoint(), &flags) == hFig && (flags & TVHT_ONITEMLABEL));
// A click on the button of the second root item expands it.
CHECK(m_tree.GetItemRect(hVeg, &rc, TRUE));
CPoint ptButton(rc.left - 3 - (int)m_tree.GetIndent() / 2, rc.CenterPoint().y);
CHECK(m_tree.HitTest(ptButton, &flags) == hVeg && (flags & TVHT_ONITEMBUTTON));
m_tree.SendMessage(WM_LBUTTONDOWN, MK_LBUTTON, MAKELPARAM(ptButton.x, ptButton.y));
m_tree.SendMessage(WM_LBUTTONUP, 0, MAKELPARAM(ptButton.x, ptButton.y));
CHECK(m_tree.GetItemState(hVeg, TVIS_EXPANDED) & TVIS_EXPANDED);
CHECK(m_nExpanding == 2);
// A collapse moves the selection to the collapsed item.
CHECK(m_tree.Expand(hFruit, TVE_COLLAPSE));
CHECK(m_tree.GetSelectedItem() == hFruit);
// A sort by the text, from the largest to the smallest.
TVSORTCB sort;
sort.hParent = hFruit;
sort.lpfnCompare = CompareDown;
sort.lParam = 0;
m_tree.SetItemData(hApple, 1);
m_tree.SetItemData(hFig, 2);
CHECK(m_tree.SortChildrenCB(&sort));
CHECK(m_tree.GetChildItem(hFruit) == hPear);
CHECK(m_tree.SortChildren(hFruit));
CHECK(m_tree.GetChildItem(hFruit) == hApple);
// The deletion of a branch notifies for each item.
int nDeleted = m_nTreeDeleted;
CHECK(m_tree.DeleteItem(hFruit));
CHECK(m_nTreeDeleted - nDeleted == 4);
CHECK(m_tree.GetCount() == 2);
CHECK(m_tree.GetRootItem() == hVeg);
CHECK(m_tree.DeleteAllItems());
CHECK(m_tree.GetCount() == 0 && m_tree.GetRootItem() == NULL);
m_tree.UpdateWindow();
}
/// Checks a tooltip: a window tool and a rectangle tool with a text
/// callback, the text, a hit test, a relayed mouse move, the show and
/// the pop, and the deletion of a tool.
void TestToolTip() {
CHECK(m_tip.Create(this, TTS_ALWAYSTIP));
CHECK(m_tip.AddTool(&m_progress, "Progress"));
CRect rcTool(0, 0, 8, 8);
CHECK(m_tip.AddTool(this, LPSTR_TEXTCALLBACK, &rcTool, IDT_RECT));
CHECK(m_tip.GetToolCount() == 2);
char szText[80];
TOOLINFO ti;
m_tip.FillInToolInfo(ti, &m_progress, 0);
ti.lpszText = szText;
CHECK(m_tip.SendMessage(TTM_GETTEXT, sizeof(szText), (LPARAM)&ti) == 8);
CHECK(strcmp(szText, "Progress") == 0);
m_tip.UpdateTipText("Done", &m_progress);
ti.lpszText = szText;
m_tip.SendMessage(TTM_GETTEXT, sizeof(szText), (LPARAM)&ti);
CHECK(strcmp(szText, "Done") == 0);
// The callback gives the text of the rectangle tool.
m_tip.FillInToolInfo(ti, this, IDT_RECT);
ti.lpszText = szText;
m_tip.SendMessage(TTM_GETTEXT, sizeof(szText), (LPARAM)&ti);
CHECK(strcmp(szText, "Corner") == 0 && m_nTipText == 1);
TTHITTESTINFO hit;
memset(&hit, 0, sizeof(hit));
hit.hwnd = m_hWnd;
hit.pt = CPoint(4, 4);
hit.ti.cbSize = TTTOOLINFO_V1_SIZE;
CHECK(m_tip.SendMessage(TTM_HITTEST, 0, (LPARAM)&hit));
CHECK(hit.ti.uId == IDT_RECT);
hit.pt = CPoint(20, 20);
CHECK(!m_tip.SendMessage(TTM_HITTEST, 0, (LPARAM)&hit));
// A relayed move makes the tool hot; TTM_POPUP shows it now.
MSG msg;
memset(&msg, 0, sizeof(msg));
msg.hwnd = m_hWnd;
msg.message = WM_MOUSEMOVE;
msg.lParam = MAKELPARAM(4, 4);
m_tip.RelayEvent(&msg);
m_tip.SendMessage(TTM_POPUP, 0, 0);
CHECK(m_tip.IsWindowVisible());
CHECK(m_nTipShow == 1);
m_tip.FillInToolInfo(ti, this, 0);
CHECK(m_tip.SendMessage(TTM_GETCURRENTTOOL, 0, (LPARAM)&ti) && ti.uId == IDT_RECT);
m_tip.Pop();
CHECK(!m_tip.IsWindowVisible());
CHECK(m_nTipPop == 1);
m_tip.DelTool(this, IDT_RECT);
CHECK(m_tip.GetToolCount() == 1);
CHECK(m_tip.SetMaxTipWidth(100) == -1);
m_tip.DestroyWindow();
}
/// Checks a hot key control: the key and its modifiers, a key press,
/// and the rules that replace a combination that is not valid.
void TestHotKey() {
CHECK(m_hotkey.Create(WS_CHILD | WS_VISIBLE | WS_BORDER, CRect(10, 310, 150, 330), this,
IDC_HOTKEY));
WORD vk = 1, mods = 1;
m_hotkey.GetHotKey(vk, mods);
CHECK(vk == 0 && mods == 0);
m_hotkey.SetHotKey('K', HOTKEYF_CONTROL | HOTKEYF_ALT);
m_hotkey.GetHotKey(vk, mods);
CHECK(vk == 'K' && mods == (HOTKEYF_CONTROL | HOTKEYF_ALT));
CHECK(m_nHotKeyChange == 0); // HKM_SETHOTKEY does not notify
// A key with no modifier is not valid: Ctrl replaces none.
m_hotkey.SetRules(HKCOMB_NONE, HOTKEYF_CONTROL);
m_hotkey.SendMessage(WM_KEYDOWN, VK_F5, 0);
m_hotkey.GetHotKey(vk, mods);
CHECK(vk == VK_F5 && mods == HOTKEYF_CONTROL);
CHECK(m_nHotKeyChange == 1);
m_hotkey.SendMessage(WM_KEYDOWN, VK_BACK, 0);
CHECK(m_hotkey.GetHotKey() == 0);
m_hotkey.UpdateWindow();
}
/// Checks an IP address control: blank, an address, the fields, a range
/// and IPN_FIELDCHANGED when a field loses the focus.
void TestIPAddress() {
CHECK(m_ipaddr.Create(WS_CHILD | WS_VISIBLE | WS_BORDER, CRect(160, 310, 300, 330), this,
IDC_IPADDR));
CHECK(m_ipaddr.IsBlank());
DWORD dw = 1;
CHECK(m_ipaddr.GetAddress(dw) == 0 && dw == 0);
m_ipaddr.SetAddress(192, 168, 1, 20);
CHECK(!m_ipaddr.IsBlank());
BYTE b0 = 0, b1 = 0, b2 = 0, b3 = 0;
CHECK(m_ipaddr.GetAddress(b0, b1, b2, b3) == 4);
CHECK(b0 == 192 && b1 == 168 && b2 == 1 && b3 == 20);
// A value above the range of the field goes down to the top of the
// range when the field loses the focus.
m_ipaddr.SetFieldRange(3, 1, 100);
m_ipaddr.SetAddress(10, 0, 0, 200);
m_ipaddr.SetFieldFocus(3);
SetFocus();
CHECK(m_nFieldChanged >= 1);
CHECK(m_ipaddr.GetAddress(dw) == 4 && FOURTH_IPADDRESS(dw) == 100);
m_ipaddr.ClearAddress();
CHECK(m_ipaddr.IsBlank());
m_ipaddr.UpdateWindow();
}
/// Checks a pager: the size of the child from PGN_CALCSIZE, the
/// buttons and the scroll position.
void TestPager() {
CHECK(m_pager.Create(WS_CHILD | WS_VISIBLE | PGS_HORZ, CRect(310, 310, 410, 340), this,
IDC_PAGER));
CWnd wndChild;
CHECK(wndChild.Create(_T("STATIC"), _T("A wide child window"), WS_CHILD | WS_VISIBLE,
CRect(0, 0, 300, 30), &m_pager, IDC_PAGERCHILD));
m_pager.SetChild(wndChild.m_hWnd);
CHECK(m_nCalcSize >= 1);
CHECK(m_pager.GetScrollPos() == 0);
CHECK(m_pager.IsButtonInvisible(PGB_TOPORLEFT));
CHECK(m_pager.IsButtonNormal(PGB_BOTTOMORRIGHT));
m_pager.SetScrollPos(50);
CHECK(m_pager.GetScrollPos() == 50);
CHECK(m_pager.IsButtonNormal(PGB_TOPORLEFT));
CRect rcChild;
wndChild.GetWindowRect(&rcChild);
m_pager.ScreenToClient(&rcChild);
CHECK(rcChild.Width() == 300 && rcChild.left < 0);
CHECK(m_pager.SetButtonSize(16) == 12 && m_pager.GetButtonSize() == 16);
m_pager.UpdateWindow();
wndChild.DestroyWindow();
}
/// Checks a link control: the links of the markup, their IDs and URLs,
/// a hit test, a click and the ideal height.
void TestLink() {
CHECK(m_link.Create(_T("See <a href=\"http://a.example/\">one</a> or ")
_T("<a id=\"two\">two</a>."),
WS_CHILD | WS_VISIBLE, CRect(10, 340, 300, 370), this, IDC_LINK));
CString str;
CHECK(m_link.GetItemUrl(0, str) && str == "http://a.example/");
CHECK(m_link.GetItemID(1, str) && str == "two");
CHECK(!m_link.GetItemUrl(2, str));
CHECK(m_link.GetIdealHeight() > 0);
// Find the first link with hit tests along the first line.
LHITTESTINFO* pHit = new LHITTESTINFO;
int xLink = -1;
for (int x = 0; x < 200 && xLink < 0; x++) {
memset(pHit, 0, sizeof(*pHit));
pHit->pt.x = x;
pHit->pt.y = 4;
if (m_link.LinkHitTest(pHit) && pHit->item.iLink == 0) xLink = x;
}
delete pHit;
CHECK(xLink > 0);
m_link.SendMessage(WM_LBUTTONDOWN, MK_LBUTTON, MAKELPARAM(xLink + 1, 4));
m_link.SendMessage(WM_LBUTTONUP, 0, MAKELPARAM(xLink + 1, 4));
CHECK(m_nLinkClick == 1 && m_iLastLink == 0);
UINT state = 0;
CHECK(m_link.GetItemState(0, &state, LIS_VISITED) && (state & LIS_VISITED));
m_link.UpdateWindow();
}
/// Checks an extended combo box: items with images, indents and data,
/// the CB_ messages through the window, and the notifications.
void TestComboBoxEx() {
CHECK(m_comboEx.Create(WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST, CRect(310, 345, 450, 445),
this, IDC_COMBOEX));
CImageList il;
CHECK(il.Create(16, 16, ILC_COLOR, 2, 0));
m_comboEx.SetImageList(&il);
CHECK(m_comboEx.GetImageList() != NULL);
static const char* const names[] = {"Drive", "Folder", "File"};
for (int i = 0; i < 3; i++) {
COMBOBOXEXITEM item;
memset(&item, 0, sizeof(item));
item.mask = CBEIF_TEXT | CBEIF_IMAGE | CBEIF_SELECTEDIMAGE | CBEIF_INDENT | CBEIF_LPARAM;
item.iItem = i;
item.pszText = (LPSTR)names[i];
item.iImage = item.iSelectedImage = i % 2;
item.iIndent = i;
item.lParam = 100 + i;
CHECK(m_comboEx.InsertItem(&item) == i);
}
CHECK(m_nCbInserted == 3);
CHECK(m_comboEx.GetCount() == 3);
CHECK(m_comboEx.GetItemData(2) == 102);
char szText[32];
COMBOBOXEXITEM item;
memset(&item, 0, sizeof(item));
item.mask = CBEIF_TEXT | CBEIF_INDENT;
item.iItem = 1;
item.pszText = szText;
item.cchTextMax = sizeof(szText);
CHECK(m_comboEx.GetItem(&item) && strcmp(szText, "Folder") == 0 && item.iIndent == 1);
CHECK(m_comboEx.SetCurSel(2) == 2 && m_comboEx.GetCurSel() == 2);
CHECK(m_comboEx.GetComboBoxCtrl() != NULL);
CHECK(m_comboEx.GetEditCtrl() == NULL); // a drop-down list has no edit control
CHECK(m_comboEx.DeleteItem(0) == 2);
CHECK(m_nCbDeleted == 1);
CHECK(m_comboEx.GetItemData(0) == 101);
m_comboEx.UpdateWindow();
}
/// Gives a SYSTEMTIME for a date and a time.
static SYSTEMTIME MakeTime(int nYear, int nMonth, int nDay, int nHour = 0, int nMinute = 0) {
SYSTEMTIME st;
memset(&st, 0, sizeof(st));
st.wYear = (WORD)nYear;
st.wMonth = (WORD)nMonth;
st.wDay = (WORD)nDay;
st.wHour = (WORD)nHour;
st.wMinute = (WORD)nMinute;
return st;
}
/// Checks the month calendar: the selection, today, the range, the
/// first day of the week, the size, and the hit test of a date and of
/// the title.
void TestMonthCal() {
CHECK(m_cal.Create(WS_CHILD | WS_VISIBLE | MCS_WEEKNUMBERS, CRect(460, 310, 700, 470), this,
IDC_MONTHCAL));
SYSTEMTIME st = MakeTime(1999, 12, 31);
CHECK(m_cal.SetCurSel(&st));
SYSTEMTIME stGot;
CHECK(m_cal.GetCurSel(&stGot) && stGot.wYear == 1999 && stGot.wMonth == 12 && stGot.wDay == 31);
CHECK(stGot.wDayOfWeek == 5); // a Friday
st = MakeTime(2000, 2, 30);
CHECK(!m_cal.SetCurSel(&st)); // not a date
st = MakeTime(2000, 1, 1);
m_cal.SendMessage(MCM_SETTODAY, 0, (LPARAM)&st);
CHECK(m_cal.SendMessage(MCM_GETTODAY, 0, (LPARAM)&stGot) && stGot.wYear == 2000 &&
stGot.wDay == 1);
SYSTEMTIME range[2];
range[0] = MakeTime(1999, 12, 1);
range[1] = MakeTime(2000, 1, 31);
CHECK(m_cal.SendMessage(MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)range));
st = MakeTime(2000, 2, 1);
CHECK(!m_cal.SetCurSel(&st)); // out of the range
CHECK(m_cal.SendMessage(MCM_GETRANGE, 0, (LPARAM)range) == (GDTR_MIN | GDTR_MAX));
m_cal.SendMessage(MCM_SETFIRSTDAYOFWEEK, 0, 0);
CHECK(LOWORD(m_cal.SendMessage(MCM_GETFIRSTDAYOFWEEK, 0, 0)) == 0);
CRect rcMin;
CHECK(m_cal.GetMinReqRect(&rcMin) && rcMin.Width() > 0 && rcMin.Height() > 0);
MCHITTESTINFO hit;
memset(&hit, 0, sizeof(hit));
hit.cbSize = sizeof(hit);
hit.pt.x = rcMin.Width() / 2;
hit.pt.y = 4;
UINT uHit = (UINT)m_cal.SendMessage(MCM_HITTEST, 0, (LPARAM)&hit);
CHECK((uHit & MCHT_TITLE) == MCHT_TITLE && uHit == hit.uHit);
hit.pt.y = rcMin.Height() / 2;
uHit = (UINT)m_cal.SendMessage(MCM_HITTEST, 0, (LPARAM)&hit);
CHECK((uHit & MCHT_CALENDAR) == MCHT_CALENDAR);
m_cal.UpdateWindow();
}
/// Checks the date and time picker: the time, its text in a custom
/// format, the range, DTS_SHOWNONE, and the arrow and digit keys.
void TestDateTime() {
CHECK(m_dtp.Create(WS_CHILD | WS_VISIBLE | WS_TABSTOP | DTS_SHOWNONE, CRect(10, 380, 200, 404),
this, IDC_DATETIME));
SYSTEMTIME st = MakeTime(2001, 3, 9, 14, 5);
CHECK(m_dtp.SetTime(&st));
CHECK(m_nDtChange == 0); // DTM_SETSYSTEMTIME sends no notification
SYSTEMTIME stGot;
CHECK(m_dtp.GetTime(&stGot) == GDT_VALID && stGot.wYear == 2001 && stGot.wDay == 9 &&
stGot.wHour == 14 && stGot.wMinute == 5);
CHECK(m_dtp.SetFormat("yyyy'-'MM'-'dd HH':'mm"));
char szText[40];
m_dtp.GetWindowText(szText, sizeof(szText));
CHECK(strcmp(szText, "2001-03-09 14:05") == 0);
m_dtp.SetFocus();
m_dtp.SendMessage(WM_KEYDOWN, VK_HOME, 0); // the first field, the year
m_dtp.SendMessage(WM_KEYDOWN, VK_UP, 0);
CHECK(m_nDtChange == 1);
CHECK(m_dtp.GetTime(&stGot) == GDT_VALID && stGot.wYear == 2002);
m_dtp.SendMessage(WM_KEYDOWN, VK_RIGHT, 0); // the month
m_dtp.SendMessage(WM_CHAR, '1', 0);
m_dtp.SendMessage(WM_CHAR, '2', 0);
CHECK(m_dtp.GetTime(&stGot) == GDT_VALID && stGot.wMonth == 12);
SYSTEMTIME range[2];
range[0] = MakeTime(2002, 1, 1);
range[1] = MakeTime(2002, 6, 30);
CHECK(m_dtp.SetRange(GDTR_MIN | GDTR_MAX, range));
CHECK(m_dtp.GetTime(&stGot) == GDT_VALID && stGot.wMonth == 6 && stGot.wDay == 30);
CHECK(m_dtp.GetRange(range) == (GDTR_MIN | GDTR_MAX) && range[1].wMonth == 6);
CHECK(m_dtp.SetTime(NULL)); // DTS_SHOWNONE clears the check box
CHECK(m_dtp.GetTime(&stGot) == GDT_NONE);
CHECK(m_dtp.GetWindowTextLength() == 0);
m_dtp.UpdateWindow();
}
/// Adds a band with an edit control to the rebar.
BOOL AddRbBand(CEdit& edit, UINT nID, LPCSTR lpszText, UINT fStyle, UINT cxMin, UINT cx,
LPARAM lParam) {
if (!edit.Create(WS_CHILD | WS_BORDER | ES_AUTOHSCROLL, CRect(0, 0, 10, 10), &m_rebar, nID))
return FALSE;
REBARBANDINFO rbbi;
memset(&rbbi, 0, sizeof(rbbi));
rbbi.cbSize = sizeof(rbbi);
rbbi.fMask = RBBIM_STYLE | RBBIM_CHILD | RBBIM_CHILDSIZE | RBBIM_SIZE | RBBIM_ID | RBBIM_LPARAM;
if (lpszText != NULL) {
rbbi.fMask |= RBBIM_TEXT;
rbbi.lpText = (LPSTR)lpszText;
}
rbbi.fStyle = fStyle;
rbbi.hwndChild = edit.m_hWnd;
rbbi.cxMinChild = cxMin;
rbbi.cyMinChild = 20;
rbbi.cx = cx;
rbbi.wID = nID;
rbbi.lParam = lParam;
return m_rebar.InsertBand((UINT)-1, &rbbi);
}
/// Checks the rebar: the bands and their information, the rows, the
/// layout along a row, the hit test, a hidden band, the removal of a
/// band, the smallest width of a band and a drag. Then checks a CReBar
/// in the frame.
void TestReBar() {
CHECK(m_rebar.Create(WS_CHILD | WS_VISIBLE | RBS_BANDBORDERS | RBS_VARHEIGHT | CCS_NODIVIDER |
CCS_NORESIZE | CCS_NOPARENTALIGN,
CRect(10, 480, 410, 540), this, IDC_REBAR));
CHECK(AddRbBand(m_rbEdit1, IDC_RBEDIT1, "Name", RBBS_GRIPPERALWAYS | RBBS_CHILDEDGE, 50, 150, 0));
CHECK(AddRbBand(m_rbEdit2, IDC_RBEDIT2, NULL, 0, 60, 100, 77));
CHECK(m_nRbHeight >= 1);
CHECK(m_rebar.GetBandCount() == 2);
CHECK(m_rebar.GetRowCount() == 1);
CHECK(m_rebar.IDToIndex(IDC_RBEDIT2) == 1);
char szText[16];
REBARBANDINFO rbbi;
memset(&rbbi, 0, sizeof(rbbi));
rbbi.cbSize = sizeof(rbbi);
rbbi.fMask = RBBIM_TEXT | RBBIM_LPARAM | RBBIM_ID;
rbbi.lpText = szText;
rbbi.cch = sizeof(szText);
CHECK(m_rebar.GetBandInfo(0, &rbbi) && strcmp(szText, "Name") == 0 && rbbi.wID == IDC_RBEDIT1);
rbbi.fMask = RBBIM_LPARAM;
CHECK(m_rebar.GetBandInfo(1, &rbbi) && rbbi.lParam == 77);
// The last band goes to the end of the row.
CRect rc0, rc1;
CHECK(m_rebar.GetRect(0, &rc0) && m_rebar.GetRect(1, &rc1));
CHECK(rc0.left == 0 && rc0.right == 150 && rc1.left == 150 && rc1.right == 400);
// The child is in its band, after the header.
CRect rcChild;
m_rbEdit1.GetWindowRect(&rcChild);
m_rebar.ScreenToClient(&rcChild);
CHECK(rcChild.left > rc0.left && rcChild.right <= rc0.right && rcChild.Height() == 20);
CHECK(m_rbEdit1.IsWindowVisible());
RBHITTESTINFO hit;
memset(&hit, 0, sizeof(hit));
hit.pt.x = rc0.left + 3;
hit.pt.y = rc0.top + rc0.Height() / 2;
CHECK(m_rebar.HitTest(&hit) == 0 && hit.flags == RBHT_GRABBER);
hit.pt.x = rcChild.left + 2;
CHECK(m_rebar.HitTest(&hit) == 0 && hit.flags == RBHT_CLIENT);
// A band with RBBS_BREAK starts a second row.
int nHeight = m_nRbHeight;
CHECK(AddRbBand(m_rbEdit3, IDC_RBEDIT3, "Find", RBBS_BREAK, 80, 200, 0));
CHECK(m_rebar.GetRowCount() == 2 && m_nRbHeight == nHeight + 1);
CHECK(m_rebar.ShowBand(2, FALSE) && m_rebar.GetRowCount() == 1);
CHECK(!m_rbEdit3.IsWindowVisible());
CHECK(m_rebar.DeleteBand(2) && m_nRbDeleted == 1 && m_rebar.GetBandCount() == 2);
// The smallest width of band 1 gives its space to band 0.
m_rebar.MinimizeBand(1);
CHECK(m_rebar.GetRect(0, &rc0) && m_rebar.GetRect(1, &rc1));
CHECK(rc0.right > 150 && rc1.right == 400 && rc1.Width() < 100);
// A drag of the left edge of band 1 to the left.
int xOld = rc1.left;
CPoint pt(rc1.left + 2, rc1.top + 2);
m_rebar.ClientToScreen(&pt);
m_rebar.BeginDrag(1, MAKELONG(pt.x, pt.y));
CHECK(m_nRbBeginDrag == 1);
pt.x -= 40;
m_rebar.DragMove(MAKELONG(pt.x, pt.y));
m_rebar.EndDrag();
CHECK(m_nRbEndDrag == 1);
CHECK(m_rebar.GetRect(1, &rc1) && rc1.left == xOld - 40 && rc1.right == 400);
m_rebar.UpdateWindow();
// CReBar puts its control bar at the top of the frame.
CHECK(m_wndReBar.Create(this));
CHECK(m_rbEdit4.Create(WS_CHILD | WS_BORDER, CRect(0, 0, 120, 22), &m_wndReBar, IDC_RBEDIT4));
CHECK(m_wndReBar.AddBar(&m_rbEdit4, "Go"));
CHECK(m_wndReBar.GetReBarCtrl().GetBandCount() == 1);
CSize size = m_wndReBar.CalcFixedLayout(TRUE, TRUE);
CHECK(size.cy >= 22);
RecalcLayout();
m_wndReBar.UpdateWindow();
}
/// Writes a DWORD to a buffer in little-endian order and moves the
/// pointer on.
static void PutDword(BYTE*& p, DWORD dw) {
for (int i = 0; i < 4; i++) *p++ = (BYTE)(dw >> (8 * i));
}
/// Writes a four-character code to a buffer and moves the pointer on.
static void PutFcc(BYTE*& p, const char* psz) {
for (int i = 0; i < 4; i++) *p++ = (BYTE)psz[i];
}
/// Writes a small AVI clip to a file: 4 by 2 pixels, 8-bit BI_RLE8,
/// with four colors and three frames. Frame 0 is red on the bottom row,
/// and green and blue on the top row. Frame 1 changes the top-left
/// pixel to white. Frame 2 is an empty chunk, the same as frame 1.
static BOOL WriteClip(LPCSTR lpszPath) {
static const BYTE frame0[] = {4, 0, 0, 0, 2, 1, 2, 2, 0, 1};
static const BYTE frame1[] = {0, 0, 1, 3, 0, 1};
BYTE buf[400];
BYTE* p = buf;
PutFcc(p, "RIFF");
BYTE* pRiffSize = p;
PutDword(p, 0);
PutFcc(p, "AVI ");
PutFcc(p, "LIST");
PutDword(p, 4 + 8 + 56 + 8 + 4 + 8 + 56 + 8 + 56);
PutFcc(p, "hdrl");
PutFcc(p, "avih");
PutDword(p, 56);
static const DWORD avih[14] = {100000, 0, 0, 0x10, 3, 0, 1, 0, 4, 2, 0, 0, 0, 0};
for (int i = 0; i < 14; i++) PutDword(p, avih[i]);
PutFcc(p, "LIST");
PutDword(p, 4 + 8 + 56 + 8 + 56);
PutFcc(p, "strl");
PutFcc(p, "strh");
PutDword(p, 56);
PutFcc(p, "vids");
PutFcc(p, "mrle");
static const DWORD strh[10] = {0, 0, 0, 1, 10, 0, 3, 0, 0xFFFFFFFFUL, 0};
for (int i = 0; i < 10; i++) PutDword(p, strh[i]);
PutDword(p, 0); // rcFrame: left, top
PutDword(p, 0x00020004); // rcFrame: right 4, bottom 2
PutFcc(p, "strf");
PutDword(p, 56);
PutDword(p, 40);
PutDword(p, 4);
PutDword(p, 2);
PutDword(p, 0x00080001); // 1 plane, 8 bits
PutDword(p, BI_RLE8);
PutDword(p, 0);
PutDword(p, 0);
PutDword(p, 0);
PutDword(p, 4);
PutDword(p, 0);
PutDword(p, 0x00FF0000); // red (RGBQUAD: blue, green, red)
PutDword(p, 0x0000FF00); // green
PutDword(p, 0x000000FF); // blue
PutDword(p, 0x00FFFFFF); // white
PutFcc(p, "LIST");
PutDword(p, 4 + 8 + sizeof(frame0) + 8 + sizeof(frame1) + 8);
BYTE* pMovi = p + 4;
PutFcc(p, "movi");
DWORD off0 = (DWORD)(p - (pMovi - 4));
PutFcc(p, "00dc");
PutDword(p, sizeof(frame0));
memcpy(p, frame0, sizeof(frame0));
p += sizeof(frame0);
DWORD off1 = (DWORD)(p - (pMovi - 4));
PutFcc(p, "00dc");
PutDword(p, sizeof(frame1));
memcpy(p, frame1, sizeof(frame1));
p += sizeof(frame1);
DWORD off2 = (DWORD)(p - (pMovi - 4));
PutFcc(p, "00dc");
PutDword(p, 0);
PutFcc(p, "idx1");
PutDword(p, 48);
PutFcc(p, "00dc");
PutDword(p, 0x10);
PutDword(p, off0);
PutDword(p, sizeof(frame0));
PutFcc(p, "00dc");
PutDword(p, 0);
PutDword(p, off1);
PutDword(p, sizeof(frame1));
PutFcc(p, "00dc");
PutDword(p, 0);
PutDword(p, off2);
PutDword(p, 0);
BYTE* pEnd = p;
p = pRiffSize;
PutDword(p, (DWORD)(pEnd - buf - 8));
HFILE hFile = ::_lcreat(lpszPath, 0);
if (hFile == HFILE_ERROR) return FALSE;
UINT cb = (UINT)(pEnd - buf);
BOOL bOk = ::_lwrite(hFile, buf, cb) == cb;
::_lclose(hFile);
return bOk;
}
/// Checks the animation control: a file that is not there, a clip from
/// a file, the size of the window, the frames (by their pixels), a
/// play with ACN_START and ACN_STOP, a range that is not in the clip,
/// and the close.
void TestAnimate() {
CHECK(m_anim.Create(WS_CHILD | WS_VISIBLE, CRect(430, 10, 470, 40), this, IDC_ANIMATE));
CHECK(!m_anim.Open("NOCLIP.AVI"));
CHECK(WriteClip("W16CMN.AVI"));
CHECK(m_anim.Open("W16CMN.AVI"));
CRect rc;
m_anim.GetClientRect(&rc);
CHECK(rc.Width() == 4 && rc.Height() == 2); // the size of a frame
m_anim.UpdateWindow();
CClientDC dc(&m_anim);
CHECK(dc.GetPixel(0, 0) == RGB(0, 255, 0)); // top left: green
CHECK(dc.GetPixel(3, 0) == RGB(0, 0, 255)); // top right: blue
CHECK(dc.GetPixel(1, 1) == RGB(255, 0, 0)); // bottom: red
CHECK(m_anim.Seek(1));
CHECK(dc.GetPixel(0, 0) == RGB(255, 255, 255)); // frame 1 changes the top left
CHECK(dc.GetPixel(3, 0) == RGB(0, 0, 255));
CHECK(m_anim.Seek(2)); // an empty chunk
CHECK(dc.GetPixel(0, 0) == RGB(255, 255, 255));
CHECK(m_anim.Seek(0)); // back to the key frame
CHECK(dc.GetPixel(0, 0) == RGB(0, 255, 0));
CHECK(m_nAnStart == 0); // a seek does not play
CHECK(m_anim.Play(0, (UINT)-1, (UINT)-1));
CHECK(m_nAnStart == 1 && m_anim.SendMessage(ACM_ISPLAYING, 0, 0));
CHECK(m_anim.Stop());
CHECK(m_nAnStop == 1 && !m_anim.SendMessage(ACM_ISPLAYING, 0, 0));
CHECK(!m_anim.Play(0, 5, 1)); // there are only three frames
CHECK(m_anim.Close());
OFSTRUCT of;
::OpenFile("W16CMN.AVI", &of, OF_DELETE);
}
/// Counts ACN_START.
afx_msg void OnAnimStart() { m_nAnStart++; }
/// Counts ACN_STOP.
afx_msg void OnAnimStop() { m_nAnStop++; }
/// Keeps the code and the position of the scroll messages of the
/// slider.
afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) {
if ((CWnd*)pScrollBar == &m_slider) {
m_nLastHScroll = nSBCode;
m_nLastHScrollPos = (int)nPos;
}
}
/// Counts the scroll messages of the up-down control.
afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) {
(void)nSBCode;
(void)nPos;
if ((CWnd*)pScrollBar == &m_spin) m_nVScrolls++;
}
/// Counts UDN_DELTAPOS and keeps its iDelta.
afx_msg void OnDeltaPos(NMHDR* pNMHDR, LRESULT* pResult) {
m_nDeltaPos++;
m_nLastDelta = ((NMUPDOWN*)pNMHDR)->iDelta;
*pResult = 0;
}
/// Counts TCN_SELCHANGING, and refuses the change when m_bRefuseTab is
/// set.
afx_msg void OnSelChanging(NMHDR* pNMHDR, LRESULT* pResult) {
(void)pNMHDR;
m_nSelChanging++;
*pResult = m_bRefuseTab;
}
/// Counts TCN_SELCHANGE.
afx_msg void OnSelChange(NMHDR* pNMHDR, LRESULT* pResult) {
(void)pNMHDR;
m_nSelChange++;
*pResult = 0;
}
/// Counts LVN_ITEMCHANGED.
afx_msg void OnItemChanged(NMHDR* pNMHDR, LRESULT* pResult) {
(void)pNMHDR;
m_nItemChanged++;
*pResult = 0;
}
/// Counts TVN_ITEMEXPANDING.
afx_msg void OnItemExpanding(NMHDR* pNMHDR, LRESULT* pResult) {
(void)pNMHDR;
m_nExpanding++;
*pResult = 0;
}
/// Counts TVN_SELCHANGED.
afx_msg void OnTreeSelChanged(NMHDR* pNMHDR, LRESULT* pResult) {
(void)pNMHDR;
m_nTreeSelChanged++;
*pResult = 0;
}
/// Counts TVN_DELETEITEM.
afx_msg void OnTreeDeleteItem(NMHDR* pNMHDR, LRESULT* pResult) {
(void)pNMHDR;
m_nTreeDeleted++;
*pResult = 0;
}
/// Gives the text of the rectangle tool of the tooltip.
afx_msg void OnTipNeedText(NMHDR* pNMHDR, LRESULT* pResult) {
NMTTDISPINFO* pInfo = (NMTTDISPINFO*)pNMHDR;
lstrcpy(pInfo->szText, "Corner");
pInfo->lpszText = pInfo->szText;
m_nTipText++;
*pResult = 0;
}
/// Counts TTN_SHOW of the rectangle tool.
afx_msg void OnTipShow(NMHDR* pNMHDR, LRESULT* pResult) {
(void)pNMHDR;
m_nTipShow++;
*pResult = 0;
}
/// Counts TTN_POP of the rectangle tool.
afx_msg void OnTipPop(NMHDR* pNMHDR, LRESULT* pResult) {
(void)pNMHDR;
m_nTipPop++;
*pResult = 0;
}
/// Counts EN_CHANGE of the hot key control.
afx_msg void OnHotKeyChange() { m_nHotKeyChange++; }
/// Counts IPN_FIELDCHANGED.
afx_msg void OnFieldChanged(NMHDR* pNMHDR, LRESULT* pResult) {
(void)pNMHDR;
m_nFieldChanged++;
*pResult = 0;
}
/// Gives the pager the width of its child for PGN_CALCSIZE.
afx_msg void OnCalcSize(NMHDR* pNMHDR, LRESULT* pResult) {
NMPGCALCSIZE* pCalc = (NMPGCALCSIZE*)pNMHDR;
if (pCalc->dwFlag & PGF_CALCWIDTH) pCalc->iWidth = 300;
m_nCalcSize++;
*pResult = 0;
}
/// Keeps the link of NM_CLICK.
afx_msg void OnLinkClick(NMHDR* pNMHDR, LRESULT* pResult) {
m_nLinkClick++;
m_iLastLink = ((NMLINK*)pNMHDR)->item.iLink;
*pResult = 0;
}
/// Counts CBEN_INSERTITEM.
afx_msg void OnCbInsertItem(NMHDR* pNMHDR, LRESULT* pResult) {
(void)pNMHDR;
m_nCbInserted++;
*pResult = 0;
}
/// Counts CBEN_DELETEITEM.
afx_msg void OnCbDeleteItem(NMHDR* pNMHDR, LRESULT* pResult) {
(void)pNMHDR;
m_nCbDeleted++;
*pResult = 0;
}
/// Counts MCN_SELCHANGE.
afx_msg void OnCalSelChange(NMHDR* pNMHDR, LRESULT* pResult) {
(void)pNMHDR;
m_nCalSelChange++;
*pResult = 0;
}
/// Counts DTN_DATETIMECHANGE.
afx_msg void OnDtChange(NMHDR* pNMHDR, LRESULT* pResult) {
(void)pNMHDR;
m_nDtChange++;
*pResult = 0;
}
/// Counts RBN_HEIGHTCHANGE.
afx_msg void OnRbHeightChange(NMHDR* pNMHDR, LRESULT* pResult) {
(void)pNMHDR;
m_nRbHeight++;
*pResult = 0;
}
/// Counts RBN_DELETEDBAND.
afx_msg void OnRbDeletedBand(NMHDR* pNMHDR, LRESULT* pResult) {
(void)pNMHDR;
m_nRbDeleted++;
*pResult = 0;
}
/// Counts RBN_BEGINDRAG, and lets the drag start.
afx_msg void OnRbBeginDrag(NMHDR* pNMHDR, LRESULT* pResult) {
(void)pNMHDR;
m_nRbBeginDrag++;
*pResult = 0;
}
/// Counts RBN_ENDDRAG.
afx_msg void OnRbEndDrag(NMHDR* pNMHDR, LRESULT* pResult) {
(void)pNMHDR;
m_nRbEndDrag++;
*pResult = 0;
}
DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
ON_WM_HSCROLL()
ON_WM_VSCROLL()
ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN, OnDeltaPos)
ON_NOTIFY(TCN_SELCHANGING, IDC_TAB, OnSelChanging)
ON_NOTIFY(TCN_SELCHANGE, IDC_TAB, OnSelChange)
ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST, OnItemChanged)
ON_NOTIFY(TVN_ITEMEXPANDING, IDC_TREE, OnItemExpanding)
ON_NOTIFY(TVN_SELCHANGED, IDC_TREE, OnTreeSelChanged)
ON_NOTIFY(TVN_DELETEITEM, IDC_TREE, OnTreeDeleteItem)
ON_NOTIFY(TTN_NEEDTEXT, IDT_RECT, OnTipNeedText)
ON_NOTIFY(TTN_SHOW, IDT_RECT, OnTipShow)
ON_NOTIFY(TTN_POP, IDT_RECT, OnTipPop)
ON_EN_CHANGE(IDC_HOTKEY, OnHotKeyChange)
ON_NOTIFY(IPN_FIELDCHANGED, IDC_IPADDR, OnFieldChanged)
ON_NOTIFY(PGN_CALCSIZE, IDC_PAGER, OnCalcSize)
ON_NOTIFY(NM_CLICK, IDC_LINK, OnLinkClick)
ON_NOTIFY(CBEN_INSERTITEM, IDC_COMBOEX, OnCbInsertItem)
ON_NOTIFY(CBEN_DELETEITEM, IDC_COMBOEX, OnCbDeleteItem)
ON_NOTIFY(MCN_SELCHANGE, IDC_MONTHCAL, OnCalSelChange)
ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DATETIME, OnDtChange)
ON_NOTIFY(RBN_HEIGHTCHANGE, IDC_REBAR, OnRbHeightChange)
ON_NOTIFY(RBN_DELETEDBAND, IDC_REBAR, OnRbDeletedBand)
ON_NOTIFY(RBN_BEGINDRAG, IDC_REBAR, OnRbBeginDrag)
ON_NOTIFY(RBN_ENDDRAG, IDC_REBAR, OnRbEndDrag)
ON_CONTROL(ACN_START, IDC_ANIMATE, OnAnimStart)
ON_CONTROL(ACN_STOP, IDC_ANIMATE, OnAnimStop)
END_MESSAGE_MAP()
class CTestApp : public CWinApp {
public:
/// Makes the main frame, runs the checks and closes the frame.
virtual BOOL InitInstance() {
CMainFrame* pFrame = new CMainFrame;
if (!pFrame->Create(NULL, "MFC Win16 common controls")) {
printf("FAIL Create\n");
return FALSE;
}
m_pMainWnd = pFrame;
pFrame->ShowWindow(m_nCmdShow);
pFrame->UpdateWindow();
pFrame->RunTests();
pFrame->DestroyWindow();
return TRUE;
}
/// Prints the result.
virtual int ExitInstance() {
CHECK(g_bDone);
printf(g_failures == 0 ? "ALL PASSED\n" : "FAILED %d\n", g_failures);
return CWinApp::ExitInstance();
}
};
CTestApp theApp;