• C++ AfxBeginThread


     

    计算从1+2+3...+100000=?

     

    关键点

    CWinThread* AfxBeginThread(

    AFX_THREADPROC pfnThreadProc,

    LPVOID pParam,

    int nPriority = THREAD_PRIORITY_NORMAL,

    UINT nStackSize = 0,

    DWORD dwCreateFlags = 0,

    LPSECURITY_ATTRIBUTES lpSecurityAttrs = NULL

    );

    UINT MyFunction( LPVOID pParam );

     

     

    实现过程

     

     

    class CMfc01Dlg : public CDialog
    {
        // Construction
    public:
        CMfc01Dlg(CWndpParent = NULL);    // standard constructor
        CWinThread *m_sumProc;
        // Dialog Data
        
        UINT SumPro(LPVOID pParam)
        {
            CMfc01Dlg *pDlg=(CMfc01Dlg*)pParam;
            __int64 nSum=0;
            char pszText[128]={0};
            for (UINT i=1;i<100000;i++)
            {
                nSum+=i;
                memset(pszText,0,128);
                wsprintf(pszText,"累计到%d的结果为%I64d",i,nSum);
                pDlg->m_listbox1.AddString(pszText);
            }
            return 0;
        } 
        
        void CMfc01Dlg::OnButton1() 
        {
            // TODO: Add your control notification handler code here
            m_sumProc=AfxBeginThread(SumPro,this,0,0,0,NULL);

     

    void CMfc01Dlg::OnClose() 
    {
        // TODO: Add your message handler code here and/or call default
        
        if (SumPro!=NULL)
        {
            DWORD dwExit=0;
            BOOL bRet=GetExitCodeThread(m_sumProc->m_hThread,&dwExit);
            if (dwExit==STILL_ACTIVE)
            {
                m_sumProc->ExitInstance();
                delete m_sumProc;
            }
        }
        
        CDialog::OnClose();

     

     

     

       


     

    备注

     

     

    相关链接

                               

     

     




  • 相关阅读:
    聊聊 Java8 以后各个版本的新特性
    如何使用SpringBoot封装自己的Starter
    Git原理入门解析
    Linux磁盘管理:LVM逻辑卷的拉伸及缩减
    LVM在线扩容
    Ubuntu setup Static IP Address
    ubuntu修改主机名
    user.sh
    升级Dell的R810固件版本
    DSET收集ESXi硬件日志
  • 原文地址:https://www.cnblogs.com/xe2011/p/3885681.html
Copyright © 2020-2023  润新知