• <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>

            成功∑信念&毅力@勤勞$堅(jiān)持

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

            統(tǒng)計(jì)

            留言簿(1)

            閱讀排行榜

            評(píng)論排行榜

            Vc編的算術(shù)運(yùn)算器

            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 醬豆腐 閱讀(394) 評(píng)論(0)  編輯 收藏 引用


            只有注冊(cè)用戶(hù)登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問(wèn)   Chat2DB   管理


            狠狠狠色丁香婷婷综合久久俺| 中文字幕成人精品久久不卡| 久久精品国产亚洲AV忘忧草18| 午夜精品久久久久9999高清| 久久精品亚洲乱码伦伦中文 | 色综合久久无码五十路人妻| 久久精品aⅴ无码中文字字幕重口| 久久免费高清视频| 亚洲欧美精品一区久久中文字幕| 久久青青草原亚洲av无码app| 久久se精品一区精品二区国产 | 亚洲中文字幕久久精品无码喷水 | 狠狠88综合久久久久综合网| 国产日韩欧美久久| 久久精品国产精品亚洲毛片| 婷婷久久综合九色综合绿巨人| 久久综合给久久狠狠97色| 国产精品久久久久久久app| 国产精品久久国产精品99盘| 久久精品国产亚洲αv忘忧草| 99久久婷婷国产综合亚洲| 欧美日韩久久中文字幕| 91亚洲国产成人久久精品| 久久香蕉国产线看观看精品yw| 久久综合给合综合久久| 久久夜色精品国产亚洲| 少妇久久久久久久久久| 久久综合亚洲鲁鲁五月天| 精品久久久久一区二区三区| 国产Av激情久久无码天堂| 日日躁夜夜躁狠狠久久AV| 久久九九久精品国产免费直播| 久久久久国产一区二区| 国产精品九九久久免费视频 | 久久av免费天堂小草播放| 99国内精品久久久久久久| 99国产欧美精品久久久蜜芽| 久久夜色精品国产噜噜噜亚洲AV| 日产精品久久久久久久性色| 久久亚洲国产精品成人AV秋霞| 久久久精品国产|