• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            成功∑信念&毅力@勤勞$堅持

            業精于勤,荒于嬉;行成于思,毀于隨. 天下皆知取之為取,而莫知與之為取.

            統計

            留言簿(1)

            閱讀排行榜

            評論排行榜

            Vc編的算術運算器

            This tutorial could well be the simplest windows program you could ever write.  All you need to understand this tutorial is the basics of windows messaging.  This tutorial is about the CButton class, and how to get a simple button working.

            This tutorial simply takes input for two numbers and depending on what button you click, does the math.  ie. if you enter 1 and 2, then click on 'Plus' the answer will be 3.  Pretty basic.

            To create this program first we need to get the framework laid out.  Now 99.9% of the time, you will be using buttons via a dialog box so that is where we will start.  Open up the AppWizard and create a new project titled ButtonDemo.  Just create a basic dialog box without any document / view architecture.


            Then click on the ResourceVew tab in the 'Workspace' window.  Proceed to edit the dialog box IDD_BUTTONDEMO_DLG.  It will already contain the Buttons 'Ok' and 'Cancel'.  Delete the 'TODO :' message and the 'Cancel' button so we can get to work.

            Just drag n' drop the buttons needed, in this example 'Plus' and 'Minus'.  Then select and right click to edit their properties.  The MFC keeps track of these buttons by their unique ID, a macro located in the "Resource.h" file.  For code clarity, change the name of the ID to ID_BUTTON_ADD and modify the caption of the button.


            Next, let's add the Edit boxes to house the values to be added or subtracted, do this in a very similar manner to the way you added the buttons.  Just drag and drop them in and then modify their ID.  We will need an Edit box for the left and right side of the equation as well as one to house the answer.  Just for clarity to the end user, check the 'disable' property of the last Edit box.  Since we won't directly be able to specify the answer.  We will also add a Static control for the equals sign.  Just drop one in and then change the caption.


            Now that our buttons and are in place we need to wire them into our application.  We do this via the class wizard.  (Control + W)  Click on the Member Variables tab and proceed to add the variables m_nX, m_nY, and m_nAnswer.  All integers; these will hold the values inputted from the Edit controls. 


            Then click on the Message Maps tab.  And add a new function for the object ID ID_BUTTON_ADD and  ID_BUTTON_SUBTRACT message BN_CLICK.  This create a function is called whenever that button is clicked once.  Denoted by OnButtonAdd and OnButtonSubtract.


            Now that we have created our buttons this is all the code we need to write to get this program working.  It is fairly self explanatory: what we did was create two functions to be called whenever the respective buttons were pressed.  The UpdateData (BOOL) functions are used to manage the data in the Edit boxes of the dialog.  UpdataData (TRUE), 'updates' the member variables linked to the Edit boxes to whatever is the current value.  UpdataData (FALSE), updates the Edit box to whatever our variable is.
            void CButtonDemoDlg::OnButtonAdd()
                        {
                        UpdateData (TRUE);
                        m_nAnswer = m_nX + m_nY;
                        UpdateData (FALSE);
                        }
                        void CButtonDemoDlg::OnButtonSubtract()
                        {
                        UpdateData (TRUE);
                        m_nAnswer = m_nX - m_nY;
                        UpdateData (FALSE);
                        }
                        

            That is it!  All we need to do to implement a simple button.


            posted on 2008-05-21 21:49 醬豆腐 閱讀(395) 評論(0)  編輯 收藏 引用

            色播久久人人爽人人爽人人片AV | 亚洲国产精品一区二区三区久久| 欧美一区二区精品久久| 国产成人精品久久免费动漫| 91久久精品电影| 久久亚洲中文字幕精品一区| 国产V亚洲V天堂无码久久久| 久久露脸国产精品| 久久精品国产网红主播| 久久996热精品xxxx| 97精品伊人久久大香线蕉| 国产99精品久久| 77777亚洲午夜久久多人| 国产一区二区精品久久凹凸| 久久国产免费观看精品3| 亚洲国产综合久久天堂| 国产精品99久久久久久董美香| 伊人久久综合精品无码AV专区| 国产精品无码久久久久| 久久大香香蕉国产| 一本一本久久a久久综合精品蜜桃| 天天爽天天爽天天片a久久网| 亚洲国产精品高清久久久| 亚洲精品无码久久久久AV麻豆| 伊人久久大香线蕉精品| 久久久久亚洲AV无码永不| 久久99精品国产麻豆宅宅| 午夜精品久久久内射近拍高清| 久久99精品久久久久久秒播| 丁香五月网久久综合| 中文字幕久久久久人妻| 女同久久| 久久人人爽人人爽人人片AV麻烦| 无码任你躁久久久久久老妇| 日本精品一区二区久久久| 免费一级欧美大片久久网| 久久久免费观成人影院| 久久久WWW成人| 国内精品伊人久久久久妇| 天天影视色香欲综合久久| 热久久视久久精品18|