zoukankan      html  css  js  c++  java
  • 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();

     

     

     

       


     

    备注

     

     

    相关链接

                               

     

     




  • 相关阅读:
    C语言II博客作业01
    学期总结
    C语言|博客作业01
    C语言|博客作业02
    C语言|博客作业08
    C语言|博客作业07
    C语言|博客作业06
    C语言|博客作业05
    C语言|博客作业04
    c语言||博客作业04
  • 原文地址:https://www.cnblogs.com/xe2011/p/3885681.html
Copyright © 2011-2022 走看看