xxxx18一60岁hd中国/日韩女同互慰一区二区/西西人体扒开双腿无遮挡/日韩欧美黄色一级片 - 色护士精品影院www

資源簡(jiǎn)介

1. 創(chuàng)建一個(gè)基于對(duì)話框的應(yīng)用程序。并增加如圖所示控件;分別為3個(gè)進(jìn)度條控件關(guān)聯(lián)三個(gè)進(jìn)度條類型的變量;并在對(duì)話框的初始化函數(shù)中,設(shè)定進(jìn)度條的范圍;為編輯框關(guān)聯(lián)一個(gè)整型的變量;為12個(gè)按鈕添加消息處理函數(shù); 2. 定義結(jié)構(gòu)體:用做線程函數(shù)的參數(shù)傳遞 typedef struct Threadinfo{ CProgressCtrl *progress;//進(jìn)度條對(duì)象 int speed; //進(jìn)度條速度 int pos; //進(jìn)度條位置 } thread,*lpthread; 3. 為對(duì)話框增加三個(gè)句柄,用于標(biāo)識(shí)各個(gè)線程; HANDLE hThread1; //線程1線程句柄 HANDLE hThread2; //線程2線程句柄 HANDLE hThread3; //線程3線程句柄 在增加三個(gè)結(jié)構(gòu)體類型的變量,用做線程函數(shù)的參數(shù)傳遞; HANDLE hThread1; //線程1線程句柄 HANDLE hThread2; //線程2線程句柄 HANDLE hThread3; //線程3線程句柄 4. 新增一個(gè)靜態(tài)的全局變量,用于記錄所有線程的狀態(tài):static int GlobalVar=10000; 5. 聲明并編寫線程函數(shù),注意只能有一個(gè)參數(shù),且函數(shù)的返回值類型也是固定的;函數(shù)名可以自定義; DWORD WINAPI ThreadFun(LPVOID pthread);//線程入口函數(shù) 6. 在啟動(dòng)按鈕的消息處理函數(shù)中編寫如下代碼: thread1.progress=&m_progress1;//進(jìn)度條對(duì)象 thread1.speed=100;//速度 thread1.pos=0;//初始位置 hThread1=CreateThread(NULL,0,ThreadFun,&thread1;,0,0);//創(chuàng)建并開始線程 if (!hThread1) { MessageBox("創(chuàng)建線程失敗"); } 7. 編寫線程函數(shù)(一般是一個(gè)死循環(huán),或者需要花費(fèi)時(shí)間很長(zhǎng)的算法!否者就失去了多線程的意義) DWORD WINAPI ThreadFun(LPVOID pthread) //線程入口函數(shù) { lpthread temp=(lpthread)pthread;//參數(shù)強(qiáng)制轉(zhuǎn)換為結(jié)構(gòu)體類型 temp->progress->SetPos(temp->pos); //設(shè)置被傳遞過來的進(jìn)度條的位置 while(temp->posspeed); /設(shè)置速度 temp->pos++; //增加進(jìn)度 temp->progress->SetPos(temp->pos); //設(shè)置進(jìn)度條的新位置 GlobalVar--; if(temp->pos==20) { temp->pos=0; //進(jìn)度條滿則歸0 } } return true; } 8. 在掛起按鈕函數(shù)中,編寫如下代碼: if(SuspendThread(hThread1)==0xFFFFFFFF) { MessageBox("掛起失敗!進(jìn)程可能已經(jīng)死亡或未創(chuàng)建!"); return; } 9. 在執(zhí)行按鈕函數(shù)中,編寫如下代碼: if(ResumeThread(hThread1)==0xFFFFFFFF) { MessageBox("執(zhí)行失敗!進(jìn)程可能已經(jīng)死亡或未創(chuàng)建!"); return; } 10. 在停止按鈕函數(shù)中,編寫如下代碼: if(TerminateThread(hThread1,0))//前些終止線程 { CloseHandle(hThread1);//銷毀線程句柄 } else { MessageBox("終止進(jìn)程失敗!"); } 11. 為應(yīng)用程序添加WM_TIMER消息,實(shí)時(shí)更新全局變量的值到編輯框;

資源截圖

代碼片段和文件信息

//?CreateThread.cpp?:?Defines?the?class?behaviors?for?the?application.
//

#include?“stdafx.h“
#include?“CreateThread.h“
#include?“CreateThreadDlg.h“

#ifdef?_DEBUG
#define?new?DEBUG_NEW
#undef?THIS_FILE
static?char?THIS_FILE[]?=?__FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
//?CCreateThreadApp

BEGIN_MESSAGE_MAP(CCreateThreadApp?CWinApp)
//{{AFX_MSG_MAP(CCreateThreadApp)
//?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()

/////////////////////////////////////////////////////////////////////////////
//?CCreateThreadApp?construction

CCreateThreadApp::CCreateThreadApp()
{
//?TODO:?add?construction?code?here
//?Place?all?significant?initialization?in?InitInstance
}

/////////////////////////////////////////////////////////////////////////////
//?The?one?and?only?CCreateThreadApp?object

CCreateThreadApp?theApp;

/////////////////////////////////////////////////////////////////////////////
//?CCreateThreadApp?initialization

BOOL?CCreateThreadApp::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

CCreateThreadDlg?dlg;
m_pMainWnd?=?&dlg;
int?nResponse?=?dlg.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;
}

?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2012-03-21?14:32??CreateThread\
?????文件???????37052??2012-03-21?15:14??CreateThread\CreateThread.aps
?????文件????????1892??2012-03-21?16:25??CreateThread\CreateThread.clw
?????文件????????2147??2008-05-07?08:58??CreateThread\CreateThread.cpp
?????文件????????4267??2008-05-07?08:58??CreateThread\CreateThread.dsp
?????文件?????????547??2008-05-07?08:58??CreateThread\CreateThread.dsw
?????文件????????1390??2008-05-07?08:58??CreateThread\CreateThread.h
?????文件???????66560??2012-03-21?16:25??CreateThread\CreateThread.ncb
?????文件???????48640??2012-03-21?16:25??CreateThread\CreateThread.opt
?????文件?????????717??2012-03-21?16:16??CreateThread\CreateThread.plg
?????文件????????6390??2012-03-21?15:14??CreateThread\CreateThread.rc
?????文件????????9833??2012-03-21?16:17??CreateThread\CreateThreadDLG.cpp
?????文件????????2232??2012-03-21?15:41??CreateThread\CreateThreadDLG.h
?????文件????????3687??2008-05-07?08:58??CreateThread\ReadMe.txt
?????目錄???????????0??2012-03-21?14:32??CreateThread\res\
?????文件????????1380??2012-03-21?15:14??CreateThread\Resource.h
?????文件????????1078??2008-05-07?08:58??CreateThread\res\CreateThread.ico
?????文件?????????404??2008-05-07?08:58??CreateThread\res\CreateThread.rc2
?????文件?????????214??2008-05-07?08:58??CreateThread\StdAfx.cpp
?????文件????????1054??2008-05-07?08:58??CreateThread\StdAfx.h

評(píng)論

共有 條評(píng)論

相關(guān)資源