DrawObj.cpp 133 KB

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