zoukankan      html  css  js  c++  java
  • VC++6.0MFC运行的简单流程

    背景:

      由于下位机做的一些东西,总是需要通过上位机来验证,以及为了直观给客户展示下位机的功能,所以时常需要编写一些简单的APP。今天就以VC++6.0为例,简单的记录下该如何快速的创建一个APP。

    正文:

      首先,本次工程文件名为“GPIOTest”,按照MFC向导一路往下,使用Dialog base窗口,结果会生成三个分类文件夹“Source files”、“Head files”、“Resource files”。具体存放什么就不用说了。

      其中会生成三个“.cpp”文件,“GPIOTest.cpp”、“GPIOTestDlg.cpp”、“StdAfx.cpp”

      运行顺序是:

      最开始在“GPIOTest.cpp”中:CGPIOTestApp::CGPIOTestApp() --> CGPIOTestApp::InitInstance() -->

      对于InitInstance()这个函数有必要贴出来说明下,代码如下:

    BOOL CSBC7111GPIO_APPApp::InitInstance()
    {
        AfxEnableControlContainer();
        // Standard initialization
        // If you are not using these features and wish to reduce the size
        //  of your final executable, you should remove from the following
        //  the specific initialization routines you do not need.
    
    #ifdef _AFXDLL
        Enable3dControls();            // Call this when using MFC in a shared DLL
    #else
        Enable3dControlsStatic();    // Call this when linking to MFC statically
    #endif
    
        CSBC7111GPIO_APPDlg dlg;
        m_pMainWnd = &dlg;
        int nResponse = dlg.DoModal();
    /* 运行到这里的时候,就在DoModal()这个函数里执行循环,响应
     * 各种消息,譬如移动窗体时,调用OnPaint()函数;点击菜单栏时,
     * 调用SysCommand()函数等等,直到,点击了“X”,或者关闭事件,
     * 即会退出DoModal()循环,返回一个参数。即以下函数所写。
     */
        if (nResponse == IDOK) {
            // TODO: Place code here to handle when the dialog is
            //  dismissed with OK
        }
        else if (nResponse == IDCANCEL) {
            // TODO: Place code here to handle when the dialog is
            //  dismissed with Cancel
        }
        // Since the dialog has been closed, return FALSE so that we exit the
        //  application, rather than start the application's message pump.
        return FALSE;
    }

      接着进入到“GPIOTestDlg.cpp”文件中的函数:

      CGPIOTestAppDlg::CGPIOTestAppDlg(CWnd* pParent /*=NULL*/): CDialog(CGPIOTestAppDlg::IDD, pParent) --> CGPIOTestAppDlg::DoDataExchange(CDataExchange* pDX) --> ::OnInitDialog()。

      之后即可以在OnInitDialog()函数内添加自己的代码了。一般都是对界面的一些控件初始化,由于现在还未使用到类似QT的信号槽之类的功能,所以暂时不做记录。

     另外粗略说明以下两个函数的作用:

      CGPIOTestAppDlg::OnPaint(),顾名思义,即当窗口有变化时会调用该函数,譬如放大缩小,移动等等;

      CGPIOTestAppDlg::::OnSysCommand(UINT nID, LPARAM lParam),该函数一般在用户使用鼠标点击菜单栏时会使用。

    记录地点:深圳WZ

    记录时间:2016年3月3日

      

  • 相关阅读:
    Reaper自定义模板
    c#3.0 特性
    C#中下载文件出现410错误。
    使用Create task with ContentType创建任务的时候,必须先在task list中加上该ContentType
    tsmmc.msc 远程桌面
    工作流的ReplicatorActivity
    关于Windows2003的远程桌面链接数量。
    【手绘】A old painting ,drawed in middle school ,grade 8
    【Notepad++】Notepad ++ plugin Compare
    【资讯】Fight for this goal ,and better than this~
  • 原文地址:https://www.cnblogs.com/ChYQ/p/5238080.html
Copyright © 2011-2022 走看看