Presentation is loading. Please wait.

Presentation is loading. Please wait.

Tran Anh Tuan A.  Help to modify a control’s behavior by deriving classes of your own from the MFC control classes  Help to build reusable, self-contained.

Similar presentations


Presentation on theme: "Tran Anh Tuan A.  Help to modify a control’s behavior by deriving classes of your own from the MFC control classes  Help to build reusable, self-contained."— Presentation transcript:

1 Tran Anh Tuan A

2  Help to modify a control’s behavior by deriving classes of your own from the MFC control classes  Help to build reusable, self-contained control classes that respond to their own notification message  Modify: MFC Control Classes + Control Events  New Style of Controls

3  Numeric Edit Controls  Owner-Draw List Boxes  Graphical Push Buttons  Customizing a Control’s Colors

4  A normal edit control accepts a wide range of characters, including numbers, letters of the alphabet, and punctuation symbols.  A numeric edit control accepts only numbers. It's perfect for entering phone numbers, serial numbers, IP addresses, and other numeric data.

5  Example : Create an edit control which allows user input Student ID and the length must be 7 characters.

6  Step 1 : New a class name : CNumEdit that is derived from MFC Classes CEdit

7  When an edit control has the input focus and a character key is pressed, the control receives a WM_CHAR message.

8  Step 2: Code in OnChar function to make the constrains

9  Step 3 : Create variable for a object from class CNumEdit in class Dialog

10  Transfer of data between a control in a dialog box and a data member.  Result in running:

11  By default, items in a list box consist of strings of text. Should you need a list box that displays graphical images instead of text, you can create an owner-draw list box—one whose contents are drawn by your application, not by Windows—by following two simple steps. ◦ Derive a new list box class from CListBox, and override CListBox::MeasureItem and CListBox::DrawItem. Also override PreCreateWindow, and make sure that either LBS_OWNERDRAWFIXED or LBS_OWNERDRAWVARIABLE is included in the list box style. ◦ Instantiate the derived class, and use Create or CreateEx to create the list box.

12  Example: Create a Graphical ListBox and show the Graphical Image when choose a Item in ListBox

13  Step 1: Design the Dialog with a ListBox and Picture Control  Remember : in the ListBox ◦ Owner Draw : Variable ◦ Has strings : Check

14  Step 2 : In Resource Tab. Insert Bitmap and remember these bitmap ID for later using

15  Choose a series of bmp Image in your Drives

16  Step 3: Create a new class COwnerDrawListBox to customize your ListBox

17  Add needed functions into the class

18  Make the code to customize the ListBox

19

20  Step 4: Add a object variable from COwnerDrawListBox into Class Dialog and make the transfer of data.

21  OnInitDialog : I do AddItem into Custom ListBox

22  Step 5: When Choose a Item In ListBox. Image will be showed. Remember Event LBN_SELCHANGE for ListBox

23  Create control variable m_samplePic for Picture control and :

24  Result :

25  Two button styles that were first introduced in Windows 95—BS_BITMAP and BS_ICON— make graphical push buttons a breeze by taking a single image and creating a push button from it.  A BS_BITMAP-style push button (henceforth, a bitmap push button) displays a bitmap on the face of a push button.  A BS_ICON-style push button (an icon push button) displays an icon.

26  Example : change the button OK and Cancel into Graphical ones  Step 1: Insert new Icons into resource

27  Step 2: Change the properties of two button and add control valuable for them

28  Step 3: Make the code change apperance of OK and Cancel button in OnInitDialog

29  MFC supports two mechanisms for changing a control's colors. Both rely on the fact that before a control paints itself, it sends its parent a message containing the handle of the device context used to do the painting.  The parent can call CDC::SetTextColor and CDC::SetBkColor on that device context to alter the attributes of any text drawn by the control. It can also alter the control's background color by returning a brush handle (HBRUSH).

30  Example : Change the background and text of input Name value for Edit Box  Step 1: Create Class CEditColor Derived from CEdit and Add variable about color and function ton change them into class

31

32  Remember : Event WM_CTLCOLOR

33

34  Step 2: Make the Transfer Data and change color in OnInitDialog

35  Result :

36


Download ppt "Tran Anh Tuan A.  Help to modify a control’s behavior by deriving classes of your own from the MFC control classes  Help to build reusable, self-contained."

Similar presentations


Ads by Google