Presentation is loading. Please wait.

Presentation is loading. Please wait.

Classic Controls Trần Anh Tuấn A. Week 1 How to create a MFC project in VS 6.0 How to create a MFC project in VS 6.0 Introduction to Classic Controls.

Similar presentations


Presentation on theme: "Classic Controls Trần Anh Tuấn A. Week 1 How to create a MFC project in VS 6.0 How to create a MFC project in VS 6.0 Introduction to Classic Controls."— Presentation transcript:

1 Classic Controls Trần Anh Tuấn A

2 Week 1 How to create a MFC project in VS 6.0 How to create a MFC project in VS 6.0 Introduction to Classic Controls Introduction to Classic Controls

3 Initial Step : New a project with specific ProjectName, Location, and kind of Project Initial Step : New a project with specific ProjectName, Location, and kind of Project File > New File > New

4 Step 1 : Based on your purpose.This step will ask users type of Application (MDI, SDI, Dialog Based

5 Here are some example of MDI, SDI, Dialog Based

6 Step 2 & 3 : Some feature and support for user to include. (Recommend for default)

7

8 Step 4 : Confirm all information about class which will be created like : Class Name, Header File (.h), Implementation File (.cpp) and Base Class

9

10 When you finish, all your specifications will be showed.

11 Now we glance at something in our project

12 In Workspace Window we have three tabs to view project components Class View : List all Classes and corresponding Functions that are present in our Project.

13 You can insert new Class into your project by Right Mouse and New Class

14 There are three class type. MFC Class (a new class derived from any MFC Classes), MFC Class (a new class derived from any MFC Classes), Generic Class ( any new classes from user view) Generic Class ( any new classes from user view) Form Class (a new class derived from Dialog Class) Form Class (a new class derived from Dialog Class)

15 Resource View : List all resources that we use in our project. Resource View : List all resources that we use in our project. Here are some kinds of Resource Here are some kinds of Resource Dialog : resource for users to create another dialogs Dialog : resource for users to create another dialogs Icon : insert or draw an icon which you like Icon : insert or draw an icon which you like String Table : allow user to define a long string by an ID String Table : allow user to define a long string by an ID For example: we define a long description with an IDS_STRING1 like : we define a long description with an IDS_STRING1 like :

16 Menu : add one or more Menu for your application Menu : add one or more Menu for your application Toolbar : Add and Design a your new toolbar. Toolbar : Add and Design a your new toolbar. Accelerator : Define a hot key for your function. Such as Ctrl+X : Close Window Accelerator : Define a hot key for your function. Such as Ctrl+X : Close Window Bitmap : Import a bitmap or draw directly by Draw Toolbar Bitmap : Import a bitmap or draw directly by Draw Toolbar

17 File View: Seperate all components by files including Source File (cpp), Header File (.h), Resource File ( files resulting from Resource View). Seperate all components by files including Source File (cpp), Header File (.h), Resource File ( files resulting from Resource View). Note : when you insert a new class into project. Always two files (.h and.cpp) will be added Note : when you insert a new class into project. Always two files (.h and.cpp) will be added

18 Class Winzards Window : Click View  Class Winzard and we see Click View  Class Winzard and we see Message Maps : a map between ObjectID with its Event. And when you map a coressponding function will be created

19 For example : We want to Push Button OK (remember ID of OK button is IDOK) and MessageBox will show with : “Now the window will close” Step 1: Class Winzards Step 1: Class Winzards Step 2: Map IDOK with event BN_CLICKED and click OK Step 2: Map IDOK with event BN_CLICKED and click OK A Confirmation Form will ask you want to change function name or not A Confirmation Form will ask you want to change function name or not

20 The function will be generated in Class Dialog and you input your code below comment // TODO:...... From left to right : Compile (Ctrl + F7), Build (F7), Stop Build (Ctrl + Break ), Execute (Ctrl + F5), Go (F5), Insert Breakpoint (F9)

21 Member Variables Allow user to add variable as a control variable or value variable of control Allow user to add variable as a control variable or value variable of control Control variable : use to do function of a control Control variable : use to do function of a control Value variable of control : use to change value on the control. (Learn more in other Lesson ) Value variable of control : use to change value on the control. (Learn more in other Lesson )

22 Batch Build : to create release the project (with exe file and all classes ) Batch Build : to create release the project (with exe file and all classes ) Click Build  Batch Build and see Click Build  Batch Build and see

23

24 Classic Controls Windows makes the classic controls available to the application programs that it hosts by registering six predefined WNDCLASSes. Windows makes the classic controls available to the application programs that it hosts by registering six predefined WNDCLASSes. The control types, their WNDCLASSes, and the corresponding MFC classes are shown in the following table. The control types, their WNDCLASSes, and the corresponding MFC classes are shown in the following table.

25 To have a control on a dialog, there are two ways : 1.Create by Code, 2. Drag and Drop from Controls Toolbar. Way 1 : Create by Code Step 1 – Create one pointer to a specific Control in Dialog Class (.h) Step 1 – Create one pointer to a specific Control in Dialog Class (.h) Step 2 – Contruct an object pointer by new operation Step 2 – Contruct an object pointer by new operation

26 Step 3 – Define an ID for the object that will be create. (with ID you can do anything with the object ) Step 3 – Define an ID for the object that will be create. (with ID you can do anything with the object ) Click View > Resource Symbols and see In this example IDC_BUTTON will be ID for the object we will create. Note : Remember each ID will have an integer value to distinguish, so input a new value that have not defined before in the range of integer.

27 Step 4 – Define all properties of the object (usually put in InitDialog function) Step 4 – Define all properties of the object (usually put in InitDialog function)

28 More Step : Although Button is Showed in dialog. But it not has any effects so you must do more. Although Button is Showed in dialog. But it not has any effects so you must do more. Example: Change label of the button when click button. Add WM_COMMAND into Dialog and check wParam by ID of the object

29

30 Way 2 : Drag and Drop From Control Bar In tab Resource, Open main Dialog and see In tab Resource, Open main Dialog and see

31

32 Example : Step 1 : Drag and Drop Button Object and put in the desired position Step 1 : Drag and Drop Button Object and put in the desired position

33 Step 2 : In property, we change ID, Caption and Others Step 2 : In property, we change ID, Caption and Others Close Property Sheet and Save all then IDC_BUTTON1 will be automatically created.

34 Step 3 : In ClassWinzards, Map Event BN_CLICKED and Object IDC_BUTTON1 to create function OnButton. In ClassWinzards, Map Event BN_CLICKED and Object IDC_BUTTON1 to create function OnButton.

35 Step 4 : Create Control Varible for button object Step 4 : Create Control Varible for button object

36

37 Some of common commands for classic controls. Static Text : Static Text : Example : We have control variable : m_ctltext and value String variable m_vartext To change the caption of label : Updatedata(TRUE); m_vartext = “Hello VN”; Updatedata(FALSE); Or m_ctltext. SetWindowText(“Hello VN”);

38 Push Button Example : To do something when click button we map ID with Event to create function Example : To do something when click button we map ID with Event to create function To change caption of button we do : SetDlgItemText ( IDC_BUTTON_EXIT, ”Thoat”)

39 Edit Box Example : To set value for edit box we create value variable m_varedit and Example : To set value for edit box we create value variable m_varedit and Updatedata(TRUE) Updatedata(TRUE) m_edit = 10; m_edit = 10; Updatedata(FALSE); Updatedata(FALSE); To do something when user input edit box. We map with event EN_CHANGE To do something when user input edit box. We map with event EN_CHANGE

40 Radio Button Radio Button Example : Step 1 : Drag and Drop radio button into dialog in order Step 1 : Drag and Drop radio button into dialog in order

41 In Property of Radio1 and Radio4 we check property Group In Property of Radio1 and Radio4 we check property Group

42 And Now we have two group of Radio Button. Group1 : Radio1,2,3 Group2 : Radio4,5,6 Group1 : Radio1,2,3 Group2 : Radio4,5,6 Create value variabe for object Radio1 and Radio4. - Now m_varsel1 is the value for group radio 1,2,3 - m_varsel4 is the value for group radio 4,5,6  Which radio is checked ?

43 Check Box : Example : When check a checkbox the message BN_CLICKED will send.So we map object with this message Group Box : Only used to group objects which have the same functions With a control variable of checkbox. To see whether checkbox is checked or not : m_English.GetCheck() 1 : checked 0 : not checked

44 Combo Box : Example : To know which item is chosen. Create a Cstring variable m_varCombo. UpdateDate(TRUE); MessageBox(varCombo);

45 List Box : Example : To create a list of student First, we create an object ListBox Second, Create a control value m_ctlList for that object Third, Use AddString to add item into ListBox m_ctldssv.AddString(str); And Last, To check which Item is chosen int ctlvitri = m_dssv.GetCurSel();

46 End Of Week 1


Download ppt "Classic Controls Trần Anh Tuấn A. Week 1 How to create a MFC project in VS 6.0 How to create a MFC project in VS 6.0 Introduction to Classic Controls."

Similar presentations


Ads by Google