CSortApp theApp;
int arry[6][11];
HWND Wnd;DWORD WINAPI ThreadFunc1(LPVOID n); //冒泡排序
DWORD WINAPI ThreadFunc2(LPVOID n); //快速排序
/////////////////////////////////////////////////////////////////////////////
// CSortAppBEGIN_MESSAGE_MAP(CSortApp, CWinApp)
//{{AFX_MSG_MAP(CSortApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
//    DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG
ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CSortApp constructionCSortApp::CSortApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}/////////////////////////////////////////////////////////////////////////////
// The one and only CSortApp object
/////////////////////////////////////////////////////////////////////////////
// CSortApp initializationBOOL CSortApp::InitInstance()
{
srand((unsigned int)time(NULL));
 for(int i=1;i<=10;i++)
 {
 arry[0][i]=arry[1][i]=arry[2][i]=arry[3][i]=arry[4][i]=arry[5][i]=rand()%35+5;
     
 }
 arry[0][0]=arry[1][0]=arry[2][0]=arry[3][0]=arry[4][0]=arry[5][0]=0;
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 CSortDlg dlg;

//dlg->Create(IDD_SORT_DIALOG);
//dlg->ShowWindow(SW_SHOWNORMAL);
m_pMainWnd = &dlg;
Wnd=dlg.m_hWnd;
int nResponse = dlg.DoModal();    HANDLE hTread1;
HANDLE hTread2;

DWORD threadId1;
DWORD threadId2;
// DWORD threadId3; hTread1=::CreateThread(NULL,0,ThreadFunc1,NULL,0,&threadId1);//创建线程1
    hTread2=::CreateThread(NULL,0,ThreadFunc2,NULL,/*CREATE_SUSPENDED*/0,&threadId2);//创建线程2
return FALSE;
}
[b]//关键是这里[/b

/************************************************************************//* 线程1负责 冒泡排序
/************************************************************************/
void mppxs(int s[]);    //冒泡排序的主要函数 DWORD WINAPI ThreadFunc1(LPVOID n)
{
//BubbleSort (num.elem, 10);
    mppxs(arry[0]);
//t++; kind[0]=t;
//printf("冒泡排序 结束\n");
// ResumeThread( hTread3);
return 0;
}
void mppxs(int s[])    //升序 
{  
int sum=0;
    int i,j;
    for(i=1;i<10;i++)
    {   for(j=10;j>=i;j--)
          if(s[j]<s[j-1])
           { s[0]=s[j-1];   //s[0]作为交换时的暂存单元 
             s[j-1]=s[j];
             s[j]=s[0];
            // sjs[4]++;
            } 
 ::SendMessage((HWND)Wnd,WM_PAINT,(WPARAM)0,(LPARAM)0);

    }
  
}/************************************************************************//* 线程2负责 快速排序                                                                    */
/************************************************************************/
void kspx(int arry[],int low,int high);
DWORD WINAPI ThreadFunc2(LPVOID n)
{
    kspx(arry[1],1, 10); return 0;
}int huafens(int s[],int i,int j) //快速升划分函数 

     s[0]=s[i]; //s[0]为辅存 
   //  kjs[5]++;
     while(i<j)
     {    
        while(i<j&&s[j]>=s[0])
          j--;
          if(i<j)
          {
          s[i]=s[j];
          i++;
        //  sjs[5]++;
          }
          while(i<j&&s[i]<=s[0])
          i++;
          if(i<j)
          {
            s[j]=s[i];
            j--;
          //  sjs[5]++;
          }
      }
     s[i]=s[0];     return i;
}
void  kspxs(int s[],int low,int high) //升序 
   {   int  sum=0;
       if(low<high)
         { int p;
            p=huafens(s,low,high); 
            sum++;
            ::SendMessage((HWND)Wnd,WM_PAINT,(WPARAM)0,(LPARAM)0);
//dlg.UpdateWindow();
            kspxs(s,low,p-1);
            kspxs(s,p+1,high);
         }
   }
void kspx(int arry[],int low,int high)

  
       kspxs(arry,1,10);
     

解决方案 »

  1.   

    CSortApp theApp; 
    int arry[6][11]; 
    HWND Wnd; DWORD WINAPI ThreadFunc1(LPVOID n); //冒泡排序 
    DWORD WINAPI ThreadFunc2(LPVOID n); //快速排序 
    ///////////////////////////////////////////////////////////////////////////// 
    // CSortApp BEGIN_MESSAGE_MAP(CSortApp, CWinApp) 
    //{{AFX_MSG_MAP(CSortApp) 
    // NOTE - the ClassWizard will add and remove mapping macros here. 
    //    DO NOT EDIT what you see in these blocks of generated code! 
    //}}AFX_MSG 
    ON_COMMAND(ID_HELP, CWinApp::OnHelp) 
    END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// 
    // CSortApp construction CSortApp::CSortApp() 

    // TODO: add construction code here, 
    // Place all significant initialization in InitInstance 
    } ///////////////////////////////////////////////////////////////////////////// 
    // The one and only CSortApp object 
    ///////////////////////////////////////////////////////////////////////////// 
    // CSortApp initialization BOOL CSortApp::InitInstance() 

    srand((unsigned int)time(NULL)); 
    for(int i=1;i <=10;i++) 

    arry[0][i]=arry[1][i]=arry[2][i]=arry[3][i]=arry[4][i]=arry[5][i]=rand()%35+5; 
        

    arry[0][0]=arry[1][0]=arry[2][0]=arry[3][0]=arry[4][0]=arry[5][0]=0; 
    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 CSortDlg dlg; //dlg->Create(IDD_SORT_DIALOG); 
    //dlg->ShowWindow(SW_SHOWNORMAL); 
    m_pMainWnd = &dlg; 
    Wnd=dlg.m_hWnd; 
    int nResponse = dlg.DoModal();     HANDLE hTread1; 
    HANDLE hTread2; DWORD threadId1; 
    DWORD threadId2; 
    // DWORD threadId3; hTread1=::CreateThread(NULL,0,ThreadFunc1,NULL,0,&threadId1);//创建线程1 
        hTread2=::CreateThread(NULL,0,ThreadFunc2,NULL,/*CREATE_SUSPENDED*/0,&threadId2);//创建线程2 return FALSE; 

    [b]//关键是这里[/b /************************************************************************/ /* 线程1负责 冒泡排序 
    /************************************************************************/ 
    void mppxs(int s[]);    //冒泡排序的主要函数 DWORD WINAPI ThreadFunc1(LPVOID n) 

    //BubbleSort (num.elem, 10); 
        mppxs(arry[0]); 
    //t++; kind[0]=t; 
    //printf("冒泡排序 结束\n"); 
    // ResumeThread( hTread3); 
    return 0; 

    void mppxs(int s[])    //升序 
    {  
    int sum=0; 
        int i,j; 
        for(i=1;i <10;i++) 
        {  for(j=10;j>=i;j--) 
              if(s[j] <s[j-1]) 
              { s[0]=s[j-1];  //s[0]作为交换时的暂存单元 
                s[j-1]=s[j]; 
                s[j]=s[0]; 
                // sjs[4]++; 
                } 
    ::SendMessage((HWND)Wnd,WM_PAINT,(WPARAM)0,(LPARAM)0);     } 
      

    /************************************************************************/ /* 线程2负责 快速排序                                                                    */ 
    /************************************************************************/ 
    void kspx(int arry[],int low,int high); 
    DWORD WINAPI ThreadFunc2(LPVOID n) 

        kspx(arry[1],1, 10); return 0; 
    } int huafens(int s[],int i,int j) //快速升划分函数 

        s[0]=s[i]; //s[0]为辅存 
      //  kjs[5]++; 
        while(i <j) 
        {    
            while(i <j&&s[j]>=s[0]) 
              j--; 
              if(i <j) 
              { 
              s[i]=s[j]; 
              i++; 
            //  sjs[5]++; 
              } 
              while(i <j&&s[i] <=s[0]) 
              i++; 
              if(i <j) 
              { 
                s[j]=s[i]; 
                j--; 
              //  sjs[5]++; 
              } 
          } 
        s[i]=s[0];     return i; 

    void  kspxs(int s[],int low,int high) //升序 
      {  int  sum=0; 
          if(low <high) 
            { int p; 
                p=huafens(s,low,high); 
                sum++; 
                ::SendMessage((HWND)Wnd,WM_PAINT,(WPARAM)0,(LPARAM)0); 
    //dlg.UpdateWindow(); 
                kspxs(s,low,p-1); 
                kspxs(s,p+1,high); 
            } 
      } 
    void kspx(int arry[],int low,int high) 

      
          kspxs(arry,1,10); 
        
      

  2.   

    BOOL CSortApp::InitInstance() 改为返回TRUE
      

  3.   

    还是没有反应啊  看下我后面有一个::SendMessage((HWND)Wnd,WM_PAINT,(WPARAM)0,(LPARAM)0); 这个会执行吗?
      

  4.   

    InitInstance 最后再加两句::WaitForSingleObject(hThread1, INFINITE);
    ::WaitForSingleObject(hThread2, INFINITE);
    return TRUE;
      

  5.   

    你是没明白当你执行完InitInstance程序就结束了,此时你创建任何线程都会被强制结束。要知道,对话框的DoModal是阻塞操作,只有当你点了OK/Cancel结束对话框,才会跑到你那地方,在对话框显示的时候,是永远抛不到你哪儿的
    你应该在对话框的OnInitDialog 里作这事情,
      

  6.   

    从逻辑上看,你的这些线程函数应该和CSortDlg的实现代码(SortDlg.cpp)放在一起
    可以在CSortDlg::OnInitDialog()中启动线程,将CSortDlg实例的m_hWnd传送给线程
    在线程和dlg之间,通过自定义的消息(WM_MY_SORT)交换信息,获得界面的友好更新及响应
      

  7.   

    .h文件中
    #define WM_MY_SORT WM_USER+1afx_msg void OnMySort(WPARAM wParam, LPARAM lParam);.cpp文件中ON_MESSAGE(WM_MY_SORT, OnMySort)void CSortDlg::OnMySort(WPARAM wParam, LPARAM lParam)
    {
    }
    用的时候
    ::SendMessage((HWND)Wnd,WM_MY_SORT,(WPARAM)0,(LPARAM)0); 
      

  8.   

    你的这个有问题啊
    下面是你的InitInstance函数CSortDlg dlg; //dlg->Create(IDD_SORT_DIALOG); 
    //dlg->ShowWindow(SW_SHOWNORMAL); 
    m_pMainWnd = &dlg; 
    Wnd=dlg.m_hWnd; 
    int nResponse = dlg.DoModal();   // 这个返回后你的主对话框都没有了,就算下面你开再多的线程也没用了// 把下面的代码移到CSortDlg 的OnInitDlg函数中HANDLE hTread1; 
    HANDLE hTread2; DWORD threadId1; 
    DWORD threadId2; 
    // DWORD threadId3; hTread1=::CreateThread(NULL,0,ThreadFunc1,NULL,0,&threadId1);//创建线程1 
    hTread2=::CreateThread(NULL,0,ThreadFunc2,NULL,/*CREATE_SUSPENDED*/0,&threadId2);//创建线程2 return FALSE;