DrawObj.cpp 134 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060
  1. // CDrawObj.cpp: implementation of the CDrawObj class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "BaseProDlg.h"
  6. #include "DynamicProPage.h"
  7. #include "computer.h"
  8. #include "bardlg.h"
  9. #include "curvedlg.h"
  10. #include "MainFrm.h"
  11. #include "IDEView.h"
  12. #include "datainputdlg.h"
  13. #include "CommondServer.h"
  14. #include "gradient.h"
  15. #include "BitmapPage.h"
  16. #include "datapage.h"
  17. #include "logicpage.h"
  18. #include "SingleBarPage.h"
  19. #include "ArcPage.h"
  20. #include "WatchPage.h"
  21. #include "ReportBasePage.h"
  22. #include "ReportColPage.h"
  23. #include "YkCmdDlg.h"
  24. #include "Dlg_OCX.h"
  25. #include "Dlg_Flash.h"
  26. #include "SysLib.h"
  27. #include "Dlg_Pwd.h"
  28. #include "DlgEditPwd.h"
  29. #include "SystemParaSetDlg.h"
  30. #include <math.h>
  31. extern CMainFrame *g_pMainFrm;
  32. #pragma warning (disable : 4805)
  33. #define DIR_UP 0
  34. #define DIR_DOWN 1
  35. #define DIR_LEFT 2
  36. #define DIR_RIGHT 3
  37. #define PIE 3.1415926
  38. // 表盘
  39. #define HOURSCALE 65
  40. #define MINUTESCALE 80
  41. #define HHAND TRUE
  42. #define MHAND FALSE
  43. #define SECONDSCALE 80
  44. #define MAXBLOBWIDTH 25
  45. #define BUFLEN 30
  46. #define REPAINT 0
  47. #define HANDPAINT 1
  48. #define UPDATE 0
  49. #define REDRAW 1
  50. #define OPEN_TLEN 450
  51. #define ICON_TLEN 45000
  52. #define CLKSCALE ((INT)8000)
  53. // END
  54. // 表盘
  55. typedef struct
  56. {
  57. SHORT sin;
  58. SHORT cos;
  59. } TRIG;
  60. TRIG CirTab[] = { // circle sin, cos, table
  61. { -7999, -0 },
  62. { -7956, -836 },
  63. { -7825, -1663 },
  64. { -7608, -2472 },
  65. { -7308, -3253 },
  66. { -6928, -4000 },
  67. { -6472, -4702 },
  68. { -5945, -5353 },
  69. { -5353, -5945 },
  70. { -4702, -6472 },
  71. { -3999, -6928 },
  72. { -3253, -7308 },
  73. { -2472, -7608 },
  74. { -1663, -7825 },
  75. { -836 , -7956 },
  76. { 0, -7999 },
  77. { 836, -7956 },
  78. { 1663, -7825 },
  79. { 2472, -7608 },
  80. { 3253, -7308 },
  81. { 3999, -6928 },
  82. { 4702, -6472 },
  83. { 5353, -5945 },
  84. { 5945, -5353 },
  85. { 6472, -4702 },
  86. { 6928, -4000 },
  87. { 7308, -3253 },
  88. { 7608, -2472 },
  89. { 7825, -1663 },
  90. { 7956, -836 },
  91. { 8000, 0 },
  92. { 7956, 836 },
  93. { 7825, 1663 },
  94. { 7608, 2472 },
  95. { 7308, 3253 },
  96. { 6928, 4000 },
  97. { 6472, 4702 },
  98. { 5945, 5353 },
  99. { 5353, 5945 },
  100. { 4702, 6472 },
  101. { 3999, 6928 },
  102. { 3253, 7308 },
  103. { 2472, 7608 },
  104. { 1663, 7825 },
  105. { 836, 7956 },
  106. { 0, 7999 },
  107. { -836, 7956 },
  108. { -1663, 7825 },
  109. { -2472, 7608 },
  110. { -3253, 7308 },
  111. { -4000, 6928 },
  112. { -4702, 6472 },
  113. { -5353, 5945 },
  114. { -5945, 5353 },
  115. { -6472, 4702 },
  116. { -6928, 3999 },
  117. { -7308, 3253 },
  118. { -7608, 2472 },
  119. { -7825, 1663 },
  120. { -7956, 836 }
  121. };
  122. // End
  123. IMPLEMENT_SERIAL(CAction, CObject, 0)
  124. CAction::CAction() :CObject()
  125. {
  126. m_nActionType = YK_COMMOND;
  127. m_strVariant = _T("");
  128. m_strActionValue = _T("");
  129. m_strPicPath = _T("");
  130. }
  131. void CAction::Serialize(CArchive& ar)
  132. {
  133. CObject::Serialize(ar);
  134. if (ar.IsStoring())
  135. {
  136. ar << m_nActionType;
  137. ar << m_strVariant;
  138. ar << m_strActionValue;
  139. ar << m_strPicPath;
  140. }
  141. else
  142. {
  143. ar >> m_nActionType;
  144. ar >> m_strVariant;
  145. ar >> m_strActionValue;
  146. ar >> m_strPicPath;
  147. }
  148. }
  149. CAction& CAction::operator=(CAction& action)
  150. {
  151. m_nActionType = action.m_nActionType;
  152. m_strVariant = action.m_strVariant;
  153. m_strActionValue = action.m_strActionValue;
  154. m_strPicPath = action.m_strPicPath;
  155. return *this;
  156. }
  157. CAction* CAction::Clone(void)
  158. {
  159. CAction* pAction = new CAction;
  160. *pAction = *this;
  161. pAction->m_nActionType = m_nActionType;
  162. pAction->m_strVariant = m_strVariant;
  163. pAction->m_strActionValue = m_strActionValue;
  164. pAction->m_strPicPath = m_strPicPath;
  165. return pAction;
  166. }
  167. //---------------------------------------------- CDrawObj ---------
  168. CStringArray CDrawObj::drawsName;
  169. CPtrArray CDrawObj::drawsRuntimeClass;
  170. BOOL CDrawObj::bRuning = FALSE; // 是否处于运行状态;
  171. IMPLEMENT_SERIAL(CDrawObj, CObject, 0)
  172. CDrawObj::CDrawObj() :CObject()
  173. {
  174. m_pView = NULL;
  175. m_nLineWidth = 1;
  176. m_strLineType = "PS_SOLID";
  177. m_clrFore = RGB(0, 0, 0);
  178. m_clrFill = RGB(0, 0, 255);
  179. m_clrLine = RGB(0, 0, 0); // 线色
  180. m_clrBack = RGB(255, 0, 0);
  181. m_clrCurrentFore = RGB(0, 255, 0);
  182. m_clrCurrentBack = RGB(255, 0, 0);
  183. m_clrCurrentLine = RGB(0, 255, 255);
  184. m_bLocked = FALSE;
  185. m_strCaption = "";
  186. m_logfont.lfHeight = -12;
  187. m_logfont.lfWidth = 0;
  188. m_logfont.lfEscapement = 0;
  189. m_logfont.lfOrientation = 0;
  190. m_logfont.lfWeight = FW_NORMAL;
  191. m_logfont.lfItalic = FALSE;
  192. m_logfont.lfUnderline = FALSE;
  193. m_logfont.lfStrikeOut = FALSE;
  194. if (strcmp(g_strLanguage, "ENG") == 0)
  195. {
  196. m_logfont.lfCharSet = GB2312_CHARSET;
  197. }
  198. else if (strcmp(g_strLanguage, "CHS") == 0)
  199. {
  200. m_logfont.lfCharSet = GB2312_CHARSET;
  201. }
  202. else if (strcmp(g_strLanguage, "CHT") == 0)
  203. {
  204. m_logfont.lfCharSet = CHINESEBIG5_CHARSET;
  205. }
  206. m_logfont.lfOutPrecision = OUT_STROKE_PRECIS;
  207. m_logfont.lfClipPrecision = CLIP_STROKE_PRECIS;
  208. m_logfont.lfQuality = DEFAULT_QUALITY;//DRAFT_QUALITY;
  209. m_logfont.lfPitchAndFamily = FIXED_PITCH | FF_MODERN;
  210. if (strcmp(g_strLanguage, "ENG") == 0)
  211. {
  212. strcpy(m_logfont.lfFaceName, g_strTimesNewRoman);
  213. }
  214. else if (strcmp(g_strLanguage, "CHS") == 0)
  215. {
  216. strcpy(m_logfont.lfFaceName, g_strTimesNewRoman);
  217. }
  218. else if (strcmp(g_strLanguage, "CHT") == 0)
  219. {
  220. strcpy(m_logfont.lfFaceName, g_strFontNameCHT);
  221. }
  222. m_bVertiSize = FALSE;
  223. m_bHorizSize = FALSE;
  224. m_bHorizPos = FALSE;
  225. m_bVertiPos = FALSE;
  226. m_bShow = TRUE;
  227. m_bShowtemp = TRUE;
  228. m_bDynShow = FALSE;
  229. m_nHorAlign = 0;
  230. m_nVerAlign = 0;
  231. m_clrDynBack = RGB(255, 0, 0);
  232. m_strDynBackCon = "";
  233. m_clrDynLine = RGB(0, 255, 0);
  234. m_strDynLineCon = "";
  235. m_fCurrentValue = 0.0;
  236. m_bDynFore = FALSE;
  237. m_bDynBack = FALSE;
  238. m_bDynLine = FALSE;
  239. m_bOnButtonDown = false;
  240. m_bOnButtonUp = false;
  241. m_bOnMove = false;
  242. m_nFillMode = 0;
  243. m_rctCurrent = m_rect;
  244. m_bHisFreshed = false;
  245. m_bModifyMore = FALSE;
  246. m_bFlag1 = true;
  247. m_bFlag2 = true;
  248. m_bFlag3 = true;
  249. }
  250. void CDrawObj::RegisterClass(CString strName, CRuntimeClass* pRuntimeClass)
  251. {
  252. if (pRuntimeClass->IsDerivedFrom(RUNTIME_CLASS(CDrawObj)))
  253. {
  254. int i = 0;
  255. int nSize = drawsName.GetSize();
  256. for (i = 0; i < nSize; i++)
  257. {
  258. if ((strName == drawsName[i]) || (pRuntimeClass == drawsRuntimeClass[i]))
  259. {
  260. break;
  261. }
  262. }
  263. if (i == nSize)
  264. {
  265. drawsName.Add(strName);
  266. drawsRuntimeClass.Add(pRuntimeClass);
  267. }
  268. }
  269. }
  270. CDrawObj& CDrawObj::operator=(CDrawObj& drawObj)
  271. {
  272. m_rect = drawObj.m_rect;
  273. m_pView = drawObj.m_pView;
  274. m_strLineType = drawObj.m_strLineType;
  275. m_clrLine = drawObj.m_clrLine;
  276. m_clrFore = drawObj.m_clrFore;
  277. m_clrBack = drawObj.m_clrBack;
  278. m_clrLine = drawObj.m_clrLine;
  279. m_strCaption = drawObj.m_strCaption;
  280. m_logfont = drawObj.m_logfont;
  281. m_nLineWidth = drawObj.m_nLineWidth;
  282. m_bVariant = drawObj.m_bVariant;
  283. m_bDynShow = drawObj.m_bDynShow;
  284. m_strDynShow = drawObj.m_strDynShow;
  285. m_clrDynFore = drawObj.m_clrDynFore;
  286. m_strDynForeCon = drawObj.m_strDynForeCon;
  287. m_clrDynBack = drawObj.m_clrDynBack;
  288. m_strDynBackCon = drawObj.m_strDynBackCon;
  289. m_clrDynLine = drawObj.m_clrDynLine;
  290. m_strDynLineCon = drawObj.m_strDynLineCon;
  291. m_bDynFore = drawObj.m_bDynFore;
  292. m_bDynBack = drawObj.m_bDynBack;
  293. m_bDynLine = drawObj.m_bDynLine;
  294. m_strHoriPos = drawObj.m_strHoriPos;
  295. m_strHoriSize = drawObj.m_strHoriSize;
  296. m_strVertiPos = drawObj.m_strVertiPos;
  297. m_strVertiSize = drawObj.m_strVertiSize;
  298. m_bVertiSize = drawObj.m_bVertiSize;
  299. m_bVertiPos = drawObj.m_bVertiPos;
  300. m_bHorizSize = drawObj.m_bHorizSize;
  301. m_bHorizPos = drawObj.m_bHorizPos;
  302. m_downAction = drawObj.m_downAction;
  303. m_bOnButtonDown = drawObj.m_bOnButtonDown;
  304. return *this;
  305. }
  306. /************************************************************************/
  307. /* 函数:Fresh[10/28/2016 Home];
  308. /* 描述:刷新页面中所有图元;
  309. /* 参数:;
  310. /* [IN] :;
  311. /* [OUT] :;
  312. /* [IN/OUT] :;
  313. /* 返回:void;
  314. /* 注意:;
  315. /* 示例:;
  316. /*
  317. /* 修改:;
  318. /* 日期:;
  319. /* 内容:;
  320. /************************************************************************/
  321. bool CDrawObj::Fresh(OUT CRect &RECT)
  322. {
  323. if (m_bVariant)
  324. {// 如果是变量;
  325. // int nValue = (int)pVariantsManager->GetAnalogValue(m_strCaption);
  326. // if( nValue == -1 ) return false;
  327. // m_fCurrentValue = pVariantsManager->GetAnalogValue(m_strCaption);
  328. // int tmp = (int)m_fCurrentValue;
  329. // m_strCurrentCaption.Format("%d", tmp);
  330. }
  331. else
  332. {
  333. m_strCurrentCaption = m_strCaption;
  334. }
  335. m_rctCurrent = m_rect;
  336. // 计算当前大小;
  337. if (m_bVertiSize)
  338. {
  339. CRealComputer com;
  340. com.SetFormula(m_strVertiSize);
  341. int tmp = com.GetResult();
  342. int height = m_rctCurrent.Height();
  343. CRect rect = m_rctCurrent;
  344. rect.NormalizeRect();
  345. if (m_nVerAlign)
  346. {
  347. if (rect.top != m_rctCurrent.top)
  348. {
  349. m_rctCurrent.bottom -= tmp - height;
  350. }
  351. else
  352. {
  353. m_rctCurrent.top -= tmp - height;
  354. }
  355. }
  356. else
  357. {
  358. if (rect.top != m_rctCurrent.top)
  359. {
  360. m_rctCurrent.top += tmp - height;
  361. }
  362. else
  363. {
  364. m_rctCurrent.bottom += tmp - height;
  365. }
  366. }
  367. }
  368. //if (m_bHorizSize) modify by chn 2012.02.06
  369. //{
  370. // CRealComputer com;
  371. // com.SetFormula(m_strHoriSize);
  372. // int tmp = com.GetResult();
  373. // int width = m_rctCurrent.Width();
  374. // CRect rect = m_rctCurrent;
  375. // rect.NormalizeRect();
  376. // if ( m_nHorAlign )
  377. // {
  378. // if (rect.right != m_rctCurrent.right )
  379. // {
  380. // m_rctCurrent.right -= tmp-width;
  381. // }
  382. // else
  383. // {
  384. // m_rctCurrent.left -= tmp-width;
  385. // }
  386. // }
  387. // else
  388. // {
  389. // if (rect.right != m_rctCurrent.right )
  390. // {
  391. // m_rctCurrent.left += tmp-width;
  392. // }
  393. // else
  394. // {
  395. // m_rctCurrent.right += tmp-width;
  396. // }
  397. // }
  398. //}
  399. // 计算当前位置
  400. if (m_bVertiPos)
  401. {
  402. CRealComputer com;
  403. com.SetFormula(m_strVertiPos);
  404. int tmp = com.GetResult();
  405. int yPos = ((CPoint)m_rctCurrent.TopLeft()).y;
  406. m_rctCurrent.OffsetRect(0, tmp - yPos);
  407. }
  408. if (m_bHorizPos)
  409. {
  410. CRealComputer com;
  411. com.SetFormula(m_strHoriPos);
  412. int tmp = com.GetResult();
  413. int xPos = ((CPoint)m_rctCurrent.TopLeft()).x;
  414. m_rctCurrent.OffsetRect(tmp - xPos, 0);
  415. }
  416. m_clrCurrentFore = m_clrFore;
  417. m_clrCurrentBack = m_clrBack;
  418. m_clrCurrentLine = m_clrLine;
  419. // 计算当前的动态颜色;
  420. if (m_bDynFore == 1)
  421. {
  422. CRealComputer com;
  423. com.SetFormula(m_strDynForeCon);
  424. int tmp = com.GetResult();
  425. if (tmp)
  426. {
  427. if (!m_bHorizSize)
  428. m_clrCurrentFore = m_clrDynFore;
  429. else
  430. {
  431. if (m_bFlag1)
  432. m_clrCurrentFore = m_clrDynFore;
  433. else
  434. {
  435. //m_clrCurrentBack = RGB( 230, 241, 249 );
  436. //m_clrCurrentLine = RGB( 230, 241, 249 );
  437. m_clrCurrentFore = RGB(230, 241, 249);
  438. }
  439. m_bFlag1 = !m_bFlag1;
  440. }
  441. }
  442. }
  443. if (m_bDynBack == 1)
  444. {
  445. CRealComputer com;
  446. com.SetFormula(m_strDynBackCon);
  447. int tmp = com.GetResult();
  448. //if( -1 != m_strDynBackCon.Find("WTH10_1_Temp_1") )
  449. //{
  450. // int a=0;
  451. //}
  452. if (tmp)
  453. {
  454. if (!m_bHorizSize)
  455. m_clrCurrentBack = m_clrDynBack;
  456. else
  457. {
  458. if (m_bFlag2)
  459. m_clrCurrentBack = m_clrDynBack;
  460. else
  461. {
  462. m_clrCurrentBack = RGB(230, 241, 249);
  463. m_clrCurrentLine = RGB(230, 241, 249);
  464. m_clrCurrentFore = RGB(230, 241, 249);
  465. }
  466. m_bFlag2 = !m_bFlag2;
  467. }
  468. }
  469. }
  470. if (m_bDynLine == 1)
  471. {
  472. CRealComputer com;
  473. com.SetFormula(m_strDynLineCon);
  474. int tmp = com.GetResult();
  475. if (tmp)
  476. {
  477. if (!m_bHorizSize)
  478. m_clrCurrentLine = m_clrDynLine;
  479. else
  480. {
  481. if (m_bFlag3)
  482. m_clrCurrentLine = m_clrDynLine;
  483. else
  484. {
  485. //m_clrCurrentBack = RGB( 230, 241, 249 );
  486. m_clrCurrentLine = RGB(230, 241, 249);
  487. //m_clrCurrentFore = RGB( 230, 241, 249 );
  488. }
  489. m_bFlag3 = !m_bFlag3;
  490. }
  491. }
  492. }
  493. // 判断是否显示;
  494. //if( m_strDynShow!="" && m_bDynShow==0 ) LOG4C((LOG_NOTICE, "m_strDynShow=< %s >,m_bDynShow = %d",m_strDynShow,m_bDynShow));
  495. if (m_bDynShow == 1)
  496. {
  497. CRealComputer com;
  498. com.SetFormula(m_strDynShow);
  499. m_bShow = (int)com.GetResult();
  500. ////测试用
  501. //if( -1 != m_strDynShow.Find("Caross_1_StartORShutStatus") )
  502. //{
  503. // if( m_bShow==0 )
  504. // m_bShow = 1;
  505. // else
  506. // m_bShow = 0;
  507. //}
  508. //if( -1 != m_strDynShow.Find("Caross_2_StartORShutStatus") )
  509. //{
  510. // if( m_bShow==0 )
  511. // m_bShow = 1;
  512. // else
  513. // m_bShow = 0;
  514. //}
  515. }
  516. RECT = m_rect;
  517. return true;
  518. }
  519. CDrawObj* CDrawObj::Clone(void)
  520. {
  521. CDrawObj *pObj = new CDrawObj;
  522. *((CDrawObj*)pObj) = *(CDrawObj*)this;
  523. pObj->m_strLineType = m_strLineType;
  524. pObj->m_clrLine = m_clrLine;
  525. pObj->m_clrFore = m_clrFore;
  526. pObj->m_clrBack = m_clrBack;
  527. pObj->m_clrLine = m_clrLine;
  528. pObj->m_strCaption = m_strCaption;
  529. pObj->m_logfont = m_logfont;
  530. pObj->m_nLineWidth = m_nLineWidth;
  531. pObj->m_bVariant = m_bVariant;
  532. pObj->m_bDynShow = m_bDynShow;
  533. pObj->m_strDynShow = m_strDynShow;
  534. pObj->m_clrDynFore = m_clrDynFore;
  535. pObj->m_strDynForeCon = m_strDynForeCon;
  536. pObj->m_clrDynBack = m_clrDynBack;
  537. pObj->m_strDynBackCon = m_strDynBackCon;
  538. pObj->m_clrDynLine = m_clrDynLine;
  539. pObj->m_strDynLineCon = m_strDynLineCon;
  540. pObj->m_bDynFore = m_bDynFore;
  541. pObj->m_bDynBack = m_bDynBack;
  542. pObj->m_bDynLine = m_bDynLine;
  543. pObj->m_strHoriPos = m_strHoriPos;
  544. pObj->m_strHoriSize = m_strHoriSize;
  545. pObj->m_strVertiPos = m_strVertiPos;
  546. pObj->m_strVertiSize = m_strVertiSize;
  547. pObj->m_bVertiSize = m_bVertiSize;
  548. pObj->m_bVertiPos = m_bVertiPos;
  549. pObj->m_bHorizSize = m_bHorizSize;
  550. pObj->m_bHorizPos = m_bHorizPos;
  551. pObj->m_downAction = m_downAction;
  552. pObj->m_upAction = m_upAction;
  553. pObj->m_moveAction = m_moveAction;
  554. pObj->m_bOnButtonUp = m_bOnButtonUp;
  555. pObj->m_bOnButtonDown = m_bOnButtonDown;
  556. pObj->m_bOnMove = m_bOnMove;
  557. return pObj;
  558. }
  559. void CDrawObj::Serialize(CArchive& ar)
  560. {
  561. CObject::Serialize(ar);
  562. if (ar.IsStoring())
  563. {
  564. ar << m_rect;
  565. ar << m_clrFore; // 前景色
  566. ar << m_clrLine; // 线色
  567. ar << m_clrBack; // 背景色
  568. ar << m_clrFill; // 填充色
  569. ar << m_nLineWidth;
  570. ar << m_strLineType;
  571. ar << m_strCaption;
  572. ar << m_bVariant;
  573. ar << m_clrDynFore;
  574. ar << m_strDynForeCon;
  575. ar << m_bDynFore;
  576. ar << m_clrDynBack;
  577. ar << m_strDynBackCon;
  578. ar << m_clrDynLine;
  579. ar << m_strDynLineCon;
  580. ar << m_bDynBack;
  581. ar << m_bDynLine;
  582. ar << m_bDynShow;
  583. ar << m_strDynShow;
  584. //if( m_strDynShow!="" ) LOG4C((LOG_NOTICE, "m_strDynShow=< %s >,m_bDynShow = %d",m_strDynShow,m_bDynShow));
  585. ar << m_strHoriPos;
  586. ar << m_strHoriSize;
  587. ar << m_strVertiPos;
  588. ar << m_strVertiSize;
  589. ar << m_bVertiSize;
  590. ar << m_bVertiPos;
  591. ar << m_bHorizSize;
  592. ar << m_bHorizPos;
  593. ar << m_bOnButtonUp;
  594. ar << m_bOnButtonDown;
  595. ar << m_bOnMove;
  596. ar << m_nHorAlign;
  597. ar << m_nVerAlign;
  598. ar << m_nFillMode;
  599. ar.Write(&m_logfont, sizeof(LOGFONT));
  600. }
  601. else
  602. {
  603. ar >> m_rect;
  604. ar >> m_clrFore; // 前景色
  605. ar >> m_clrLine; // 线色
  606. ar >> m_clrBack; // 背景色
  607. ar >> m_clrFill; // 填充色
  608. ar >> m_nLineWidth;
  609. ar >> m_strLineType;
  610. ar >> m_strCaption;
  611. ar >> m_bVariant;
  612. ar >> m_clrDynFore;
  613. ar >> m_strDynForeCon;
  614. ar >> m_bDynFore;
  615. ar >> m_clrDynBack;
  616. ar >> m_strDynBackCon;
  617. ar >> m_clrDynLine;
  618. ar >> m_strDynLineCon;
  619. ar >> m_bDynBack;
  620. ar >> m_bDynLine;
  621. ar >> m_bDynShow;
  622. ar >> m_strDynShow;
  623. //if( m_strDynShow!="" ) LOG4C((LOG_NOTICE, "m_strDynShow=< %s >,m_bDynShow = %d",m_strDynShow,m_bDynShow));
  624. ar >> m_strHoriPos;
  625. ar >> m_strHoriSize;
  626. ar >> m_strVertiPos;
  627. ar >> m_strVertiSize;
  628. ar >> m_bVertiSize;
  629. ar >> m_bVertiPos;
  630. ar >> m_bHorizSize;
  631. ar >> m_bHorizPos;
  632. ar >> m_bOnButtonUp;
  633. ar >> m_bOnButtonDown;
  634. ar >> m_bOnMove;
  635. ar >> m_nHorAlign;
  636. ar >> m_nVerAlign;
  637. ar >> m_nFillMode;
  638. ar.Read(&m_logfont, sizeof(LOGFONT));
  639. m_rctCurrent = m_rect;
  640. }
  641. m_downAction.Serialize(ar);
  642. m_upAction.Serialize(ar);
  643. m_moveAction.Serialize(ar);
  644. m_clrCurrentLine = m_clrLine;
  645. m_clrCurrentFore = m_clrFore;
  646. m_clrCurrentBack = m_clrBack;
  647. }
  648. BOOL CDrawObj::OnAttrib(void)
  649. {// 可设置成回调函数,让外部实现回调细节;
  650. CPropertySheet sheet;
  651. CBaseProDlg pageBase;
  652. pageBase.m_clrBack = m_clrBack;
  653. pageBase.m_clrFore = m_clrFore;
  654. pageBase.m_clrLine = m_clrLine;
  655. pageBase.m_clrFill = m_clrFill;
  656. pageBase.m_logfont = m_logfont;
  657. pageBase.m_strCaption = m_strCaption;
  658. pageBase.m_strLineWidth.Format("%d", m_nLineWidth);
  659. pageBase.m_strLineType = m_strLineType;
  660. pageBase.m_bDynShow = m_bDynShow;
  661. pageBase.m_strShowCondition = m_strDynShow;
  662. pageBase.m_bVariant = m_bVariant;
  663. pageBase.m_nFillMode = m_nFillMode;
  664. sheet.AddPage(&pageBase);
  665. // 编辑多个
  666. if (m_bModifyMore)
  667. {
  668. //CDataPage page;
  669. //page.m_nFormat = 1;
  670. //sheet.AddPage(&page);
  671. pageBase.m_bMoreEdit = true;
  672. sheet.Construct(g_strParamSet);
  673. sheet.m_psh.dwFlags |= PSH_NOAPPLYNOW;
  674. if (sheet.DoModal() == IDOK)
  675. {
  676. m_clrBack = pageBase.m_clrBack;
  677. m_clrFore = pageBase.m_clrFore;
  678. m_clrLine = pageBase.m_clrLine;
  679. m_clrFill = pageBase.m_clrFill;
  680. m_logfont = pageBase.m_logfont;
  681. m_nLineWidth = atoi(pageBase.m_strLineWidth);
  682. m_strLineType = pageBase.m_strLineType;
  683. m_nFillMode = pageBase.m_nFillMode;
  684. for (int i = 0; i < (int)pageBase.m_vtbitmapList.size(); i++)
  685. {
  686. delete pageBase.m_vtbitmapList[i];
  687. }
  688. return TRUE;
  689. }
  690. for (int i = 0; i < (int)pageBase.m_vtbitmapList.size(); i++)
  691. {
  692. delete pageBase.m_vtbitmapList[i];
  693. }
  694. return FALSE;
  695. }
  696. CDynamicProPage pageDynamic;
  697. pageDynamic.m_clrForeColor = m_clrDynFore;
  698. pageDynamic.m_strForeColorCondition = m_strDynForeCon;
  699. pageDynamic.m_bForeColor = m_bDynFore;
  700. pageDynamic.m_strHoriPos = m_strHoriPos;
  701. pageDynamic.m_strHoriSize = m_strHoriSize;
  702. pageDynamic.m_strVertiPos = m_strVertiPos;
  703. pageDynamic.m_strVertiSize = m_strVertiSize;
  704. pageDynamic.m_bVertiSize = m_bVertiSize;
  705. pageDynamic.m_bVertiPos = m_bVertiPos;
  706. pageDynamic.m_bHorizSize = m_bHorizSize;
  707. pageDynamic.m_bHorizPos = m_bHorizPos;
  708. pageDynamic.m_bBackColor = m_bDynBack;
  709. pageDynamic.m_bLineColor = m_bDynLine;
  710. pageDynamic.m_clrBackColor = m_clrDynBack;
  711. pageDynamic.m_clrLineColor = m_clrDynLine;
  712. pageDynamic.m_strBackColorCondition = m_strDynBackCon;
  713. pageDynamic.m_strFLineColorCondition = m_strDynLineCon;
  714. pageDynamic.m_downAction = m_downAction;
  715. pageDynamic.m_upAction = m_upAction;
  716. pageDynamic.m_moveAction = m_moveAction;
  717. pageDynamic.m_bOnButtonUp = m_bOnButtonUp;
  718. pageDynamic.m_bOnButtonDown = m_bOnButtonDown;
  719. //pageDynamic.m_bOnMove = m_bOnMove;
  720. pageDynamic.m_nHorAlign = m_nHorAlign;
  721. pageDynamic.m_nVerAlign = m_nVerAlign;
  722. sheet.AddPage(&pageDynamic);
  723. sheet.m_psh.dwFlags |= PSH_NOAPPLYNOW;
  724. if (OnAttrib(sheet))
  725. {
  726. m_clrBack = pageBase.m_clrBack;
  727. m_clrFore = pageBase.m_clrFore;
  728. m_clrLine = pageBase.m_clrLine;
  729. m_clrFill = pageBase.m_clrFill;
  730. m_logfont = pageBase.m_logfont;
  731. m_strCaption = pageBase.m_strCaption;
  732. m_nLineWidth = atoi(pageBase.m_strLineWidth);
  733. m_strLineType = pageBase.m_strLineType;
  734. m_bDynShow = pageBase.m_bDynShow;
  735. m_strDynShow = pageBase.m_strShowCondition;
  736. m_bVariant = pageBase.m_bVariant;
  737. m_nFillMode = pageBase.m_nFillMode;
  738. m_clrDynFore = pageDynamic.m_clrForeColor;
  739. m_strDynForeCon = pageDynamic.m_strForeColorCondition;
  740. m_bDynBack = pageDynamic.m_bBackColor;
  741. m_bDynLine = pageDynamic.m_bLineColor;
  742. m_clrDynBack = pageDynamic.m_clrBackColor;
  743. m_clrDynLine = pageDynamic.m_clrLineColor;
  744. m_strDynBackCon = pageDynamic.m_strBackColorCondition;
  745. m_strDynLineCon = pageDynamic.m_strFLineColorCondition;
  746. m_bDynFore = pageDynamic.m_bForeColor;
  747. m_strHoriPos = pageDynamic.m_strHoriPos;
  748. m_strHoriSize = pageDynamic.m_strHoriSize;
  749. m_strVertiPos = pageDynamic.m_strVertiPos;
  750. m_strVertiSize = pageDynamic.m_strVertiSize;
  751. m_bVertiSize = pageDynamic.m_bVertiSize;
  752. m_bVertiPos = pageDynamic.m_bVertiPos;
  753. m_bHorizSize = pageDynamic.m_bHorizSize;
  754. m_bHorizPos = pageDynamic.m_bHorizPos;
  755. m_downAction = pageDynamic.m_downAction;
  756. m_upAction = pageDynamic.m_upAction;
  757. m_moveAction = pageDynamic.m_moveAction;
  758. m_bOnButtonUp = pageDynamic.m_bOnButtonUp;
  759. m_bOnButtonDown = pageDynamic.m_bOnButtonDown;
  760. //m_bOnMove = pageDynamic.m_bOnMove;
  761. m_nHorAlign = pageDynamic.m_nHorAlign;
  762. m_nVerAlign = pageDynamic.m_nVerAlign;
  763. for (int i = 0; i < (int)pageBase.m_vtbitmapList.size(); i++)
  764. {
  765. //m_vtbitmapList.pop_back();
  766. delete pageBase.m_vtbitmapList[i];
  767. }
  768. Invalidate();
  769. return TRUE;
  770. }
  771. for (int i = 0; i < (int)pageBase.m_vtbitmapList.size(); i++)
  772. {
  773. //m_vtbitmapList.pop_back();
  774. delete pageBase.m_vtbitmapList[i];
  775. }
  776. return FALSE;
  777. }
  778. BOOL CDrawObj::OnAttrib(CPropertySheet& sheet)
  779. {
  780. CString strName;
  781. int nSize = drawsRuntimeClass.GetSize();
  782. int i = 0;
  783. for (i = 0; i < nSize; i++)
  784. {
  785. CRuntimeClass* pRuntimeClass = (CRuntimeClass*)drawsRuntimeClass[i];
  786. if (IsKindOf(pRuntimeClass))
  787. {
  788. strName = drawsName[i];
  789. break;
  790. }
  791. }
  792. if (i == nSize) return FALSE;
  793. sheet.Construct(g_strParamSet);
  794. if (sheet.DoModal() == IDOK)
  795. {
  796. return TRUE;
  797. }
  798. return FALSE;
  799. }
  800. void CDrawObj::Draw(CDC* pDC)
  801. {
  802. if (!g_bRun)
  803. {// 编辑状态下;
  804. m_clrCurrentLine = m_clrLine;
  805. m_clrCurrentFore = m_clrFore;
  806. m_clrCurrentBack = m_clrBack;
  807. }
  808. }
  809. void CDrawObj::DrawText(CDC* pDC)
  810. {
  811. COLORREF clrFore = m_clrFore;
  812. CRect rect = m_rect;
  813. if (bRuning)
  814. {
  815. clrFore = m_clrCurrentFore;
  816. rect = m_rctCurrent;
  817. }
  818. pDC->SetTextColor(clrFore);
  819. pDC->SetTextAlign(TA_CENTER | TA_TOP);
  820. CFont font;
  821. font.CreateFontIndirect(&m_logfont);
  822. CFont* pOldFont = pDC->SelectObject(&font);
  823. int height = abs(m_logfont.lfHeight);
  824. rect.NormalizeRect();
  825. int nX0 = (rect.left + rect.right) / 2;
  826. int nY0 = (rect.top + rect.bottom) / 2;
  827. if (rect.Width() >= rect.Height())
  828. {
  829. pDC->TextOut(nX0, nY0 - height / 2, m_strCaption);
  830. }
  831. else
  832. {
  833. int xt = nX0;
  834. int yt = nY0;
  835. int Length = m_strCaption.GetLength();
  836. const char *p = (const char*)m_strCaption;
  837. int ystart = yt;
  838. int i = 0;
  839. for (i = 0; i < Length; i++)
  840. {
  841. ystart -= height / 2;
  842. if (*(p + i) < 0) i++;
  843. }
  844. for (i = 0; i < Length; i++)
  845. {
  846. if (*(p + i) < 0)
  847. {
  848. pDC->TextOut(xt, ystart, p + i, 2);
  849. i++;
  850. }
  851. else pDC->TextOut(xt, ystart, p + i, 1);
  852. ystart += height;
  853. }
  854. }
  855. pDC->SelectObject(pOldFont);
  856. DeleteObject(font);
  857. }
  858. /************************************************************************/
  859. /* 函数:Layout[10/30/2016 Home];
  860. /* 描述:布局图元;
  861. /* 参数:;
  862. /* [IN] Sharp:要布局的图元形状;
  863. /* [IN/OUT] pLayout:布局信息;
  864. /* 返回:void;
  865. /* 注意:;
  866. /* 示例:;
  867. /*
  868. /* 修改:;
  869. /* 日期:;
  870. /* 内容:;
  871. /************************************************************************/
  872. void CDrawObj::Layout(IN BYTE Sharp, IN OUT LAYOUTSTRUCT* pLayout)
  873. {
  874. ASSERT(Sharp > 0);
  875. pLayout->rect = m_rect;
  876. pLayout->rect.NormalizeRect();
  877. pLayout->nX1 = pLayout->rect.left;
  878. pLayout->nX2 = pLayout->rect.right;
  879. pLayout->nY1 = pLayout->rect.top;
  880. pLayout->nY2 = pLayout->rect.bottom;
  881. pLayout->nXX = pLayout->nX2 - pLayout->nX1;
  882. pLayout->nYY = pLayout->nY2 - pLayout->nY1;
  883. pLayout->nX0 = (pLayout->nX1 + pLayout->nX2) / 2;
  884. pLayout->nY0 = (pLayout->nY1 + pLayout->nY2) / 2;
  885. pLayout->bXInvert = m_rect.left > m_rect.right;
  886. pLayout->bYInvert = m_rect.top > m_rect.bottom;
  887. if (pLayout->nXX >= pLayout->nYY)
  888. {
  889. pLayout->bHoriz = TRUE;
  890. pLayout->nMinSize = min(pLayout->nXX / Sharp, pLayout->nYY);
  891. }
  892. else
  893. {
  894. pLayout->bHoriz = FALSE;
  895. pLayout->nMinSize = min(pLayout->nXX, pLayout->nYY / Sharp);
  896. }
  897. }
  898. int CDrawObj::GetHandleCount(void)
  899. {
  900. return 8;
  901. }
  902. CPoint CDrawObj::GetHandle(int nHandle)
  903. {
  904. #if 0
  905. int x, y, xCenter, yCenter;
  906. xCenter = m_rect.left + m_rect.Width() / 2;
  907. yCenter = m_rect.top + m_rect.Height() / 2;
  908. switch (nHandle)
  909. {
  910. case 1: x = m_rect.left; y = m_rect.top; break;
  911. case 2: x = xCenter; y = m_rect.top; break;
  912. case 3: x = m_rect.right; y = m_rect.top; break;
  913. case 4: x = m_rect.right; y = yCenter; break;
  914. case 5: x = m_rect.right; y = m_rect.bottom; break;
  915. case 6: x = xCenter; y = m_rect.bottom; break;
  916. case 7: x = m_rect.left; y = m_rect.bottom; break;
  917. case 8: x = m_rect.left; y = yCenter; break;
  918. }
  919. return CPoint(x, y);
  920. #else
  921. if (nHandle == 1)
  922. return CPoint(m_rect.left, m_rect.top);
  923. else if (nHandle == 2)
  924. return CPoint(m_rect.left + m_rect.Width() / 2, m_rect.top);
  925. else if (nHandle == 3)
  926. return CPoint(m_rect.right, m_rect.top);
  927. else if (nHandle == 4)
  928. return CPoint(m_rect.right, m_rect.top + m_rect.Height() / 2);
  929. else if (nHandle == 5)
  930. return CPoint(m_rect.right, m_rect.bottom);
  931. else if (nHandle == 6)
  932. return CPoint(m_rect.left + m_rect.Width() / 2, m_rect.bottom);
  933. else if (nHandle == 7)
  934. return CPoint(m_rect.left, m_rect.bottom);
  935. else if (nHandle == 8)
  936. return CPoint(m_rect.left, m_rect.top + m_rect.Height() / 2);
  937. return CPoint(0, 0);
  938. #endif
  939. }
  940. CRect CDrawObj::GetHandleRect(int nHandle)
  941. {
  942. CRect rect;
  943. CPoint point = GetHandle(nHandle);
  944. rect.SetRect(point.x - 3, point.y - 3, point.x + 3, point.y + 3);
  945. return rect;
  946. }
  947. HCURSOR CDrawObj::GetHandleCursor()
  948. {
  949. return AfxGetApp()->LoadCursor(IDC_CURSOR2);
  950. }
  951. void CDrawObj::MoveTo(CRect rect)
  952. {
  953. if (rect == m_rect) return;
  954. Invalidate();
  955. m_rect = rect;
  956. Invalidate();
  957. }
  958. void CDrawObj::MoveHandleTo(int nHandle, CPoint point)
  959. {
  960. CRect rect = m_rect;
  961. switch (nHandle)
  962. {
  963. case 1: rect.left = point.x; rect.top = point.y; break;
  964. case 2: rect.top = point.y; break;
  965. case 3: rect.right = point.x; rect.top = point.y; break;
  966. case 4: rect.right = point.x; break;
  967. case 5: rect.right = point.x; rect.bottom = point.y; break;
  968. case 6: rect.bottom = point.y; break;
  969. case 7: rect.left = point.x; rect.bottom = point.y; break;
  970. case 8: rect.left = point.x; break;
  971. }
  972. MoveTo(rect);
  973. }
  974. void CDrawObj::DrawTracker(CDC* pDC)
  975. {
  976. // 除CDrawPoly对象外,其他图元都是返回8个点;
  977. int nHandleCount = GetHandleCount();
  978. for (int nHandle = 1; nHandle <= nHandleCount; nHandle++)
  979. {
  980. CPoint handle = GetHandle(nHandle);
  981. pDC->PatBlt(handle.x - 3, handle.y - 3, 7, 7, DSTINVERT);
  982. }
  983. }
  984. int CDrawObj::HitTest(CPoint point)
  985. {
  986. int nHandleCount = GetHandleCount();
  987. for (int nHandle = 1; nHandle <= nHandleCount; nHandle++)
  988. {
  989. CRect rc = GetHandleRect(nHandle);
  990. if (rc.PtInRect(point)) return nHandle;
  991. }
  992. return 0;
  993. }
  994. BOOL CDrawObj::Intersects(CRect rect)
  995. {
  996. CRect fixed = m_rect;
  997. fixed.NormalizeRect();
  998. CRect rectT = rect;
  999. rectT.NormalizeRect();
  1000. return !(rectT & fixed).IsRectEmpty();
  1001. }
  1002. void CDrawObj::Invalidate(void)
  1003. {
  1004. CRect rect = m_rect;
  1005. rect.NormalizeRect();
  1006. rect.InflateRect(5, 5, 5, 5);
  1007. CClientDC dc(m_pView);
  1008. m_pView->OnPrepareDC(&dc);
  1009. dc.LPtoDP(&rect);
  1010. m_pView->InvalidateRect(rect, FALSE);
  1011. }
  1012. int CDrawObj::GetPenStyle(CString penType)
  1013. {
  1014. if (penType == "PS_SOLID")
  1015. {
  1016. return PS_SOLID;
  1017. }
  1018. else if (penType == "PS_DASH")
  1019. {
  1020. return PS_DASH;
  1021. }
  1022. else if (penType == "PS_DOT")
  1023. {
  1024. return PS_DOT;
  1025. }
  1026. else if (penType == "PS_DASHDOT")
  1027. {
  1028. return PS_DASHDOT;
  1029. }
  1030. else if (penType == "PS_DASHDOTDOT")
  1031. {
  1032. return PS_DASHDOTDOT;
  1033. }
  1034. else if (penType == "PS_NULL")
  1035. {
  1036. return PS_NULL;
  1037. }
  1038. return PS_SOLID;
  1039. }
  1040. // 控制类型:
  1041. // 遥控:控分;控合;取反
  1042. // 遥设:设定;固定;动态输入
  1043. // 增减;固定;动态
  1044. void CDrawObj::ProcessAction(int type)
  1045. {
  1046. CAction action;
  1047. switch (type)
  1048. {
  1049. case MOUSE_CLICK_DOWN:
  1050. action = m_downAction; break;
  1051. case MOUSE_CLICK_UP:
  1052. action = m_upAction; break;
  1053. case MOUSE_MOVE:
  1054. action = m_moveAction; break;
  1055. };
  1056. // exit
  1057. if (action.m_nActionType == EXIT_COMMOND)
  1058. {
  1059. CMainFrame *pFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
  1060. pFrame->OnSuperEnd();
  1061. return;
  1062. }
  1063. // link
  1064. else if (action.m_nActionType == LINK_COMMOND)
  1065. {
  1066. char picDir[_MAX_PATH] = { 0 };
  1067. strcpy(picDir, g_strDirectory);
  1068. strcat(picDir, "\\");
  1069. strcat(picDir, _PICTUREDIR);
  1070. strcat(picDir, action.m_strVariant);
  1071. strcat(picDir, ".view");
  1072. //CString str;
  1073. //str = action.m_strPicPath + ".view";
  1074. CMainFrame *pFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
  1075. pFrame->AddIDEView(action.m_strVariant, picDir);
  1076. return;
  1077. }
  1078. // extern link
  1079. else if (action.m_nActionType == EXTERN_COMMOND)
  1080. {
  1081. ShellExecute(0, "open", action.m_strActionValue, NULL, NULL, SW_SHOWNORMAL);
  1082. }
  1083. // 测试报警
  1084. else if (action.m_nActionType == TEST_ALARM)
  1085. {
  1086. }
  1087. // 报警记录
  1088. else if (action.m_nActionType == ALARM_RECORD)
  1089. {
  1090. }
  1091. // 通知记录
  1092. else if (action.m_nActionType == NOTICE_RECORD)
  1093. {
  1094. }
  1095. // 设备日志
  1096. else if (action.m_nActionType == DEVICE_LOG)
  1097. {
  1098. CString strFileName;
  1099. //strFileName.Format("%s\\Query.exe", g_strDirectory);
  1100. //ShellExecute(0, "open", strFileName, NULL, NULL, SW_SHOWNORMAL);
  1101. }
  1102. // 系统日志
  1103. else if (action.m_nActionType == SYSTEM_LOG)
  1104. {
  1105. }
  1106. // 变量管理
  1107. else if (action.m_nActionType == VAR_MANAGE)
  1108. {
  1109. }
  1110. // 用户管理
  1111. else if (action.m_nActionType == USER_MANAGE)
  1112. {
  1113. }
  1114. // 修改密码
  1115. else if (action.m_nActionType == PWD_MANAGE)
  1116. {
  1117. }
  1118. // 首页设置
  1119. else if (action.m_nActionType == FIRST_PAGE)
  1120. {
  1121. CSystemParaSetDlg dlg;
  1122. dlg.m_bStartRun = g_bStartRun;
  1123. dlg.m_bAlarmVoice = g_bAlarmVoice;
  1124. dlg.m_bEventAlarm = g_bEventAlarm;
  1125. dlg.m_bHideTask = g_bHideTask;
  1126. dlg.m_strStartPic = g_strStartPic;
  1127. dlg.m_strStartPath = g_strStartPath;
  1128. if (dlg.DoModal() == IDOK)
  1129. {
  1130. #if 0 //程序退出之前不改变状态
  1131. g_bStartRun = dlg.m_bStartRun;
  1132. #endif
  1133. //int nPos = dlg.m_strStartPath.Find("\\\\");
  1134. //if( nPos!=-1 )
  1135. //{
  1136. // dlg.m_strStartPath.Delete( nPos );
  1137. //}
  1138. //
  1139. //int nLen = dlg.m_strStartPath.GetLength();
  1140. //nPos = dlg.m_strStartPath.Find("view");
  1141. //CString sTemp;
  1142. //if( nPos<nLen-7 )
  1143. // sTemp = dlg.m_strStartPath.Right( nLen-nPos-7 );
  1144. //if( sTemp!="" )
  1145. // g_strStartPic = sTemp+"\\"+dlg.m_strStartPic;
  1146. //else
  1147. g_strStartPic = dlg.m_strStartPic;
  1148. g_strStartPath = dlg.m_strStartPath;
  1149. g_bEventAlarm = dlg.m_bEventAlarm;
  1150. g_bAlarmVoice = dlg.m_bAlarmVoice;
  1151. g_bHideTask = dlg.m_bHideTask;
  1152. g_pMainFrm->StoreRunPara(dlg.m_bStartRun);
  1153. }
  1154. }
  1155. // 导航树
  1156. else if (action.m_nActionType == NAVIGATION_TREE)
  1157. {
  1158. g_pMainFrm->m_hleftDockBar.ShowWindow(SW_SHOW);
  1159. SendMessage(g_pMainFrm->m_hleftDockBar, WM_MY_INVALIDATE, 0, 0);
  1160. }
  1161. // set yt SET_COMMOND为设置 YT_COMMOND为调节
  1162. if ((action.m_nActionType == SET_COMMOND) || (action.m_nActionType == YT_COMMOND))
  1163. {
  1164. if (g_bHaveControlPwd)
  1165. {
  1166. CDlg_Pwd Dlg_Pwd;
  1167. Dlg_Pwd.m_nShowType = 1;
  1168. if (Dlg_Pwd.DoModal() != IDOK)
  1169. return;
  1170. }
  1171. if (m_downAction.m_strActionValue == "")
  1172. {
  1173. CDataInputDlg dlg;
  1174. dlg.m_strVarName = action.m_strVariant;
  1175. if (dlg.DoModal() == IDOK)
  1176. {
  1177. action.m_strActionValue = dlg.m_strData;
  1178. }
  1179. else
  1180. {
  1181. return;
  1182. }
  1183. }
  1184. else
  1185. {
  1186. MessageBox(NULL, "命令已经发送", "提示", MB_OK);
  1187. }
  1188. }
  1189. // yk 控制
  1190. if (action.m_nActionType == YK_COMMOND)
  1191. {
  1192. if (g_bHaveControlPwd)
  1193. {
  1194. CDlg_Pwd Dlg_Pwd;
  1195. Dlg_Pwd.m_nShowType = 1;
  1196. if (Dlg_Pwd.DoModal() != IDOK)
  1197. return;
  1198. }
  1199. CYkCmdDlg dlg;
  1200. if (m_downAction.m_strActionValue == "")
  1201. dlg.m_strValue = "1-0";
  1202. else
  1203. dlg.m_strValue = m_downAction.m_strActionValue;
  1204. if (dlg.DoModal() == IDOK)
  1205. {
  1206. action.m_strActionValue = dlg.m_strValue;
  1207. }
  1208. else
  1209. {
  1210. return;
  1211. }
  1212. }
  1213. CCommondServer server;
  1214. server.PushCommondToDevice(&action);
  1215. }
  1216. void CDrawObj::DrawFrame(CDC *pDC)
  1217. {
  1218. CRect rect = m_rect;
  1219. rect.NormalizeRect();
  1220. CRect rectLeft = CRect(rect.left - 4, rect.top - 4, rect.left, rect.bottom);
  1221. CRect rectBottom = CRect(rect.left - 4, rect.bottom, rect.right, rect.bottom + 4);
  1222. CRect rectRight = CRect(rect.right, rect.top, rect.right + 4, rect.bottom + 4);
  1223. CRect rectTop = CRect(rect.left, rect.top - 4, rect.right + 4, rect.top);
  1224. pDC->FillSolidRect(rectLeft, RGB(0, 0, 255));
  1225. pDC->FillSolidRect(rectBottom, RGB(0, 0, 255));
  1226. pDC->FillSolidRect(rectRight, RGB(0, 0, 255));
  1227. pDC->FillSolidRect(rectTop, RGB(0, 0, 255));
  1228. }
  1229. void CDrawObj::DrawVKedu(CDC* pDC, CRect rect, int nKedu, COLORREF clrKedu)
  1230. {
  1231. CPen pen(PS_SOLID, 1, clrKedu);
  1232. CPen *pOldPen = pDC->SelectObject(&pen);
  1233. pDC->MoveTo(rect.TopLeft());
  1234. pDC->LineTo(rect.left, rect.bottom);
  1235. //for(int i=0;i<=nKedu;i++)
  1236. //{
  1237. // int nY = rect.top + i*(rect.Height()*1.0/nKedu);
  1238. // if (i == nKedu )
  1239. // nY = rect.bottom;
  1240. // pDC->MoveTo(rect.left, nY);
  1241. // pDC->LineTo(rect.right, nY);
  1242. //}
  1243. pDC->SelectObject(pOldPen);
  1244. DeleteObject(pen);
  1245. }
  1246. void CDrawObj::DrawHKedu(CDC* pDC, CRect rect, int nKedu, COLORREF clrKedu)
  1247. {
  1248. CPen pen(PS_SOLID, 1, clrKedu);
  1249. CPen *pOldPen = pDC->SelectObject(&pen);
  1250. pDC->MoveTo(rect.right, rect.bottom);
  1251. pDC->LineTo(rect.left, rect.bottom);
  1252. for (int i = 0; i <= nKedu; i++)
  1253. {
  1254. int nX = rect.left + i*(rect.Width()*1.0 / nKedu);
  1255. pDC->MoveTo(nX, rect.top);
  1256. pDC->LineTo(nX, rect.bottom);
  1257. }
  1258. pDC->SelectObject(pOldPen);
  1259. DeleteObject(pen);
  1260. }
  1261. void CDrawObj::DrawArcKedu(CDC* pDC, CRect rect, int nStartAngle, int nEndAngle, int nKedu, COLORREF clrKedu)
  1262. {
  1263. CPen pen(PS_SOLID, 1, clrKedu);
  1264. CPen *pOldPen = pDC->SelectObject(&pen);
  1265. pDC->SelectObject(pOldPen);
  1266. DeleteObject(pen);
  1267. }
  1268. LOGBRUSH CDrawObj::GetBrush()
  1269. {
  1270. LOGBRUSH brushlog;
  1271. brushlog.lbColor = m_clrCurrentBack;
  1272. if (m_nFillMode == 0)
  1273. brushlog.lbStyle = BS_NULL;
  1274. else if (m_nFillMode == 1)
  1275. brushlog.lbStyle = BS_SOLID;
  1276. else if (m_nFillMode < 8)
  1277. {
  1278. brushlog.lbStyle = BS_HATCHED;
  1279. brushlog.lbHatch = m_nFillMode - 2;
  1280. }
  1281. else
  1282. brushlog.lbStyle = BS_SOLID;
  1283. return brushlog;
  1284. }
  1285. //---------------------------------------------- CDrawComposite ---
  1286. IMPLEMENT_SERIAL(CDrawComposite, CDrawObj, 0)
  1287. CDrawComposite::CDrawComposite() :CDrawObj()
  1288. {
  1289. }
  1290. CDrawComposite::CDrawComposite(CDrawObjList &ObjList) : CDrawObj()
  1291. {
  1292. m_ObjList.RemoveAll();
  1293. POSITION pos = ObjList.GetHeadPosition();
  1294. bool bFirst = true;
  1295. while (pos != NULL)
  1296. {
  1297. CDrawObj *pObj = ObjList.GetNext(pos);
  1298. CDrawObj *pNewObj = pObj->Clone();
  1299. m_ObjList.AddTail(pNewObj);
  1300. if (bFirst)
  1301. {
  1302. m_rect = pNewObj->m_rect;
  1303. bFirst = false;
  1304. }
  1305. else
  1306. {
  1307. int nLeft = min(m_rect.left, pNewObj->m_rect.left);
  1308. int nTop = min(m_rect.top, pNewObj->m_rect.top);
  1309. int nBottom = max(m_rect.bottom, pNewObj->m_rect.bottom);
  1310. int nRight = max(m_rect.right, pNewObj->m_rect.right);
  1311. m_rect = CRect(nLeft, nTop, nRight, nBottom);
  1312. }
  1313. }
  1314. pos = m_ObjList.GetHeadPosition();
  1315. while (pos != NULL)
  1316. {
  1317. CDrawObj *pObj = m_ObjList.GetNext(pos);
  1318. pObj->m_dbLeftRate = (pObj->m_rect.left - m_rect.left)*1.0 / m_rect.Width();
  1319. pObj->m_dbRightRate = (pObj->m_rect.right - m_rect.left)*1.0 / m_rect.Width();
  1320. pObj->m_dbTopRate = (pObj->m_rect.top - m_rect.top)*1.0 / m_rect.Height();
  1321. pObj->m_dbBottomRate = (pObj->m_rect.bottom - m_rect.top)*1.0 / m_rect.Height();
  1322. }
  1323. }
  1324. CDrawComposite::~CDrawComposite()
  1325. {
  1326. POSITION pos = m_ObjList.GetHeadPosition();
  1327. while (pos != NULL) delete m_ObjList.GetNext(pos);
  1328. m_ObjList.RemoveAll();
  1329. }
  1330. CDrawComposite& CDrawComposite::operator=(CDrawComposite& drawObj)
  1331. {
  1332. CDrawComposite* pComposite = new CDrawComposite();
  1333. return *pComposite;
  1334. }
  1335. CDrawObj* CDrawComposite::Clone(void)
  1336. {
  1337. CDrawComposite* pComposite = new CDrawComposite();
  1338. *((CDrawObj*)pComposite) = *(CDrawObj*)this;
  1339. pComposite->m_ObjList.RemoveAll();
  1340. POSITION pos = m_ObjList.GetHeadPosition();
  1341. bool bFirst = true;
  1342. while (pos != NULL)
  1343. {
  1344. CDrawObj *pObj = m_ObjList.GetNext(pos);
  1345. CDrawObj *pNewObj = pObj->Clone();
  1346. pComposite->m_ObjList.AddTail(pNewObj);
  1347. if (bFirst)
  1348. {
  1349. pComposite->m_rect = pNewObj->m_rect;
  1350. bFirst = false;
  1351. }
  1352. else
  1353. {
  1354. int nLeft = min(pComposite->m_rect.left, pNewObj->m_rect.left);
  1355. int nTop = min(pComposite->m_rect.top, pNewObj->m_rect.top);
  1356. int nBottom = max(pComposite->m_rect.bottom, pNewObj->m_rect.bottom);
  1357. int nRight = max(pComposite->m_rect.right, pNewObj->m_rect.right);
  1358. pComposite->m_rect = CRect(nLeft, nTop, nRight, nBottom);
  1359. }
  1360. }
  1361. pos = pComposite->m_ObjList.GetHeadPosition();
  1362. while (pos != NULL)
  1363. {
  1364. CDrawObj *pObj = pComposite->m_ObjList.GetNext(pos);
  1365. pObj->m_dbLeftRate = (pObj->m_rect.left - pComposite->m_rect.left)*1.0 / pComposite->m_rect.Width();
  1366. pObj->m_dbRightRate = (pObj->m_rect.right - pComposite->m_rect.left)*1.0 / pComposite->m_rect.Width();
  1367. pObj->m_dbTopRate = (pObj->m_rect.top - pComposite->m_rect.top)*1.0 / pComposite->m_rect.Height();
  1368. pObj->m_dbBottomRate = (pObj->m_rect.bottom - pComposite->m_rect.top)*1.0 / pComposite->m_rect.Height();
  1369. }
  1370. return pComposite;
  1371. }
  1372. void CDrawComposite::Serialize(CArchive& ar)
  1373. {
  1374. CDrawObj::Serialize(ar);
  1375. m_ObjList.Serialize(ar);
  1376. POSITION pos = m_ObjList.GetHeadPosition();
  1377. while (pos != NULL)
  1378. {
  1379. CDrawObj *pObj = m_ObjList.GetNext(pos);
  1380. pObj->m_dbLeftRate = (pObj->m_rect.left - m_rect.left)*1.0 / m_rect.Width();
  1381. pObj->m_dbRightRate = (pObj->m_rect.right - m_rect.left)*1.0 / m_rect.Width();
  1382. pObj->m_dbTopRate = (pObj->m_rect.top - m_rect.top)*1.0 / m_rect.Height();
  1383. pObj->m_dbBottomRate = (pObj->m_rect.bottom - m_rect.top)*1.0 / m_rect.Height();
  1384. }
  1385. }
  1386. void CDrawComposite::Draw(CDC* pDC)
  1387. {
  1388. POSITION pos = m_ObjList.GetHeadPosition();
  1389. while (pos != NULL)
  1390. {
  1391. CDrawObj* pObj = m_ObjList.GetNext(pos);
  1392. CRect rect = pObj->m_rect;
  1393. rect.NormalizeRect();
  1394. rect.InflateRect(5, 5, 5, 5);
  1395. if (rect.IntersectRect(&rect, &m_rect))
  1396. {
  1397. pObj->Draw(pDC);
  1398. }
  1399. }
  1400. }
  1401. void CDrawComposite::MoveTo(CRect rect)
  1402. {
  1403. if (rect == m_rect)
  1404. {
  1405. return;
  1406. }
  1407. POSITION pos = m_ObjList.GetHeadPosition();
  1408. while (pos != NULL)
  1409. {
  1410. CDrawObj* pObj = m_ObjList.GetNext(pos);
  1411. pObj->m_rect.left = rect.left + pObj->m_dbLeftRate*rect.Width();
  1412. pObj->m_rect.right = rect.left + pObj->m_dbRightRate*rect.Width();
  1413. pObj->m_rect.top = rect.top + pObj->m_dbTopRate * rect.Height();
  1414. pObj->m_rect.bottom = rect.top + pObj->m_dbBottomRate * rect.Height();
  1415. }
  1416. m_rect = rect;
  1417. Invalidate();
  1418. }
  1419. //////////////////////////////////////////////////////////////////////////
  1420. //---------------------------------------------- CDrawTLine --------
  1421. IMPLEMENT_SERIAL(CDrawTLine, CDrawObj, 0)
  1422. CDrawTLine::CDrawTLine() :CDrawObj()
  1423. {
  1424. }
  1425. CDrawObj* CDrawTLine::Clone(void)
  1426. {
  1427. CDrawTLine *pObj = new CDrawTLine;
  1428. *((CDrawObj*)pObj) = *(CDrawObj*)this;
  1429. return pObj;
  1430. }
  1431. void CDrawTLine::Draw(CDC* pDC)
  1432. {
  1433. COLORREF clrLine = m_clrLine;
  1434. CRect rect = m_rect;
  1435. if (bRuning)
  1436. {
  1437. clrLine = m_clrCurrentLine;
  1438. rect = m_rctCurrent;
  1439. }
  1440. CPen pen(GetPenStyle(m_strLineType), m_nLineWidth, clrLine);
  1441. CPen* pOldPen = pDC->SelectObject(&pen);
  1442. rect.NormalizeRect();
  1443. if (rect.Width() >= rect.Height())
  1444. {
  1445. int nY0 = (rect.top + rect.bottom) / 2;
  1446. pDC->MoveTo(rect.left, nY0);
  1447. pDC->LineTo(rect.right, nY0);
  1448. }
  1449. else
  1450. {
  1451. int nX0 = (rect.left + rect.right) / 2;
  1452. pDC->MoveTo(nX0, rect.top);
  1453. pDC->LineTo(nX0, rect.bottom);
  1454. }
  1455. pDC->SelectObject(pOldPen);
  1456. DeleteObject(pen);
  1457. }
  1458. //////////////////////////////////////////////////////////////////////////
  1459. //---------------------------------------------- CDrawLine --------
  1460. IMPLEMENT_SERIAL(CDrawLine, CDrawObj, 0)
  1461. CDrawLine::CDrawLine() :CDrawObj()
  1462. {
  1463. }
  1464. CDrawObj* CDrawLine::Clone(void)
  1465. {
  1466. CDrawLine *pObj = new CDrawLine;
  1467. *((CDrawObj*)pObj) = *(CDrawObj*)this;
  1468. return pObj;
  1469. }
  1470. void CDrawLine::Draw(CDC* pDC)
  1471. {
  1472. COLORREF clrLine = m_clrLine;
  1473. CRect rect = m_rect;
  1474. if (bRuning)
  1475. {
  1476. clrLine = m_clrCurrentLine;
  1477. rect = m_rctCurrent;
  1478. }
  1479. CPen pen(GetPenStyle(m_strLineType), m_nLineWidth, clrLine);
  1480. CPen* pOldPen = pDC->SelectObject(&pen);
  1481. pDC->MoveTo(rect.left, rect.top);
  1482. pDC->LineTo(rect.right, rect.bottom);
  1483. pDC->SelectObject(pOldPen);
  1484. DeleteObject(pen);
  1485. }
  1486. //////////////////////////////////////////////////////////////////////////
  1487. //---------------------------------------------- CDrawText --------
  1488. IMPLEMENT_SERIAL(CDrawText, CDrawObj, 0)
  1489. CDrawText::CDrawText() :CDrawObj()
  1490. {
  1491. m_strCaption = g_strCharacter;
  1492. m_clrFore = RGB(0, 0, 0);
  1493. }
  1494. CDrawObj* CDrawText::Clone(void)
  1495. {
  1496. CDrawText *pObj = new CDrawText;
  1497. *((CDrawObj*)pObj) = *(CDrawObj*)this;
  1498. return pObj;
  1499. }
  1500. bool CDrawText::Fresh(CRect &RECT)
  1501. {
  1502. CDrawObj::Fresh(RECT);
  1503. //Invalidate( );
  1504. RECT = m_rect;
  1505. return true;
  1506. }
  1507. void CDrawText::Draw(CDC* pDC)
  1508. {
  1509. CDrawObj::Draw(pDC);
  1510. if (!m_bShow && bRuning) return;
  1511. if (!pDC->IsPrinting())
  1512. {// 非打印状态下;
  1513. CRect rectRgn = m_rctCurrent;
  1514. if (!bRuning) rectRgn = m_rect;
  1515. rectRgn.NormalizeRect();
  1516. pDC->LPtoDP(&rectRgn);
  1517. CRgn rgn;
  1518. rgn.CreateRectRgnIndirect(&rectRgn);
  1519. pDC->SelectClipRgn(&rgn);
  1520. DrawText(pDC);
  1521. pDC->SelectClipRgn(NULL);
  1522. DeleteObject(rgn);
  1523. }
  1524. else
  1525. DrawText(pDC);
  1526. }
  1527. void CDrawText::DrawText(CDC* pDC)
  1528. {
  1529. COLORREF clrFore = m_clrFore;
  1530. CRect rect = m_rect;
  1531. if (bRuning)
  1532. {
  1533. clrFore = m_clrCurrentFore;
  1534. rect = m_rctCurrent;
  1535. }
  1536. pDC->SetTextColor(clrFore);
  1537. pDC->SetTextAlign(TA_LEFT | TA_TOP);
  1538. CFont font;
  1539. font.CreateFontIndirect(&m_logfont);
  1540. CFont* pOldFont = pDC->SelectObject(&font);
  1541. int height = abs(m_logfont.lfHeight);
  1542. rect.NormalizeRect();
  1543. //int nX0 = (rect.left+rect.right) / 2;
  1544. //int nY0 = (rect.top+rect.bottom) / 2;
  1545. //if(rect.Width()>=rect.Height())
  1546. //{
  1547. // int yt = nY0;
  1548. // int Length = m_strCaption.GetLength();
  1549. // const char *p = (const char*)m_strCaption;
  1550. // int ystart = yt;
  1551. // for(int i=0;i<Length;i++)
  1552. // {
  1553. // ystart -= height / 2;
  1554. // if(*(p+i)<0) i++;
  1555. // }
  1556. // pDC->TextOut(rect.left, ystart, m_strCaption);
  1557. //}
  1558. //else
  1559. //{
  1560. // int xt = nX0;
  1561. // int yt = nY0;
  1562. // int Length = m_strCaption.GetLength();
  1563. // const char *p = (const char*)m_strCaption;
  1564. // int ystart = yt;
  1565. // for(int i=0;i<Length;i++)
  1566. // {
  1567. // ystart -= height / 2;
  1568. // if(*(p+i)<0) i++;
  1569. // }
  1570. // for(i=0;i<Length;i++)
  1571. // {
  1572. // if(*(p+i)<0)
  1573. // {
  1574. // pDC->TextOut(xt,ystart,p+i,2);
  1575. // i++;
  1576. // }
  1577. // else pDC->TextOut(xt,ystart,p+i,1);
  1578. // ystart += height;
  1579. // }
  1580. //}
  1581. //pDC->SelectObject(pOldFont);
  1582. //DeleteObject( font );
  1583. int nX0 = (rect.left + rect.right) / 2;
  1584. int nY0 = (rect.top + rect.bottom) / 2;
  1585. CSize sizeText = pDC->GetTextExtent(m_strCaption);
  1586. int nInterval = sizeText.cy / 2;
  1587. int nYText = nY0 - nInterval + 1;
  1588. int nXText;
  1589. //pDC->SetTextAlign(TA_CENTER|TA_TOP);
  1590. nXText = rect.left;
  1591. //pDC->SetTextColor(txtColor);
  1592. pDC->TextOut(nXText, nYText, m_strCaption);
  1593. pDC->SelectObject(pOldFont);
  1594. DeleteObject(font);
  1595. }
  1596. //////////////////////////////////////////////////////////////////////////
  1597. //---------------------------------------------- CDrawRect --------
  1598. IMPLEMENT_SERIAL(CDrawRect, CDrawObj, 0)
  1599. CDrawRect::CDrawRect() :CDrawObj()
  1600. {
  1601. }
  1602. CDrawObj* CDrawRect::Clone(void)
  1603. {
  1604. CDrawRect *pObj = new CDrawRect;
  1605. *((CDrawObj*)pObj) = *(CDrawObj*)this;
  1606. pObj->m_strLineType = m_strLineType;
  1607. pObj->m_clrLine = m_clrLine;
  1608. return pObj;
  1609. }
  1610. void CDrawRect::Draw(CDC* pDC)
  1611. {
  1612. CDrawObj::Draw(pDC);
  1613. if (!m_bShow && bRuning) return;
  1614. COLORREF clrLine = m_clrCurrentLine;
  1615. CRect rect = m_rctCurrent;
  1616. if (!bRuning)
  1617. {
  1618. clrLine = m_clrLine;
  1619. rect = m_rect;
  1620. }
  1621. CPen pen(GetPenStyle(m_strLineType), m_nLineWidth, clrLine);
  1622. CPen* pOldPen = pDC->SelectObject(&pen);
  1623. // CBrush
  1624. LOGBRUSH brushlog = GetBrush();
  1625. CBrush m_brush;
  1626. m_brush.CreateBrushIndirect(&brushlog);
  1627. CBrush* pOldBrush = (CBrush*)pDC->SelectObject(&m_brush);
  1628. if (m_nFillMode < 8)
  1629. {
  1630. pDC->Rectangle(rect);
  1631. }
  1632. else // 渐变填充
  1633. {
  1634. CGradient gradient;
  1635. CRect tmp = rect;
  1636. switch (m_nFillMode)
  1637. {
  1638. case 8:
  1639. gradient.HorizontalGradient(pDC, rect, m_clrFill, m_clrBack);
  1640. break;
  1641. case 9:
  1642. gradient.HorizontalGradient(pDC, rect, m_clrBack, m_clrFill);
  1643. break;
  1644. case 10:
  1645. tmp.NormalizeRect();
  1646. tmp.right = (tmp.left + tmp.right) / 2 + 1;
  1647. gradient.HorizontalGradient(pDC, tmp, m_clrFill, m_clrBack);
  1648. tmp = rect;
  1649. tmp.NormalizeRect();
  1650. tmp.left = (tmp.left + tmp.right) / 2 - 1;
  1651. gradient.HorizontalGradient(pDC, tmp, m_clrBack, m_clrFill);
  1652. break;
  1653. case 11:
  1654. gradient.VerticalGradient(pDC, rect, m_clrFill, m_clrBack);
  1655. break;
  1656. case 12:
  1657. gradient.VerticalGradient(pDC, rect, m_clrBack, m_clrFill);
  1658. break;
  1659. case 13:
  1660. tmp.NormalizeRect();
  1661. tmp.top = (tmp.top + tmp.bottom) / 2 - 1;
  1662. gradient.VerticalGradient(pDC, tmp, m_clrBack, m_clrFill);
  1663. tmp = rect;
  1664. tmp.NormalizeRect();
  1665. tmp.bottom = (tmp.top + tmp.bottom) / 2 + 1;
  1666. gradient.VerticalGradient(pDC, tmp, m_clrFill, m_clrBack);
  1667. break;
  1668. }
  1669. }
  1670. pDC->SelectObject(pOldPen);
  1671. pDC->SelectObject(pOldBrush);
  1672. DeleteObject(pen);
  1673. DeleteObject(m_brush);
  1674. }
  1675. //---------------------------------------------- CDrawRoundRect --------
  1676. IMPLEMENT_SERIAL(CDrawRoundRect, CDrawObj, 0)
  1677. CDrawRoundRect::CDrawRoundRect() :CDrawObj()
  1678. {
  1679. }
  1680. CDrawObj* CDrawRoundRect::Clone(void)
  1681. {
  1682. CDrawRoundRect *pObj = new CDrawRoundRect;
  1683. *((CDrawObj*)pObj) = *(CDrawObj*)this;
  1684. pObj->m_strLineType = m_strLineType;
  1685. pObj->m_clrLine = m_clrLine;
  1686. return pObj;
  1687. }
  1688. void CDrawRoundRect::Draw(CDC* pDC)
  1689. {
  1690. CDrawObj::Draw(pDC);
  1691. if (!m_bShow && bRuning) return;
  1692. COLORREF clrLine = m_clrCurrentLine;
  1693. CRect rect = m_rctCurrent;
  1694. if (!bRuning)
  1695. {
  1696. clrLine = m_clrLine;
  1697. rect = m_rect;
  1698. }
  1699. CPen pen(GetPenStyle(m_strLineType), m_nLineWidth, clrLine);
  1700. CPen* pOldPen = pDC->SelectObject(&pen);
  1701. // CBrush
  1702. LOGBRUSH brushlog = GetBrush();
  1703. CBrush m_brush;
  1704. m_brush.CreateBrushIndirect(&brushlog);
  1705. CBrush* pOldBrush = (CBrush*)pDC->SelectObject(&m_brush);
  1706. CPoint pt;
  1707. pt.x = 20;
  1708. pt.y = 20;
  1709. pDC->RoundRect(rect, pt);
  1710. pDC->SelectObject(pOldPen);
  1711. pDC->SelectObject(pOldBrush);
  1712. DeleteObject(pen);
  1713. DeleteObject(m_brush);
  1714. }
  1715. //////////////////////////////////////////////////////////////////////////
  1716. //---------------------------------------------- CDrawOval --------
  1717. IMPLEMENT_SERIAL(CDrawOval, CDrawObj, 0)
  1718. CDrawOval::CDrawOval() :CDrawObj()
  1719. {
  1720. }
  1721. CDrawObj* CDrawOval::Clone(void)
  1722. {
  1723. CDrawOval *pObj = new CDrawOval;
  1724. *((CDrawObj*)pObj) = *(CDrawObj*)this;
  1725. return pObj;
  1726. }
  1727. void CDrawOval::Draw(CDC* pDC)
  1728. {
  1729. CDrawObj::Draw(pDC);
  1730. if (!m_bShow && bRuning) return;
  1731. COLORREF clrLine = m_clrLine;
  1732. COLORREF clrBack = m_clrBack;
  1733. CRect rect = m_rect;
  1734. if (bRuning)
  1735. {
  1736. clrLine = m_clrCurrentLine;
  1737. clrBack = m_clrCurrentBack;
  1738. rect = m_rctCurrent;
  1739. }
  1740. CPen pen(GetPenStyle(m_strLineType), m_nLineWidth, clrLine);
  1741. CPen* pOldPen = pDC->SelectObject(&pen);
  1742. // CBrush
  1743. LOGBRUSH brushlog = GetBrush();
  1744. CBrush m_brush;
  1745. m_brush.CreateBrushIndirect(&brushlog);
  1746. CBrush* pOldBrush = (CBrush*)pDC->SelectObject(&m_brush);
  1747. pDC->Ellipse(rect);
  1748. pDC->SelectObject(pOldPen);
  1749. pDC->SelectObject(pOldBrush);
  1750. DeleteObject(pen);
  1751. DeleteObject(m_brush);
  1752. }
  1753. //---------------------------------------------- CDrawPie --------
  1754. IMPLEMENT_SERIAL(CDrawPie, CDrawObj, 0)
  1755. CDrawPie::CDrawPie() :CDrawObj()
  1756. {
  1757. m_nStartAngle = 0;
  1758. m_nSweepAngle = 90;
  1759. }
  1760. CDrawObj* CDrawPie::Clone(void)
  1761. {
  1762. CDrawPie *pObj = new CDrawPie;
  1763. *((CDrawObj*)pObj) = *(CDrawObj*)this;
  1764. return pObj;
  1765. }
  1766. void CDrawPie::Draw(CDC* pDC)
  1767. {
  1768. CDrawObj::Draw(pDC);
  1769. if (!m_bShow && bRuning) return;
  1770. COLORREF clrLine = m_clrLine;
  1771. COLORREF clrBack = m_clrBack;
  1772. CRect rect = m_rect;
  1773. if (bRuning)
  1774. {
  1775. clrLine = m_clrCurrentLine;
  1776. clrBack = m_clrCurrentBack;
  1777. rect = m_rctCurrent;
  1778. }
  1779. CPen pen(GetPenStyle(m_strLineType), m_nLineWidth, clrLine);
  1780. CPen* pOldPen = pDC->SelectObject(&pen);
  1781. // CBrush
  1782. LOGBRUSH brushlog = GetBrush();
  1783. CBrush m_brush;
  1784. m_brush.CreateBrushIndirect(&brushlog);
  1785. CBrush* pOldBrush = (CBrush*)pDC->SelectObject(&m_brush);
  1786. rect.NormalizeRect();
  1787. // 根据角度计算两个点;
  1788. CPoint s = CPoint(rect.right, (rect.top + rect.bottom) / 2);
  1789. CRgn rgn;
  1790. rgn.CreateEllipticRgnIndirect(rect);
  1791. int bLeft = (m_nSweepAngle > 90 && m_nSweepAngle < 270) ? -1 : 1;
  1792. CPoint e;
  1793. bool bIn = true;
  1794. for (int i = 0; i < rect.Width() / 2; i++)
  1795. {
  1796. e.x = rect.CenterPoint().x + i*bLeft;
  1797. e.y = rect.CenterPoint().y - i*bLeft*tan(m_nSweepAngle*PIE / 180);
  1798. if (!rgn.PtInRegion(e))
  1799. {
  1800. break;
  1801. }
  1802. }
  1803. pDC->Pie(&rect, s, e);
  1804. pDC->SelectObject(pOldPen);
  1805. pDC->SelectObject(pOldBrush);
  1806. DeleteObject(pen);
  1807. DeleteObject(m_brush);
  1808. DeleteObject(rgn);
  1809. }
  1810. BOOL CDrawPie::OnAttrib(CPropertySheet& sheet)
  1811. {
  1812. CArcPage page;
  1813. page.m_nStartAngle = m_nStartAngle;
  1814. page.m_nSweepAngle = m_nSweepAngle;
  1815. sheet.AddPage(&page);
  1816. sheet.Construct(g_strParamSet);
  1817. sheet.m_psh.dwFlags |= PSH_NOAPPLYNOW;
  1818. if (sheet.DoModal() == IDOK)
  1819. {
  1820. m_nStartAngle = page.m_nStartAngle;
  1821. m_nSweepAngle = page.m_nSweepAngle;
  1822. return TRUE;
  1823. }
  1824. return FALSE;
  1825. }
  1826. void CDrawPie::Serialize(CArchive& ar)
  1827. {
  1828. CDrawObj::Serialize(ar);
  1829. if (ar.IsStoring())
  1830. {
  1831. ar << m_nStartAngle;
  1832. ar << m_nSweepAngle;
  1833. }
  1834. else
  1835. {
  1836. ar >> m_nStartAngle;
  1837. ar >> m_nSweepAngle;
  1838. }
  1839. }
  1840. //---------------------------------------------- CDrawFan --------
  1841. IMPLEMENT_SERIAL(CDrawFan, CDrawObj, 0)
  1842. CDrawFan::CDrawFan() :CDrawObj()
  1843. {
  1844. m_nStep = 0;
  1845. m_bComputed = false;
  1846. m_bRun = false;
  1847. m_clrLine = RGB(0, 0, 0);
  1848. m_clrBack = RGB(255, 255, 0);
  1849. m_clrFore = RGB(0, 255, 0);
  1850. }
  1851. CDrawObj* CDrawFan::Clone(void)
  1852. {
  1853. CDrawFan *pObj = new CDrawFan;
  1854. *((CDrawObj*)pObj) = *(CDrawObj*)this;
  1855. pObj->m_strLogic = m_strLogic;
  1856. return pObj;
  1857. }
  1858. void CDrawFan::Serialize(CArchive& ar)
  1859. {
  1860. CDrawObj::Serialize(ar);
  1861. if (ar.IsStoring())
  1862. {
  1863. ar << m_strLogic;
  1864. }
  1865. else
  1866. {
  1867. ar >> m_strLogic;
  1868. }
  1869. }
  1870. BOOL CDrawFan::OnAttrib(CPropertySheet& sheet)
  1871. {
  1872. CLogicPage page;
  1873. page.m_strLogic = m_strLogic;
  1874. sheet.AddPage(&page);
  1875. sheet.Construct(g_strParamSet);
  1876. sheet.m_psh.dwFlags |= PSH_NOAPPLYNOW;
  1877. if (sheet.DoModal() == IDOK)
  1878. {
  1879. m_strLogic = page.m_strLogic;
  1880. return TRUE;
  1881. }
  1882. return FALSE;
  1883. }
  1884. bool CDrawFan::Fresh(CRect &RECT)
  1885. {
  1886. CDrawObj::Fresh(RECT);
  1887. CRealComputer com;
  1888. com.SetFormula(m_strLogic);
  1889. m_bRun = (int)com.GetResult();
  1890. RECT = m_rect;
  1891. return true;
  1892. }
  1893. void CDrawFan::Draw(CDC* pDC)
  1894. {
  1895. if (!m_bShow && bRuning) return;
  1896. COLORREF clrLine = m_clrLine;
  1897. COLORREF clrBack = m_clrBack;
  1898. COLORREF clrFore = m_clrFore;
  1899. CRect rect = m_rect;
  1900. if (bRuning)
  1901. {
  1902. clrLine = m_clrCurrentLine;
  1903. clrBack = m_clrCurrentBack;
  1904. clrFore = m_clrCurrentFore;
  1905. rect = m_rctCurrent;
  1906. }
  1907. CPen pen(GetPenStyle(m_strLineType), m_nLineWidth, clrLine);
  1908. CPen* pOldPen = pDC->SelectObject(&pen);
  1909. rect.NormalizeRect();
  1910. if (bRuning && m_bRun)
  1911. {
  1912. m_nStep++;
  1913. m_nStep = m_nStep % 8;
  1914. }
  1915. // 计算落点数组
  1916. if (!bRuning || !m_bComputed)
  1917. {
  1918. CPoint center = rect.CenterPoint();
  1919. float h = rect.Height();
  1920. float w = rect.Width();
  1921. float y = 0;
  1922. tagPoint[0] = CPoint(rect.right, (rect.top + rect.bottom) / 2);
  1923. tagPoint[2] = CPoint((rect.left + rect.right) / 2, rect.top);
  1924. tagPoint[4] = CPoint(rect.left, (rect.top + rect.bottom) / 2);
  1925. tagPoint[6] = CPoint((rect.left + rect.right) / 2, rect.bottom);
  1926. int x = 0;
  1927. for (x = w / 4; x < w / 2; x++)
  1928. {
  1929. y = 1.0*x*rect.Height() / rect.Width();
  1930. float delta = x*x*(h / 2)*(h / 2) + y*y*(w / 2)*(w / 2) - (h / 2)*(h / 2)*(w / 2)*(w / 2);
  1931. if (delta > -1 && delta < 1)
  1932. {
  1933. break;
  1934. }
  1935. }
  1936. int yP = (int)y;
  1937. tagPoint[1] = center + CSize(x, -yP);
  1938. tagPoint[3] = center + CSize(-x, -yP);
  1939. tagPoint[5] = center + CSize(-x, yP);
  1940. tagPoint[7] = center + CSize(x, yP);
  1941. m_bComputed = true;
  1942. }
  1943. CBrush brush(m_clrBack);
  1944. pDC->SelectObject(&brush);
  1945. pDC->Pie(&rect, tagPoint[m_nStep], tagPoint[(m_nStep + 2) % 8]);
  1946. pDC->Pie(&rect, tagPoint[(m_nStep + 4) % 8], tagPoint[(m_nStep + 6) % 8]);
  1947. CBrush brush1(m_clrFore);
  1948. CBrush *pOldBrush = pDC->SelectObject(&brush1);
  1949. pDC->Pie(&rect, tagPoint[(m_nStep + 2) % 8], tagPoint[(m_nStep + 4) % 8]);
  1950. pDC->Pie(&rect, tagPoint[(m_nStep + 6) % 8], tagPoint[(m_nStep) % 8]);
  1951. pDC->SelectObject(pOldBrush);
  1952. pDC->SelectObject(pOldPen);
  1953. DeleteObject(pen);
  1954. DeleteObject(brush);
  1955. DeleteObject(brush1);
  1956. }
  1957. //---------------------------------------------- CDrawArc --------
  1958. IMPLEMENT_SERIAL(CDrawArc, CDrawObj, 0)
  1959. CDrawArc::CDrawArc() :CDrawObj()
  1960. {
  1961. m_nStartAngle = 0;
  1962. m_nSweepAngle = 120;
  1963. }
  1964. CDrawObj* CDrawArc::Clone(void)
  1965. {
  1966. CDrawArc *pObj = new CDrawArc;
  1967. *((CDrawObj*)pObj) = *(CDrawObj*)this;
  1968. pObj->m_nStartAngle = m_nStartAngle;
  1969. pObj->m_nSweepAngle = m_nSweepAngle;
  1970. return pObj;
  1971. }
  1972. void CDrawArc::Draw(CDC* pDC)
  1973. {
  1974. CRect rect = m_rect;
  1975. COLORREF clrLine = m_clrLine;
  1976. if (bRuning)
  1977. {
  1978. clrLine = m_clrCurrentLine;
  1979. rect = m_rctCurrent;
  1980. }
  1981. CPen pen(GetPenStyle(m_strLineType), m_nLineWidth, clrLine);
  1982. CPen* pOldPen = pDC->SelectObject(&pen);
  1983. int x = (rect.left + rect.right) / 2;
  1984. int y = (rect.top + rect.bottom) / 2;
  1985. int r = (rect.Width() < rect.Height() ? rect.Width() : rect.Height()) / 2;
  1986. pDC->MoveTo(x + r * cos(m_nStartAngle * PIE / 180), y - r * sin(m_nStartAngle * PIE / 180));
  1987. pDC->AngleArc(x, y, r, m_nStartAngle, m_nSweepAngle);
  1988. pDC->SelectObject(pOldPen);
  1989. DeleteObject(pen);
  1990. }
  1991. BOOL CDrawArc::OnAttrib(CPropertySheet& sheet)
  1992. {
  1993. CArcPage page;
  1994. page.m_nStartAngle = m_nStartAngle;
  1995. page.m_nSweepAngle = m_nSweepAngle;
  1996. sheet.AddPage(&page);
  1997. sheet.Construct(g_strParamSet);
  1998. sheet.m_psh.dwFlags |= PSH_NOAPPLYNOW;
  1999. if (sheet.DoModal() == IDOK)
  2000. {
  2001. m_nStartAngle = page.m_nStartAngle;
  2002. m_nSweepAngle = page.m_nSweepAngle;
  2003. return TRUE;
  2004. }
  2005. return FALSE;
  2006. }
  2007. void CDrawArc::Serialize(CArchive& ar)
  2008. {
  2009. CDrawObj::Serialize(ar);
  2010. if (ar.IsStoring())
  2011. {
  2012. ar << m_nStartAngle;
  2013. ar << m_nSweepAngle;
  2014. }
  2015. else
  2016. {
  2017. ar >> m_nStartAngle;
  2018. ar >> m_nSweepAngle;
  2019. }
  2020. }
  2021. //---------------------------------------------- CDrawPoly --------
  2022. IMPLEMENT_SERIAL(CDrawPoly, CDrawObj, 0)
  2023. CDrawPoly::CDrawPoly() :CDrawObj()
  2024. {
  2025. m_points = NULL;
  2026. m_nPoints = 0;
  2027. m_nAllocPoints = 0;
  2028. }
  2029. CDrawPoly::~CDrawPoly()
  2030. {
  2031. //chn mem
  2032. if (m_points != NULL)
  2033. {
  2034. delete[] m_points;
  2035. m_points = NULL;
  2036. }
  2037. }
  2038. void CDrawPoly::AddPoint(const CPoint& point)
  2039. {
  2040. ASSERT_VALID(this);
  2041. if (m_nPoints < 0) return;
  2042. if (m_nPoints == m_nAllocPoints)
  2043. {
  2044. CPoint* newPoints = new CPoint[m_nAllocPoints + 10];
  2045. if (m_points != NULL)
  2046. {
  2047. memcpy(newPoints, m_points, sizeof(CPoint) * m_nAllocPoints);
  2048. delete[] m_points;
  2049. }
  2050. m_points = newPoints;
  2051. m_nAllocPoints += 10;
  2052. }
  2053. if (m_nPoints == 0 || m_points[m_nPoints - 1] != point)
  2054. {
  2055. m_points[m_nPoints++] = point;
  2056. if (!RecalcBounds())
  2057. {
  2058. Invalidate();
  2059. }
  2060. }
  2061. }
  2062. BOOL CDrawPoly::RecalcBounds()
  2063. {
  2064. ASSERT_VALID(this);
  2065. if (m_nPoints == 0)
  2066. return FALSE;
  2067. CRect bounds(m_points[0], CSize(0, 0));
  2068. for (int i = 1; i < m_nPoints; ++i)
  2069. {
  2070. if (m_points[i].x < bounds.left)
  2071. bounds.left = m_points[i].x;
  2072. if (m_points[i].x > bounds.right)
  2073. bounds.right = m_points[i].x;
  2074. if (m_points[i].y < bounds.top)
  2075. bounds.top = m_points[i].y;
  2076. if (m_points[i].y > bounds.bottom)
  2077. bounds.bottom = m_points[i].y;
  2078. }
  2079. if (bounds == m_rect)
  2080. return FALSE;
  2081. Invalidate();
  2082. m_rect = bounds;
  2083. Invalidate();
  2084. return TRUE;
  2085. }
  2086. void CDrawPoly::Draw(CDC* pDC)
  2087. {
  2088. CDrawObj::Draw(pDC);
  2089. COLORREF clrLine = m_clrLine;
  2090. COLORREF clrBack = m_clrBack;
  2091. CRect rect = m_rect;
  2092. if (bRuning)
  2093. {
  2094. clrLine = m_clrCurrentLine;
  2095. clrBack = m_clrCurrentBack;
  2096. rect = m_rctCurrent;
  2097. }
  2098. CPen pen(GetPenStyle(m_strLineType), m_nLineWidth, clrLine);
  2099. CPen* pOldPen = pDC->SelectObject(&pen);
  2100. // CBrush
  2101. LOGBRUSH brushlog = GetBrush();
  2102. CBrush m_brush;
  2103. m_brush.CreateBrushIndirect(&brushlog);
  2104. CBrush* pOldBrush = (CBrush*)pDC->SelectObject(&m_brush);
  2105. if (m_nFillMode < 8)
  2106. {
  2107. pDC->Polygon(m_points, m_nPoints);
  2108. }
  2109. else // 渐变填充
  2110. {
  2111. CGradient gradient;
  2112. HRGN hRgn = CreatePolygonRgn(m_points, m_nPoints, ALTERNATE);
  2113. CRect tmp = rect;
  2114. switch (m_nFillMode)
  2115. {
  2116. case 8:
  2117. gradient.HorizontalGradient(pDC, hRgn, m_clrFill, clrBack);
  2118. break;
  2119. case 9:
  2120. case 10:
  2121. gradient.HorizontalGradient(pDC, hRgn, clrBack, m_clrFill);
  2122. break;
  2123. case 11:
  2124. gradient.VerticalGradient(pDC, hRgn, m_clrFill, clrBack);
  2125. break;
  2126. case 12:
  2127. case 13:
  2128. gradient.VerticalGradient(pDC, hRgn, m_clrBack, m_clrFill);
  2129. break;
  2130. }
  2131. DeleteObject(hRgn);
  2132. }
  2133. pDC->SelectObject(pOldBrush);
  2134. pDC->SelectObject(pOldPen);
  2135. DeleteObject(pen);
  2136. DeleteObject(m_brush);
  2137. }
  2138. void CDrawPoly::Serialize(CArchive& ar)
  2139. {
  2140. int i;
  2141. CDrawObj::Serialize(ar);
  2142. if (ar.IsStoring())
  2143. {
  2144. ar << (WORD)m_nPoints;
  2145. ar << (WORD)m_nAllocPoints;
  2146. for (i = 0; i < m_nPoints; i++)
  2147. ar << m_points[i];
  2148. }
  2149. else
  2150. {
  2151. WORD wTemp;
  2152. ar >> wTemp; m_nPoints = wTemp;
  2153. ar >> wTemp; m_nAllocPoints = wTemp;
  2154. m_points = new CPoint[m_nAllocPoints];
  2155. for (i = 0; i < m_nPoints; i++)
  2156. ar >> m_points[i];
  2157. }
  2158. }
  2159. CDrawObj* CDrawPoly::Clone()
  2160. {
  2161. CDrawPoly* pClone = new CDrawPoly();
  2162. *((CDrawObj*)pClone) = *(CDrawObj*)this;
  2163. pClone->m_points = new CPoint[m_nAllocPoints];
  2164. memcpy(pClone->m_points, m_points, sizeof(CPoint) * m_nPoints);
  2165. pClone->m_nAllocPoints = m_nAllocPoints;
  2166. pClone->m_nPoints = m_nPoints;
  2167. return pClone;
  2168. }
  2169. void CDrawPoly::MoveTo(CRect rect)
  2170. {
  2171. ASSERT_VALID(this);
  2172. if (rect == m_rect)
  2173. return;
  2174. Invalidate();
  2175. for (int i = 0; i < m_nPoints; i += 1)
  2176. {
  2177. m_points[i].x += rect.left - m_rect.left;
  2178. m_points[i].y += rect.top - m_rect.top;
  2179. }
  2180. m_rect = rect;
  2181. Invalidate();
  2182. }
  2183. int CDrawPoly::GetHandleCount()
  2184. {
  2185. return m_nPoints;
  2186. }
  2187. CPoint CDrawPoly::GetHandle(int nHandle)
  2188. {
  2189. ASSERT_VALID(this);
  2190. ASSERT(nHandle >= 1 && nHandle <= m_nPoints);
  2191. return m_points[nHandle - 1];
  2192. }
  2193. void CDrawPoly::MoveHandleTo(int nHandle, CPoint point)
  2194. {
  2195. ASSERT(nHandle >= 1 && nHandle <= m_nPoints);
  2196. if (m_points[nHandle - 1] == point)
  2197. return;
  2198. m_points[nHandle - 1] = point;
  2199. RecalcBounds();
  2200. Invalidate();
  2201. }
  2202. //---------------------------------------------- CDrawMLine --------
  2203. IMPLEMENT_SERIAL(CDrawMLine, CDrawPoly, 0)
  2204. CDrawMLine::CDrawMLine() :CDrawPoly()
  2205. {
  2206. }
  2207. void CDrawMLine::Draw(CDC* pDC)
  2208. {
  2209. ASSERT_VALID(this);
  2210. COLORREF clrLine = m_clrLine;
  2211. COLORREF clrBack = m_clrBack;
  2212. CRect rect = m_rect;
  2213. if (bRuning)
  2214. {
  2215. clrLine = m_clrCurrentLine;
  2216. clrBack = m_clrCurrentBack;
  2217. rect = m_rctCurrent;
  2218. }
  2219. CPen pen(GetPenStyle(m_strLineType), m_nLineWidth, clrLine);
  2220. CPen* pOldPen = pDC->SelectObject(&pen);
  2221. if (m_nPoints > 0)
  2222. pDC->MoveTo(m_points[0]);
  2223. for (int i = 1; i < m_nPoints; i++)
  2224. pDC->LineTo(m_points[i]);
  2225. pDC->SelectObject(pOldPen);
  2226. DeleteObject(pen);
  2227. }
  2228. CDrawObj* CDrawMLine::Clone()
  2229. {
  2230. CDrawMLine* pClone = new CDrawMLine();
  2231. *((CDrawObj*)pClone) = *(CDrawObj*)this;
  2232. pClone->m_points = new CPoint[m_nAllocPoints];
  2233. memcpy(pClone->m_points, m_points, sizeof(CPoint) * m_nPoints);
  2234. pClone->m_nAllocPoints = m_nAllocPoints;
  2235. pClone->m_nPoints = m_nPoints;
  2236. return pClone;
  2237. }
  2238. //---------------------------------------------- CDrawArrow -------
  2239. IMPLEMENT_SERIAL(CDrawArrow, CDrawObj, 0)
  2240. CDrawArrow::CDrawArrow() :CDrawObj()
  2241. {
  2242. }
  2243. CDrawObj* CDrawArrow::Clone(void)
  2244. {
  2245. CDrawArrow *pObj = new CDrawArrow;
  2246. *((CDrawObj*)pObj) = *(CDrawObj*)this;
  2247. return pObj;
  2248. }
  2249. void CDrawArrow::Draw(CDC* pDC)
  2250. {
  2251. CRect rect = m_rect;
  2252. rect.NormalizeRect();
  2253. int nXX = rect.right - rect.left;
  2254. int nYY = rect.bottom - rect.top;
  2255. if (nXX < 2 || nYY < 2) return;
  2256. if (nXX >= nYY)
  2257. {
  2258. if (m_rect.left >= m_rect.right)
  2259. DrawArrow(pDC, rect, DIR_LEFT, m_clrBack);
  2260. else
  2261. DrawArrow(pDC, rect, DIR_RIGHT, m_clrBack);
  2262. }
  2263. else
  2264. {
  2265. if (m_rect.top >= m_rect.bottom)
  2266. DrawArrow(pDC, rect, DIR_DOWN, m_clrBack);
  2267. else
  2268. DrawArrow(pDC, rect, DIR_UP, m_clrBack);
  2269. }
  2270. }
  2271. void CDrawArrow::DrawArrow(CDC* pDC, CRect rect, BYTE Direction, COLORREF clrArrow)
  2272. {
  2273. if (Direction == DIR_UP || Direction == DIR_DOWN)
  2274. {
  2275. int middle = (rect.left + rect.right) / 2;
  2276. for (int i = 0; i < rect.Height(); i++)
  2277. {
  2278. int nY = rect.top + i;
  2279. if (Direction == DIR_DOWN)
  2280. {
  2281. int nX1 = rect.left + i*((1.0*rect.Width() / 2) / rect.Height());
  2282. int nX2 = rect.right - i*((1.0*rect.Width() / 2) / rect.Height());
  2283. CRect rect1(nX1, nY, nX2, nY + 1);
  2284. pDC->FillSolidRect(rect1, clrArrow);
  2285. }
  2286. else
  2287. {
  2288. int nX1 = middle - i*((1.0*rect.Width() / 2) / rect.Height());
  2289. int nX2 = middle + i*((1.0*rect.Width() / 2) / rect.Height());
  2290. CRect rect1(nX1, nY, nX2, nY + 1);
  2291. pDC->FillSolidRect(rect1, clrArrow);
  2292. }
  2293. }
  2294. }
  2295. if (Direction == DIR_LEFT || Direction == DIR_RIGHT)
  2296. {
  2297. int middle = (rect.top + rect.bottom) / 2;
  2298. for (int i = 0; i < rect.Width(); i++)
  2299. {
  2300. int nX = rect.left + i;
  2301. if (Direction == DIR_RIGHT)
  2302. {
  2303. int nY1 = rect.top + i*((1.0*rect.Height() / 2) / rect.Width());
  2304. int nY2 = rect.bottom - i*((1.0*rect.Height() / 2) / rect.Width());
  2305. CRect rect1(nX, nY1, nX + 1, nY2);
  2306. pDC->FillSolidRect(rect1, clrArrow);
  2307. }
  2308. else
  2309. {
  2310. int nY1 = middle + i*((1.0*rect.Height() / 2) / rect.Width());
  2311. int nY2 = middle - i*((1.0*rect.Height() / 2) / rect.Width());
  2312. CRect rect1(nX, nY1, nX + 1, nY2);
  2313. pDC->FillSolidRect(rect1, clrArrow);
  2314. }
  2315. }
  2316. }
  2317. }
  2318. //---------------------------------------------- CDrawBreaker --------
  2319. IMPLEMENT_SERIAL(CDrawBreaker, CDrawObj, 0)
  2320. CDrawBreaker::CDrawBreaker() :CDrawObj()
  2321. {
  2322. }
  2323. CDrawObj* CDrawBreaker::Clone(void)
  2324. {
  2325. CDrawBreaker *pObj = new CDrawBreaker;
  2326. *((CDrawObj*)pObj) = *(CDrawObj*)this;
  2327. return pObj;
  2328. }
  2329. void CDrawBreaker::Draw(CDC* pDC)
  2330. {
  2331. if (!m_bShow && bRuning) return;
  2332. COLORREF clrLine = m_clrLine;
  2333. COLORREF clrBack = m_clrBack;
  2334. CRect rect = m_rect;
  2335. if (bRuning)
  2336. {
  2337. clrLine = m_clrCurrentLine;
  2338. clrBack = m_clrCurrentBack;
  2339. rect = m_rctCurrent;
  2340. }
  2341. CPen pen(GetPenStyle(m_strLineType), m_nLineWidth, clrLine);
  2342. CBrush brush(clrBack);
  2343. CPen* pOldPen = pDC->SelectObject(&pen);
  2344. CBrush* pOldBrush = pDC->SelectObject(&brush);
  2345. rect.NormalizeRect();
  2346. int nMidX = rect.left + rect.Width() / 2;
  2347. pDC->MoveTo(nMidX, rect.top);
  2348. pDC->LineTo(nMidX, rect.top + rect.Height() / 4);
  2349. pDC->MoveTo(nMidX, rect.top + rect.Height() * 3 / 4);
  2350. pDC->LineTo(nMidX, rect.bottom);
  2351. rect.DeflateRect(0, rect.Height() / 4, 0, rect.Height() / 4);
  2352. pDC->Rectangle(rect);
  2353. pDC->SelectObject(pOldPen);
  2354. pDC->SelectObject(pOldBrush);
  2355. DeleteObject(pen);
  2356. DeleteObject(brush);
  2357. }
  2358. //---------------------------------------------- CDrawSwitch --------
  2359. IMPLEMENT_SERIAL(CDrawSwitch, CDrawObj, 0)
  2360. CDrawSwitch::CDrawSwitch() :CDrawObj()
  2361. {
  2362. m_clrLine = RGB(0, 255, 0);
  2363. m_bRun = FALSE;
  2364. m_strLogic = "";
  2365. }
  2366. CDrawObj* CDrawSwitch::Clone(void)
  2367. {
  2368. CDrawSwitch *pObj = new CDrawSwitch;
  2369. *((CDrawObj*)pObj) = *(CDrawObj*)this;
  2370. pObj->m_strLogic = m_strLogic;
  2371. return pObj;
  2372. }
  2373. void CDrawSwitch::Serialize(CArchive& ar)
  2374. {
  2375. CDrawObj::Serialize(ar);
  2376. if (ar.IsStoring())
  2377. {
  2378. ar << m_strLogic;
  2379. }
  2380. else
  2381. {
  2382. ar >> m_strLogic;
  2383. }
  2384. }
  2385. BOOL CDrawSwitch::OnAttrib(CPropertySheet& sheet)
  2386. {
  2387. CLogicPage page;
  2388. page.m_strLogic = m_strLogic;
  2389. sheet.AddPage(&page);
  2390. sheet.Construct(g_strParamSet);
  2391. sheet.m_psh.dwFlags |= PSH_NOAPPLYNOW;
  2392. if (sheet.DoModal() == IDOK)
  2393. {
  2394. m_strLogic = page.m_strLogic;
  2395. return TRUE;
  2396. }
  2397. return FALSE;
  2398. }
  2399. bool CDrawSwitch::Fresh(CRect &RECT)
  2400. {
  2401. CDrawObj::Fresh(RECT);
  2402. CRealComputer com;
  2403. com.SetFormula(m_strLogic);
  2404. m_bRun = (int)com.GetResult();
  2405. RECT = m_rect;
  2406. return true;
  2407. }
  2408. void CDrawSwitch::Draw(CDC* pDC)
  2409. {
  2410. if (!m_bShow && bRuning) return;
  2411. CRect rect = m_rect;
  2412. CPen pen(GetPenStyle(m_strLineType), m_nLineWidth, (bRuning&&m_bRun) ? RGB(255, 0, 0) : RGB(0, 255, 0));
  2413. CPen* pOldPen = pDC->SelectObject(&pen);
  2414. rect.NormalizeRect();
  2415. int nMidX = rect.left + rect.Width() / 2;
  2416. pDC->MoveTo(nMidX, rect.top);
  2417. pDC->LineTo(nMidX, rect.top + rect.Height() / 4);
  2418. pDC->MoveTo(rect.left + rect.Width() / 4, rect.top + rect.Height() / 4);
  2419. pDC->LineTo(rect.right - rect.Width() / 4, rect.top + rect.Height() / 4);
  2420. if (bRuning && m_bRun)
  2421. {
  2422. pDC->MoveTo(nMidX, rect.top + rect.Height() / 4);
  2423. pDC->LineTo(nMidX, rect.top + rect.Height() * 3 / 4);
  2424. }
  2425. else
  2426. {
  2427. pDC->MoveTo(rect.left, rect.top + rect.Height() / 4);
  2428. pDC->LineTo(nMidX, rect.top + rect.Height() * 3 / 4);
  2429. }
  2430. pDC->MoveTo(nMidX, rect.top + rect.Height() * 3 / 4);
  2431. pDC->LineTo(nMidX, rect.bottom);
  2432. pDC->SelectObject(pOldPen);
  2433. DeleteObject(pen);
  2434. }
  2435. //---------------------------------------------- CDrawGrid --------
  2436. IMPLEMENT_SERIAL(CDrawGrid, CDrawObj, 0)
  2437. CDrawGrid::CDrawGrid() :CDrawObj()
  2438. {
  2439. m_clrLine = RGB(0, 255, 0);
  2440. }
  2441. CDrawObj* CDrawGrid::Clone(void)
  2442. {
  2443. CDrawGrid *pObj = new CDrawGrid;
  2444. *((CDrawObj*)pObj) = *(CDrawObj*)this;
  2445. return pObj;
  2446. }
  2447. void CDrawGrid::Draw(CDC* pDC)
  2448. {
  2449. if (!m_bShow && bRuning) return;
  2450. COLORREF clrLine = m_clrLine;
  2451. COLORREF clrBack = m_clrBack;
  2452. CRect rect = m_rect;
  2453. if (bRuning)
  2454. {
  2455. clrLine = m_clrCurrentLine;
  2456. clrBack = m_clrCurrentBack;
  2457. rect = m_rctCurrent;
  2458. }
  2459. CPen pen(GetPenStyle(m_strLineType), m_nLineWidth, clrLine);
  2460. CPen* pOldPen = pDC->SelectObject(&pen);
  2461. rect.NormalizeRect();
  2462. int nXNum = 5;
  2463. int nYNum = 5;
  2464. int nDX = rect.Width() / nXNum;
  2465. int nDY = rect.Height() / nYNum;
  2466. for (int i = 0; i <= nXNum; i++)
  2467. {
  2468. int nX = rect.left + nDX*i;
  2469. pDC->MoveTo(nX, rect.top);
  2470. pDC->LineTo(nX, rect.top + nDY*nYNum);
  2471. }
  2472. for (int j = 0; j <= nYNum; j++)
  2473. {
  2474. int nY = rect.top + nDY*j;
  2475. pDC->MoveTo(rect.left, nY);
  2476. pDC->LineTo(rect.left + nDX*nXNum, nY);
  2477. }
  2478. pDC->SelectObject(pOldPen);
  2479. DeleteObject(pen);
  2480. }
  2481. //---------------------------------------------- CDrawTable --------
  2482. IMPLEMENT_SERIAL(CDrawTable, CDrawObj, 0)
  2483. CDrawTable::CDrawTable() :CDrawObj()
  2484. {
  2485. m_clrLine = RGB(0, 255, 0);
  2486. m_clrFore = RGB(255, 255, 0);
  2487. m_nFillMode = 0;
  2488. m_bAddAve = false;
  2489. m_bAddMax = false;
  2490. m_bAddMin = false;
  2491. m_bShowRowHead = true;
  2492. m_nType = 0;
  2493. for (int i = 0; i < 8; i++)
  2494. {
  2495. CColPro* pObj = new CColPro;
  2496. m_colList.AddTail(pObj);
  2497. }
  2498. }
  2499. CDrawObj* CDrawTable::Clone(void)
  2500. {
  2501. CDrawTable *pObj = new CDrawTable;
  2502. *((CDrawObj*)pObj) = *(CDrawObj*)this;
  2503. return pObj;
  2504. }
  2505. void CDrawTable::Serialize(CArchive& ar)
  2506. {
  2507. CDrawObj::Serialize(ar);
  2508. if (ar.IsStoring())
  2509. {
  2510. ar << m_bAddAve;
  2511. ar << m_bAddMax;
  2512. ar << m_bAddMin;
  2513. ar << m_nType;
  2514. ar << m_bShowRowHead;
  2515. }
  2516. else
  2517. {
  2518. m_colList.RemoveAll();
  2519. ar >> m_bAddAve;
  2520. ar >> m_bAddMax;
  2521. ar >> m_bAddMin;
  2522. ar >> m_nType;
  2523. ar >> m_bShowRowHead;
  2524. }
  2525. m_colList.Serialize(ar);
  2526. }
  2527. BOOL CDrawTable::OnAttrib(CPropertySheet& sheet)
  2528. {
  2529. CReportBasePage page;
  2530. page.m_bAddAve = m_bAddAve;
  2531. page.m_bAddMin = m_bAddMin;
  2532. page.m_bAddMax = m_bAddMax;
  2533. page.m_nType = m_nType;
  2534. page.m_bShowRowHead = m_bShowRowHead;
  2535. sheet.AddPage(&page);
  2536. CReportColPage cPage;
  2537. POSITION pos = m_colList.GetHeadPosition();
  2538. while (pos != NULL)
  2539. {
  2540. CColPro* pObj = m_colList.GetNext(pos);
  2541. CColPro *pNewObj = pObj->Clone();
  2542. cPage.m_colList.AddTail(pNewObj);
  2543. }
  2544. sheet.AddPage(&cPage);
  2545. sheet.Construct(g_strParamSet);
  2546. sheet.m_psh.dwFlags |= PSH_NOAPPLYNOW;
  2547. if (sheet.DoModal() == IDOK)
  2548. {
  2549. m_bAddAve = page.m_bAddAve;
  2550. m_bAddMin = page.m_bAddMin;
  2551. m_bAddMax = page.m_bAddMax;
  2552. m_nType = page.m_nType;
  2553. m_bShowRowHead = page.m_bShowRowHead;
  2554. m_colList.RemoveAll();
  2555. pos = cPage.m_colList.GetHeadPosition();
  2556. while (pos != NULL)
  2557. {
  2558. CColPro* pObj = cPage.m_colList.GetNext(pos);
  2559. CColPro *pNewObj = pObj->Clone();
  2560. m_colList.AddTail(pNewObj);
  2561. }
  2562. return TRUE;
  2563. }
  2564. return FALSE;
  2565. }
  2566. CString CDrawTable::GetColFormat(int col)
  2567. {
  2568. int i = 1;
  2569. POSITION pos = m_colList.GetHeadPosition();
  2570. while (pos != NULL)
  2571. {
  2572. CColPro* pObj = m_colList.GetNext(pos);
  2573. if (i == col)
  2574. {
  2575. return pObj->m_strFormat;
  2576. }
  2577. i++;
  2578. }
  2579. return "####";
  2580. }
  2581. void CDrawTable::Draw(CDC* pDC)
  2582. {
  2583. if (!m_bShow && bRuning) return;
  2584. COLORREF clrLine = m_clrLine;
  2585. COLORREF clrFore = m_clrFore;
  2586. CRect rect = m_rect;
  2587. if (bRuning)
  2588. {
  2589. clrLine = m_clrCurrentLine;
  2590. clrFore = m_clrCurrentFore;
  2591. rect = m_rctCurrent;
  2592. }
  2593. // CBrush
  2594. LOGBRUSH brushlog = GetBrush();
  2595. CBrush m_brush;
  2596. m_brush.CreateBrushIndirect(&brushlog);
  2597. CBrush* pOldBrush = (CBrush*)pDC->SelectObject(&m_brush);
  2598. if (m_nFillMode < 8)
  2599. {
  2600. pDC->Rectangle(rect);
  2601. }
  2602. else // 渐变填充
  2603. {
  2604. CGradient gradient;
  2605. CRect tmp = rect;
  2606. switch (m_nFillMode)
  2607. {
  2608. case 8:
  2609. gradient.HorizontalGradient(pDC, rect, m_clrFill, m_clrBack);
  2610. break;
  2611. case 9:
  2612. gradient.HorizontalGradient(pDC, rect, m_clrBack, m_clrFill);
  2613. break;
  2614. case 10:
  2615. tmp.NormalizeRect();
  2616. tmp.right = (tmp.left + tmp.right) / 2 + 1;
  2617. gradient.HorizontalGradient(pDC, tmp, m_clrFill, m_clrBack);
  2618. tmp = rect;
  2619. tmp.NormalizeRect();
  2620. tmp.left = (tmp.left + tmp.right) / 2 - 1;
  2621. gradient.HorizontalGradient(pDC, tmp, m_clrBack, m_clrFill);
  2622. break;
  2623. case 11:
  2624. gradient.VerticalGradient(pDC, rect, m_clrFill, m_clrBack);
  2625. break;
  2626. case 12:
  2627. gradient.VerticalGradient(pDC, rect, m_clrBack, m_clrFill);
  2628. break;
  2629. case 13:
  2630. tmp.NormalizeRect();
  2631. tmp.top = (tmp.top + tmp.bottom) / 2 - 1;
  2632. gradient.VerticalGradient(pDC, tmp, m_clrBack, m_clrFill);
  2633. tmp = rect;
  2634. tmp.NormalizeRect();
  2635. tmp.bottom = (tmp.top + tmp.bottom) / 2 + 1;
  2636. gradient.VerticalGradient(pDC, tmp, m_clrFill, m_clrBack);
  2637. break;
  2638. }
  2639. }
  2640. pDC->SelectObject(pOldBrush);
  2641. CPen pen(GetPenStyle(m_strLineType), m_nLineWidth, clrLine);
  2642. CPen* pOldPen = pDC->SelectObject(&pen);
  2643. rect.NormalizeRect();
  2644. pDC->SetTextColor(clrFore);
  2645. CFont font;
  2646. font.CreateFontIndirect(&m_logfont);
  2647. CFont* pOldFont = pDC->SelectObject(&font);
  2648. int nXNum = m_colList.GetCount();
  2649. if (m_bShowRowHead)
  2650. nXNum++;
  2651. int nYNum;
  2652. if (m_nType == 0)
  2653. nYNum = 25;
  2654. else
  2655. nYNum = 32;
  2656. if (m_bAddAve) nYNum++;
  2657. if (m_bAddMax) nYNum++;
  2658. if (m_bAddMin) nYNum++;
  2659. float nDX = 1.0*rect.Width() / nXNum;
  2660. float nDY = 1.0*rect.Height() / nYNum;
  2661. int i = 0;
  2662. for (i = 0; i <= nXNum; i++)
  2663. {
  2664. int nX = rect.left + nDX*i;
  2665. if (i == nXNum) nX = rect.right;
  2666. pDC->MoveTo(nX, rect.top);
  2667. pDC->LineTo(nX, rect.bottom);
  2668. }
  2669. int j = 0;
  2670. for (j = 0; j <= nYNum; j++)
  2671. {
  2672. int nY = rect.top + nDY*j;
  2673. if (j == nYNum) nY = rect.bottom;
  2674. pDC->MoveTo(rect.left, nY);
  2675. pDC->LineTo(rect.right, nY);
  2676. }
  2677. for (i = m_bShowRowHead ? 1 : 0; i < nXNum; i++)
  2678. for (j = 1; j < nYNum; j++)
  2679. {
  2680. pDC->SetTextAlign(TA_RIGHT | TA_TOP);
  2681. int y = rect.top + nDY*j + 5;
  2682. int x = rect.left + nDX*(i + 1) - 5;
  2683. CString format = GetColFormat(i);
  2684. if (!bRuning)
  2685. pDC->TextOut(x, y, format);
  2686. else
  2687. {
  2688. format.Replace("#", "0");
  2689. pDC->TextOut(x, y, format);
  2690. }
  2691. }
  2692. // 画列名
  2693. int col = m_bShowRowHead ? 1 : 0;
  2694. POSITION pos = m_colList.GetHeadPosition();
  2695. while (pos != NULL)
  2696. {
  2697. CColPro* pObj = m_colList.GetNext(pos);
  2698. int y = rect.top + 5;
  2699. int x = rect.left + nDX*(col + 1) - 5;
  2700. pDC->TextOut(x, y, pObj->m_strTitle);
  2701. col++;
  2702. }
  2703. pDC->SetTextAlign(TA_LEFT);
  2704. // 画行名
  2705. if (m_bShowRowHead)
  2706. {
  2707. int col = 1;
  2708. if (m_nType == 0)
  2709. {
  2710. for (int i = 0; i < 24; i++)
  2711. {
  2712. int y = rect.top + nDY*col + 5;
  2713. int x = rect.left + 5;
  2714. CString tmp;
  2715. tmp.Format(g_strHour, i + 1);
  2716. pDC->TextOut(x, y, tmp);
  2717. col++;
  2718. }
  2719. }
  2720. else
  2721. {
  2722. for (int i = 0; i < 31; i++)
  2723. {
  2724. int y = rect.top + nDY*col + 5;
  2725. int x = rect.left + 5;
  2726. CString tmp;
  2727. tmp.Format(g_strDate, i + 1);
  2728. pDC->TextOut(x, y, tmp);
  2729. col++;
  2730. }
  2731. }
  2732. if (m_bAddAve)
  2733. {
  2734. int y = rect.top + nDY*col + 5;
  2735. int x = rect.left + 5;
  2736. pDC->TextOut(x, y, g_strMean);
  2737. col++;
  2738. }
  2739. if (m_bAddMax)
  2740. {
  2741. int y = rect.top + nDY*col + 5;
  2742. int x = rect.left + 5;
  2743. pDC->TextOut(x, y, g_strMaxValues);
  2744. col++;
  2745. }
  2746. if (m_bAddMin)
  2747. {
  2748. int y = rect.top + nDY*col + 5;
  2749. int x = rect.left + 5;
  2750. pDC->TextOut(x, y, g_strMinValues);
  2751. col++;
  2752. }
  2753. }
  2754. pDC->SelectObject(pOldPen);
  2755. DeleteObject(pen);
  2756. DeleteObject(m_brush);
  2757. DeleteObject(font);
  2758. }
  2759. //---------------------------------------------- CDrawZhePipe --------
  2760. IMPLEMENT_SERIAL(CDrawZhePipe, CDrawObj, 0)
  2761. CDrawZhePipe::CDrawZhePipe() :CDrawObj()
  2762. {
  2763. m_clrLine = RGB(0, 255, 0);
  2764. }
  2765. CDrawObj* CDrawZhePipe::Clone(void)
  2766. {
  2767. CDrawZhePipe *pObj = new CDrawZhePipe;
  2768. *((CDrawObj*)pObj) = *(CDrawObj*)this;
  2769. return pObj;
  2770. }
  2771. void CDrawZhePipe::Draw(CDC* pDC)
  2772. {
  2773. if (!m_bShow && bRuning) return;
  2774. CRect rect = m_rctCurrent;
  2775. COLORREF clrFill = m_clrCurrentBack;
  2776. if (!bRuning)
  2777. {
  2778. clrFill = m_clrBack;
  2779. rect = m_rect;
  2780. }
  2781. unsigned char red = (unsigned char)(GetRValue(clrFill));
  2782. unsigned char green = (unsigned char)(GetGValue(clrFill));
  2783. unsigned char blue = (unsigned char)(GetBValue(clrFill));
  2784. unsigned char cred, cgreen, cblue;
  2785. int width = abs(rect.Width() / 2);
  2786. int i = 0;
  2787. for (i = 0; i < width; i++)
  2788. {
  2789. int crate = abs(rect.Width() / 4);
  2790. if (i < crate)
  2791. {
  2792. cred = (int)(red + i*(255.0 - red)*1.0 / crate);
  2793. cgreen = (int)(green + i*(255.0 - green)*1.0 / crate);
  2794. cblue = (int)(blue + i*(255.0 - blue)*1.0 / crate);
  2795. }
  2796. else
  2797. {
  2798. cred = 510 - (int)(red + i*(255.0 - red)*1.0 / crate);
  2799. cgreen = 510 - (int)(green + i*(255.0 - green)*1.0 / crate);
  2800. cblue = 510 - (int)(blue + i*(255.0 - blue)*1.0 / crate);
  2801. }
  2802. COLORREF color = RGB(cred, cgreen, cblue);
  2803. CRect rct = CRect(rect.left + i, rect.top, rect.left + i + 1, rect.bottom);
  2804. if (rect.left > rect.right)
  2805. rct = CRect(rect.left - i, rect.top, rect.left - i - 1, rect.bottom);
  2806. pDC->FillSolidRect(rct, color);
  2807. }
  2808. int height = abs(rect.Height() / 2);
  2809. for (i = 0; i < height; i++)
  2810. {
  2811. int crate = abs(rect.Height() / 4);
  2812. if (i < crate)
  2813. {
  2814. cred = (int)(red + i*(255.0 - red)*1.0 / crate);
  2815. cgreen = (int)(green + i*(255.0 - green)*1.0 / crate);
  2816. cblue = (int)(blue + i*(255.0 - blue)*1.0 / crate);
  2817. }
  2818. else
  2819. {
  2820. cred = 510 - (int)(red + i*(255.0 - red)*1.0 / crate);
  2821. cgreen = 510 - (int)(green + i*(255.0 - green)*1.0 / crate);
  2822. cblue = 510 - (int)(blue + i*(255.0 - blue)*1.0 / crate);
  2823. }
  2824. COLORREF color = RGB(cred, cgreen, cblue);
  2825. float rate = 1.0*abs(rect.Width()) / abs(rect.Height());
  2826. CRect rct = CRect(rect.left + i*rate, rect.top + i, rect.right, rect.top + i + 1);
  2827. if (rect.left > rect.right)
  2828. {
  2829. rct = CRect(rect.left - i*rate, rect.top + i, rect.right, rect.top + i + 1);
  2830. }
  2831. if (rect.top > rect.bottom)
  2832. {
  2833. rct = CRect(rect.left + i*rate - 1, rect.top - i, rect.right, rect.top - i + 1);
  2834. if (rect.left > rect.right)
  2835. {
  2836. rct = CRect(rect.left - i*rate, rect.top - i, rect.right, rect.top - i + 1);
  2837. }
  2838. }
  2839. pDC->FillSolidRect(rct, color);
  2840. }
  2841. }
  2842. //---------------------------------------------- CDrawYPipe --------
  2843. IMPLEMENT_SERIAL(CDrawYPipe, CDrawObj, 0)
  2844. CDrawYPipe::CDrawYPipe() :CDrawObj()
  2845. {
  2846. m_clrLine = RGB(0, 255, 0);
  2847. }
  2848. CDrawObj* CDrawYPipe::Clone(void)
  2849. {
  2850. CDrawPipe *pObj = new CDrawPipe;
  2851. *((CDrawObj*)pObj) = *(CDrawObj*)this;
  2852. return pObj;
  2853. }
  2854. void CDrawYPipe::Draw(CDC* pDC)
  2855. {
  2856. if (!m_bShow && bRuning) return;
  2857. CRect rect = m_rctCurrent;
  2858. COLORREF clrFill = m_clrCurrentBack;
  2859. if (!bRuning)
  2860. {
  2861. clrFill = m_clrBack;
  2862. rect = m_rect;
  2863. }
  2864. unsigned char red = (unsigned char)(GetRValue(clrFill));
  2865. unsigned char green = (unsigned char)(GetGValue(clrFill));
  2866. unsigned char blue = (unsigned char)(GetBValue(clrFill));
  2867. unsigned char cred, cgreen, cblue;
  2868. int width = abs(rect.Width() / 2);
  2869. int i = 0;
  2870. for (i = 0; i < width; i++)
  2871. {
  2872. int crate = abs(rect.Width() / 4);
  2873. if (i < crate)
  2874. {
  2875. cred = (int)(red + i*(255.0 - red)*1.0 / crate);
  2876. cgreen = (int)(green + i*(255.0 - green)*1.0 / crate);
  2877. cblue = (int)(blue + i*(255.0 - blue)*1.0 / crate);
  2878. }
  2879. else
  2880. {
  2881. cred = 510 - (int)(red + i*(255.0 - red)*1.0 / crate);
  2882. cgreen = 510 - (int)(green + i*(255.0 - green)*1.0 / crate);
  2883. cblue = 510 - (int)(blue + i*(255.0 - blue)*1.0 / crate);
  2884. }
  2885. COLORREF color = RGB(cred, cgreen, cblue);
  2886. CRect rct = CRect(rect.left + i, rect.top, rect.left + i + 1, rect.bottom);
  2887. if (rect.left > rect.right)
  2888. rct = CRect(rect.left - i, rect.top, rect.left - i - 1, rect.bottom);
  2889. pDC->FillSolidRect(rct, color);
  2890. }
  2891. int middle = (rect.top + rect.bottom) / 2;
  2892. int height = abs(rect.Height() / 4);
  2893. for (i = 0; i < height; i++)
  2894. {
  2895. cred = (int)(255 - i*(255.0 - red)*1.0 / height);
  2896. cgreen = (int)(255 - i*(255.0 - green)*1.0 / height);
  2897. cblue = (int)(255 - i*(255.0 - blue)*1.0 / height);
  2898. COLORREF color = RGB(cred, cgreen, cblue);
  2899. float rate = 1.0*abs(rect.Width()) / abs(rect.Height());
  2900. CRect rct = CRect(rect.left + abs(rect.Width()) / 4 + i*rate, middle + i, rect.right, middle + i + 1);
  2901. CRect rct1 = CRect(rect.left + abs(rect.Width()) / 4 + i*rate, middle - i, rect.right, middle - i - 1);
  2902. if (rect.left > rect.right)
  2903. {
  2904. rct = CRect(rect.left - i*rate - abs(rect.Width()) / 4, middle + i, rect.right, middle + i + 1);
  2905. rct1 = CRect(rect.left - i*rate - abs(rect.Width()) / 4, middle - i, rect.right, middle - i - 1);
  2906. }
  2907. if (rect.top > rect.bottom)
  2908. {
  2909. rct = CRect(rect.left + abs(rect.Width()) / 4 + i*rate - 1, middle - i, rect.right, middle - i + 1);
  2910. rct1 = CRect(rect.left + abs(rect.Width()) / 4 + i*rate, middle + i, rect.right, middle + i - 1);
  2911. if (rect.left > rect.right)
  2912. {
  2913. rct = CRect(rect.left - abs(rect.Width()) / 4 - i*rate, middle - i, rect.right, middle - i + 1);
  2914. rct1 = CRect(rect.left - abs(rect.Width()) / 4 - i*rate, middle + i, rect.right, middle + i - 1);
  2915. }
  2916. }
  2917. pDC->FillSolidRect(rct, color);
  2918. pDC->FillSolidRect(rct1, color);
  2919. }
  2920. }
  2921. //---------------------------------------------- CDrawPipe --------
  2922. IMPLEMENT_SERIAL(CDrawPipe, CDrawObj, 0)
  2923. CDrawPipe::CDrawPipe() :CDrawObj()
  2924. {
  2925. m_clrLine = RGB(0, 255, 0);
  2926. }
  2927. CDrawObj* CDrawPipe::Clone(void)
  2928. {
  2929. CDrawPipe *pObj = new CDrawPipe;
  2930. *((CDrawObj*)pObj) = *(CDrawObj*)this;
  2931. return pObj;
  2932. }
  2933. void CDrawPipe::Draw(CDC* pDC)
  2934. {
  2935. CDrawObj::Draw(pDC);
  2936. if (!m_bShow && bRuning) return;
  2937. CRect rect = m_rctCurrent;
  2938. COLORREF clrFill = m_clrCurrentBack;
  2939. if (!bRuning)
  2940. {
  2941. clrFill = m_clrBack;
  2942. rect = m_rect;
  2943. }
  2944. rect.NormalizeRect();
  2945. CRect tmp = rect;
  2946. CGradient gradient;
  2947. if (rect.Width() < rect.Height())
  2948. {
  2949. tmp.NormalizeRect();
  2950. tmp.right = (tmp.left + tmp.right) / 2 + 1;
  2951. gradient.HorizontalGradient(pDC, tmp, clrFill, RGB(255, 255, 255));
  2952. tmp = rect;
  2953. tmp.NormalizeRect();
  2954. tmp.left = (tmp.left + tmp.right) / 2 - 1;
  2955. gradient.HorizontalGradient(pDC, tmp, RGB(255, 255, 255), clrFill);
  2956. }
  2957. else
  2958. {
  2959. tmp.NormalizeRect();
  2960. tmp.top = (tmp.top + tmp.bottom) / 2 - 1;
  2961. gradient.VerticalGradient(pDC, tmp, RGB(255, 255, 255), clrFill);
  2962. tmp = rect;
  2963. tmp.NormalizeRect();
  2964. tmp.bottom = (tmp.top + tmp.bottom) / 2 + 1;
  2965. gradient.VerticalGradient(pDC, tmp, clrFill, RGB(255, 255, 255));
  2966. }
  2967. }
  2968. //---------------------------------------------- CDrawBitmap --------
  2969. IMPLEMENT_SERIAL(CDrawBitmap, CDrawObj, 0)
  2970. CDrawBitmap::CDrawBitmap() :CDrawObj()
  2971. {
  2972. m_strStaticFile = "home.bmp";
  2973. //m_strStaticFile = "";
  2974. m_strDynFile = "";
  2975. m_bDyn = FALSE;
  2976. m_strDynCondition = "";
  2977. m_bStretch = FALSE;
  2978. m_bUseDnyFile = FALSE;
  2979. m_image = NULL;
  2980. }
  2981. CDrawBitmap::~CDrawBitmap()
  2982. {
  2983. if (m_image)
  2984. {
  2985. delete m_image;
  2986. m_image = NULL;
  2987. }
  2988. }
  2989. CDrawObj* CDrawBitmap::Clone(void)
  2990. {
  2991. CDrawBitmap *pObj = new CDrawBitmap;
  2992. *((CDrawObj*)pObj) = *(CDrawObj*)this;
  2993. pObj->m_strStaticFile = m_strStaticFile;
  2994. pObj->m_strDynFile = m_strDynFile;
  2995. pObj->m_bDyn = m_bDyn;
  2996. pObj->m_strDynCondition = m_strDynCondition;
  2997. pObj->m_bStretch = m_bStretch;
  2998. pObj->m_bUseDnyFile = m_bUseDnyFile;
  2999. return pObj;
  3000. }
  3001. bool CDrawBitmap::Fresh(CRect &RECT)
  3002. {
  3003. CDrawObj::Fresh(RECT);
  3004. CRealComputer com;
  3005. com.SetFormula(m_strDynCondition);
  3006. m_bUseDnyFile = com.GetResult();
  3007. RECT = m_rect;
  3008. CString sTemp1 = m_strStaticFile, sTemp2 = m_strDynFile;
  3009. sTemp1 = sTemp1.MakeLower();
  3010. sTemp2 = sTemp2.MakeLower();
  3011. if (-1 != sTemp1.Find(".bmp") || -1 != sTemp2.Find(".bmp"))
  3012. return true;
  3013. else if (-1 != sTemp1.Find(".png") || -1 != sTemp2.Find(".png"))
  3014. return true;
  3015. else if (-1 != sTemp1.Find(".gif") || -1 != sTemp2.Find(".gif"))
  3016. {
  3017. if (!m_bShow)
  3018. {
  3019. m_bShowtemp = FALSE;
  3020. return true;
  3021. }
  3022. else if (!m_bShowtemp)
  3023. {
  3024. m_bShowtemp = TRUE;
  3025. return true;
  3026. }
  3027. else
  3028. return false;
  3029. }
  3030. else if (-1 != sTemp1.Find(".jpg") || -1 != sTemp2.Find(".jpg"))
  3031. return true;
  3032. return true;
  3033. }
  3034. void CDrawBitmap::Serialize(CArchive& ar)
  3035. {
  3036. CDrawObj::Serialize(ar);
  3037. if (ar.IsStoring())
  3038. {
  3039. ar << m_strStaticFile;
  3040. ar << m_strDynFile;
  3041. ar << m_bDyn;
  3042. ar << m_strDynCondition;
  3043. ar << m_bStretch;
  3044. }
  3045. else
  3046. {
  3047. ar >> m_strStaticFile;
  3048. ar >> m_strDynFile;
  3049. ar >> m_bDyn;
  3050. ar >> m_strDynCondition;
  3051. ar >> m_bStretch;
  3052. }
  3053. }
  3054. void CDrawBitmap::Draw(CDC* pDC)
  3055. {
  3056. if (!m_bShow && bRuning)
  3057. {
  3058. CString sTemp1 = m_sOldFilePath;
  3059. sTemp1 = sTemp1.MakeLower();
  3060. if (-1 != sTemp1.Find(".gif"))
  3061. {
  3062. if (m_image)
  3063. {
  3064. delete m_image;
  3065. m_image = NULL;
  3066. }
  3067. }
  3068. return;
  3069. }
  3070. CRect rect = m_rect;
  3071. rect.NormalizeRect();
  3072. int nX1 = rect.left;
  3073. int nY1 = rect.top;
  3074. int nXX = rect.right - rect.left;
  3075. int nYY = rect.bottom - rect.top;
  3076. char curDir[256];
  3077. strcpy(curDir, g_strDirectory);
  3078. strcat(curDir, "\\");
  3079. strcat(curDir, _BITMAPDIR);
  3080. #if 1
  3081. CString sTemp1 = m_strStaticFile, sTemp2 = m_strDynFile;
  3082. sTemp1 = sTemp1.MakeLower();
  3083. sTemp2 = sTemp2.MakeLower();
  3084. if (-1 != sTemp1.Find(".bmp") || -1 != sTemp2.Find(".bmp"))
  3085. {
  3086. if (bRuning && m_bDyn && m_bUseDnyFile)
  3087. DisplayBMP(pDC, nX1, nY1, nXX, nYY, CString(curDir) + m_strDynFile, m_bStretch);
  3088. else
  3089. DisplayBMP(pDC, nX1, nY1, nXX, nYY, CString(curDir) + m_strStaticFile, m_bStretch);
  3090. }
  3091. else if (-1 != sTemp1.Find(".png") || -1 != sTemp2.Find(".png"))
  3092. {
  3093. if (bRuning && m_bDyn && m_bUseDnyFile)
  3094. DisplayPNG(pDC, nX1, nY1, nXX, nYY, CString(curDir) + m_strDynFile, m_bStretch);
  3095. else
  3096. DisplayPNG(pDC, nX1, nY1, nXX, nYY, CString(curDir) + m_strStaticFile, m_bStretch);
  3097. }
  3098. else if (-1 != sTemp1.Find(".gif") || -1 != sTemp2.Find(".gif"))
  3099. {
  3100. if (bRuning && m_bDyn && m_bUseDnyFile)
  3101. DisplayGIF(pDC, nX1, nY1, nXX, nYY, CString(curDir) + m_strDynFile, m_bStretch);
  3102. else
  3103. DisplayGIF(pDC, nX1, nY1, nXX, nYY, CString(curDir) + m_strStaticFile, m_bStretch);
  3104. }
  3105. else if (-1 != sTemp1.Find(".jpg") || -1 != sTemp2.Find(".jpg"))
  3106. {
  3107. if (bRuning && m_bDyn && m_bUseDnyFile)
  3108. DisplayJPG(pDC, nX1, nY1, nXX, nYY, CString(curDir) + m_strDynFile, m_bStretch);
  3109. else
  3110. DisplayJPG(pDC, nX1, nY1, nXX, nYY, CString(curDir) + m_strStaticFile, m_bStretch);
  3111. }
  3112. #else
  3113. if (bRuning && m_bDyn && m_bUseDnyFile)
  3114. DisplayJPG(pDC, nX1, nY1, nXX, nYY, CString(curDir) + m_strDynFile, m_bStretch);
  3115. else
  3116. DisplayJPG(pDC, nX1, nY1, nXX, nYY, CString(curDir) + m_strStaticFile, m_bStretch);
  3117. #endif
  3118. }
  3119. BOOL CDrawBitmap::DisplayJPG(CDC* pDC,int nStartX,int nStartY,int nWidth,int nHeight,CString strJPGFile,BOOL bStretch)
  3120. {
  3121. CString sTemp1 = m_sOldFilePath;
  3122. sTemp1 = sTemp1.MakeLower();
  3123. if (-1 != sTemp1.Find(".gif"))
  3124. {
  3125. if (m_image)
  3126. {
  3127. delete m_image;
  3128. m_image = NULL;
  3129. }
  3130. }
  3131. BSTR strtmp = strJPGFile.AllocSysString();
  3132. Graphics graphics(pDC->m_hDC);
  3133. Image image(strtmp, FALSE);
  3134. SysFreeString(strtmp);
  3135. if (bStretch)
  3136. {
  3137. graphics.DrawImage(&image, nStartX, nStartY, nWidth, nHeight);
  3138. }
  3139. else
  3140. {
  3141. Rect rcDest(nStartX, nStartY, nWidth, nHeight);
  3142. graphics.DrawImage(&image, rcDest, 0, 0, nWidth, nHeight, UnitPixel);
  3143. }
  3144. return TRUE;
  3145. }
  3146. BOOL CDrawBitmap::DisplayBMP(CDC* pDC, int nStartX, int nStartY, int nWidth, int nHeight, CString strBMPFile, BOOL bStretch)
  3147. {
  3148. #if 0
  3149. CString sTemp1 = m_sOldFilePath;
  3150. sTemp1 = sTemp1.MakeLower();
  3151. if (-1 != sTemp1.Find(".gif"))
  3152. {
  3153. if (m_image)
  3154. {
  3155. delete m_image;
  3156. m_image = NULL;
  3157. }
  3158. }
  3159. GdiplusStartupInput m_gdiplusStartupInput;
  3160. // ULONG_PTR m_pGdiToken;
  3161. wchar_t m_wstrServerName[255];
  3162. MultiByteToWideChar(CP_ACP, 0, strBMPFile, -1, m_wstrServerName, 256);
  3163. Graphics graphics(pDC->m_hDC);
  3164. //wchar_t * p=strJPGFile.AllocSysStrinig();
  3165. Image image(m_wstrServerName, FALSE);
  3166. if (bStretch)
  3167. {
  3168. graphics.DrawImage(&image, nX1, nY1, nXX, nYY);
  3169. }
  3170. else
  3171. {
  3172. WORD Width = (WORD)image.GetWidth();
  3173. WORD Height = (WORD)image.GetHeight();
  3174. //Width = min(Width,nXX);
  3175. //Height = min(Height,nYY);
  3176. //graphics.DrawImage( &image, nX1,nY1,Width,Height );
  3177. graphics.DrawImage(&image, nX1, nY1, 0, 0, nXX, nYY, UnitPixel);
  3178. }
  3179. return true;
  3180. #else
  3181. CString sTemp1 = m_sOldFilePath;
  3182. sTemp1 = sTemp1.MakeLower();
  3183. if (-1 != sTemp1.Find(".gif"))
  3184. {
  3185. if (m_image)
  3186. {
  3187. delete m_image;
  3188. m_image = NULL;
  3189. }
  3190. }
  3191. OFSTRUCT of;
  3192. unsigned fh = OpenFile((char const*)strBMPFile, &of, OF_READ);
  3193. if (fh == -1) return FALSE;
  3194. DWORD size = (DWORD)(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
  3195. HANDLE hDIBInfo = GlobalAlloc(GMEM_MOVEABLE, size);
  3196. SetStretchBltMode(pDC->m_hDC, HALFTONE);
  3197. BITMAPFILEHEADER bf;
  3198. LPBITMAPINFOHEADER lpbi;
  3199. lpbi = (LPBITMAPINFOHEADER)GlobalLock(hDIBInfo);
  3200. _lread(fh, (LPSTR)&bf, sizeof(bf));
  3201. _lread(fh, (LPSTR)lpbi, sizeof(BITMAPINFOHEADER));
  3202. WORD nClrs = (WORD)lpbi->biClrUsed;
  3203. size = ((((lpbi->biWidth*lpbi->biBitCount) + 31)&~31) >> 3)*lpbi->biHeight;
  3204. if (nClrs == 0 && lpbi->biBitCount != 24) nClrs = 1 << lpbi->biBitCount;
  3205. if (lpbi->biClrUsed == 0) lpbi->biClrUsed = (DWORD)nClrs;
  3206. if (lpbi->biSizeImage == 0) lpbi->biSizeImage = size;
  3207. WORD Size = (WORD)lpbi->biSize;
  3208. WORD Width = (WORD)lpbi->biWidth;
  3209. WORD Height = (WORD)lpbi->biHeight;
  3210. WORD ClrUsed = (WORD)lpbi->biClrUsed;
  3211. WORD BitCount = (WORD)lpbi->biBitCount;
  3212. DWORD SizeImage = lpbi->biSizeImage;
  3213. WORD SizeRGB = nClrs * sizeof(RGBQUAD);
  3214. WORD SizeHeader = Size + SizeRGB;
  3215. GlobalUnlock(hDIBInfo);
  3216. hDIBInfo = GlobalReAlloc(hDIBInfo, SizeHeader + SizeImage, 0);
  3217. lpbi = (LPBITMAPINFOHEADER)GlobalLock(hDIBInfo);
  3218. _lread(fh, (LPSTR)(lpbi)+Size, SizeRGB);
  3219. if (bf.bfOffBits != 0L) _llseek(fh, bf.bfOffBits, SEEK_SET);
  3220. DWORD ul = SizeImage;
  3221. BYTE *hp = (BYTE *)((LPSTR)lpbi + SizeHeader);
  3222. while (ul > 30000L)
  3223. {
  3224. _lread(fh, (LPSTR)hp, 30000L);
  3225. ul -= 30000L;
  3226. hp += 30000L;
  3227. }
  3228. _lread(fh, (LPSTR)hp, (WORD)ul);
  3229. _lclose(fh);
  3230. HPALETTE hPalette, hOldPal;
  3231. HANDLE hPalHeader = NULL;
  3232. HDC hDC = pDC->m_hDC;
  3233. LPBITMAPINFOHEADER lpHeader = lpbi;
  3234. WORD wDIBUse = DIB_RGB_COLORS;
  3235. if (ClrUsed)
  3236. {
  3237. WORD size = sizeof(LOGPALETTE) + ClrUsed * sizeof(PALETTEENTRY);
  3238. NPLOGPALETTE npPal = (NPLOGPALETTE)LocalAlloc(LMEM_FIXED, size);
  3239. npPal->palVersion = 0x300;
  3240. npPal->palNumEntries = ClrUsed;
  3241. RGBQUAD FAR *lpRGB = (RGBQUAD FAR *)((LPSTR)lpbi + Size);
  3242. for (WORD i = 0; i < ClrUsed; i++, lpRGB++)
  3243. {
  3244. npPal->palPalEntry[i].peRed = lpRGB->rgbRed;
  3245. npPal->palPalEntry[i].peGreen = lpRGB->rgbGreen;
  3246. npPal->palPalEntry[i].peBlue = lpRGB->rgbBlue;
  3247. npPal->palPalEntry[i].peFlags = 0;
  3248. }
  3249. hPalette = CreatePalette((LPLOGPALETTE)npPal);
  3250. LocalFree((HANDLE)npPal);
  3251. hOldPal = SelectPalette(hDC, hPalette, FALSE);
  3252. RealizePalette(hDC);
  3253. if (BitCount != 24)
  3254. {
  3255. size = Size + ClrUsed * sizeof(WORD);
  3256. hPalHeader = GlobalAlloc(GMEM_MOVEABLE, size);
  3257. LPBITMAPINFOHEADER lpPalInfo;
  3258. lpPalInfo = (LPBITMAPINFOHEADER)GlobalLock(hPalHeader);
  3259. *lpPalInfo = *lpbi;
  3260. WORD FAR *lpTable = (WORD FAR *)((LPSTR)lpPalInfo + Size);
  3261. for (WORD i = 0; i < ClrUsed; i++) *lpTable++ = i;
  3262. GlobalUnlock(hPalHeader);
  3263. lpHeader = (LPBITMAPINFOHEADER)GlobalLock(hPalHeader);
  3264. wDIBUse = DIB_PAL_COLORS;
  3265. }
  3266. }
  3267. HDC hMemDC = CreateCompatibleDC(hDC);
  3268. HBITMAP hDDBitmap = CreateCompatibleBitmap(hDC, Width, Height);
  3269. SetDIBits(hDC, hDDBitmap, 0, Height, (LPSTR)lpbi + SizeHeader,
  3270. (LPBITMAPINFO)lpHeader, wDIBUse);
  3271. HBITMAP hOldBitmap = (HBITMAP)SelectObject(hMemDC, hDDBitmap);
  3272. if (bStretch)
  3273. {
  3274. StretchBlt(hDC, nStartX, nStartY, nWidth, nHeight, hMemDC, 0, 0, Width, Height, SRCCOPY);
  3275. }
  3276. else
  3277. {
  3278. Width = min(Width, nWidth);
  3279. Height = min(Height, nHeight);
  3280. BitBlt(hDC, nStartX, nStartY, Width, Height, hMemDC, 0, 0, SRCCOPY);
  3281. }
  3282. SelectObject(hMemDC, hOldBitmap);
  3283. DeleteDC(hMemDC);
  3284. DeleteObject(hDDBitmap);
  3285. if (ClrUsed)
  3286. {
  3287. SelectPalette(hDC, hOldPal, FALSE);
  3288. DeleteObject(hPalette);
  3289. if (BitCount != 24)
  3290. {
  3291. GlobalUnlock(hPalHeader);
  3292. GlobalFree(hPalHeader);
  3293. }
  3294. }
  3295. GlobalUnlock(hDIBInfo);
  3296. GlobalFree(hDIBInfo);
  3297. return TRUE;
  3298. #endif
  3299. }
  3300. BOOL CDrawBitmap::DisplayPNG(CDC* pDC, int nStartX, int nStartY, int nWidth, int nHeight, CString strPNGFile, BOOL bStretch)
  3301. {
  3302. CString sTemp1 = m_sOldFilePath;
  3303. sTemp1 = sTemp1.MakeLower();
  3304. if (-1 != sTemp1.Find(".gif"))
  3305. {
  3306. if (m_image)
  3307. {
  3308. delete m_image;
  3309. m_image = NULL;
  3310. }
  3311. }
  3312. BSTR strtmp = strPNGFile.AllocSysString();
  3313. Graphics graphics(pDC->m_hDC);
  3314. Image image(strtmp, FALSE);
  3315. SysFreeString(strtmp);
  3316. if (bStretch)
  3317. {
  3318. graphics.DrawImage(&image, nStartX, nStartY, nWidth, nHeight);
  3319. }
  3320. else
  3321. {
  3322. Rect rcDest(nStartX, nStartY, nWidth, nHeight);
  3323. graphics.DrawImage(&image, rcDest, 0, 0, nWidth, nHeight, UnitPixel);
  3324. }
  3325. return true;
  3326. }
  3327. BOOL CDrawBitmap::DisplayGIF(CDC* pDC, int nX1, int nY1, int nXX, int nYY, CString strJPGFile, BOOL bStretch)
  3328. {
  3329. if (m_sOldFilePath != strJPGFile)
  3330. {
  3331. if (m_image)
  3332. {
  3333. delete m_image;
  3334. m_image = NULL;
  3335. }
  3336. }
  3337. if (m_image == NULL)
  3338. {
  3339. //char curDir[256] = {0};
  3340. ////strcpy(curDir, g_strDirectory);
  3341. //strcat(curDir, ".\\\\");
  3342. //strcat(curDir, _BITMAPDIR);
  3343. //if( m_strStaticFile=="" )//gif 路徑為Bitmap,默認名為StounU.gif
  3344. // m_strStaticFile = "StounU.gif";
  3345. //CString strGifFileName = CString(curDir) + m_strStaticFile;
  3346. m_sOldFilePath = strJPGFile;
  3347. // GDI+
  3348. m_image = new ImageEx(StrToWchar(strJPGFile));
  3349. }
  3350. if (m_image)
  3351. {
  3352. //CRect rect = m_rect;
  3353. //rect.NormalizeRect();
  3354. //int nX1 = rect.left;
  3355. //int nY1 = rect.top;
  3356. //CPoint pt(nX1, nY1);
  3357. CMainFrame* pFrame = (CMainFrame*)AfxGetApp()->GetMainWnd();
  3358. HWND hwnd = m_pView->GetSafeHwnd();//pFrame->m_pActiveView->m_hWnd;
  3359. m_image->InitAnimation(hwnd, CRect(nX1, nY1, nX1 + nXX, nY1 + nYY), bStretch);
  3360. }
  3361. return true;
  3362. }
  3363. BOOL CDrawBitmap::OnAttrib(CPropertySheet& sheet)
  3364. {
  3365. CBitmapPage page;
  3366. page.m_strDynFile = m_strDynFile;
  3367. page.m_strStaticFile = m_strStaticFile;
  3368. page.m_bStretch = m_bStretch;
  3369. page.m_bDyn = m_bDyn;
  3370. page.m_strDynCondition = m_strDynCondition;
  3371. sheet.AddPage(&page);
  3372. sheet.Construct(g_strParamSet);
  3373. sheet.m_psh.dwFlags |= PSH_NOAPPLYNOW;
  3374. if (sheet.DoModal() == IDOK)
  3375. {
  3376. m_strDynFile = page.m_strDynFile;
  3377. m_strStaticFile = page.m_strStaticFile;
  3378. m_bStretch = page.m_bStretch;
  3379. m_bDyn = page.m_bDyn;
  3380. m_strDynCondition = page.m_strDynCondition;
  3381. return TRUE;
  3382. }
  3383. return FALSE;
  3384. }
  3385. //---------------------------------------------- CDrawGif --------
  3386. IMPLEMENT_SERIAL(CDrawGif, CDrawObj, 0)
  3387. CDrawGif::CDrawGif() :CDrawObj()
  3388. {
  3389. //m_strStaticFile = "statusAlarm.gif";
  3390. m_strStaticFile = "";
  3391. m_strDynFile = "";
  3392. m_bDyn = FALSE;
  3393. m_strDynCondition = "";
  3394. m_bStretch = TRUE;
  3395. m_bUseDnyFile = FALSE;
  3396. //char curDir[256] = {0};
  3397. ////strcpy(curDir, g_strDirectory);
  3398. //strcat(curDir, ".\\\\");
  3399. //strcat(curDir, _BITMAPDIR);
  3400. //CString strGifFileName = CString(curDir) + m_strStaticFile;
  3401. // GDI+
  3402. m_image = NULL;
  3403. }
  3404. CDrawGif::~CDrawGif()
  3405. {
  3406. if (m_image)
  3407. {
  3408. delete m_image;
  3409. m_image = NULL;
  3410. }
  3411. }
  3412. CDrawObj* CDrawGif::Clone(void)
  3413. {
  3414. CDrawGif *pObj = new CDrawGif;
  3415. *((CDrawObj*)pObj) = *(CDrawObj*)this;
  3416. pObj->m_strStaticFile = m_strStaticFile;
  3417. pObj->m_strDynFile = m_strDynFile;
  3418. pObj->m_bDyn = m_bDyn;
  3419. pObj->m_strDynCondition = m_strDynCondition;
  3420. pObj->m_bStretch = m_bStretch;
  3421. pObj->m_bUseDnyFile = m_bUseDnyFile;
  3422. return pObj;
  3423. }
  3424. bool CDrawGif::Fresh(CRect &RECT)
  3425. {
  3426. CDrawObj::Fresh(RECT);
  3427. CRealComputer com;
  3428. com.SetFormula(m_strDynCondition);
  3429. m_bUseDnyFile = com.GetResult();
  3430. //this->Invalidate( );
  3431. //if( m_image )
  3432. //{
  3433. // CRect rect = m_rect;
  3434. // rect.NormalizeRect();
  3435. // int nX1 = rect.left;
  3436. // int nY1 = rect.top;
  3437. // CPoint pt(nX1, nY1);
  3438. // CMainFrame* pFrame = (CMainFrame*)AfxGetApp()->GetMainWnd();
  3439. // HWND hwnd = pFrame->m_pActiveView->m_hWnd;
  3440. // m_image->InitAnimation(hwnd, pt);
  3441. //}
  3442. RECT = m_rect;
  3443. return false;
  3444. }
  3445. void CDrawGif::Serialize(CArchive& ar)
  3446. {
  3447. CDrawObj::Serialize(ar);
  3448. if (ar.IsStoring())
  3449. {
  3450. ar << m_strStaticFile;
  3451. ar << m_strDynFile;
  3452. ar << m_bDyn;
  3453. ar << m_strDynCondition;
  3454. ar << m_bStretch;
  3455. }
  3456. else
  3457. {
  3458. ar >> m_strStaticFile;
  3459. ar >> m_strDynFile;
  3460. ar >> m_bDyn;
  3461. ar >> m_strDynCondition;
  3462. ar >> m_bStretch;
  3463. }
  3464. }
  3465. void CDrawGif::Draw(CDC* pDC)
  3466. {
  3467. if (m_image == NULL)
  3468. {
  3469. char curDir[256] = { 0 };
  3470. //strcpy(curDir, g_strDirectory);
  3471. strcat(curDir, ".\\\\");
  3472. strcat(curDir, _BITMAPDIR);
  3473. if (m_strStaticFile == "")//gif 路徑為Bitmap,默認名為StounU.gif
  3474. m_strStaticFile = "StounU.gif";
  3475. CString strGifFileName = CString(curDir) + m_strStaticFile;
  3476. // GDI+
  3477. m_image = new ImageEx(StrToWchar(strGifFileName));
  3478. }
  3479. if (m_image)
  3480. {
  3481. CRect rect = m_rect;
  3482. rect.NormalizeRect();
  3483. int nX1 = rect.left;
  3484. int nY1 = rect.top;
  3485. CPoint pt(nX1, nY1);
  3486. CMainFrame* pFrame = (CMainFrame*)AfxGetApp()->GetMainWnd();
  3487. HWND hwnd = pFrame->m_pActiveView->m_hWnd;
  3488. m_image->InitAnimation(hwnd, pt);
  3489. }
  3490. }
  3491. BOOL CDrawGif::OnAttrib(CPropertySheet& sheet)
  3492. {
  3493. CBitmapPage page;
  3494. page.m_strDynFile = m_strDynFile;
  3495. page.m_strStaticFile = m_strStaticFile;
  3496. page.m_bStretch = m_bStretch;
  3497. page.m_bDyn = m_bDyn;
  3498. page.m_strDynCondition = m_strDynCondition;
  3499. sheet.AddPage(&page);
  3500. sheet.Construct(g_strParamSet);
  3501. sheet.m_psh.dwFlags |= PSH_NOAPPLYNOW;
  3502. if (sheet.DoModal() == IDOK)
  3503. {
  3504. m_strDynFile = page.m_strDynFile;
  3505. m_strStaticFile = page.m_strStaticFile;
  3506. m_bStretch = page.m_bStretch;
  3507. m_bDyn = page.m_bDyn;
  3508. m_strDynCondition = page.m_strDynCondition;
  3509. char curDir[256];
  3510. strcpy(curDir, g_strDirectory);
  3511. strcat(curDir, "\\");
  3512. strcat(curDir, _BITMAPDIR);
  3513. CString strGifFileName = CString(curDir) + m_strStaticFile;
  3514. m_image->FromFile(StrToWchar(strGifFileName));
  3515. CRect rect = m_rect;
  3516. rect.NormalizeRect();
  3517. int nX1 = rect.left;
  3518. int nY1 = rect.top;
  3519. CPoint pt(nX1, nY1);
  3520. CMainFrame* pFrame = (CMainFrame*)AfxGetApp()->GetMainWnd();
  3521. HWND hwnd = pFrame->m_pActiveView->m_hWnd;
  3522. m_image->InitAnimation(hwnd, pt);
  3523. return TRUE;
  3524. }
  3525. return FALSE;
  3526. }
  3527. //---------------------------------------------- CDrawTransfer --------
  3528. IMPLEMENT_SERIAL(CDrawTransfer, CDrawObj, 0)
  3529. CDrawTransfer::CDrawTransfer() :CDrawObj()
  3530. {
  3531. m_clrLine = RGB(0, 255, 0);
  3532. }
  3533. CDrawObj* CDrawTransfer::Clone(void)
  3534. {
  3535. CDrawTransfer *pObj = new CDrawTransfer;
  3536. *((CDrawObj*)pObj) = *(CDrawObj*)this;
  3537. return pObj;
  3538. }
  3539. void CDrawTransfer::Draw(CDC* pDC)
  3540. {
  3541. if (!m_bShow && bRuning) return;
  3542. COLORREF clrLine = m_clrLine;
  3543. COLORREF clrBack = m_clrBack;
  3544. CRect rect = m_rect;
  3545. if (bRuning)
  3546. {
  3547. clrLine = m_clrCurrentLine;
  3548. clrBack = m_clrCurrentBack;
  3549. rect = m_rctCurrent;
  3550. }
  3551. CPen pen(GetPenStyle(m_strLineType), m_nLineWidth, clrLine);
  3552. CPen* pOldPen = pDC->SelectObject(&pen);
  3553. rect.NormalizeRect();
  3554. int x = (rect.left + rect.right) / 2;
  3555. int y = (rect.top + rect.bottom) / 2;
  3556. int r = min(rect.Width(), rect.Height()) * 0.25;
  3557. DrawCircle(pDC, CPoint(x, y - 0.7*r), r);
  3558. CPen pen1(GetPenStyle(m_strLineType), m_nLineWidth, clrBack);
  3559. pDC->SelectObject(&pen1);
  3560. pDC->SelectObject(&pen1);
  3561. DrawCircle(pDC, CPoint(x, y + 0.7*r), r);
  3562. pDC->SelectObject(pOldPen);
  3563. DeleteObject(pen);
  3564. DeleteObject(pen1);
  3565. }
  3566. void CDrawTransfer::DrawCircle(CDC *pDC, POINT origin, int radius)
  3567. {
  3568. pDC->MoveTo(origin.x + radius, origin.y);
  3569. pDC->AngleArc(origin.x, origin.y, radius, 0, 360);
  3570. }
  3571. //---------------------------------------------- CDrawButton ------
  3572. IMPLEMENT_SERIAL(CDrawButton, CDrawObj, 0)
  3573. CDrawButton::CDrawButton() :CDrawObj()
  3574. {
  3575. m_clrFore = RGB(255, 255, 255);
  3576. m_clrBack = RGB(255, 128, 0);
  3577. m_strCaption = "按钮";
  3578. m_clrCurrentBack = m_clrBack;
  3579. }
  3580. CDrawObj* CDrawButton::Clone(void)
  3581. {
  3582. CDrawButton *pObj = new CDrawButton;
  3583. *((CDrawObj*)pObj) = *(CDrawObj*)this;
  3584. return pObj;
  3585. }
  3586. void CDrawButton::Draw(CDC* pDC)
  3587. {
  3588. CDrawObj::Draw(pDC);
  3589. if (!m_bShow && bRuning) return;
  3590. CRect rect = m_rctCurrent;
  3591. COLORREF color = m_clrCurrentBack;
  3592. if (!bRuning)
  3593. {
  3594. rect = m_rect;
  3595. color = m_clrBack;
  3596. }
  3597. pDC->FillSolidRect(rect, color);
  3598. int Width = 2;
  3599. int nR0 = GetRValue(color);
  3600. int nG0 = GetGValue(color);
  3601. int nB0 = GetBValue(color);
  3602. int nRMin = nR0 / 2;
  3603. int nGMin = nG0 / 2;
  3604. int nBMin = nB0 / 2;
  3605. int nRMax = min(nR0 * 2, 255);
  3606. int nGMax = min(nG0 * 2, 255);
  3607. int nBMax = min(nB0 * 2, 255);
  3608. for (int i = 0; i < Width; i++)
  3609. {
  3610. int n = i;
  3611. int nR1 = (n*nR0 + (Width - n)*nRMax) / Width;
  3612. int nG1 = (n*nG0 + (Width - n)*nGMax) / Width;
  3613. int nB1 = (n*nB0 + (Width - n)*nBMax) / Width;
  3614. COLORREF clrLight = RGB(nR1, nG1, nB1);
  3615. int nR2 = (n*nR0 + (Width - n)*nRMin) / Width;
  3616. int nG2 = (n*nG0 + (Width - n)*nGMin) / Width;
  3617. int nB2 = (n*nB0 + (Width - n)*nBMin) / Width;
  3618. COLORREF clrDark = RGB(nR2, nG2, nB2);
  3619. pDC->Draw3dRect(rect, clrLight, clrDark);
  3620. rect.DeflateRect(1, 1, 1, 1);
  3621. }
  3622. DrawText(pDC);
  3623. }
  3624. //---------------------------------------------- CDrawDatabox -----
  3625. IMPLEMENT_SERIAL(CDrawDatabox, CDrawObj, 0)
  3626. CDrawDatabox::CDrawDatabox() :CDrawObj()
  3627. {
  3628. m_clrLine = RGB(0, 0, 0);
  3629. m_clrBack = RGB(255, 0, 0);//RGB(255,128,0);
  3630. m_clrFore = RGB(0, 0, 0);
  3631. m_clrFill = RGB(255, 0, 0);
  3632. m_nFillMode = 0;
  3633. m_nFormat = 1;
  3634. m_bVariant = true;
  3635. }
  3636. CDrawObj* CDrawDatabox::Clone(void)
  3637. {
  3638. CDrawDatabox *pObj = new CDrawDatabox;
  3639. *((CDrawObj*)pObj) = *(CDrawObj*)this;
  3640. pObj->m_nFormat = m_nFormat;
  3641. pObj->m_nFillMode = m_nFillMode;
  3642. return pObj;
  3643. }
  3644. bool CDrawDatabox::Fresh(CRect &RECT)
  3645. {
  3646. CDrawObj::Fresh(RECT);
  3647. //InvalidateRect( g_pMainFrm->GetSafeHwnd(),m_rctCurrent,false );
  3648. //Invalidate( );
  3649. RECT = m_rect;
  3650. return true;
  3651. }
  3652. void CDrawDatabox::Draw(CDC* pDC)
  3653. {
  3654. CDrawObj::Draw(pDC);
  3655. if (!m_bShow && bRuning) return;
  3656. CRect rectRgn = m_rctCurrent;
  3657. COLORREF clrPen = m_clrCurrentLine;
  3658. COLORREF clrBrush = m_clrCurrentBack;
  3659. COLORREF clrText = m_clrCurrentFore;
  3660. if (!bRuning)
  3661. {
  3662. rectRgn = m_rect;
  3663. clrPen = m_clrLine;
  3664. clrBrush = m_clrBack;
  3665. clrText = m_clrFore;
  3666. }
  3667. CString value = "";
  3668. if (!m_bVariant)
  3669. value = m_strCaption;
  3670. else
  3671. {
  3672. int nValue = 0;
  3673. switch (m_nFormat)
  3674. {
  3675. case 0:
  3676. nValue = (int)m_fCurrentValue;
  3677. value.Format("%d", nValue);
  3678. break;
  3679. case 1:
  3680. value.Format("%.1f", m_fCurrentValue);
  3681. break;
  3682. case 2:
  3683. value.Format("%.2f", m_fCurrentValue);
  3684. break;
  3685. case 3:
  3686. value.Format("%.3f", m_fCurrentValue);
  3687. break;
  3688. }
  3689. }
  3690. CPen pen(GetPenStyle(m_strLineType), m_nLineWidth, clrPen);
  3691. CPen* pOldPen = pDC->SelectObject(&pen);
  3692. CBrush brush;
  3693. CBrush* pOldBrush;
  3694. if (m_bVariant)
  3695. {
  3696. int nRet = 0;//pVariantsManager->VarIsAlarm( m_strCaption );
  3697. if (nRet == 1 && bRuning)//报警
  3698. {
  3699. brush.CreateSolidBrush(clrBrush);
  3700. pOldBrush = pDC->SelectObject(&brush);
  3701. }
  3702. else
  3703. {
  3704. LOGBRUSH logBrush = GetBrush();
  3705. brush.CreateBrushIndirect(&logBrush);
  3706. pOldBrush = pDC->SelectObject(&brush);
  3707. }
  3708. }
  3709. else
  3710. {
  3711. LOGBRUSH logBrush = GetBrush();
  3712. brush.CreateBrushIndirect(&logBrush);
  3713. pOldBrush = pDC->SelectObject(&brush);
  3714. }
  3715. pDC->Rectangle(rectRgn);
  3716. //pDC->SelectObject(pOldPen);
  3717. //pDC->SelectObject(pOldBrush);
  3718. rectRgn.NormalizeRect();
  3719. pDC->LPtoDP(&rectRgn);
  3720. CRgn rgn;
  3721. rgn.CreateRectRgnIndirect(&rectRgn);
  3722. pDC->SelectClipRgn(&rgn);
  3723. DrawText(pDC, value);
  3724. pDC->SelectClipRgn(NULL);
  3725. DeleteObject(pen);
  3726. DeleteObject(brush);
  3727. DeleteObject(rgn);
  3728. }
  3729. void CDrawDatabox::DrawText(CDC* pDC, CString& strText)
  3730. {
  3731. CRect rect = m_rctCurrent;
  3732. COLORREF txtColor = m_clrCurrentFore;
  3733. if (!bRuning)
  3734. {
  3735. rect = m_rect;
  3736. txtColor = m_clrFore;
  3737. }
  3738. int nX0 = (rect.left + rect.right) / 2;
  3739. int nY0 = (rect.top + rect.bottom) / 2;
  3740. CFont font;
  3741. font.CreateFontIndirect(&m_logfont);
  3742. CFont* pOldFont = pDC->SelectObject(&font);
  3743. CSize sizeText = pDC->GetTextExtent(strText);
  3744. int nInterval = sizeText.cy / 2;
  3745. int nYText = nY0 - nInterval + 1;
  3746. int nXText;
  3747. pDC->SetTextAlign(TA_CENTER | TA_TOP);
  3748. nXText = nX0;
  3749. pDC->SetTextColor(txtColor);
  3750. pDC->TextOut(nXText, nYText, strText);
  3751. pDC->SelectObject(pOldFont);
  3752. DeleteObject(font);
  3753. }
  3754. void CDrawDatabox::Serialize(CArchive& ar)
  3755. {
  3756. CDrawObj::Serialize(ar);
  3757. if (ar.IsStoring())
  3758. {
  3759. ar << m_nFormat;
  3760. }
  3761. else
  3762. {
  3763. ar >> m_nFormat;
  3764. }
  3765. }
  3766. BOOL CDrawDatabox::OnAttrib(CPropertySheet& sheet)
  3767. {
  3768. CDataPage page;
  3769. page.m_nFormat = m_nFormat;
  3770. sheet.AddPage(&page);
  3771. sheet.Construct(g_strParamSet);
  3772. sheet.m_psh.dwFlags |= PSH_NOAPPLYNOW;
  3773. if (sheet.DoModal() == IDOK)
  3774. {
  3775. m_nFormat = page.m_nFormat;
  3776. return TRUE;
  3777. }
  3778. return FALSE;
  3779. }
  3780. //---------------------------------------------- CDrawWatch -----
  3781. IMPLEMENT_SERIAL(CDrawWatch, CDrawObj, 0)
  3782. CDrawWatch::CDrawWatch() :CDrawObj()
  3783. {
  3784. m_clrLine = RGB(255, 0, 0);
  3785. m_clrBack = RGB(192, 192, 192);
  3786. m_clrFore = RGB(0, 0, 0);
  3787. m_nLineWidth = 1;
  3788. m_nLowwer = 0;
  3789. m_nUpper = 1000;
  3790. m_strVar = "";
  3791. }
  3792. CDrawObj* CDrawWatch::Clone(void)
  3793. {
  3794. CDrawWatch *pObj = new CDrawWatch;
  3795. *((CDrawObj*)pObj) = *(CDrawObj*)this;
  3796. return pObj;
  3797. }
  3798. void CDrawWatch::Draw(CDC* pDC)
  3799. {
  3800. if (!m_bShow && bRuning) return;
  3801. CRect rectRgn = m_rctCurrent;
  3802. COLORREF clrPen = m_clrCurrentLine;
  3803. COLORREF clrBrush = m_clrCurrentBack;
  3804. COLORREF clrText = m_clrCurrentFore;
  3805. if (!bRuning)
  3806. {
  3807. rectRgn = m_rect;
  3808. clrPen = m_clrLine;
  3809. clrBrush = m_clrBack;
  3810. clrText = m_clrFore;
  3811. }
  3812. if (!m_bVariant)
  3813. m_strCurrentCaption = m_strCaption;
  3814. rectRgn.NormalizeRect();
  3815. CBrush brush(clrText);
  3816. CBrush *prebrush = pDC->SelectObject(&brush);
  3817. pDC->FillSolidRect(rectRgn, clrBrush);
  3818. int top = rectRgn.top + 10;
  3819. int middle = rectRgn.bottom - 40;
  3820. if (middle < top) middle = top;
  3821. CRect rectPie = CRect(rectRgn.left + 10, top, rectRgn.right - 10, top + 2 * (middle - top));
  3822. CPoint s = CPoint(rectRgn.right - 10, middle);
  3823. CPoint e = CPoint(rectRgn.left + 10, middle);
  3824. INT HorzRes = pDC->GetDeviceCaps(HORZRES);
  3825. INT VertRes = pDC->GetDeviceCaps(VERTRES);
  3826. INT VertSize = pDC->GetDeviceCaps(VERTSIZE);
  3827. INT HorzSize = pDC->GetDeviceCaps(HORZSIZE);
  3828. m_lAspectN = ((LONG)VertRes * 100) / (LONG)VertSize;
  3829. m_lAspectD = ((LONG)HorzRes * 100) / (LONG)HorzSize;
  3830. // 画指针
  3831. CPen pen(GetPenStyle(m_strLineType), m_nLineWidth, m_clrLine);
  3832. CPen* pOldPen = pDC->SelectObject(&pen);
  3833. pDC->MoveTo(rectPie.CenterPoint());
  3834. // 计算指针位置
  3835. rectPie.DeflateRect(5, 5, 5, 5);
  3836. CRgn rgn;
  3837. rgn.CreateEllipticRgnIndirect(rectPie);
  3838. float angle = 180 - 180 * (m_fCurrentValue - m_nLowwer) / (m_nUpper - m_nLowwer);
  3839. int bLeft = 1;
  3840. if (angle < 90) bLeft = -1;
  3841. CPoint lastPoint;
  3842. int clockRadius = min(m_rect.Width() / 2 - 10, m_rect.Height() - 50) - 10;
  3843. lastPoint.x = rectPie.CenterPoint().x + clockRadius*cos(angle / 180 * PI);
  3844. lastPoint.y = rectPie.CenterPoint().y - clockRadius*sin(angle / 180 * PI);
  3845. pDC->LineTo(lastPoint);
  3846. pDC->SelectObject(pOldPen);
  3847. pDC->DrawEdge(&rectRgn, BDR_RAISEDOUTER, BF_RECT);
  3848. rectRgn.DeflateRect(1, 1);
  3849. pDC->DrawEdge(rectRgn, BDR_RAISEDOUTER, BF_RECT);
  3850. rectRgn.left = rectRgn.left + 5;
  3851. rectRgn.right = rectRgn.right - 5;
  3852. rectRgn.top = rectRgn.top + 5;
  3853. rectRgn.bottom = rectRgn.bottom - 35;
  3854. pDC->DrawEdge(&rectRgn, BDR_SUNKENOUTER, BF_RECT);
  3855. pDC->SelectObject(prebrush);
  3856. pDC->SelectObject(pOldPen);
  3857. //DrawFace(pDC);
  3858. DeleteObject(pen);
  3859. DeleteObject(brush);
  3860. DeleteObject(rgn);
  3861. }
  3862. void CDrawWatch::DrawFace(CDC* pDC)
  3863. {
  3864. INT i;
  3865. RECT tRect;
  3866. tagPOINT clockCenter;
  3867. char c[5] = { 0 };
  3868. int clockRadius = min(m_rect.Width() / 2 - 10, m_rect.Height() - 50);
  3869. clockCenter.y = m_rect.bottom - 20;
  3870. clockCenter.x = m_rect.left + m_rect.Width() / 2;
  3871. for (i = 0; i < 31; i++)
  3872. {
  3873. tRect.top = (INT)(((LONG)(CirTab[i].cos) * clockRadius) / CLKSCALE + clockCenter.y - 20);
  3874. tRect.left = (INT)(((LONG)(CirTab[i].sin) * clockRadius) / CLKSCALE + clockCenter.x);
  3875. if (i % 5)
  3876. {
  3877. tRect.right = tRect.left + 2;
  3878. tRect.bottom = tRect.top + 2;
  3879. pDC->FillSolidRect(&tRect, RGB(255, 0, 0));
  3880. }
  3881. else
  3882. {
  3883. tRect.right = tRect.left + 2;
  3884. tRect.bottom = tRect.top + 2;
  3885. if ((i / 5) == 0)
  3886. _itoa(m_nLowwer, c, 10);
  3887. else
  3888. _itoa((m_nUpper - m_nLowwer) * i / 30, c, 10);
  3889. pDC->SetTextColor(m_clrFore);
  3890. pDC->TextOut(tRect.left - 1, tRect.top - 2, c, (int)strlen(c));
  3891. }
  3892. }
  3893. }
  3894. void CDrawWatch::DrawText(CDC* pDC, CString& strText)
  3895. {
  3896. CRect rect = m_rctCurrent;
  3897. COLORREF txtColor = m_clrCurrentFore;
  3898. if (!bRuning)
  3899. {
  3900. rect = m_rect;
  3901. txtColor = m_clrFore;
  3902. }
  3903. int nX0 = (rect.left + rect.right) / 2;
  3904. int nY0 = (rect.top + rect.bottom) / 2;
  3905. CFont font;
  3906. font.CreateFontIndirect(&m_logfont);
  3907. CFont* pOldFont = pDC->SelectObject(&font);
  3908. CSize sizeText = pDC->GetTextExtent(strText);
  3909. int nInterval = sizeText.cy / 2;
  3910. int nYText = nY0 - nInterval + 1;
  3911. int nXText;
  3912. pDC->SetTextAlign(TA_CENTER | TA_TOP);
  3913. nXText = nX0;
  3914. pDC->SetTextColor(txtColor);
  3915. pDC->TextOut(nXText, nYText, strText);
  3916. pDC->SelectObject(pOldFont);
  3917. DeleteObject(font);
  3918. }
  3919. void CDrawWatch::Serialize(CArchive& ar)
  3920. {
  3921. CDrawObj::Serialize(ar);
  3922. if (ar.IsStoring())
  3923. {
  3924. ar << m_nLowwer;
  3925. ar << m_nUpper;
  3926. ar << m_strVar;
  3927. }
  3928. else
  3929. {
  3930. ar >> m_nLowwer;
  3931. ar >> m_nUpper;
  3932. ar >> m_strVar;
  3933. }
  3934. }
  3935. BOOL CDrawWatch::OnAttrib(CPropertySheet& sheet)
  3936. {
  3937. CWatchPage page;
  3938. page.m_nLowwer = m_nLowwer;
  3939. page.m_nUpper = m_nUpper;
  3940. sheet.AddPage(&page);
  3941. sheet.Construct(g_strParamSet);
  3942. sheet.m_psh.dwFlags |= PSH_NOAPPLYNOW;
  3943. if (sheet.DoModal() == IDOK)
  3944. {
  3945. m_nLowwer = page.m_nLowwer;
  3946. m_nUpper = page.m_nUpper;
  3947. return TRUE;
  3948. }
  3949. return FALSE;
  3950. }
  3951. //---------------------------------------------- CDrawSingleBar -----
  3952. IMPLEMENT_SERIAL(CDrawSingleBar, CDrawObj, 0)
  3953. CDrawSingleBar::CDrawSingleBar() :CDrawObj()
  3954. {
  3955. m_clrLine = RGB(0, 0, 64);
  3956. m_clrBack = RGB(192, 192, 192);
  3957. m_clrFore = RGB(255, 0, 0);
  3958. m_nLineWidth = 2;
  3959. m_nLowwer = 0;
  3960. m_nUpper = 100;
  3961. }
  3962. CDrawObj* CDrawSingleBar::Clone(void)
  3963. {
  3964. CDrawSingleBar *pObj = new CDrawSingleBar;
  3965. *((CDrawObj*)pObj) = *(CDrawObj*)this;
  3966. return pObj;
  3967. }
  3968. void CDrawSingleBar::Draw(CDC* pDC)
  3969. {
  3970. if (!m_bShow && bRuning) return;
  3971. CRect rectRgn = m_rctCurrent;
  3972. COLORREF clrPen = m_clrCurrentLine;
  3973. COLORREF clrBrush = m_clrCurrentBack;
  3974. COLORREF clrText = m_clrCurrentFore;
  3975. if (!bRuning)
  3976. {
  3977. rectRgn = m_rect;
  3978. clrPen = m_clrLine;
  3979. clrBrush = m_clrBack;
  3980. clrText = m_clrFore;
  3981. }
  3982. if (!m_bVariant)
  3983. m_strCurrentCaption = m_strCaption;
  3984. rectRgn.NormalizeRect();
  3985. CBrush brush(clrText);
  3986. CBrush *prebrush = pDC->SelectObject(&brush);
  3987. pDC->FillSolidRect(rectRgn, clrBrush);
  3988. pDC->DrawEdge(&rectRgn, BDR_RAISEDOUTER, BF_RECT);
  3989. CRect kedu = rectRgn;
  3990. kedu.left += 3;
  3991. kedu.right = kedu.left + 5;
  3992. kedu.top += 4;
  3993. kedu.bottom -= 5;
  3994. DrawVKedu(pDC, kedu, 50, m_clrLine);
  3995. rectRgn.left = rectRgn.left + 10;
  3996. rectRgn.right = rectRgn.right - 4;
  3997. rectRgn.top = rectRgn.top + 4;
  3998. rectRgn.bottom = rectRgn.bottom - 4;
  3999. pDC->DrawEdge(&rectRgn, BDR_SUNKENOUTER, BF_RECT);
  4000. // 画值
  4001. rectRgn.NormalizeRect();
  4002. rectRgn.left = rectRgn.left + 3;
  4003. rectRgn.right = rectRgn.right - 3;
  4004. float rate = (m_fCurrentValue - m_nLowwer) / (m_nUpper - m_nLowwer);
  4005. rectRgn.top = rectRgn.top + rectRgn.Height()*rate;
  4006. rectRgn.bottom = rectRgn.bottom - 3;
  4007. pDC->FillSolidRect(rectRgn, clrText);
  4008. pDC->SelectObject(prebrush);
  4009. DeleteObject(brush);
  4010. }
  4011. void CDrawSingleBar::DrawText(CDC* pDC, CString& strText)
  4012. {
  4013. CRect rect = m_rctCurrent;
  4014. COLORREF txtColor = m_clrCurrentFore;
  4015. if (!bRuning)
  4016. {
  4017. rect = m_rect;
  4018. txtColor = m_clrFore;
  4019. }
  4020. int nX0 = (rect.left + rect.right) / 2;
  4021. int nY0 = (rect.top + rect.bottom) / 2;
  4022. CFont font;
  4023. font.CreateFontIndirect(&m_logfont);
  4024. CFont* pOldFont = pDC->SelectObject(&font);
  4025. CSize sizeText = pDC->GetTextExtent(strText);
  4026. int nInterval = sizeText.cy / 2;
  4027. int nYText = nY0 - nInterval + 1;
  4028. int nXText;
  4029. pDC->SetTextAlign(TA_CENTER | TA_TOP);
  4030. nXText = nX0;
  4031. pDC->SetTextColor(txtColor);
  4032. pDC->TextOut(nXText, nYText, strText);
  4033. pDC->SelectObject(pOldFont);
  4034. DeleteObject(font);
  4035. }
  4036. BOOL CDrawSingleBar::OnAttrib(CPropertySheet& sheet)
  4037. {
  4038. CSingleBarPage page;
  4039. page.m_nLower = m_nLowwer;
  4040. page.m_nUpper = m_nUpper;
  4041. sheet.AddPage(&page);
  4042. sheet.Construct(g_strParamSet);
  4043. sheet.m_psh.dwFlags |= PSH_NOAPPLYNOW;
  4044. if (sheet.DoModal() == IDOK)
  4045. {
  4046. m_nLowwer = page.m_nLower;
  4047. m_nUpper = page.m_nUpper;
  4048. return TRUE;
  4049. }
  4050. return FALSE;
  4051. }
  4052. //---------------------------------------------- CDraw3dCircle ----
  4053. IMPLEMENT_SERIAL(CDraw3dCircle, CDrawObj, 0)
  4054. CDraw3dCircle::CDraw3dCircle()
  4055. {
  4056. m_clrFore = RGB(0, 255, 0);
  4057. m_clrBack = RGB(0, 128, 0);
  4058. m_clrLine = RGB(255, 255, 255);
  4059. //m_clrCurrentLine = RGB( 255,255,255 );
  4060. }
  4061. CDrawObj* CDraw3dCircle::Clone(void)
  4062. {
  4063. CDraw3dCircle *pObj = new CDraw3dCircle;
  4064. *((CDrawObj*)pObj) = *(CDrawObj*)this;
  4065. return pObj;
  4066. }
  4067. void CDraw3dCircle::Draw(CDC* pDC)
  4068. {
  4069. CDrawObj::Draw(pDC);
  4070. if (!m_bShow && bRuning) return;
  4071. COLORREF clrPen = m_clrLine;
  4072. CRect rect = m_rctCurrent;
  4073. COLORREF color = m_clrCurrentBack;
  4074. if (!bRuning)
  4075. {
  4076. rect = m_rect;
  4077. color = m_clrBack;
  4078. }
  4079. rect.NormalizeRect();
  4080. int nX0 = (rect.left + rect.right) / 2;
  4081. int nY0 = (rect.top + rect.bottom) / 2;
  4082. int nRadius = min(rect.Width() / 2, rect.Height() / 2);
  4083. rect = CRect(nX0 - nRadius, nY0 - nRadius, nX0 + nRadius, nY0 + nRadius);
  4084. CBrush brush;
  4085. brush.CreateSolidBrush(color);
  4086. pDC->SelectObject(&brush);
  4087. CPen framePen;
  4088. framePen.CreatePen(PS_NULL, m_nLineWidth, m_clrLine);
  4089. pDC->SelectObject(&framePen);
  4090. pDC->Ellipse(rect);
  4091. CPen arcpen;
  4092. arcpen.CreatePen(PS_SOLID, 2, m_clrCurrentLine);//RGB(255,255,255));
  4093. pDC->SelectObject(&arcpen);
  4094. pDC->Arc(CRect(nX0 - nRadius / 2, nY0 - nRadius / 2, nX0 + nRadius / 2, nY0 + nRadius / 2),
  4095. CPoint(nX0, nY0 - nRadius / 2), CPoint(nX0 - nRadius / 2, nY0));
  4096. DeleteObject(arcpen);
  4097. DeleteObject(brush);
  4098. }
  4099. //---------------------------------------------- CDrawBar -------
  4100. IMPLEMENT_SERIAL(CDrawBar, CDrawObj, 0)
  4101. CDrawBar::CDrawBar() :CDrawObj()
  4102. {
  4103. m_clrBar1 = RGB(255, 0, 0);
  4104. m_clrBar2 = RGB(0, 255, 0);
  4105. m_clrBar3 = RGB(0, 0, 255);
  4106. m_nLowwer = 0;
  4107. m_nUpper = 200;
  4108. m_strVar1 = "";
  4109. m_strVar2 = "";
  4110. m_strVar3 = "";
  4111. m_nValue1 = 0;
  4112. m_nValue2 = 0;
  4113. m_nValue3 = 0;
  4114. m_clrFill = RGB(255, 255, 255);
  4115. m_nFillMode = 1;
  4116. }
  4117. CDrawObj* CDrawBar::Clone(void)
  4118. {
  4119. CDrawBar *pObj = new CDrawBar;
  4120. *((CDrawObj*)pObj) = *(CDrawObj*)this;
  4121. pObj->m_clrBar1 = m_clrBar1;
  4122. pObj->m_clrBar2 = m_clrBar2;
  4123. pObj->m_clrBar3 = m_clrBar3;
  4124. pObj->m_nLowwer = m_nLowwer;
  4125. pObj->m_nUpper = m_nUpper;
  4126. pObj->m_strVar1 = m_strVar1;
  4127. pObj->m_strVar2 = m_strVar2;
  4128. pObj->m_strVar3 = m_strVar3;
  4129. return pObj;
  4130. }
  4131. void CDrawBar::DrawBar(CDC* pDC, int data, int x1, int x2, COLORREF clrBar)
  4132. {
  4133. CRect rect = m_rect;
  4134. rect.NormalizeRect();
  4135. float rate = (1.0*(data - m_nLowwer)) / (m_nUpper - m_nLowwer);
  4136. int y1 = rect.bottom - int(rect.Height()*rate);
  4137. y1 = max(rect.top, y1);
  4138. y1 = min(rect.bottom, y1);
  4139. pDC->FillSolidRect(x1, y1, x2 - x1, rect.bottom - y1, clrBar);
  4140. }
  4141. void CDrawBar::Draw(CDC* pDC)
  4142. {
  4143. CDrawObj::Draw(pDC);
  4144. CRect rect = m_rect;
  4145. rect.NormalizeRect();
  4146. int width = rect.Width();
  4147. LOGBRUSH brushlog = GetBrush();
  4148. CBrush m_brush;
  4149. m_brush.CreateBrushIndirect(&brushlog);
  4150. CBrush* pOldBrush = (CBrush*)pDC->SelectObject(&m_brush);
  4151. if (m_nFillMode < 8)
  4152. {
  4153. pDC->Rectangle(rect);
  4154. }
  4155. int num = GetBarNum();
  4156. int barWidth = width;
  4157. if (num != 0)
  4158. {
  4159. barWidth = width / (num * 2 + 1);
  4160. }
  4161. int hadDraw = 0;
  4162. // 画刻度
  4163. CPen pen(PS_SOLID, 1, RGB(255, 255, 255));
  4164. CPen* pOldPen = pDC->SelectObject(&pen);
  4165. pDC->MoveTo(rect.left, rect.top);
  4166. pDC->LineTo(rect.left, rect.bottom);
  4167. pDC->LineTo(rect.right, rect.bottom);
  4168. pDC->LineTo(rect.right, rect.top);
  4169. pDC->LineTo(rect.left, rect.top);
  4170. pDC->SelectObject(pOldPen);
  4171. if (bRuning)
  4172. {
  4173. if (!m_strVar1.IsEmpty())
  4174. {
  4175. int left = rect.left + barWidth;
  4176. int right = rect.left + barWidth * 2;
  4177. DrawBar(pDC, m_nValue1, left, right, m_clrBar1);
  4178. hadDraw++;
  4179. }
  4180. if (!m_strVar2.IsEmpty())
  4181. {
  4182. int left = rect.left + barWidth + hadDraw*barWidth * 2;
  4183. int right = rect.left + barWidth * 2 + hadDraw*barWidth * 2;
  4184. DrawBar(pDC, m_nValue2, left, right, m_clrBar2);
  4185. hadDraw++;
  4186. }
  4187. if (!m_strVar3.IsEmpty())
  4188. {
  4189. int left = rect.left + barWidth + hadDraw*barWidth * 2;
  4190. int right = rect.left + barWidth * 2 + hadDraw*barWidth * 2;
  4191. DrawBar(pDC, m_nValue3, left, right, m_clrBar3);
  4192. }
  4193. }
  4194. else
  4195. {
  4196. DrawBar(pDC, 50, rect.left + width / 7, rect.left + width / 7 * 2, m_clrBar1);
  4197. DrawBar(pDC, 100, rect.left + width / 7 * 3, rect.left + width / 7 * 4, m_clrBar2);
  4198. DrawBar(pDC, 150, rect.left + width / 7 * 5, rect.left + width / 7 * 6, m_clrBar3);
  4199. }
  4200. // 网格
  4201. CPen penGrid(PS_DOT, 1, RGB(128, 128, 128));
  4202. pOldPen = pDC->SelectObject(&penGrid);
  4203. for (int i = 1; i < 5; i++)
  4204. {
  4205. pDC->MoveTo(rect.left, rect.top + rect.Height() / 5 * i);
  4206. pDC->LineTo(rect.right, rect.top + rect.Height() / 5 * i);
  4207. }
  4208. pDC->SelectObject(pOldPen);
  4209. DeleteObject(pen);
  4210. DeleteObject(penGrid);
  4211. DeleteObject(m_brush);
  4212. }
  4213. void CDrawBar::Serialize(CArchive& ar)
  4214. {
  4215. CDrawObj::Serialize(ar);
  4216. if (ar.IsStoring())
  4217. {
  4218. ar << m_clrBar1;
  4219. ar << m_clrBar2;
  4220. ar << m_clrBar3;
  4221. ar << m_nLowwer;
  4222. ar << m_nUpper;
  4223. ar << m_strVar1;
  4224. ar << m_strVar2;
  4225. ar << m_strVar3;
  4226. }
  4227. else
  4228. {
  4229. ar >> m_clrBar1;
  4230. ar >> m_clrBar2;
  4231. ar >> m_clrBar3;
  4232. ar >> m_nLowwer;
  4233. ar >> m_nUpper;
  4234. ar >> m_strVar1;
  4235. ar >> m_strVar2;
  4236. ar >> m_strVar3;
  4237. }
  4238. }
  4239. BOOL CDrawBar::OnAttrib(CPropertySheet& sheet)
  4240. {
  4241. CBarPage page;
  4242. page.m_nLowwer = m_nLowwer;
  4243. page.m_nUpper = m_nUpper;
  4244. page.m_strVar1 = m_strVar1;
  4245. page.m_strVar2 = m_strVar2;
  4246. page.m_strVar3 = m_strVar3;
  4247. page.m_clrBar1 = m_clrBar1;
  4248. page.m_clrBar2 = m_clrBar2;
  4249. page.m_clrBar3 = m_clrBar3;
  4250. sheet.AddPage(&page);
  4251. sheet.Construct(g_strParamSet);
  4252. sheet.m_psh.dwFlags |= PSH_NOAPPLYNOW;
  4253. if (sheet.DoModal() == IDOK)
  4254. {
  4255. m_nLowwer = page.m_nLowwer;
  4256. m_nUpper = page.m_nUpper;
  4257. m_strVar1 = page.m_strVar1;
  4258. m_strVar2 = page.m_strVar2;
  4259. m_strVar3 = page.m_strVar3;
  4260. m_clrBar1 = page.m_clrBar1;
  4261. m_clrBar2 = page.m_clrBar2;
  4262. m_clrBar3 = page.m_clrBar3;
  4263. return TRUE;
  4264. }
  4265. return FALSE;
  4266. }
  4267. bool CDrawBar::Fresh(CRect &RECT)
  4268. {
  4269. if (!m_strVar1.IsEmpty())
  4270. {
  4271. // int nValue = (int) pVariantsManager->GetAnalogValue(m_strVar1);
  4272. // if( nValue == -1 ) return true;
  4273. // m_nValue1 = (int) pVariantsManager->GetAnalogValue(m_strVar1);
  4274. }
  4275. if (!m_strVar2.IsEmpty())
  4276. {
  4277. // int nValue = (int) pVariantsManager->GetAnalogValue(m_strVar2);
  4278. // if( nValue == -1 ) return true;
  4279. // m_nValue2 = (int) pVariantsManager->GetAnalogValue(m_strVar2);
  4280. }
  4281. if (!m_strVar3.IsEmpty())
  4282. {
  4283. // int nValue = (int) pVariantsManager->GetAnalogValue(m_strVar3);
  4284. // if( nValue == -1 ) return true;
  4285. // m_nValue3 = (int) pVariantsManager->GetAnalogValue(m_strVar3);
  4286. }
  4287. RECT = m_rect;
  4288. return true;
  4289. }
  4290. int CDrawBar::GetBarNum()
  4291. {
  4292. int num = 0;
  4293. if (!m_strVar1.IsEmpty())
  4294. {
  4295. num++;
  4296. }
  4297. if (!m_strVar2.IsEmpty())
  4298. {
  4299. num++;
  4300. }
  4301. if (!m_strVar3.IsEmpty())
  4302. {
  4303. num++;
  4304. }
  4305. return num;
  4306. }
  4307. //---------------------------------------------- CDrawCurve -------
  4308. IMPLEMENT_SERIAL(CDrawCurve, CDrawObj, 0)
  4309. CDrawCurve::CDrawCurve() :CDrawObj()
  4310. {
  4311. m_clrFore = RGB(0, 0, 0);
  4312. //m_clrFill = RGB(0, 0, 255);
  4313. //m_clrLine = RGB(0, 0, 255); // 线色
  4314. m_clrBack = RGB(64, 128, 128);
  4315. //m_clrCurrentFore = RGB(0, 0, 255);
  4316. //m_clrCurrentBack = RGB(0, 0, 255);
  4317. //m_clrCurrentLine = RGB(0, 0, 255);
  4318. m_clrFill = RGB(255, 255, 255);
  4319. m_clrCurve1 = RGB(255, 0, 0);
  4320. m_clrCurve2 = RGB(0, 255, 0);
  4321. m_clrCurve3 = RGB(0, 0, 255);
  4322. m_clrLine = RGB(0, 0, 0);
  4323. m_nLowwer = 0;
  4324. m_nUpper = 200;
  4325. m_strVar1 = "";
  4326. m_strVar2 = "";
  4327. m_strVar3 = "";
  4328. m_nFillMode = 1;
  4329. m_fValue1 = 0.0;
  4330. m_fValue2 = 0.0;
  4331. m_fValue3 = 0.0;
  4332. for (int i = 0; i < 60; i++)
  4333. {
  4334. m_nValue1[i] = 0;
  4335. m_nValue2[i] = 0;
  4336. m_nValue3[i] = 0;
  4337. }
  4338. }
  4339. CDrawObj* CDrawCurve::Clone(void)
  4340. {
  4341. CDrawCurve *pObj = new CDrawCurve;
  4342. *((CDrawObj*)pObj) = *(CDrawObj*)this;
  4343. pObj->m_clrCurve1 = m_clrCurve1;
  4344. pObj->m_clrCurve2 = m_clrCurve2;
  4345. pObj->m_clrCurve3 = m_clrCurve3;
  4346. pObj->m_nLowwer = m_nLowwer;
  4347. pObj->m_nUpper = m_nUpper;
  4348. pObj->m_strVar1 = m_strVar1;
  4349. pObj->m_strVar2 = m_strVar2;
  4350. pObj->m_strVar3 = m_strVar3;
  4351. return pObj;
  4352. }
  4353. void CDrawCurve::Draw(CDC* pDC)
  4354. {
  4355. CDrawObj::Draw(pDC);
  4356. CRect rect = m_rect;
  4357. rect.NormalizeRect();
  4358. CString sText;
  4359. LOGBRUSH brushlog = GetBrush();
  4360. CBrush m_brush;
  4361. m_brush.CreateBrushIndirect(&brushlog);
  4362. CBrush* pOldBrush = (CBrush*)pDC->SelectObject(&m_brush);
  4363. if (m_nFillMode < 8)
  4364. {
  4365. pDC->Rectangle(rect);
  4366. }
  4367. DeleteObject(m_brush);
  4368. // 边框
  4369. pDC->DrawEdge(rect, BDR_RAISEDINNER, BF_RECT);
  4370. CRect inner;
  4371. inner.left = rect.left + 40;
  4372. inner.right = rect.right - 10;
  4373. inner.top = rect.top + 10;
  4374. inner.bottom = rect.bottom - 30;
  4375. //pDC->DrawEdge(&inner,EDGE_ETCHED ,BF_RECT);
  4376. // 显示60个点,1s一个点
  4377. if (bRuning)
  4378. {
  4379. if (!m_strVar1.IsEmpty())
  4380. {
  4381. DrawCurve(pDC, inner, m_nValue1, m_clrCurve1);
  4382. }
  4383. if (!m_strVar2.IsEmpty())
  4384. {
  4385. DrawCurve(pDC, inner, m_nValue2, m_clrCurve2);
  4386. }
  4387. if (!m_strVar3.IsEmpty())
  4388. {
  4389. DrawCurve(pDC, inner, m_nValue3, m_clrCurve3);
  4390. }
  4391. }
  4392. else
  4393. {
  4394. for (int i = 0; i < 60; i++)
  4395. {
  4396. m_nValue1[i] = 100 + (i % 10) * 4 - (i % 15);
  4397. m_nValue2[i] = 80 + (i % 15) * 3 - i;
  4398. m_nValue3[i] = 60 + (i % 20) * 3 + i;
  4399. }
  4400. DrawCurve(pDC, inner, m_nValue1, m_clrCurve1);
  4401. DrawCurve(pDC, inner, m_nValue2, m_clrCurve2);
  4402. DrawCurve(pDC, inner, m_nValue3, m_clrCurve3);
  4403. }
  4404. // 网格
  4405. CPen penGrid(PS_DOT, 1, RGB(192, 192, 192));
  4406. CPen* pOldPen = pDC->SelectObject(&penGrid);
  4407. pDC->SetTextColor(m_clrFore);
  4408. pDC->SetTextAlign(TA_RIGHT);
  4409. int Y = 0;
  4410. float rate = 0;//(1.0*(m_nLowerLimit-m_nLowwer)) / (m_nUpper-m_nLowwer);
  4411. int nSpace = (m_nUpper - m_nLowwer) / 10;
  4412. if (nSpace % 10 != 0)
  4413. nSpace += (10 - nSpace % 10);
  4414. if (m_nUpper == 2 && m_nLowwer == 0)
  4415. nSpace = 1;
  4416. for (int i = m_nLowwer + nSpace; i < m_nUpper; i += nSpace)
  4417. {
  4418. rate = (1.0*(i - m_nLowwer)) / (m_nUpper - m_nLowwer);
  4419. Y = inner.bottom - int(inner.Height()*rate);
  4420. if (Y > inner.bottom)
  4421. Y = inner.bottom;
  4422. if (Y < inner.top)
  4423. Y = inner.top;
  4424. pDC->MoveTo(inner.left, Y);
  4425. pDC->LineTo(inner.right, Y);
  4426. sText.Format("%d", i);
  4427. pDC->TextOut(inner.left - 5, Y - 7, sText);
  4428. }
  4429. DeleteObject(penGrid);
  4430. CPen penFrame(PS_SOLID, 1, RGB(0, 0, 0));
  4431. pDC->SelectObject(&penFrame);
  4432. pDC->MoveTo(inner.left, inner.top);
  4433. pDC->LineTo(inner.right, inner.top);
  4434. pDC->LineTo(inner.right, inner.bottom);
  4435. CRect leftKedu = inner;
  4436. leftKedu.right = leftKedu.left + 5;
  4437. DrawVKedu(pDC, leftKedu, 50, m_clrLine);
  4438. CRect bottomKedu = inner;
  4439. bottomKedu.top = leftKedu.bottom - 5;
  4440. DrawHKedu(pDC, bottomKedu, 60, m_clrLine);
  4441. pDC->SelectObject(pOldPen);
  4442. DeleteObject(penFrame);
  4443. ////////////////////
  4444. if (m_strVarDes1 != "")
  4445. {
  4446. pDC->SetTextAlign(TA_LEFT);
  4447. pDC->SetTextColor(m_clrCurve1);
  4448. sText.Format("%s【%0.1f】", m_strVarDes1, m_fValue1);
  4449. pDC->TextOut(rect.left + 20, rect.bottom - 23, sText);
  4450. }
  4451. if (m_strVarDes2 != "")
  4452. {
  4453. pDC->SetTextAlign(TA_CENTER);
  4454. pDC->SetTextColor(m_clrCurve2);
  4455. sText.Format("%s【%0.1f】", m_strVarDes2, m_fValue2);
  4456. pDC->TextOut(rect.left + rect.Width() / 2, rect.bottom - 23, sText);
  4457. }
  4458. if (m_strVarDes3 != "")
  4459. {
  4460. pDC->SetTextAlign(TA_RIGHT);
  4461. pDC->SetTextColor(m_clrCurve3);
  4462. sText.Format("%s【%0.1f】", m_strVarDes3, m_fValue3);
  4463. pDC->TextOut(rect.right - 20, rect.bottom - 23, sText);
  4464. }
  4465. }
  4466. void CDrawCurve::Serialize(CArchive& ar)
  4467. {
  4468. CDrawObj::Serialize(ar);
  4469. if (ar.IsStoring())
  4470. {
  4471. ar << m_clrCurve1;
  4472. ar << m_clrCurve2;
  4473. ar << m_clrCurve3;
  4474. ar << m_nLowwer;
  4475. ar << m_nUpper;
  4476. ar << m_strVar1;
  4477. ar << m_strVar2;
  4478. ar << m_strVar3;
  4479. }
  4480. else
  4481. {
  4482. ar >> m_clrCurve1;
  4483. ar >> m_clrCurve2;
  4484. ar >> m_clrCurve3;
  4485. ar >> m_nLowwer;
  4486. ar >> m_nUpper;
  4487. ar >> m_strVar1;
  4488. ar >> m_strVar2;
  4489. ar >> m_strVar3;
  4490. //得到 上限,下限
  4491. int nLowwer1 = 0, nUpper1 = 0, nLowwer2 = 0, nUpper2 = 0, nLowwer3 = 0, nUpper3 = 0;
  4492. // pVariantsManager->GetAnalogValue(m_strVar1,nLowwer1,nUpper1);
  4493. // pVariantsManager->GetAnalogValue(m_strVar2,nLowwer2,nUpper2);
  4494. // pVariantsManager->GetAnalogValue(m_strVar3,nLowwer3,nUpper3);
  4495. m_nLowwer = nLowwer1;
  4496. if (nLowwer2 < nLowwer1 && nLowwer2 < nLowwer3)
  4497. m_nLowwer = nLowwer2;
  4498. if (nLowwer3 < nLowwer1 && nLowwer3 < nLowwer2)
  4499. m_nLowwer = nLowwer3;
  4500. m_nUpper = nUpper1;
  4501. if (nUpper2 > nUpper1 && nUpper2 > nUpper3)
  4502. m_nUpper = nUpper2;
  4503. if (nUpper3 > nUpper1 && nUpper3 > nUpper2)
  4504. m_nUpper = nUpper3;
  4505. if (m_nLowwer == m_nUpper)
  4506. {
  4507. m_nLowwer = 0;
  4508. m_nUpper = 2;
  4509. }
  4510. else
  4511. {
  4512. m_nLowwer = getMin(m_nLowwer);
  4513. m_nUpper = getMax(m_nUpper);
  4514. }
  4515. //得到 描述
  4516. // pVariantsManager->GetAnalogValue(m_strVar1,m_strVarDes1);
  4517. // pVariantsManager->GetAnalogValue(m_strVar2,m_strVarDes2);
  4518. // pVariantsManager->GetAnalogValue(m_strVar3,m_strVarDes3);
  4519. }
  4520. }
  4521. int CDrawCurve::getMin(int iLowwer)
  4522. {
  4523. int nRet = 0;
  4524. nRet = iLowwer - 20;
  4525. if (nRet < 0)
  4526. nRet = 0;
  4527. int nMod = nRet % 10;
  4528. if (nMod != 0)
  4529. nRet -= nMod;
  4530. return nRet;
  4531. }
  4532. int CDrawCurve::getMax(int iUpper)
  4533. {
  4534. int nRet = 0;
  4535. nRet = iUpper + 20;
  4536. int nMod = nRet % 10;
  4537. if (nMod != 0)
  4538. nRet += (10 - nMod);
  4539. return nRet;
  4540. }
  4541. BOOL CDrawCurve::OnAttrib(CPropertySheet& sheet)
  4542. {
  4543. CurvePage page;
  4544. page.m_nLowwer = m_nLowwer;
  4545. page.m_nUpper = m_nUpper;
  4546. page.m_strVar1 = m_strVar1;
  4547. page.m_strVar2 = m_strVar2;
  4548. page.m_strVar3 = m_strVar3;
  4549. page.m_clrCurve1 = m_clrCurve1;
  4550. page.m_clrCurve2 = m_clrCurve2;
  4551. page.m_clrCurve3 = m_clrCurve3;
  4552. sheet.AddPage(&page);
  4553. sheet.Construct(g_strParamSet);
  4554. sheet.m_psh.dwFlags |= PSH_NOAPPLYNOW;
  4555. if (sheet.DoModal() == IDOK)
  4556. {
  4557. m_nLowwer = page.m_nLowwer;
  4558. m_nUpper = page.m_nUpper;
  4559. m_strVar1 = page.m_strVar1;
  4560. m_strVar2 = page.m_strVar2;
  4561. m_strVar3 = page.m_strVar3;
  4562. m_clrCurve1 = page.m_clrCurve1;
  4563. m_clrCurve2 = page.m_clrCurve2;
  4564. m_clrCurve3 = page.m_clrCurve3;
  4565. return TRUE;
  4566. }
  4567. return FALSE;
  4568. }
  4569. bool CDrawCurve::Fresh(CRect &RECT)
  4570. {
  4571. SYSTEMTIME st;
  4572. GetLocalTime(&st);
  4573. if (m_nSecond != st.wSecond)
  4574. {
  4575. m_nSecond = st.wSecond;
  4576. }
  4577. else
  4578. return true;
  4579. if (g_nRunEditVarTick == 0)
  4580. g_nRunEditVarTick = GetTickCount();
  4581. if (GetTickCount() - g_nRunEditVarTick > 1000 * 2)
  4582. {
  4583. g_bRunEditVar = false;
  4584. }
  4585. else if (g_bRunEditVar)
  4586. {
  4587. //得到 上限,下限
  4588. int nLowwer1 = 0, nUpper1 = 0, nLowwer2 = 0, nUpper2 = 0, nLowwer3 = 0, nUpper3 = 0;
  4589. // pVariantsManager->GetAnalogValue(m_strVar1,nLowwer1,nUpper1);
  4590. // pVariantsManager->GetAnalogValue(m_strVar2,nLowwer2,nUpper2);
  4591. // pVariantsManager->GetAnalogValue(m_strVar3,nLowwer3,nUpper3);
  4592. m_nLowwer = nLowwer1;
  4593. if (nLowwer2 < nLowwer1 && nLowwer2 < nLowwer3)
  4594. m_nLowwer = nLowwer2;
  4595. if (nLowwer3 < nLowwer1 && nLowwer3 < nLowwer2)
  4596. m_nLowwer = nLowwer3;
  4597. m_nUpper = nUpper1;
  4598. if (nUpper2 > nUpper1 && nUpper2 > nUpper3)
  4599. m_nUpper = nUpper2;
  4600. if (nUpper3 > nUpper1 && nUpper3 > nUpper2)
  4601. m_nUpper = nUpper3;
  4602. if (m_nLowwer == m_nUpper)
  4603. {
  4604. m_nLowwer = 0;
  4605. m_nUpper = 2;
  4606. }
  4607. else
  4608. {
  4609. m_nLowwer = getMin(m_nLowwer);
  4610. m_nUpper = getMax(m_nUpper);
  4611. }
  4612. //得到 描述
  4613. // pVariantsManager->GetAnalogValue(m_strVar1,m_strVarDes1);
  4614. // pVariantsManager->GetAnalogValue(m_strVar2,m_strVarDes2);
  4615. // pVariantsManager->GetAnalogValue(m_strVar3,m_strVarDes3);
  4616. }
  4617. if (!m_strVar1.IsEmpty())
  4618. {
  4619. for (int i = 0; i < 59; i++)
  4620. {
  4621. m_nValue1[i] = m_nValue1[i + 1];
  4622. }
  4623. //m_fValue1 = pVariantsManager->GetAnalogValue(m_strVar1);
  4624. m_nValue1[59] = (int)m_fValue1;
  4625. }
  4626. if (!m_strVar2.IsEmpty())
  4627. {
  4628. for (int i = 0; i < 59; i++)
  4629. {
  4630. m_nValue2[i] = m_nValue2[i + 1];
  4631. }
  4632. //m_fValue2 = pVariantsManager->GetAnalogValue(m_strVar2);
  4633. m_nValue2[59] = (int)m_fValue2;
  4634. }
  4635. if (!m_strVar3.IsEmpty())
  4636. {
  4637. for (int i = 0; i < 59; i++)
  4638. {
  4639. m_nValue3[i] = m_nValue3[i + 1];
  4640. }
  4641. //m_fValue3 = pVariantsManager->GetAnalogValue(m_strVar3);
  4642. m_nValue3[59] = (int)m_fValue3;
  4643. }
  4644. RECT = m_rect;
  4645. return true;
  4646. }
  4647. void CDrawCurve::DrawCurve(CDC* pDC, CRect rect, int* data, COLORREF color)
  4648. {
  4649. rect.NormalizeRect();
  4650. CPen PenBackGrid(PS_SOLID, m_nLineWidth, color);
  4651. CPen* pOldPen = pDC->SelectObject(&PenBackGrid);
  4652. bool f = false;
  4653. for (int i = 0; i < 60; i++)
  4654. {
  4655. CPoint point;
  4656. point.x = rect.left + i*(1.0*rect.Width() / 59);
  4657. float rate = (1.0*(data[i] - m_nLowwer)) / (m_nUpper - m_nLowwer);
  4658. point.y = rect.bottom - int(rect.Height()*rate);
  4659. if (point.y > rect.bottom)
  4660. point.y = rect.bottom;
  4661. if (point.y < rect.top)
  4662. point.y = rect.top;
  4663. if (point.x < rect.left)
  4664. point.x = rect.left;
  4665. if (point.x > rect.right)
  4666. point.x = rect.right;
  4667. if (!f && point.y != rect.bottom)
  4668. {
  4669. f = true;
  4670. pDC->MoveTo(point);
  4671. }
  4672. else if (f)
  4673. {
  4674. pDC->LineTo(point);
  4675. }
  4676. }
  4677. pDC->SelectObject(pOldPen);
  4678. DeleteObject(PenBackGrid);
  4679. }
  4680. //---------------------------------------------- CDrawHisCurve -------
  4681. IMPLEMENT_SERIAL(CDrawHisCurve, CDrawObj, 0)
  4682. CDrawHisCurve::CDrawHisCurve() :CDrawObj()
  4683. {
  4684. m_clrFill = RGB(255, 255, 255);
  4685. m_clrCurve1 = RGB(255, 0, 0);
  4686. m_clrCurve2 = RGB(0, 255, 0);
  4687. m_clrCurve3 = RGB(0, 0, 255);
  4688. m_clrLine = RGB(0, 0, 0);
  4689. m_nLowwer = 0;
  4690. m_nUpper = 200;
  4691. m_strVar1 = "";
  4692. m_strVar2 = "";
  4693. m_strVar3 = "";
  4694. m_nFillMode = 1;
  4695. for (int i = 0; i < 60; i++)
  4696. {
  4697. m_nValue1[i] = 0;
  4698. m_nValue2[i] = 0;
  4699. m_nValue3[i] = 0;
  4700. }
  4701. }
  4702. CDrawObj* CDrawHisCurve::Clone(void)
  4703. {
  4704. CDrawHisCurve *pObj = new CDrawHisCurve;
  4705. *((CDrawObj*)pObj) = *(CDrawObj*)this;
  4706. pObj->m_clrCurve1 = m_clrCurve1;
  4707. pObj->m_clrCurve2 = m_clrCurve2;
  4708. pObj->m_clrCurve3 = m_clrCurve3;
  4709. pObj->m_nLowwer = m_nLowwer;
  4710. pObj->m_nUpper = m_nUpper;
  4711. pObj->m_strVar1 = m_strVar1;
  4712. pObj->m_strVar2 = m_strVar2;
  4713. pObj->m_strVar3 = m_strVar3;
  4714. return pObj;
  4715. }
  4716. void CDrawHisCurve::Draw(CDC* pDC)
  4717. {
  4718. CDrawObj::Draw(pDC);
  4719. CRect rect = m_rect;
  4720. rect.NormalizeRect();
  4721. LOGBRUSH brushlog = GetBrush();
  4722. CBrush m_brush;
  4723. m_brush.CreateBrushIndirect(&brushlog);
  4724. CBrush* pOldBrush = (CBrush*)pDC->SelectObject(&m_brush);
  4725. if (m_nFillMode < 8)
  4726. {
  4727. pDC->Rectangle(rect);
  4728. }
  4729. // 边框
  4730. pDC->DrawEdge(rect, BDR_RAISEDINNER, BF_RECT);
  4731. CRect inner;
  4732. inner.left = rect.left + 40;
  4733. inner.right = rect.right - 10;
  4734. inner.top = rect.top + 10;
  4735. inner.bottom = rect.bottom - 30;
  4736. // 显示60个点,1s一个点
  4737. if (bRuning)
  4738. {
  4739. if (!m_strVar1.IsEmpty())
  4740. {
  4741. DrawCurve(pDC, inner, m_nValue1, m_clrCurve1);
  4742. }
  4743. if (!m_strVar2.IsEmpty())
  4744. {
  4745. DrawCurve(pDC, inner, m_nValue2, m_clrCurve2);
  4746. }
  4747. if (!m_strVar3.IsEmpty())
  4748. {
  4749. DrawCurve(pDC, inner, m_nValue3, m_clrCurve3);
  4750. }
  4751. }
  4752. else
  4753. {
  4754. for (int i = 0; i < 60; i++)
  4755. {
  4756. m_nValue1[i] = 100 + (i % 10) * 4 - (i % 15);
  4757. m_nValue2[i] = 80 + (i % 15) * 3 - i;
  4758. m_nValue3[i] = 60 + (i % 20) * 3 + i;
  4759. }
  4760. DrawCurve(pDC, inner, m_nValue1, m_clrCurve1);
  4761. DrawCurve(pDC, inner, m_nValue2, m_clrCurve2);
  4762. DrawCurve(pDC, inner, m_nValue3, m_clrCurve3);
  4763. }
  4764. // 网格
  4765. CPen penGrid(PS_DOT, 1, RGB(192, 192, 192));
  4766. CPen* pOldPen = pDC->SelectObject(&penGrid);
  4767. int i = 0;
  4768. for (i = 1; i < 5; i++)
  4769. {
  4770. pDC->MoveTo(inner.left, inner.top + inner.Height()*i / 5);
  4771. pDC->LineTo(inner.right, inner.top + inner.Height()*i / 5);
  4772. }
  4773. for (i = 1; i < 6; i++)
  4774. {
  4775. pDC->MoveTo(inner.left + inner.Width()*i / 6, inner.top);
  4776. pDC->LineTo(inner.left + inner.Width()*i / 6, inner.bottom);
  4777. }
  4778. CPen penFrame(PS_SOLID, 1, RGB(0, 0, 0));
  4779. pDC->SelectObject(&penFrame);
  4780. pDC->MoveTo(inner.left, inner.top);
  4781. pDC->LineTo(inner.right, inner.top);
  4782. pDC->LineTo(inner.right, inner.bottom);
  4783. CRect leftKedu = inner;
  4784. leftKedu.right = leftKedu.left + 5;
  4785. DrawVKedu(pDC, leftKedu, 50, m_clrLine);
  4786. CRect bottomKedu = inner;
  4787. bottomKedu.top = leftKedu.bottom - 5;
  4788. DrawHKedu(pDC, bottomKedu, 60, m_clrLine);
  4789. pDC->SelectObject(pOldPen);
  4790. DeleteObject(m_brush);
  4791. DeleteObject(penGrid);
  4792. DeleteObject(penFrame);
  4793. }
  4794. void CDrawHisCurve::Serialize(CArchive& ar)
  4795. {
  4796. CDrawObj::Serialize(ar);
  4797. if (ar.IsStoring())
  4798. {
  4799. ar << m_clrCurve1;
  4800. ar << m_clrCurve2;
  4801. ar << m_clrCurve3;
  4802. ar << m_nLowwer;
  4803. ar << m_nUpper;
  4804. ar << m_strVar1;
  4805. ar << m_strVar2;
  4806. ar << m_strVar3;
  4807. }
  4808. else
  4809. {
  4810. ar >> m_clrCurve1;
  4811. ar >> m_clrCurve2;
  4812. ar >> m_clrCurve3;
  4813. ar >> m_nLowwer;
  4814. ar >> m_nUpper;
  4815. ar >> m_strVar1;
  4816. ar >> m_strVar2;
  4817. ar >> m_strVar3;
  4818. }
  4819. }
  4820. BOOL CDrawHisCurve::OnAttrib(CPropertySheet& sheet)
  4821. {
  4822. CurvePage page;
  4823. page.m_nLowwer = m_nLowwer;
  4824. page.m_nUpper = m_nUpper;
  4825. page.m_strVar1 = m_strVar1;
  4826. page.m_strVar2 = m_strVar2;
  4827. page.m_strVar3 = m_strVar3;
  4828. page.m_clrCurve1 = m_clrCurve1;
  4829. page.m_clrCurve2 = m_clrCurve2;
  4830. page.m_clrCurve3 = m_clrCurve3;
  4831. sheet.AddPage(&page);
  4832. sheet.Construct(g_strParamSet);
  4833. sheet.m_psh.dwFlags |= PSH_NOAPPLYNOW;
  4834. if (sheet.DoModal() == IDOK)
  4835. {
  4836. m_nLowwer = page.m_nLowwer;
  4837. m_nUpper = page.m_nUpper;
  4838. m_strVar1 = page.m_strVar1;
  4839. m_strVar2 = page.m_strVar2;
  4840. m_strVar3 = page.m_strVar3;
  4841. m_clrCurve1 = page.m_clrCurve1;
  4842. m_clrCurve2 = page.m_clrCurve2;
  4843. m_clrCurve3 = page.m_clrCurve3;
  4844. return TRUE;
  4845. }
  4846. return FALSE;
  4847. }
  4848. bool CDrawHisCurve::Fresh(CRect &RECT)
  4849. {
  4850. SYSTEMTIME st;
  4851. GetLocalTime(&st);
  4852. if (m_nSecond != st.wSecond)
  4853. {
  4854. m_nSecond = st.wSecond;
  4855. }
  4856. else
  4857. return true;
  4858. if (!m_strVar1.IsEmpty())
  4859. {
  4860. for (int i = 0; i < 59; i++)
  4861. {
  4862. m_nValue1[i] = m_nValue1[i + 1];
  4863. }
  4864. //m_nValue1[59] = (int) pVariantsManager->GetAnalogValue(m_strVar1);
  4865. }
  4866. if (!m_strVar2.IsEmpty())
  4867. {
  4868. for (int i = 0; i < 59; i++)
  4869. {
  4870. m_nValue2[i] = m_nValue2[i + 1];
  4871. }
  4872. //m_nValue2[59] = (int) pVariantsManager->GetAnalogValue(m_strVar2);
  4873. }
  4874. if (!m_strVar3.IsEmpty())
  4875. {
  4876. for (int i = 0; i < 59; i++)
  4877. {
  4878. m_nValue3[i] = m_nValue3[i + 1];
  4879. }
  4880. //m_nValue3[59] = (int) pVariantsManager->GetAnalogValue(m_strVar3);
  4881. }
  4882. RECT = m_rect;
  4883. return true;
  4884. }
  4885. void CDrawHisCurve::DrawCurve(CDC* pDC, CRect rect, int* data, COLORREF color)
  4886. {
  4887. rect.NormalizeRect();
  4888. CPen PenBackGrid(PS_SOLID, 1, color);
  4889. CPen* pOldPen = pDC->SelectObject(&PenBackGrid);
  4890. for (int i = 0; i < 60; i++)
  4891. {
  4892. CPoint point;
  4893. point.x = rect.left + i*(1.0*rect.Width() / 59);
  4894. float rate = (1.0*(data[i] - m_nLowwer)) / (m_nUpper - m_nLowwer);
  4895. point.y = rect.bottom - int(rect.Height()*rate);
  4896. if (point.y > rect.bottom)
  4897. point.y = rect.bottom;
  4898. if (point.y < rect.top)
  4899. point.y = rect.top;
  4900. if (point.x < rect.left)
  4901. point.x = rect.left;
  4902. if (point.x > rect.right)
  4903. point.x = rect.right;
  4904. if (i == 0)
  4905. {
  4906. pDC->MoveTo(point);
  4907. }
  4908. else
  4909. {
  4910. pDC->LineTo(point);
  4911. }
  4912. }
  4913. pDC->SelectObject(pOldPen);
  4914. }
  4915. //---------------------------------------------- CDrawOCX --------
  4916. IMPLEMENT_SERIAL(CDrawOCX, CDrawObj, 0)
  4917. CDrawOCX::CDrawOCX() :CDrawObj()
  4918. {
  4919. m_clrFore = RGB(0x80, 0x00, 0x00);;
  4920. m_clrBack = RGB(0xD1, 0xE1, 0xF8);//(120, 120, 120);
  4921. m_strCaption = "OCX";
  4922. m_strOcxPath = "";
  4923. m_nOcxIndex = 0;
  4924. }
  4925. CDrawObj* CDrawOCX::Clone(void)
  4926. {
  4927. CDrawOCX *pObj = new CDrawOCX;
  4928. *((CDrawObj*)pObj) = *(CDrawObj*)this;
  4929. pObj->m_strOcxPath = m_strOcxPath;
  4930. pObj->m_nOcxIndex = m_nOcxIndex;
  4931. return pObj;
  4932. }
  4933. bool CDrawOCX::Fresh(CRect &RECT)
  4934. {
  4935. CDrawObj::Fresh(RECT);
  4936. RECT = m_rect;
  4937. if (!m_bShow)
  4938. {
  4939. m_bShowtemp = FALSE;
  4940. return true;
  4941. }
  4942. else if (!m_bShowtemp)
  4943. {
  4944. m_bShowtemp = TRUE;
  4945. return true;
  4946. }
  4947. else
  4948. return false;
  4949. }
  4950. void CDrawOCX::Draw(CDC* pDC)
  4951. {
  4952. if (!m_bShow && bRuning) return;
  4953. if (!g_bRun)
  4954. {
  4955. CRect rect = m_rctCurrent;
  4956. COLORREF color = m_clrCurrentBack;
  4957. if (!bRuning)
  4958. {
  4959. rect = m_rect;
  4960. color = m_clrBack;
  4961. }
  4962. pDC->FillSolidRect(rect, color);
  4963. CPen pen(GetPenStyle(m_strLineType), 5, RGB(255, 128, 0));
  4964. CPen* pOldPen = pDC->SelectObject(&pen);
  4965. // CBrush
  4966. LOGBRUSH brushlog = GetBrush();
  4967. CBrush m_brush;
  4968. m_brush.CreateBrushIndirect(&brushlog);
  4969. CBrush* pOldBrush = (CBrush*)pDC->SelectObject(&m_brush);
  4970. pDC->Rectangle(rect);
  4971. CBrush *pBrushNull = CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH));
  4972. pOldBrush = pDC->SelectObject(pBrushNull);//选入设备描述表
  4973. CPen pen2(GetPenStyle(m_strLineType), 2, RGB(255, 255, 255));
  4974. pOldPen = pDC->SelectObject(&pen2);
  4975. //rect.left+=1;
  4976. //rect.right-=1;
  4977. //rect.top+=1;
  4978. //rect.bottom-=1;
  4979. pDC->Rectangle(rect);
  4980. pDC->SelectObject(pOldPen);
  4981. pDC->SelectObject(pOldBrush);
  4982. DrawText(pDC);
  4983. DeleteObject(m_brush);
  4984. DeleteObject(pBrushNull);
  4985. DeleteObject(pen);
  4986. DeleteObject(pen2);
  4987. }
  4988. else
  4989. {
  4990. }
  4991. }
  4992. void CDrawOCX::DrawText(CDC* pDC)
  4993. {
  4994. CFont *pFont = NULL;
  4995. COLORREF clrFore = m_clrFore;
  4996. CRect rect = m_rect;
  4997. if (bRuning)
  4998. {
  4999. clrFore = m_clrCurrentFore;
  5000. rect = m_rctCurrent;
  5001. }
  5002. pDC->SetTextColor(clrFore);
  5003. pDC->SetTextAlign(TA_LEFT | TA_TOP);
  5004. CFont font;
  5005. font.CreateFontIndirect(&m_logfont);
  5006. CFont* pOldFont = pDC->SelectObject(&font);
  5007. int height = abs(m_logfont.lfHeight);
  5008. rect.NormalizeRect();
  5009. int nX0 = (rect.left + rect.right) / 2;
  5010. int nY0 = (rect.top + rect.bottom) / 2;
  5011. //if(rect.Width()>=rect.Height())
  5012. {
  5013. pFont = new CFont;
  5014. pFont->CreateFont(rect.Height() * 2 / 4, // nHeight
  5015. 0, // nWidth
  5016. 0, // nEscapement
  5017. 0, // nOrientation
  5018. FW_BOLD, // nWeight
  5019. false, // bItalic
  5020. FALSE, // bUnderline
  5021. 0, // cStrikeOut
  5022. ANSI_CHARSET, // nCharSet
  5023. OUT_DEFAULT_PRECIS, // nOutPrecision
  5024. CLIP_DEFAULT_PRECIS, // nClipPrecision
  5025. DEFAULT_QUALITY, // nQuality
  5026. DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily
  5027. _T("黑体")); // lpszFac
  5028. pDC->SelectObject(pFont);
  5029. pDC->DrawText(m_strCaption, -1, &rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
  5030. }
  5031. DeleteObject(font);
  5032. pDC->SelectObject(pOldFont);
  5033. if (pFont)
  5034. delete pFont;
  5035. }
  5036. BOOL CDrawOCX::OnAttrib(CPropertySheet& sheet)
  5037. {
  5038. CDlg_OCX page;
  5039. page.m_sEdit_OCXPath = m_strOcxPath;
  5040. page.m_nComb_OCXIndex = m_nOcxIndex;
  5041. sheet.AddPage(&page);
  5042. sheet.Construct(g_strParamSet);
  5043. sheet.m_psh.dwFlags |= PSH_NOAPPLYNOW;
  5044. if (sheet.DoModal() == IDOK)
  5045. {
  5046. m_strOcxPath = page.m_sEdit_OCXPath;
  5047. m_nOcxIndex = page.m_nComb_OCXIndex;
  5048. return TRUE;
  5049. }
  5050. return FALSE;
  5051. }
  5052. void CDrawOCX::Serialize(CArchive& ar)
  5053. {
  5054. CDrawObj::Serialize(ar);
  5055. if (ar.IsStoring())
  5056. {
  5057. ar << m_strOcxPath;
  5058. ar << m_nOcxIndex;
  5059. }
  5060. else
  5061. {
  5062. ar >> m_strOcxPath;
  5063. ar >> m_nOcxIndex;
  5064. }
  5065. }
  5066. //---------------------------------------------- CDrawFlash --------
  5067. IMPLEMENT_SERIAL(CDrawFlash, CDrawObj, 0)
  5068. CDrawFlash::CDrawFlash() :CDrawObj()
  5069. {
  5070. m_clrFore = RGB(0x80, 0x00, 0x00);;
  5071. m_clrBack = RGB(0xD1, 0xE1, 0xF8);//(120, 120, 120);
  5072. m_strCaption = "swf";
  5073. m_strFlashPath = "";
  5074. m_pCtrlFlash = NULL;
  5075. m_bFlashCreate = false;
  5076. }
  5077. CDrawFlash::~CDrawFlash()
  5078. {
  5079. if (m_pCtrlFlash)
  5080. {
  5081. delete m_pCtrlFlash;
  5082. m_pCtrlFlash = NULL;
  5083. m_bFlashCreate = false;
  5084. }
  5085. }
  5086. CDrawObj* CDrawFlash::Clone(void)
  5087. {
  5088. CDrawFlash *pObj = new CDrawFlash;
  5089. *((CDrawObj*)pObj) = *(CDrawObj*)this;
  5090. pObj->m_strFlashPath = m_strFlashPath;
  5091. return pObj;
  5092. }
  5093. void CDrawFlash::Serialize(CArchive& ar)
  5094. {
  5095. CDrawObj::Serialize(ar);
  5096. if (ar.IsStoring())
  5097. {
  5098. ar << m_strFlashPath;
  5099. }
  5100. else
  5101. {
  5102. ar >> m_strFlashPath;
  5103. }
  5104. }
  5105. bool CDrawFlash::Fresh(CRect &RECT)
  5106. {
  5107. CDrawObj::Fresh(RECT);
  5108. RECT = m_rect;
  5109. #if 1
  5110. if (m_pCtrlFlash)
  5111. {
  5112. CRect rect = m_rect;
  5113. rect.NormalizeRect();
  5114. int nX1 = rect.left;
  5115. int nY1 = rect.top;
  5116. CPoint pt(nX1, nY1);
  5117. CMainFrame* pFrame = (CMainFrame*)AfxGetApp()->GetMainWnd();
  5118. HWND hwnd = pFrame->m_pActiveView->m_hWnd;
  5119. //m_image->InitAnimation(hwnd, pt);
  5120. if (!m_bFlashCreate && m_strFlashPath != "")
  5121. {
  5122. m_bFlashCreate = true;
  5123. m_pCtrlFlash->Create("", "", WS_CHILD | WS_VISIBLE, rect, CWnd::FromHandle(hwnd), 10000);
  5124. char curDir[256] = { 0 };
  5125. strcpy(curDir, g_strDirectory);
  5126. strcat(curDir, "\\");
  5127. strcat(curDir, _BITMAPDIR);
  5128. CString strFileName = m_strFlashPath;//CString(curDir) +
  5129. m_pCtrlFlash->SetMovie(strFileName);
  5130. }
  5131. int a = rand() % 100;
  5132. CString str;
  5133. str.Format("当前值:%d", a);
  5134. if (m_pCtrlFlash)
  5135. m_pCtrlFlash->SetVariable("a", str);
  5136. }
  5137. #endif
  5138. if (!m_bShow)
  5139. {
  5140. m_bShowtemp = FALSE;
  5141. return true;
  5142. }
  5143. else if (!m_bShowtemp)
  5144. {
  5145. m_bShowtemp = TRUE;
  5146. return true;
  5147. }
  5148. else
  5149. return false;
  5150. }
  5151. void CDrawFlash::Draw(CDC* pDC)
  5152. {
  5153. if (!m_bShow && bRuning)
  5154. {
  5155. if (m_pCtrlFlash)
  5156. {
  5157. delete m_pCtrlFlash;
  5158. m_pCtrlFlash = NULL;
  5159. m_bFlashCreate = false;
  5160. }
  5161. return;
  5162. }
  5163. if (!g_bRun)
  5164. {
  5165. CRect rect = m_rctCurrent;
  5166. COLORREF color = m_clrCurrentBack;
  5167. if (!bRuning)
  5168. {
  5169. rect = m_rect;
  5170. color = m_clrBack;
  5171. }
  5172. pDC->FillSolidRect(rect, color);
  5173. CPen pen(GetPenStyle(m_strLineType), 5, RGB(255, 128, 0));
  5174. CPen* pOldPen = pDC->SelectObject(&pen);
  5175. // CBrush
  5176. LOGBRUSH brushlog = GetBrush();
  5177. CBrush m_brush;
  5178. m_brush.CreateBrushIndirect(&brushlog);
  5179. CBrush* pOldBrush = (CBrush*)pDC->SelectObject(&m_brush);
  5180. pDC->Rectangle(rect);
  5181. CBrush *pBrushNull = CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH));
  5182. pOldBrush = pDC->SelectObject(pBrushNull);//选入设备描述表
  5183. CPen pen2(GetPenStyle(m_strLineType), 2, RGB(255, 255, 255));
  5184. pOldPen = pDC->SelectObject(&pen2);
  5185. //rect.left+=1;
  5186. //rect.right-=1;
  5187. //rect.top+=1;
  5188. //rect.bottom-=1;
  5189. pDC->Rectangle(rect);
  5190. pDC->SelectObject(pOldPen);
  5191. pDC->SelectObject(pOldBrush);
  5192. DrawText(pDC);
  5193. DeleteObject(m_brush);
  5194. DeleteObject(pBrushNull);
  5195. DeleteObject(pen);
  5196. DeleteObject(pen2);
  5197. }
  5198. if (g_bRun)
  5199. {
  5200. if (m_pCtrlFlash == NULL)
  5201. {
  5202. //char curDir[256] = {0};
  5203. ////strcpy(curDir, g_strDirectory);
  5204. //strcat(curDir, ".\\\\");
  5205. //strcat(curDir, _BITMAPDIR);
  5206. //if( m_strStaticFile=="" )//gif 路徑為Bitmap,默認名為StounU.gif
  5207. // m_strStaticFile = "StounU.gif";
  5208. //CString strGifFileName = CString(curDir) + m_strStaticFile;
  5209. //GDI+
  5210. m_pCtrlFlash = new CShockwaveFlash();
  5211. }
  5212. if (m_pCtrlFlash)
  5213. {
  5214. CRect rect = m_rect;
  5215. rect.NormalizeRect();
  5216. int nX1 = rect.left;
  5217. int nY1 = rect.top;
  5218. CPoint pt(nX1, nY1);
  5219. CMainFrame* pFrame = (CMainFrame*)AfxGetApp()->GetMainWnd();
  5220. HWND hwnd = pFrame->m_pActiveView->m_hWnd;
  5221. //m_image->InitAnimation(hwnd, pt);
  5222. if (!m_bFlashCreate && m_strFlashPath != "")
  5223. {
  5224. m_bFlashCreate = true;
  5225. m_pCtrlFlash->Create("", "", WS_CHILD | WS_VISIBLE, rect, CWnd::FromHandle(hwnd), 10000);
  5226. char curDir[256] = { 0 };
  5227. strcpy(curDir, g_strDirectory);
  5228. strcat(curDir, "\\");
  5229. strcat(curDir, _BITMAPDIR);
  5230. CString strFileName = m_strFlashPath;//CString(curDir) +
  5231. m_pCtrlFlash->SetMovie(strFileName);
  5232. }
  5233. int a = rand() % 100;
  5234. CString str;
  5235. str.Format("当前值:%d", a);
  5236. if (m_pCtrlFlash)
  5237. m_pCtrlFlash->SetVariable("a", str);
  5238. }
  5239. }
  5240. }
  5241. BOOL CDrawFlash::OnAttrib(CPropertySheet& sheet)
  5242. {
  5243. CDlg_Flash page;
  5244. page.m_sEdit_FlashPath = m_strFlashPath;
  5245. sheet.AddPage(&page);
  5246. sheet.Construct(g_strParamSet);
  5247. sheet.m_psh.dwFlags |= PSH_NOAPPLYNOW;
  5248. if (sheet.DoModal() == IDOK)
  5249. {
  5250. m_strFlashPath = page.m_sEdit_FlashPath;
  5251. return TRUE;
  5252. }
  5253. return FALSE;
  5254. }
  5255. void CDrawFlash::DrawText(CDC* pDC)
  5256. {
  5257. CFont *pFont = NULL;
  5258. COLORREF clrFore = m_clrFore;
  5259. CRect rect = m_rect;
  5260. if (bRuning)
  5261. {
  5262. clrFore = m_clrCurrentFore;
  5263. rect = m_rctCurrent;
  5264. }
  5265. pDC->SetTextColor(clrFore);
  5266. pDC->SetTextAlign(TA_LEFT | TA_TOP);
  5267. CFont font;
  5268. font.CreateFontIndirect(&m_logfont);
  5269. CFont* pOldFont = pDC->SelectObject(&font);
  5270. int height = abs(m_logfont.lfHeight);
  5271. rect.NormalizeRect();
  5272. int nX0 = (rect.left + rect.right) / 2;
  5273. int nY0 = (rect.top + rect.bottom) / 2;
  5274. //if(rect.Width()>=rect.Height())
  5275. {
  5276. pFont = new CFont;
  5277. pFont->CreateFont(rect.Height() * 2 / 4, // nHeight
  5278. 0, // nWidth
  5279. 0, // nEscapement
  5280. 0, // nOrientation
  5281. FW_BOLD, // nWeight
  5282. false, // bItalic
  5283. FALSE, // bUnderline
  5284. 0, // cStrikeOut
  5285. ANSI_CHARSET, // nCharSet
  5286. OUT_DEFAULT_PRECIS, // nOutPrecision
  5287. CLIP_DEFAULT_PRECIS, // nClipPrecision
  5288. DEFAULT_QUALITY, // nQuality
  5289. DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily
  5290. _T("黑体")); // lpszFac
  5291. pDC->SelectObject(pFont);
  5292. pDC->DrawText(m_strCaption, -1, &rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
  5293. }
  5294. pDC->SelectObject(pOldFont);
  5295. DeleteObject(font);
  5296. if (pFont)
  5297. delete pFont;
  5298. }