Presentation is loading. Please wait.

Presentation is loading. Please wait.

Assign one variable to each group of radio buttons To do this, assign one integer variable to the first radio button in each group. All the subsequent.

Similar presentations


Presentation on theme: "Assign one variable to each group of radio buttons To do this, assign one integer variable to the first radio button in each group. All the subsequent."— Presentation transcript:

1 Assign one variable to each group of radio buttons To do this, assign one integer variable to the first radio button in each group. All the subsequent radio buttons in each group will assigned to the same variable. ObjectNameCategoryTypeAccess IDC_RTPENm_iToolvalueintpublic IDC_RSLINEm_iShapevalueintpublic IDC_RCBLACKm_iColorvalueintpublic

2 寫 Exit 鈕的事件程序 呼叫父類別的 OnOK 函式 Adding the second dialog – 在「資源檢視」視窗中, insert 一個 dialog 至 dialog folder – 移除 dialog 上已存在的控制項 – 設定屬性值 「 System Menu 」選項設成 False (Prevent users from closing this dialog without exiting the application) 「 ID 」設成 IDD_PAINT_DLG

3 Adding the second dialog Right-click the dialog and choose 「 Add Class 」 –Specify the name of the new class as 「 CPaintDlg 」, and make sure the base class is set to 「 CDialog 」 –Click 「 Finish 」 to create the new class Now that we have defined the second dialog, we need to add the code in the first dialog to open the second dialog

4 Add the code in the first dialog to open the second dialog Expand the class tree to show the CXXXDlg class Right-click the CXXXDlg class and choose Add, Add variable Specify the variable type as CPaintDlg, the name as m_dlgPaint, and the access as Private. Click finish to add the variable Expand the CXXXDlg node to show the methods. Double-click the OnInitDialog method

5 Add the code in the first dialog to open the second dialog 加入以下程式碼(加在 TODO 後面): //Initialize the variables and update the dialog window m_iColor=0; m_iShape=0; m_iTool=0; UpdateData(FALSE); //Create the second dialog window //Pass a pointer to the first dialog as the parent window for the second window //This set up a parent-child relationship between these two windows m_dlgPaint.Create(IDD_PAINT_DLG, this); //Show the second dialog window m_dlgPaint.ShowWindow(SW_SHOW);

6 Adding the Graphics Capabilities Drawing Lines –Add a new member variable to the second dialog class, CpaintDlg public: static const COLORREF m_crColors[8]; –Open the source code file for the second dialog class(PaintDlg.cpp) and add the color table const COLORREF CPaintDlg::m_crColors[8]= { RGB( 0, 0, 0), //Black RGB( 0, 0,128), //Dark Blue RGB( 0,128, 0), //Dark Green RGB( 0,128,128), //Dark Cyan RGB(128, 0, 0), //Dark Red RGB(128, 0,128), //Dark Magenta RGB(128,128, 0), //Dark Yellow RGB(128,128,128) //----- };

7 OnPaint Function Whenever a window needs to be redrawn, the O.S. trigger the dialogs OnPaint Function –Add an event handler for the WM_PAINT message on the second dialog class – 加入以下程式碼 CDialog_2Dlg *pWnd = (CDialog_2Dlg*)GetParent(); if (pWnd) { if (pWnd->m_iTool==2) {} else { if (pWnd->m_iShape==0) DrawLine(&dc, pWnd->m_iColor); }

8 DrawLine Function Add DrawLine Function to CPaintDlg class –Right-click the CPaintDlg class, Choose Add, Add Function from the context menu. Return type : void Function Name : DrawLine Function access : Private First parameter : CpaintDC* pdc Second parameter : int iColor 程式碼內容參照 DrawLine.txt 在 paintDlg.cpp 的程式上方加「 #include “dialog_2Dlg.h” 」

9 The second window needs to be redrawn whenever users change a selection on the first dialog The function Invalidate –Is a member function of the CWnd clas. –It tells the window, and the Operating system, that the display area is no longer valid and that it needs to be redrawn

10 Write the event handler for all radio buttons Select the first radio button on the first dialog Add an event handler for the BN_CLICKED event message. –Don’t accept the default name for this function ; Enter the name 「 OnRSelection 」 –Open the XXXDlg.cpp file and locate the Message Map section for the CGraphicsDlg class. –Copy the ON_BN_CLICKED macro, and paste it in the message map 13 more times. Edit these new copies of the ON_BN_CLICKED macro, replacing the ID for the first radio button with the IDs of the other 13 radio buttons.

11 Write the event handler for all radio buttons 在 XXXDlg.cpp 中的 OnRSelection 函式中加入以下 程式碼: //Synchronize the data UpdateData(TRUE); //Repaint the second dialog m_dlgPaint.Invalidate();

12 Drawing Circles and Squares Modify OnPaint Function if (pWnd->m_iShape==0) DrawLine(&dc, pWnd->m_iColor); else//We are drawing a ellipse or rectangle DrawRegion(&dc, pWnd->m_iColor, pWnd->m_iTool, pWnd->m_iShape);

13 Add the DrawRegion Function Add a new function to the second dialog class –Return type : void –Function Name : DrawRegion –Function access : Private –First parameter : CpaintDC* pdc –Second parameter : int iColor –Third parameter : int iTool –Fourth parameter : int iShape 程式內容如 DrawRegion.txt

14 Loading Bitmaps Add the following variables to the CXXXDlg class Add an event-handler function to the clicked event of the Bitmap button 程式碼詳見 ClickedBitmap.txt NameTypeAccess 用途 m_strBitmapCstringpublicTo hold the bitmap name m_bmtBitmapCBitmapPublicTo hold bitmap image

15 Displaying Bitmaps Add a member function to the second dialog class –Return type : void –Fuction name : ShowBitmap –Parameter : CPaintDC* pdc –Fuction Acess : private Code in the ShowBitmap Function : ShowBitmap.txt

16 Modify OnPaint Function if (pWnd->m_iTool==2) { //Is there a bitmap selected and loaded? if (pWnd->m_strBitmap.GetLength() > 0) ShowBitmap(&dc); }


Download ppt "Assign one variable to each group of radio buttons To do this, assign one integer variable to the first radio button in each group. All the subsequent."

Similar presentations


Ads by Google