CWordArray Class

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at CWordArray Class.

Supports arrays of 16-bit words.

class CWordArray : public CObject  

The member functions of CWordArray are similar to the member functions of class CObArray. Because of this similarity, you can use the CObArray reference documentation for member function specifics. Wherever you see a CObject pointer as a function parameter or return value, substitute a WORD.

CObject* CObArray::GetAt( int <nIndex> ) const;

for example, translates to

WORD CWordArray::GetAt( int <nIndex> ) const;

Public Constructors

NameDescription
CObArray::CObArrayConstructs an empty array.

Public Methods

NameDescription
CObArray::AddAdds an element to the end of the array; grows the array if necessary.
CObArray::AppendAppends another array to the array; grows the array if necessary.
CObArray::CopyCopies another array to the array; grows the array if necessary.
CObArray::ElementAtReturns a temporary reference to the element pointer within the array.
CObArray::FreeExtraFrees all unused memory above the current upper bound.
CObArray::GetAtReturns the value at a given index.
CObArray::GetCountGets the number of elements in this array.
CObArray::GetDataAllows access to elements in the array. Can be NULL.
CObArray::GetSizeGets the number of elements in this array.
CObArray::GetUpperBoundReturns the largest valid index.
CObArray::InsertAtInserts an element (or all the elements in another array) at a specified index.
CObArray::IsEmptyDetermines if the array is empty.
CObArray::RemoveAllRemoves all the elements from this array.
CObArray::RemoveAtRemoves an element at a specific index.
CObArray::SetAtSets the value for a given index; array not allowed to grow.
CObArray::SetAtGrowSets the value for a given index; grows the array if necessary.
CObArray::SetSizeSets the number of elements to be contained in this array.

Public Operators

NameDescription
CObArray::operator []Sets or gets the element at the specified index.

CWordArray incorporates the [IMPLEMENT_SERIAL]--brokenlink--(../Topic/not%20found.md#implement_serial) macro to support serialization and dumping of its elements. If an array of words is stored to an archive, either with an overloaded insertion operator or with the CObject::Serialize member function, each element is, in turn, serialized.

System_CAPS_ICON_note.jpg Note

Before using an array, use SetSize to establish its size and allocate memory for it. If you do not use SetSize, adding elements to your array causes it to be frequently reallocated and copied. Frequent reallocation and copying are inefficient and can fragment memory.

If you need a dump of individual elements in the array, you must set the depth of the dump context to 1 or greater.

For more information on using CWordArray, see the article Collections.

CObject

CWordArray

Header: afxcoll.h

Manages commands sent from a command source object to a user control.

interface class ICommandSource  

Remarks

When you host a user control in an MFC View, CWinFormsView Class routes commands and update command UI messages to the user control to allow it to handle MFC commands (for example, frame menu items and toolbar buttons). By implementing , you give the user control a reference to the ICommandSource object.

See How to: Add Command Routing to the Windows Forms Control for an example of how to use ICommandTarget.

For more information on using Windows Forms, see Using a Windows Form User Control in MFC.

Adds a command handler to a command source object.

void AddCommandHandler(
    unsigned int cmdID,  
    CommandHandler^ cmdHandler);

Parameters

cmdID
The command ID.

cmdHandler
A handle to the command handler method.

Remarks

This method adds the command handler cmdHandler to the command source object and maps the handler to cmdID.

See How to: Add Command Routing to the Windows Forms Control for an example of how to use AddCommandHandler.

Adds a group of command handlers to a command source object.

void AddCommandRangeHandler(
    unsigned int cmdIDMin,  
    unsigned int cmdIDMax,  
    CommandHandler^ cmdHandler);

Parameters

cmdIDMin
The beginning index of the command ID range.

cmdIDMax
The ending index of the command ID range.

cmdHandler
A handle to the message handler method to which the commands are mapped.

Remarks

This method maps a contiguous range of command IDs to a single message handler and adds it to the command source object. This is used for handling a group of related buttons with one method.

Adds a group of user interface command message handlers to a command source object.

void AddCommandRangeUIHandler(
    unsigned int cmdIDMin,   
    unsigned int cmdIDMax,   
    CommandUIHandler^ cmdUIHandler);

Parameters

cmdIDMin
The beginning index of the command ID range.

cmdIDMax
The ending index of the command ID range.

cmdHandler
A handle to the message handler method to which the commands are mapped.

Remarks

This method maps a contiguous range of command IDs to a single user interface command message handler and adds it to the command source object. This is used for handling a group of related buttons with one method.

Adds a user interface command message handler to a command source object.

void AddCommandUIHandler(
    unsigned int cmdID,   
    CommandUIHandler^ cmdUIHandler);

Parameters

cmdID
The command ID.

cmdUIHandler
A handle to the user interface command message handler method.

Remarks

This method adds the user interface command message handler cmdHandler to the command source object and maps the handler to cmdID.

Posts a message without waiting for it to be processed.

void PostCommand(unsigned int command);

Parameters

command
The command ID of the message to be posted.

Remarks

This method asynchronously posts the message mapped to the ID specified by command. It calls CWnd::PostMessage to place the message in the window's message queue and then returns without waiting for the corresponding window to process the message.

Removes a command handler from a command source object.

void RemoveCommandHandler(unsigned int cmdID);

Parameters

cmdID
The command ID.

Remarks

This method removes the command handler mapped to cmdID from the command source object.

Removes a group of command handlers from a command source object.

void RemoveCommandRangeUIHandler(
    unsigned int cmdIDMin,  
    unsigned int cmdIDMax);

Parameters

cmdIDMin
The beginning index of the command ID range.

cmdIDMax
The ending index of the command ID range.

Remarks

This method removes a group of message handlers, mapped to the command IDs specifed by cmdIDMin and cmdIDMax, from the command source object.

Removes a group of user interface command message handlers from a command source object.

void RemoveCommandRangeUIHandler(
    unsigned int cmdIDMin,  
    unsigned int cmdIDMax);

Parameters

cmdIDMin
The beginning index of the command ID range.

cmdIDMax
The ending index of the command ID range.

Remarks

This method removes a group of user interface command message handlers, mapped to the command IDs specifed by cmdIDMin and cmdIDMax, from the command source object.

Removes a user interface command message handler from a command source object.

void RemoveCommandUIHandler(unsigned int cmdID);

Parameters

cmdID
The command ID.

Remarks

This method removes the user interface command message handler mapped to cmdID from the command source object.

Sends a message and waits for it to be processed before returning.

void SendCommand(unsigned int command);

Parameters

command
The command ID of the message to be sent.

Remarks

This method synchronously sends the message mapped to the ID specified by command. It calls CWnd::SendMessage to place the message in the window's message queue and waits until that window procedure has processed the message before returning.

Provides a user control with an interface to receive commands from a command source object.

interface class ICommandTarget  

Remarks

When you host a user control in an MFC View, CWinFormsView routes commands and update command UI messages to the user control to allow it to handle MFC commands (for example, frame menu items and toolbar buttons). By implementing ICommandTarget, you give the user control a reference to the object.

See How to: Add Command Routing to the Windows Forms Control for an example of how to use ICommandTarget.

For more information on using Windows Forms, see Using a Windows Form User Control in MFC.

Initializes the command target object.

void Initialize(ICommandSource^ cmdSource);

Parameters

cmdSource
A handle to the command source object.

Remarks

When you host a user control in an MFC View, CWinFormsView routes commands and update command UI messages to the user control to allow it to handle MFC commands.

This method initializes the command target object and associates it with the specified command source object cmdSource. It should be called in the user control class implementation. At initialization, you should register command handlers with the command source object by calling ICommandSource::AddCommandHandler in the Initialize implementation. See [How to: Add Command Routing to the Windows Forms Control]--brokenlink--(../Topic/not%20found.md#how_to__add_command_routing_to_the_windows_forms_control) for an example of how to use Initialize to do this.

Manages user interface commands.

interface class ICommandUI  

Remarks

This interface provides methods and properties that manage user interface commands. ICommandUI is similar to CCmdUI Class, except that ICommandUI is used for MFC applications that interoperate with .NET components.

ICommandUI is used within an ON_UPDATE_COMMAND_UI handler in an -derived class. When a user of an application activates (selects or clicks) a menu, each menu item is displayed as enabled or disabled. The target of each menu command provides this information by implementing an ON_UPDATE_COMMAND_UI handler. For each of the command user interface objects in your application, use the Properties window to create a message-map entry and function prototype for each handler.

For more information on how the ICommandUI interface is used in command routing, see How to: Add Command Routing to the Windows Forms Control.

For more information on using Windows Forms, see Using a Windows Form User Control in MFC.

For more information on how user interface commands are managed in MFC, see CCmdUI Class.

Sets the user interface item for this command to the appropriate check state.

property UICheckState Check;  

Remarks

This property sets the user interface item for this command to the appropriate check state. Set Check to the following values:

TermDefinition
0Uncheck
1Check
2Set indeterminate

Tells the command routing mechanism to continue routing the current message down the chain of handlers.

void ContinueRouting();

Remarks

This is an advanced member function that should be used in conjunction with an ON_COMMAND_EX handler that returns FALSE. For more information, see Technical Note TN006: Message Maps.

Enables or disables the user interface item for this command.

property bool Enabled;  

Remarks

This property enables or disables the user interface item for this command. Set Enabled to TRUE to enable the item, FALSE to disable it.

Gets the ID of the user interface object represented by the ICommandUI object.

property unsigned int ID;  

Remarks

This property gets the ID (a handle) of the menu item, toolbar button, or other user interface object represented by the ICommandUI object.

Gets the index of the user interface object represented by the ICommandUI object.

property unsigned int Index;  

Remarks

This property gets the index (a handle) of the menu item, toolbar button, or other user interface object represented by the ICommandUI object.

Sets the user interface item for this command to the appropriate check state.

property bool Radio;  

Remarks

This property sets the user interface item for this command to the appropriate check state. Set Radio to TRUE to enable the item; otherwise FALSE.

Sets the text of the user interface item for this command.

property String^ Text;  

Remarks

This property sets the text of the user interface item for this command. Set Text to a text string handle.

Implements several methods that CWinFormsView uses to send view notifications to a managed control.

interface class IView  

Remarks

IView implements several methods that CWinFormsView uses to forward common view notifications to a hosted managed control. These are OnInitialUpdate, OnUpdate and OnActivateView.

IView is similar to CView, but is used only with managed views and controls.

For more information on using Windows Forms, see Using a Windows Form User Control in MFC.

Called by MFC when a view is activated or deactivated.

void OnActivateView(bool activate);

Parameters

activate
Indicates whether the view is being activated or deactivated.

Called by the framework after the view is first attached to the document, but before the view is initially displayed.

void OnInitialUpdate();

Called by MFC after the view's document has been modified.

void OnUpdate();

Remarks

This function allows the view to update its display to reflect modifications.

MFC Sample COLLECT
CObject Class
Hierarchy Chart

Show: