MFCC Common class Introduction

Source: Internet
Author: User
Tags function prototype

Http://www.cnblogs.com/lzmfywz/archive/2012/04/22/2465069.html

CStatic

CObject

└ccmdtarget

└cwnd

└cstatic

The CStatic class provides the performance of a Windows static control. A static control is used to display a text string, a box, a rectangle, an icon, a cursor, a bitmap, or an enhanced metafile. It can be used as a label, a box, or to separate other controls. A static control does not receive input, nor does it provide output, but if it is created in a ss_notify style, it can notify its parent of a message about the device's click. Create a static control in two steps. First, call the constructor to construct this CStatic object, and then call the Create member function to create the static control and connect it to the CStatic object. If you created a static control (through a dialog resource) in a dialog box, the CStatic object is automatically destroyed when the user closes the dialog box. If you created a CStatic object in a window, you must destroy it. The CStatic object created in the stack of a window is automatically destroyed. If you are using the new function to create a CStatic object in the heap, you must call Delete to destroy the CStatic object when you are done using it.

#include <afxwin.h>

Please refer to:

Cwnd,cbutton,ccombobox,cedit,clistbox,cscrollbar,cdialog

CStatic Class Members

Structure

CStatic

Constructs a CStatic object

Initialization

Create

Create a Windows static control and connect it to the CStatic object

Operator

SetBitmap

Specifies the bitmap to display in this static control

Getbitmap

Gets the handle of the bitmap previously set with SetBitmap

SetIcon

Specify an icon to display in this static control

GetIcon

Gets the handle of the icon previously set with SetIcon

SetCursor

Specifies the cursor image to display in this static control

GetCursor

Gets the handle of the cursor image previously set with SetCursor

Setenhmetafile

Specifies the enhanced metafile to display in this static control

GetEnhMetaFile

Gets the handle to the enhanced metafile previously set with Setenhmetafile

CEdit

CObject

└ccmdtarget

└cwnd

└cedit

The CEdit class provides functionality in the Windows edit control. The edit control is a child window rectangle where the user can enter text.

You can create an edit control from a dialog template or directly from your code. In both cases, first call the CEdit constructor to construct the CEdit object, and then call the Create member function to create the Windows edit control and connect it to the CEdit object.

Constructs can be implemented in a single step in a derived class of CEdit. Write the constructor for the derived class and call create from the constructor.

CEdit inherits important functionality from CWnd, to set or get the text in the CEdit object, using CWnd member functions SetWindowText and GetWindowText, you can set and get the entire contents of the edit control, even if it is a multiline control. If the edit control is multiline, use the CEdit member function Getline,getsel,getsel and Replacesel to get and write part of the text of the control.

If you want to handle the notification message for the edit control to its parent class (typically a CDialog-derived class), add a message-map entry and a message-handling member function to the parent class for each message.

Each message map entry can take the following form:

On_notification (ID,MEMBERFXN)

Where ID specifies the name of the parent member function that sends a notification to the Edit Control's child window ID,MEMBERFXN for the processing notification that you have written.

The parent function has the following form:

AFX_MSGVOIDMEMBERFXN ();

The following is a set of possible message-map portals, and in which case a description is sent to the parent class:

·

On_en_change

Actions taken by the user may change the text of the edit control. Unlike the EN_UPDATE notification message, this notification is sent after the Windows Update is displayed.

·

On_en_errspace

The edit control cannot allocate enough space for a specific request.

·

On_en_hscroll

The user clicked the horizontal scroll bar in the edit control, and the parent window was notified before the screen was updated.

·

On_en_killfocus

The edit control loses the input focus.

·

On_en_maxtext

The current input exceeds the number specified for the edit control and is truncated. A message is sent when the edit control does not have a on_en_hscroll style and the character to be entered exceeds the width of the edit control. A message is also sent when the edit control does not have a on_en_vscroll style and the character to be entered exceeds the height of the edit control.

·

On_en_setfocus

The edit control gets the focus.

·

On_en_update

The edit control will display the changed text. Sends a message after the control has formatted the text but before the text is displayed so that the window size is changed if necessary.

·

On_en_vscroll

The user clicked the vertical scroll bar in the edit control, and the parent window was notified before the screen was updated.

If you create a CEdit object within a dialog box, the CEdit object is automatically deleted when the user closes the dialog box.

If you use the dialog editor to create a CEdit object from a dialog resource, the CEdit object is automatically deleted when the user closes the dialog box.

If you create a CEdit object within a window, you also need to delete it. If the CEdit object is created on the stack, it is automatically deleted. If you use the new function to create a CEdit object on the heap, you must call delete on it when the user aborts the edit control. If you allocate storage space in the CEdit object, overwrite the CEdit destructor to handle the assignment.

For more information on CEdit, see the "Control topics" in the online documentation, "Visualc++ Programmer's Guide."

#include <afxwin.h>

Please refer to:

Cwnd,cbutton,ccombobox,clistbox,cscrollbar,cstatic,cdialog

Members of the CEdit class

constructor function

CEdit

Constructs a CEdit control object

Create

Create a Windows edit control and connect it to the CEdit object

Property

CanUndo

Determines whether an edit control action can be undone

Getlinecount

Get the number of rows in a multiline edit control

GetModify

Determines whether the contents of the edit control are modified

Setmodify

Set or clear modify marks for an edit control

GetRect

Get a formatted rectangle for an edit control

GetHandle

Gets the handle of the memory allocated for the current multi-line edit control

SetHandle

A handle to the local memory that is set to use for multi-line edit controls

SetMargins

Set the left and right blank boundaries for CEdit

Getmargins

Get the left and right blank borders set for CEdit

Setlimittext

Sets the maximum amount of text that CEdit can hold

Getlimittext

Get the maximum amount of text that CEdit can hold

Posfromchar

Gets the coordinates of the upper-left corner of the specified character index

Charfrompos

Get the word closest and character index closest to the specified position

GetLine

Get a line of text from an edit control

Getpasswordchar

Gets the password that is displayed in the edit control when the user enters text

Getfirstvisibleleline

Determines the topmost visible row in the edit control

Operation

Emptyundobuffer

Reset (Clear) The undo tag of the edit control

Fmtlines

Set soft return on or off in multiple-line edit controls

Limittext

Text length limit for users when entering text

Linefromchar

Gets the number of rows that contain the specified character index

Lineindex

Gets the character index of a row in a multiple-line edit control

LineLength

Get the length of a row in an edit control

Linescroll

Scrolling text in a multi-line edit control

Replacesel

Overwrites the currently selected text in the edit control with the specified text

Setpasswordchar

Sets or clears the password that is displayed in the edit control when the user enters text

SetRect

Sets a formatted rectangle for a multiline edit control and updates the control

Setrectnp

Sets the formatted rectangle of a multiline edit control without having to redraw

SetSel

Select text in an Edit Control settabstops setting tab stops for multiple-line edit controls

Setreadonly

To set the read-only state for an edit control

Clipboard operations

Undo

Undo the last Edit control action

Clear

Delete (Clear) the currently selected text in the edit control

Copy

Copies the currently selected text in the edit control to the Clipboard in CF_TEXT format

Cut

Deletes the currently selected text in the edit control and copies the deleted text to the Clipboard in CF_TEXT format

Paste

Inserts the text inside the Clipboard at the current cursor position. Insert only if clipboard data is in CF_TEXT format

CButton

CObject

└ccmdtarget

└cwnd

└cbutton

The CButton class provides operations on the Windows button control. A button control is a small rectangular child window that can be selected by clicking (pressed) or unchecked. Buttons can be used alone or in groups, and they can have text captions as well. When the user clicks on it, the button usually changes the appearance of the display.

Typical button controls are: check box, radio button, and push-button (pushbutton). A CButton object can be one of them, which is determined by its button style and the initialization of the member function create.

In addition, the class Cbuttonbitmap is inherited from the class CButton, but it supports the image label of the button. A Cbuttonbitmap object can set different bitmaps for its four states (not pressed, pressed, focusable, and Forbidden), respectively.

You can either create a button control from a dialog template, or you can create it directly in your code.

In either case, you first call the constructor CButton to construct a CButton object, and then call the member function create creates a Windows button control and applies it to the CButton object.

In a class derived from class CButton, constructs can be completed in one step. Programmers can write a constructor for this derived class and invoke the CREATE function in it.

If you want to process a notification message for Windows, such as a message from a bitmap button control to its parent object (typically inherited from CDialog), include the message map entry in the parent object and the member function that processes each message.

The format for each message-map entry is as follows:

On_notification (ID,MEMBERFXN)

Where ID specifies the ID of the child window of the control that sent the notification, and MEMBERFXN specifies the name of the member function in the parent object that handles the notification.

The function prototype format of the parent object is as follows:

AFX_MSGVOIDMEMBERFXN ();

The possible message map portals are as follows:

Map Portal

When to send a message to a parent object

On_bn_clicked

When the user clicks the button

On_bn_doubleclicked

When the user double-clicks the button

If you create a CButton object in a dialog resource, the CButton object is automatically undone when the user closes the dialog box. If you create a CButton object in a window, you may need to undo it yourself. If you created the object in the heap of memory with the new function, you must undo it with the delete function when the user closes the Window button control. If you create the object in the stack, or if it is embedded in the parent dialog object, it is automatically undone.

#include <afxwin.h>

Please refer to:

Cwnd,ccombobox,cedit,clistbox,cscrollbar,cstatic,cbitmapbutton,cdialog

Members of the CButton class

constructor function

CButton

Constructs a CButton object

initialization function

Create

Create a Windows button control and apply it on a CButton object

Operation

GetState

Retrieves the selected state of a button control, the highlight state, and the gain focus state

SetState

Set the highlight state of a button control

Getcheck

Retrieves the selected state of a button control

SetCheck

Set the selected state of a button control

Getbuttonstyle

Retrieving the style of a button control

SetButtonStyle

Set the style of a button control

GetIcon

Retrieves an icon handle that was previously called SetIcon settings

SetIcon

Specify an icon to display on the button

Getbitmap

Retrieves a handle to a bitmap previously called SetBitmap settings

SetBitmap

Set the bitmap to display on the button

GetCursor

Retrieves a handle to the cursor image that was previously called SetCursor settings

SetCursor

Set the cursor image to be displayed on the button

Functions that can be overridden

DrawItem

You can override it to draw a custom CButton object

CFileDialog

CObject

└ccmdtarget

└cwnd

└cdialog

└ccommondialog

└cfiledialog

The CFileDialog class encapsulates the Windows Common File dialog box. The frequently used file dialogs provide a simple file opening and File Save dialog box that is consistent with Windows standards.

You can use CFileDialog in a way that the constructor provides, or you can derive your own dialog class from CFileDialog and write a constructor to suit your needs. In each case, the dialog box works just like the standard MFC dialog box. Because they are all derived classes of the Ccommondialog class.

To use CFileDialog, first construct an object with the CFileDialog constructor, and when you have created a dialog box, you can set or modify any value in the M_OFN structure to initialize the value or state of the dialog box control. The M_OFN structure is of the openfilename type. For more information, refer to the OPENFILENAME structure in the online documentation "WIN32SDK".

After initializing the dialog box control, call the DoModal member function to display the dialog box and enable the user to enter the path and file. DoModal returns whether the user selects the OK (IDOK) or Cancel (IDCANCEL) button.

When DoModal returns IDOK, you can use the public member function of one of the CFileDialog to get the information entered by the user.

CFileDialog contains a number of protection members that allow you to handle common sharing conflicts, file name legality checks, and list box change notifications. These protection members are of little use to many applications because the default processing is automatic. For these functions, the message-map portals are unnecessary because they are standard virtual functions.

You can use the Windowscommdlgextenderror function to determine whether an error occurred during the initialization of the dialog box and to obtain more information about the error.

Destructors a CFileDialog object is automatic without calling Cdialog::enddialog.

To enable users to select multiple files, set the OFN_ALLOWMULTISELECT flag before calling DoModal. You should provide a file name buffer to place a list of multiple filenames that are returned, which is done by replacing m_ofn.lpstrfile with an assigned buffer pointer, before calling DoModal after the CFileDialog has been created. In addition, you must set M_ofn.nmaxfile with the number of buffer bytes that m_ofn.lpstrfile points to.

CFileDialog relies on the COMMDLG.DLL in Windows3.1 and later versions.

If a new class is derived from CFileDialog, the message map can be used for processing. To extend message processing, derive a class from CWnd, add a message map to the new class, and provide a member function for the new message without having to provide a hook function to customize the dialog box.

To customize a dialog box, derive an object from CFileDialog, provide a custom dialog template, add a message map from the extension control, and process the notification message. Any unhandled messages are passed to the base class.

No need to customize the hook function.

To learn about using CFileDialog, refer to the "Common conversation class" in the online documentation "Visualc++ Programmer's Guide".

#include <afxdlgs.h>

Members of the CFileDialog class

Data members

M_ofn

Windowsopenfilename structure, providing access to basic file dialog parameters

constructor function

CFileDialog

Constructs a CFileDialog object operation

DoModal

Display a dialog box and enable the user to make a selection

GetPathName

Returns the full path of the selected file

GetFileName

Returns the filename of the selected file

Getfileext

Returns the extension file name of the selected file

GetFileTitle

Returns the title of the selected file

Getnextpathname

Returns the full path of the next selected file

Getreadonlypref

Returns the read-only status of the selected file

GetStartPosition

Returns the first element position of a list of file names

Functions that can be overridden

Onshareviolation

Called when a sharing violation occurs

Onfilenameok

Confirm the file name in the Type dialog box

Onlbselchangednotify

Called when the list box selection changes

Oninitdone

Handling Wm_notifycdn_initdone Messages

OnFileNameChange

Handling Wm_notifycdn_selchange Messages

Onfolderchange

Handling Wm_notifycdn_folderchange Messages

Ontypechange

Handling Wm_notifycdn_typechange Messages

CListBox

CObject

└ccmdtarget

└cwnd

└clistbox

The CListBox class provides the functionality of a Windows list box. A list box displays a list of items, such as the name of the file that the user can see and select.

In the single-selection list box, the user can select only one item. In the Multiple-selection list box, you can select many items. When the user selects an item, it is highlighted and the list box sends a notification message to the parent window.

You can create a list box from a dialog template or directly in your code. When created directly, construct the CListBox object, and then call the Create member function to create a Windows ListBox control and attach it to the CListBox object. To use a list box in a dialog template, you declare a CListBox variable in the dialog class, and then use DDX_ in the DoDataExchange of the dialog box class Control connects member variables to this control (ClassWizard is automatically implemented for you when you add a control variable to a dialog Class).

A constructor can be a single-step process for a class derived from CListBox. Write the constructor for the derived class and call create from it.

If you are processing a Windows notification message that is sent by a list box to its father (typically a class derived from CDialog), add a message map entry and a message-handling member function to the parent class for each message.

Each message-map entry has the following form:

On_notification (ID,MEMBERFXN)

The ID specifies the child window of the list box control that sends the notification, MEMBERFXN is the place to write the name of the parent member function that handles the notification.

The parent function prototype is as follows:

AFX_MSGVOIDMEMBERFXN ();

Below is a list of possible message-map portals and descriptions of what they might be sent to the father:

On_lbn_dblclk

The user double-clicks the string in the list box. Only the Lbs_notify-style list box will send this notification message.

On_lbn_errspace

The list box cannot reassign enough memory to satisfy the request.

On_lbn_killfocus

The list box is losing input focus.

On_lbn_selcancel

The current list box selection is canceled. This message is sent only if the list box is lbs_notify style.

On_lbn_selchange

The selection in the list box may change. If you choose to be changed by the Clistbox::setcursel member function, the notification is not sent. This notification applies only to Lbs_notify-style list boxes. The LBN_SELCHANGE notification message is sent to the multiple-selection list box whenever the user presses the arrow keys, even if the selection is not changed.

On_lbn_setfocus

The list box is receiving input focus.

On_wm_chartoitem

A non-string self-drawing list accepts WM_CHAR messages.

On_wm_vkeytoitem

The Lbs_wantkeyboardinput-style list box accepts WM_KEYDOWN messages.

If you construct a CListBox object (through a dialog resource) in a dialog box, the CListBox object automatically destroys when the user closes the dialog box.

If you construct a CListBox object in a window, you may need to destroys the CListBox object. If the CListBox object is created on the stack, it is automatically destroys. If you use the new function to create a CListBox object on the heap, you must call delete on the object to destroys it when the user closes the parent window.

If you allocate memory in a CListBox object, you can override the CListBox destructor to release the allocated memory.

#include <afxwin.h>

Please refer to: cwnd,cbutton,ccombobox,cedit,cscrollbar,cstatic

Members of the CListBox class

constructor function

CListBox

Constructs a CListBox object

Initialization

Create

Create a Windows list box and attach to the CListBox object

InitStorage

Pre-allocating memory blocks for list box items and strings

General operation

GetCount

Returns the number of strings in a list box

Gethorizontalextent

Returns the horizontal width of the list box, expressed in pixels

SetHorizontalExtent

Sets the horizontal width of the list box, expressed in pixels

Gettopindex

Returns the index of the first visible string in a list box

Settopindex

Sets the zero-based index of the first visible string in a list box

GetItemData

Returns the 32-bit value associated with a list box

Getitemdataptr

Returns a pointer to a list box

SetItemData

Set the 32-bit value for a list box

SetItemDataPtr

Set a pointer to a list box

GetItemRect

Returns the corresponding rectangle for the currently displayed list box item

Itemfrompoint

Returns the index of the list box item closest to a point

SetItemHeight

Set the height of items in a list box

GetItemHeight

Determines the height of items in a list box

GetSel

Returns the selection of an item in a list box

GetText

Copy a list box item to a buffer

GetTextLen

Returns the byte length of the list box

Setcolumnwidth

Set the column width of a multicolumn list box

SetTabStops

Set list box tab stop position

GetLocale

Gets the location identifier of the list box

SetLocale

Set the location identifier for a list box

Single-selection operation

GetCurSel

Returns the zero-based index of the current selection string in the list box

SetCurSel

Select a list box string

Multi-Select operation

SetSel

Select or uncheck a list box item in a multiple-selection list box

Getcaretindex

Determines the index of the item that has the focus rectangle in the multiple-selection list box

Setcaretindex

Sets the focus rectangle to the specified index entry in the Multiple-selection list box

Getselcount

Returns the number of currently selected strings in a multiple-selection list box

Getselitems

Returns the index of the currently selected string in the list box

Selitemrange

Select/Uncheck some strings in the Multiple-selection list box

Setanchorindex

Set the anchor point of a multiple-selection list box to begin the extended selection

Getanchorindex

Gets the zero-based index of the current anchor point item in the list box

String manipulation

AddString

Add a string to the list box

DeleteString

Remove a string from the list box

Insertstring

Inserts a string in the specified position in the list box

Resetcontent

Empty list box all entrances

Dir

Add a file name to the list box from the current directory

FindString

Find a string in a list box

FindStringExact

Finds the first list box string that matches a specified string

SelectString

Find and select a string in a single-selection list box

Functions that can be overridden

DrawItem

Called by the framework when a visible part of the self-drawn list box changes

MeasureItem

Called by the framework to determine the dimension of a list box when it is created from a draw list box

CompareItem

Called by the framework to determine the position of a new item in a series of list boxes

DeleteItem

Called by the framework when a user deletes an item from the Draw list box

Vkeytoitem

Overrides the custom Wm_keydown required to provide settings for the Lbs_wantkeyboardinput style list box

Chartoitem

Overwrite to provide self-drawing list box without string custom WM_CHAR

CCheckListBox

CObject

└ccmdtarget

└cwnd

└clistbox

└cchecklistbox

Class CCheckListBox implements the Windows Check list box. A check list box displays a list of items, such as the file name lists. Each item in the list has a check box.

CCheckListBox is used only for custom controls, and the list contains more than just string literals.

Of course a simple check list box can have only string literals and corresponding check boxes. You can actually have no text. For example, it can be a bitmap and a list corresponding to the check box.

Create your own check list box to derive a subclass from the class CCheckListBox. Then write a constructor for it and call the member function create.

If the Check list box is in the default form (consisting of a string with a fixed-size check box on the left), you can draw a check list box with the default cchecklistbox::D rawitem function. Otherwise, the function Clistbox::compareitem, CCheckListBox::D Rawitem and Cchecklistbox::meas-ureitem will be overwritten.

You can create a check list box directly in a dialog box template or in your program code.

#include <afxwin.h>

Please refer to: CListBox

Members of the CCheckListBox class

constructor function

CCheckListBox

Constructs a CCheckListBox object

Create

Create a Windows Check list box and apply it to the CCheckListBox object

Property functions

Setcheckstyle

Set the style of the control's check box

Getcheckstyle

Gets the style of the control's check box

SetCheck

Set the state of a check box for an item

Getcheck

Gets the state of a check box for an item

Enable

Allow or disallow access to an item

IsEnabled

Detects if an item is allowed access

OnGetCheckPosition

Called by the framework to get the state of a check box for an item

Functions that can be overridden

DrawItem

Called by the framework when a visual property of a custom list box changes

MeasureItem

Called by the framework when the style of a custom list box changes

MFCC Common class Introduction

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.