Note: How to make WTL available
CMenu menu; menu.Attach( LoadMenu( _Module.GetResourceInstance(), MAKEINTRESOURCE(IDR_MENU1)));
TestWin.Create( NULL, rcPos, _T("Name Goes Here"), 0, 0, (HMENU)menu);
BEGIN_MSG_MAP(CATLWindow) MESSAGE_HANDLER( WM_CLOSE, OnClose) // to link a method per item: COMMAND_ID_HANDLER( ID_MENU_ITEM_1, OnMenuItem1) COMMAND_ID_HANDLER( ID_MENU_ITEM_2, OnMenuItem1) // to make a handler for all messages at once: MESSAGE_HANDLER( WM_COMMAND, OnMenu) END_MSG_MAP()
LRESULT OnMenuItem1( WORD code, WORD id, HWND hwnd, BOOL& bHandled)
{
return 0;
}
LRESULT OnMenu( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
PostQuitMessage(0);
return 0;
}
#include "atlcontrols.h"
// If Default buttons are removed, remember to remove (and the functions):
COMMAND_HANDLER(IDOK, BN_CLICKED, OnClickedOK)
COMMAND_HANDLER(IDCANCEL, BN_CLICKED, OnClickedCancel)
NOTE: This no longer appears to be valid
// If ActiveX controls don't need to be hosted,
// This:
class CTestDialog :
public CAxDialogImpl<ctestdialog>
// Can be replaced with this:
class CTestDialog :
public CDialogImpl<ctestdialog>
Note: Set bHandled to false
if you would like to tell the message handling system to continue passing the
message on to other handlers (or leave it true to signal that you
have processed the message, and no other handlers need to see it).
BEGIN_MSG_MAP(CMainCtrl)
MESSAGE_HANDLER( WM_PAINT, OnPaint)
MESSAGE_HANDLER( WM_SETFOCUS, OnSetFocus)
MESSAGE_HANDLER( WM_KILLFOCUS, OnKillFocus)
MESSAGE_HANDLER( WM_CREATE, OnCreate)
// Routes other messages to the chained MSG_MAP:
CHAIN_MSG_MAP(CMoreMainCtrl)
ALT_MSG_MAP(1)
MESSAGE_HANDLER( WM_LBUTTONDBLCLK, OnLButtonDblClick)
ALT_MSG_MAP( {AltMsgMapIdNumber} )
...
END_MSG_MAP
| Macro | Parameters |
|---|---|
| MESSAGE_HANDLER | msg, func |
| MESSAGE_RANGE_HANDLER | msgFirst, msgLast, func |
| COMMAND_HANDLER | id, code, func |
| COMMAND_ID_HANDLER | id, func |
| COMMAND_CODE_HANDLER | code, func |
| COMMAND_RANGE_HANDLER | idFirst, idLast, func |
| NOTIFY_HANDLER | id, code, func |
| NOTIFY_CODE_HANDLER | code, func |
| NOTIFY_RANGE_HANDLER | idFirst, idLast, func |
| Parameter | Description |
|---|---|
| msg | The message to handle. |
| func | The handler function. |
| msgFirst, msgLast | A range of messages to handle. (?inclusive?) |
| id | The identifier for the menu item, control, or accelerator. |
| code | The notification code. |
| idFirst, idLast | A range of identifiers of message sources whose messages will be handled |
| Handler Type | Function Signature |
|---|---|
| MESSAGE | LRESULT MessageHandler( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) |
| COMMAND | LRESULT CommandHandler( WORD wNotifyCode, WORD wId, HWND hWndCtl, BOOL& bHandled) |
| NOTIFY | LRESULT NotifyHandler( int idCtrl, LPNMHDR pnmh, BOOL& bHandled) |
| Macro | Parameters | Description |
|---|---|---|
| CHAIN_MSG_MAP | theChainClass | Routes the message to the default message map in a base class. |
| CHAIN_MSG_MAP_ALT | theChainClass, msgMapID | Routes the message to an alternate message map in a base class. |
| CHAIN_MSG_MAP_MEMBER | theChainMember | Routes the message to the default meassge map in a data member. |
| CHAIN_MSG_MAP_ALT_MEMBER | theChainMember | Routes the message to an alternate meassge map in a data member. |
| CHAIN_MSG_MAP_DYNAMIC | dynaChainId | Routes the message to the default message map of a member that is determined at runtime |
| Parameter | Description |
|---|---|
| theChainClass | Base class containing the message map. |
| msgMapId | Alternate message map identifier. |
| theChainMember | A data member that has a message map. |
| dynaChainId | Identifies an object with a message map. |
To use CHAIN_MSG_MAP_DYNAMIC the class defining the MSG_MAP must
derive from CDynamicChain. It should use
BOOL SetChainEntry( DWORD dwChainId, CMessageMap* pObject, DWORD dwMsgMapId = 0)
to set where chainging for the registered
id needs to go (the destination can be set [?and changed?] dynamically at run time)
How is it used?? Somehow sends the original message plus OCM_BASE and sends it
back to the child control that sent it.
| Macro | Description |
|---|---|
| DEFAULT_REFLECTION_HANDLER | A default handler for reflected messages that you can place in the message map of the child control. |
| REFLECT_NOTIFICATIONS | When encountered in the message map of the parent, this macro will cause a message to be reflected back to the child conrol whose identifier is specified in the message. |
// DO NOT USE #include <windows.h>
// This part can go into stdafx.h:
#include <atlbase.h>
extern CComModule _Module;
#include <atlwin.h>
#include <atlcom.h>
//old way: #include <atlcontrols.h>
//old way: using namespace ATLControls;
#include <atlapp.h>
#include <atlctrls.h>
using namespace WTL;
// This should go into a .cpp file:
CComModule _Module;
class CATLWindow :
public CWindowImpl<CATLWindow, CWindow,
CWinTraits<WS_SIZEBOX | WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE, 0>
>
{
public:
CATLWindow()
{
}
~CATLWindow()
{
if (::IsWindow(m_hWnd) ) {
DestroyWindow();
}
}
BEGIN_MSG_MAP(CATLWindow)
MESSAGE_HANDLER( WM_CLOSE, OnClose)
END_MSG_MAP()
LRESULT OnClose( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
PostQuitMessage(0);
return 0;
}
};
int APIENTRY WinMain( HINSTANCE hInst, HINSTANCE /*Prev*/, LPSTR lpCmdLine, int nCmdShow)
{
_Module.Init( NULL, hInst);
CATLWindow TestWin;
RECT rcPos = { 0, 0, 300, 100 };
TestWin.Create( NULL, rcPos, _T("Name Goes Here"));
TestWin.ShowWindow(SW_SHOW);
MSG msg;
while( GetMessage(&msg, 0, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int) msg.wParam;
}
Get the header file atlcontrols.h and put it somewhere reachable, ...\Vc7\include
| Table 1: Wrapper classes | ||
| Class | Win32 class name | Description |
| CStatic | STATIC | Static label |
| CButton | BUTTON | Command button |
| CListBox | LISTBOX | List box |
| CDragListBox | LISTBOX | List box with support for dragging items |
| CComboBox | COMBOBOX | Combo box |
| CEdit | EDIT | Text box |
| CScrollBar | SCROLLBAR | Scroll bar |
| CRichEditCtrl | RICHEDIT | Rich edit control |
| CListViewCtrl | SysListView32 | List view, like the right-hand pane of Windows Explorer |
| CTreeViewCtrl | SysTreeView32 | Tree view, like the left-hand pane of Windows Explorer |
| CTreeViewCtrlEx | SysTreeView32 | Same as CTreeViewCtrl but uses the wrapper class CTreeItem rather than the raw HTREEITEM |
| CHeaderCtrl | SysHeader32 | Headers with resizable columns |
| CToolBarCtrl | ToolbarWindow32 | Tool bar positioned below a menu |
| CStatusBarCtrl | msctls_statusbar32 | Status bar positioned at the bottom of a window |
| CTabCtrl | SysTabControl32 | Tabs, like those used in a tabbed dialog |
| CToolTipCtrl | tooltips_class32 | Tool tip |
| CTrackBarCtrl | msctls_trackbar32 | A slider control used to set a value |
| CUpDownCtrl | msctls_updown32 | A control used to increment and decrement values |
| CProgressBarCtrl | msctls_progress32 | Visual progress indication |
| CHotKeyCtrl | msctls_hotkey32 | Used to specify that a key combination will perform some action |
| CAnimateCtrl | SysAnimate32 | Control used to play an AVI |
| CReBarCtrl | ReBarWindow32 | The fancy toolbars used by IE4 |
| CComboBoxEx | ComboBoxEx32 | A combo box that can have images for the items |
| CDateTimePickerCtrl | SysDateTimePick32 | An edit box-like control through which you can pick a date or time |
| CMonthCalendarCtrl | SysMonthCal32 | Control that shows a month’s dates |
| CIPAddressCtrl | SysIPAddress32 | An edit box-like control with four fields separated by dots |
| CPagerCtrl | SysPager | A control that allows you to ”scroll” another window |
| Table 2: Utility classes | |
| Class | Description |
| CImageList | Wraps an HIMAGELIST for use with list views and tree views |
| CTreeItem | Wraps a HTREEITEM, used with CTreeViewCtrlEx |
| CToolInfo | Wraps a TOOLINFO, used with CToolTipCtrl |
| CDragListNotifyImpl | Class used to handle notifications from a drag list box |
| CFlatScrollBar | Changes a window to use flat control bars |
| CCustomDraw | Class used to add custom draw support |