资源描述:
《mfc中多线程的应用(ApplicationofmultithreadinMFC)》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、mfc中多线程的应用(ApplicationofmultithreadinMFC)Itrytousetheirownwordstoexpresstheconceptofthethread,thereisashorttimeforasmallsampleprogram(Idonotknow,Idonotknowright?Cantellnot・・),laughed・Infact,themainprogramthreadandwindowsstandard(WinMain)notwo.・・Themainprogramisaspecialthread,calledthemainthr
2、ead・Infact,youcanimaginethethreadwithWinMain******operationatthesametime,butcanaccesseachother(thatis,inanaddressspace)somesmallWinMaintheprogram**.Asthemainthread,whichcancreateawindow,getnews,etc•・・Becausethreadsarerunninginanaddressspaceandrimningatthesametime,theycancausesometrouble・Beca
3、useweareusingotherprogrammingfunctions,orintermediatevariablesandtheirfunctionswhichoftenhavealotofstaticorglobal,thereismutualdependeneeisverycomplex,iftheexecutionofafunctionisnotserializable(calledserializability,isonlyafunctioncallreturnafteranotherathreadcancall,cannotcallatthesametime,
4、itwillcauseconfusion.)onthisthread,atermcalledsynchronous,windowsprovidesanumberofsynchronizationmethodforus,MFCalsoprovidesclassesthatencapsulatesomesynchronizationcoreobjects・Foralibraryfunctioncall,callthreadsafe・Forexample,theMFCclasslibraryisnotthreadsafe・Nowletmegiveyouasimpleexampleto
5、illustratetheseconcepts・Thefollowingdialogboxapplicationismultithreaded・Demonstratestwosmallanimations:(1)thefirstanimationisdrivenbythemainthreadoftheTimer,thesecondanimationcreatedbythemainthreadtodrivethework.Aredisplayedindifferentpositions・ThereasonwhyIwanttojoinTimer,butalsototheformat
6、ionofthecontrolthreaddriverandtimerdriver,thisisthetwodrivingmodes(andanimationinidledrive)・(2)thetwoanimationisalwaysdifferent・Itisforexample:avariableisavariablewillcry,laugh,thelaugh,cry.ThisbecomesanimatedpicturesfromOICQintheFacedirectory,generallythesamepicturewillbeOICQwilltakethreepi
7、ctures(*一1.bmp*一2・bmp,一3.bmp,*一2.bmp*)isgraypicture,Itook1and3picturesforanimation・Severalkeypointsofthisprogramneedtobepaidattentionto:(1)themainthreadcommunicateswiththeworkerthreadusingPostThreadMessage・TheworkerthreadusesPeekMessagetoretrieveth