UIManager.cpp 130 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623
  1. #include "StdAfx.h"
  2. #include <zmouse.h>
  3. #pragma warning(push)
  4. #pragma warning(disable:4838 4244)
  5. namespace DuiLib
  6. {
  7. /////////////////////////////////////////////////////////////////////////////////////
  8. //
  9. //
  10. static void GetChildWndRect(HWND hWnd, HWND hChildWnd, RECT& rcChildWnd)
  11. {
  12. ::GetWindowRect(hChildWnd, &rcChildWnd);
  13. POINT pt;
  14. pt.x = rcChildWnd.left;
  15. pt.y = rcChildWnd.top;
  16. ::ScreenToClient(hWnd, &pt);
  17. rcChildWnd.left = pt.x;
  18. rcChildWnd.top = pt.y;
  19. pt.x = rcChildWnd.right;
  20. pt.y = rcChildWnd.bottom;
  21. ::ScreenToClient(hWnd, &pt);
  22. rcChildWnd.right = pt.x;
  23. rcChildWnd.bottom = pt.y;
  24. }
  25. static UINT MapKeyState()
  26. {
  27. UINT uState = 0;
  28. if (::GetKeyState(VK_CONTROL) < 0) uState |= MK_CONTROL;
  29. if (::GetKeyState(VK_LBUTTON) < 0) uState |= MK_LBUTTON;
  30. if (::GetKeyState(VK_RBUTTON) < 0) uState |= MK_RBUTTON;
  31. if (::GetKeyState(VK_SHIFT) < 0) uState |= MK_SHIFT;
  32. if (::GetKeyState(VK_MENU) < 0) uState |= MK_ALT;
  33. return uState;
  34. }
  35. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  36. ///
  37. typedef struct tagFINDTABINFO
  38. {
  39. CControlUI* pFocus;
  40. CControlUI* pLast;
  41. bool bForward;
  42. bool bNextIsIt;
  43. } FINDTABINFO;
  44. typedef struct tagFINDSHORTCUT
  45. {
  46. TCHAR ch;
  47. bool bPickNext;
  48. } FINDSHORTCUT;
  49. typedef struct tagTIMERINFO
  50. {
  51. CControlUI* pSender;
  52. UINT nLocalID;
  53. HWND hWnd;
  54. UINT uWinTimer;
  55. bool bKilled;
  56. } TIMERINFO;
  57. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  58. ///
  59. tagTImageInfo::tagTImageInfo()
  60. {
  61. pImage = NULL;
  62. hBitmap = NULL;
  63. }
  64. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  65. ///
  66. tagTDrawInfo::tagTDrawInfo()
  67. {
  68. Clear();
  69. }
  70. void tagTDrawInfo::Parse(LPCTSTR pStrImage, LPCTSTR pStrModify, CPaintManagerUI* pManager)
  71. {
  72. // 1、aaa.jpg
  73. // 2、file='aaa.jpg' res='' restype='0' dest='0,0,0,0' source='0,0,0,0' corner='0,0,0,0'
  74. // mask='#FF0000' fade='255' hole='false' xtiled='false' ytiled='false'
  75. sDrawString = pStrImage;
  76. sDrawModify = pStrModify;
  77. sImageName = pStrImage;
  78. CDuiString sItem;
  79. CDuiString sValue;
  80. LPTSTR pstr = NULL;
  81. for (int i = 0; i < 2; ++i)
  82. {
  83. if (i == 1) pStrImage = pStrModify;
  84. if (!pStrImage) continue;
  85. while (*pStrImage != _T('\0'))
  86. {
  87. sItem.Empty();
  88. sValue.Empty();
  89. while (*pStrImage > _T('\0') && *pStrImage <= _T(' ')) pStrImage = ::CharNext(pStrImage);
  90. while (*pStrImage != _T('\0') && *pStrImage != _T('=') && *pStrImage > _T(' '))
  91. {
  92. LPTSTR pstrTemp = ::CharNext(pStrImage);
  93. while (pStrImage < pstrTemp)
  94. {
  95. sItem += *pStrImage++;
  96. }
  97. }
  98. while (*pStrImage > _T('\0') && *pStrImage <= _T(' ')) pStrImage = ::CharNext(pStrImage);
  99. if (*pStrImage++ != _T('=')) break;
  100. while (*pStrImage > _T('\0') && *pStrImage <= _T(' ')) pStrImage = ::CharNext(pStrImage);
  101. if (*pStrImage++ != _T('\'')) break;
  102. while (*pStrImage != _T('\0') && *pStrImage != _T('\''))
  103. {
  104. LPTSTR pstrTemp = ::CharNext(pStrImage);
  105. while (pStrImage < pstrTemp)
  106. {
  107. sValue += *pStrImage++;
  108. }
  109. }
  110. if (*pStrImage++ != _T('\'')) break;
  111. if (!sValue.IsEmpty())
  112. {
  113. if (sItem == _T("file") || sItem == _T("res"))
  114. {
  115. sImageName = sValue;
  116. }
  117. else if (sItem == _T("restype"))
  118. {
  119. sResType = sValue;
  120. }
  121. else if (sItem == _T("dest"))
  122. {
  123. rcDest.left = _tcstol(sValue.GetData(), &pstr, 10); ASSERT(pstr);
  124. rcDest.top = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  125. rcDest.right = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  126. rcDest.bottom = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  127. //if(pManager != NULL) pManager->GetDPIObj()->Scale(&rcDest);
  128. }
  129. else if (sItem == _T("source"))
  130. {
  131. rcSource.left = _tcstol(sValue.GetData(), &pstr, 10); ASSERT(pstr);
  132. rcSource.top = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  133. rcSource.right = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  134. rcSource.bottom = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  135. //if(pManager != NULL) pManager->GetDPIObj()->Scale(&rcSource);
  136. }
  137. else if (sItem == _T("corner"))
  138. {
  139. rcCorner.left = _tcstol(sValue.GetData(), &pstr, 10); ASSERT(pstr);
  140. rcCorner.top = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  141. rcCorner.right = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  142. rcCorner.bottom = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  143. //if(pManager != NULL) pManager->GetDPIObj()->Scale(&rcCorner);
  144. }
  145. else if (sItem == _T("mask"))
  146. {
  147. if (sValue[0] == _T('#')) dwMask = _tcstoul(sValue.GetData() + 1, &pstr, 16);
  148. else dwMask = _tcstoul(sValue.GetData(), &pstr, 16);
  149. }
  150. else if (sItem == _T("fade"))
  151. {
  152. uFade = (UINT)_tcstoul(sValue.GetData(), &pstr, 10);
  153. }
  154. else if (sItem == _T("rotate"))
  155. {
  156. uRotate = (UINT)_tcstoul(sValue.GetData(), &pstr, 10);
  157. bGdiplus = true;
  158. }
  159. else if (sItem == _T("gdiplus"))
  160. {
  161. bGdiplus = (_tcsicmp(sValue.GetData(), _T("true")) == 0);
  162. }
  163. else if (sItem == _T("hole"))
  164. {
  165. bHole = (_tcsicmp(sValue.GetData(), _T("true")) == 0);
  166. }
  167. else if (sItem == _T("xtiled"))
  168. {
  169. bTiledX = (_tcsicmp(sValue.GetData(), _T("true")) == 0);
  170. }
  171. else if (sItem == _T("ytiled"))
  172. {
  173. bTiledY = (_tcsicmp(sValue.GetData(), _T("true")) == 0);
  174. }
  175. else if (sItem == _T("hsl"))
  176. {
  177. bHSL = (_tcsicmp(sValue.GetData(), _T("true")) == 0);
  178. }
  179. else if (sItem == _T("size"))
  180. {
  181. szImage.cx = _tcstol(sValue.GetData(), &pstr, 10); ASSERT(pstr);
  182. szImage.cy = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  183. }
  184. else if (sItem == _T("align"))
  185. {
  186. sAlign = sValue;
  187. }
  188. else if (sItem == _T("padding"))
  189. {
  190. rcPadding.left = _tcstol(sValue.GetData(), &pstr, 10); ASSERT(pstr);
  191. rcPadding.top = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  192. rcPadding.right = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  193. rcPadding.bottom = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  194. //if(pManager != NULL) pManager->GetDPIObj()->Scale(&rcPadding);
  195. }
  196. }
  197. if (*pStrImage++ != _T(' ')) break;
  198. }
  199. }
  200. // 调整DPI资源
  201. if (pManager != NULL && pManager->GetDPIObj()->GetScale() != 100)
  202. {
  203. CDuiString sScale;
  204. sScale.Format(_T("@%d."), pManager->GetDPIObj()->GetScale());
  205. sImageName.Replace(_T("."), sScale);
  206. }
  207. }
  208. void tagTDrawInfo::Clear()
  209. {
  210. sDrawString.Empty();
  211. sDrawModify.Empty();
  212. sImageName.Empty();
  213. memset(&rcDest, 0, sizeof(RECT));
  214. memset(&rcSource, 0, sizeof(RECT));
  215. memset(&rcCorner, 0, sizeof(RECT));
  216. dwMask = 0;
  217. uFade = 255;
  218. uRotate = 0;
  219. bHole = false;
  220. bTiledX = false;
  221. bTiledY = false;
  222. bHSL = false;
  223. bGdiplus = false;
  224. szImage.cx = szImage.cy = 0;
  225. sAlign.Empty();
  226. memset(&rcPadding, 0, sizeof(RECT));
  227. }
  228. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  229. ///
  230. typedef BOOL(__stdcall* PFUNCUPDATELAYEREDWINDOW)(HWND, HDC, POINT*, SIZE*, HDC, POINT*, COLORREF, BLENDFUNCTION*, DWORD);
  231. PFUNCUPDATELAYEREDWINDOW g_fUpdateLayeredWindow = NULL;
  232. HPEN m_hUpdateRectPen = NULL;
  233. HINSTANCE CPaintManagerUI::m_hResourceInstance = NULL;
  234. CDuiString CPaintManagerUI::m_pStrResourcePath;
  235. CDuiString CPaintManagerUI::m_pStrResourceZip;
  236. CDuiString CPaintManagerUI::m_pStrResourceZipPwd; //Garfield 20160325 带密码zip包解密
  237. HANDLE CPaintManagerUI::m_hResourceZip = NULL;
  238. bool CPaintManagerUI::m_bCachedResourceZip = true;
  239. BYTE* CPaintManagerUI::m_cbZipBuf = nullptr;
  240. int CPaintManagerUI::m_nResType = UILIB_FILE;
  241. TResInfo CPaintManagerUI::m_SharedResInfo;
  242. HINSTANCE CPaintManagerUI::m_hInstance = NULL;
  243. bool CPaintManagerUI::m_bUseHSL = false;
  244. short CPaintManagerUI::m_H = 180;
  245. short CPaintManagerUI::m_S = 100;
  246. short CPaintManagerUI::m_L = 100;
  247. CStdPtrArray CPaintManagerUI::m_aPreMessages;
  248. CStdPtrArray CPaintManagerUI::m_aPlugins;
  249. CPaintManagerUI::CPaintManagerUI() :
  250. m_hWndPaint(NULL),
  251. m_hDcPaint(NULL),
  252. m_hDcOffscreen(NULL),
  253. m_hDcBackground(NULL),
  254. m_bOffscreenPaint(true),
  255. m_hbmpOffscreen(NULL),
  256. m_pOffscreenBits(NULL),
  257. m_hbmpBackground(NULL),
  258. m_pBackgroundBits(NULL),
  259. m_hwndTooltip(NULL),
  260. m_uTimerID(0x1000),
  261. m_pRoot(NULL),
  262. m_pFocus(NULL),
  263. m_pEventHover(NULL),
  264. m_pEventClick(NULL),
  265. m_pEventRClick(NULL),
  266. m_pEventKey(NULL),
  267. m_bFirstLayout(true),
  268. m_bFocusNeeded(false),
  269. m_bUpdateNeeded(false),
  270. m_bMouseTracking(false),
  271. m_bMouseCapture(false),
  272. m_bAsyncNotifyPosted(false),
  273. m_bUsedVirtualWnd(false),
  274. m_bForceUseSharedRes(false),
  275. m_nOpacity(0xFF),
  276. m_bLayered(false),
  277. m_bLayeredChanged(false),
  278. m_bShowUpdateRect(false),
  279. m_bUseGdiplusText(false),
  280. m_trh(0),
  281. m_bDragDrop(false),
  282. m_bDragMode(false),
  283. m_hDragBitmap(NULL),
  284. m_pDPI(NULL),
  285. m_iHoverTime(400UL),
  286. // [FIX] m_bNoActivate 原本未初始化:Debug 堆新块填充 0xCD -> 读到 true;
  287. // Release 下则是随机垃圾值,属偶发性隐患。
  288. // 后果:本文件中 3 处 "if (!m_bNoActivate) ::SetFocus(m_hWndPaint);"
  289. // (WM_LBUTTONDOWN 1738 / CPaintManagerUI::SetFocus 2442 / SetFocusNeeded 2475) 全部被跳过,
  290. // 系统焦点无法回到主窗口 -> 原生 EDIT 子窗 CEditWnd 收不到 WM_KILLFOCUS ->
  291. // 其唯一的销毁途径 PostMessage(WM_CLOSE) 永不触发 -> 光标常闪、点空白不丢焦点。
  292. // XML 侧仅在显式书写 noactivate 属性时才赋值(UIDlgBuilder.cpp),故此处必须先给确定初值。
  293. m_bNoActivate(false),
  294. // 以下两个成员同样是漏网之鱼(全库无赋值点),一并清零以防后患。
  295. m_bIsPainting(false),
  296. m_pLastToolTip(NULL)
  297. {
  298. if (m_SharedResInfo.m_DefaultFontInfo.sFontName.IsEmpty())
  299. {
  300. m_SharedResInfo.m_dwDefaultDisabledColor = 0xFFA7A6AA;
  301. m_SharedResInfo.m_dwDefaultFontColor = 0xFF000000;
  302. m_SharedResInfo.m_dwDefaultLinkFontColor = 0xFF0000FF;
  303. m_SharedResInfo.m_dwDefaultLinkHoverFontColor = 0xFFD3215F;
  304. m_SharedResInfo.m_dwDefaultSelectedBkColor = 0xFFBAE4FF;
  305. LOGFONT lf = { 0 };
  306. ::GetObject(::GetStockObject(DEFAULT_GUI_FONT), sizeof(LOGFONT), &lf);
  307. lf.lfCharSet = DEFAULT_CHARSET;
  308. HFONT hDefaultFont = ::CreateFontIndirect(&lf);
  309. m_SharedResInfo.m_DefaultFontInfo.hFont = hDefaultFont;
  310. m_SharedResInfo.m_DefaultFontInfo.sFontName = lf.lfFaceName;
  311. m_SharedResInfo.m_DefaultFontInfo.iSize = -lf.lfHeight;
  312. m_SharedResInfo.m_DefaultFontInfo.bBold = (lf.lfWeight >= FW_BOLD);
  313. m_SharedResInfo.m_DefaultFontInfo.bUnderline = (lf.lfUnderline == TRUE);
  314. m_SharedResInfo.m_DefaultFontInfo.bItalic = (lf.lfItalic == TRUE);
  315. ::ZeroMemory(&m_SharedResInfo.m_DefaultFontInfo.tm, sizeof(m_SharedResInfo.m_DefaultFontInfo.tm));
  316. }
  317. m_ResInfo.m_dwDefaultDisabledColor = m_SharedResInfo.m_dwDefaultDisabledColor;
  318. m_ResInfo.m_dwDefaultFontColor = m_SharedResInfo.m_dwDefaultFontColor;
  319. m_ResInfo.m_dwDefaultLinkFontColor = m_SharedResInfo.m_dwDefaultLinkFontColor;
  320. m_ResInfo.m_dwDefaultLinkHoverFontColor = m_SharedResInfo.m_dwDefaultLinkHoverFontColor;
  321. m_ResInfo.m_dwDefaultSelectedBkColor = m_SharedResInfo.m_dwDefaultSelectedBkColor;
  322. if (m_hUpdateRectPen == NULL)
  323. {
  324. m_hUpdateRectPen = ::CreatePen(PS_SOLID, 1, RGB(220, 0, 0));
  325. // Boot Windows Common Controls (for the ToolTip control)
  326. ::InitCommonControls();
  327. ::LoadLibrary(_T("msimg32.dll"));
  328. }
  329. m_szMinWindow.cx = 0;
  330. m_szMinWindow.cy = 0;
  331. m_szMaxWindow.cx = 0;
  332. m_szMaxWindow.cy = 0;
  333. m_szInitWindowSize.cx = 0;
  334. m_szInitWindowSize.cy = 0;
  335. m_szRoundCorner.cx = m_szRoundCorner.cy = 0;
  336. ::ZeroMemory(&m_rcSizeBox, sizeof(m_rcSizeBox));
  337. ::ZeroMemory(&m_rcCaption, sizeof(m_rcCaption));
  338. ::ZeroMemory(&m_rcLayeredInset, sizeof(m_rcLayeredInset));
  339. ::ZeroMemory(&m_rcLayeredUpdate, sizeof(m_rcLayeredUpdate));
  340. m_ptLastMousePos.x = m_ptLastMousePos.y = -1;
  341. m_pGdiplusStartupInput = new Gdiplus::GdiplusStartupInput;
  342. Gdiplus::GdiplusStartup(&m_gdiplusToken, m_pGdiplusStartupInput, NULL); // 加载GDI接口
  343. CShadowUI::Initialize(m_hInstance);
  344. m_pDragDrop = NULL;
  345. }
  346. CPaintManagerUI::~CPaintManagerUI()
  347. {
  348. // Delete the control-tree structures
  349. for (int i = 0; i < m_aDelayedCleanup.GetSize(); i++) delete static_cast<CControlUI*>(m_aDelayedCleanup[i]);
  350. m_aDelayedCleanup.Resize(0);
  351. for (int i = 0; i < m_aAsyncNotify.GetSize(); i++) delete static_cast<TNotifyUI*>(m_aAsyncNotify[i]);
  352. m_aAsyncNotify.Resize(0);
  353. m_mNameHash.Resize(0);
  354. if (m_pRoot != NULL) delete m_pRoot;
  355. ::DeleteObject(m_ResInfo.m_DefaultFontInfo.hFont);
  356. RemoveAllFonts();
  357. RemoveAllImages();
  358. RemoveAllStyle();
  359. RemoveAllDefaultAttributeList();
  360. RemoveAllWindowCustomAttribute();
  361. RemoveAllOptionGroups();
  362. RemoveAllTimers();
  363. RemoveAllDrawInfos();
  364. if (m_hwndTooltip != NULL)
  365. {
  366. ::DestroyWindow(m_hwndTooltip);
  367. m_hwndTooltip = NULL;
  368. }
  369. if (!m_aFonts.IsEmpty())
  370. {
  371. for (int i = 0; i < m_aFonts.GetSize(); ++i)
  372. {
  373. HANDLE handle = static_cast<HANDLE>(m_aFonts.GetAt(i));
  374. ::RemoveFontMemResourceEx(handle);
  375. }
  376. }
  377. if (m_hDcOffscreen != NULL) ::DeleteDC(m_hDcOffscreen);
  378. if (m_hDcBackground != NULL) ::DeleteDC(m_hDcBackground);
  379. if (m_hbmpOffscreen != NULL) ::DeleteObject(m_hbmpOffscreen);
  380. if (m_hbmpBackground != NULL) ::DeleteObject(m_hbmpBackground);
  381. if (m_hDcPaint != NULL) ::ReleaseDC(m_hWndPaint, m_hDcPaint);
  382. m_aPreMessages.Remove(m_aPreMessages.Find(this));
  383. // 销毁拖拽图片
  384. if (m_hDragBitmap != NULL) ::DeleteObject(m_hDragBitmap);
  385. //卸载GDIPlus
  386. Gdiplus::GdiplusShutdown(m_gdiplusToken);
  387. delete m_pGdiplusStartupInput;
  388. // DPI管理对象
  389. if (m_pDPI != NULL)
  390. {
  391. delete m_pDPI;
  392. m_pDPI = NULL;
  393. }
  394. }
  395. void CPaintManagerUI::Init(HWND hWnd, LPCTSTR pstrName)
  396. {
  397. ASSERT(::IsWindow(hWnd));
  398. m_mNameHash.Resize();
  399. RemoveAllFonts();
  400. RemoveAllImages();
  401. RemoveAllStyle();
  402. RemoveAllDefaultAttributeList();
  403. RemoveAllWindowCustomAttribute();
  404. RemoveAllOptionGroups();
  405. RemoveAllTimers();
  406. m_sName.Empty();
  407. if (pstrName != NULL) m_sName = pstrName;
  408. if (m_hWndPaint != hWnd)
  409. {
  410. m_hWndPaint = hWnd;
  411. m_hDcPaint = ::GetDC(hWnd);
  412. m_aPreMessages.Add(this);
  413. }
  414. }
  415. void CPaintManagerUI::DeletePtr(void* ptr)
  416. {
  417. if (ptr)
  418. {
  419. delete ptr; ptr = NULL;
  420. }
  421. }
  422. HINSTANCE CPaintManagerUI::GetInstance()
  423. {
  424. return m_hInstance;
  425. }
  426. CDuiString CPaintManagerUI::GetInstancePath()
  427. {
  428. if (m_hInstance == NULL) return _T('\0');
  429. TCHAR tszModule[MAX_PATH + 1] = { 0 };
  430. ::GetModuleFileName(m_hInstance, tszModule, MAX_PATH);
  431. CDuiString sInstancePath = tszModule;
  432. int pos = sInstancePath.ReverseFind(_T('\\'));
  433. if (pos >= 0) sInstancePath = sInstancePath.Left(pos + 1);
  434. return sInstancePath;
  435. }
  436. CDuiString CPaintManagerUI::GetCurrentPath()
  437. {
  438. TCHAR tszModule[MAX_PATH + 1] = { 0 };
  439. ::GetCurrentDirectory(MAX_PATH, tszModule);
  440. return tszModule;
  441. }
  442. HINSTANCE CPaintManagerUI::GetResourceDll()
  443. {
  444. if (m_hResourceInstance == NULL) return m_hInstance;
  445. return m_hResourceInstance;
  446. }
  447. const CDuiString& CPaintManagerUI::GetResourcePath()
  448. {
  449. return m_pStrResourcePath;
  450. }
  451. const CDuiString& CPaintManagerUI::GetResourceZip()
  452. {
  453. return m_pStrResourceZip;
  454. }
  455. const CDuiString& CPaintManagerUI::GetResourceZipPwd()
  456. {
  457. return m_pStrResourceZipPwd;
  458. }
  459. bool CPaintManagerUI::IsCachedResourceZip()
  460. {
  461. return m_bCachedResourceZip;
  462. }
  463. HANDLE CPaintManagerUI::GetResourceZipHandle()
  464. {
  465. return m_hResourceZip;
  466. }
  467. void CPaintManagerUI::SetInstance(HINSTANCE hInst)
  468. {
  469. m_hInstance = hInst;
  470. }
  471. void CPaintManagerUI::SetCurrentPath(LPCTSTR pStrPath)
  472. {
  473. ::SetCurrentDirectory(pStrPath);
  474. }
  475. void CPaintManagerUI::SetResourceDll(HINSTANCE hInst)
  476. {
  477. m_hResourceInstance = hInst;
  478. }
  479. void CPaintManagerUI::SetResourcePath(LPCTSTR pStrPath)
  480. {
  481. m_pStrResourcePath = pStrPath;
  482. if (m_pStrResourcePath.IsEmpty()) return;
  483. TCHAR cEnd = m_pStrResourcePath.GetAt(m_pStrResourcePath.GetLength() - 1);
  484. if (cEnd != _T('\\') && cEnd != _T('/')) m_pStrResourcePath += _T('\\');
  485. }
  486. void CPaintManagerUI::SetResourceZip(LPVOID pVoid, unsigned int len, LPCTSTR password)
  487. {
  488. if (m_pStrResourceZip == _T("membuffer")) return;
  489. if (m_bCachedResourceZip && m_hResourceZip != NULL)
  490. {
  491. CloseZip((HZIP)m_hResourceZip);
  492. m_hResourceZip = NULL;
  493. }
  494. m_pStrResourceZip = _T("membuffer");
  495. if (m_cbZipBuf)
  496. {
  497. delete[] m_cbZipBuf;
  498. m_cbZipBuf = nullptr;
  499. }
  500. if (!m_cbZipBuf)
  501. {
  502. m_cbZipBuf = new BYTE[len];
  503. memcpy(m_cbZipBuf, pVoid, len);
  504. }
  505. m_bCachedResourceZip = true;
  506. m_pStrResourceZipPwd = password; //Garfield 20160325 带密码zip包解密
  507. if (m_bCachedResourceZip)
  508. {
  509. #ifdef UNICODE
  510. char* pwd = w2a((wchar_t*)password);
  511. m_hResourceZip = (HANDLE)OpenZip(m_cbZipBuf, len, pwd);
  512. if (pwd)
  513. {
  514. delete[] pwd;
  515. pwd = NULL;
  516. }
  517. #else
  518. m_hResourceZip = (HANDLE)OpenZip(m_cbZipBuf, len, password);
  519. #endif
  520. }
  521. }
  522. void CPaintManagerUI::SetResourceZip(LPCTSTR pStrPath, bool bCachedResourceZip, LPCTSTR password)
  523. {
  524. if (m_pStrResourceZip == pStrPath && m_bCachedResourceZip == bCachedResourceZip) return;
  525. if (m_bCachedResourceZip && m_hResourceZip != NULL)
  526. {
  527. CloseZip((HZIP)m_hResourceZip);
  528. m_hResourceZip = NULL;
  529. }
  530. m_pStrResourceZip = pStrPath;
  531. m_bCachedResourceZip = bCachedResourceZip;
  532. m_pStrResourceZipPwd = password;
  533. if (m_bCachedResourceZip)
  534. {
  535. CDuiString sFile = CPaintManagerUI::GetResourcePath();
  536. sFile += CPaintManagerUI::GetResourceZip();
  537. #ifdef UNICODE
  538. char* pwd = w2a((wchar_t*)password);
  539. m_hResourceZip = (HANDLE)OpenZip(sFile.GetData(), pwd);
  540. if (pwd)
  541. {
  542. delete[] pwd;
  543. pwd = NULL;
  544. }
  545. #else
  546. m_hResourceZip = (HANDLE)OpenZip(sFile.GetData(), password);
  547. #endif
  548. }
  549. }
  550. void CPaintManagerUI::SetResourceType(int nType)
  551. {
  552. m_nResType = nType;
  553. }
  554. int CPaintManagerUI::GetResourceType()
  555. {
  556. return m_nResType;
  557. }
  558. bool CPaintManagerUI::GetHSL(short* H, short* S, short* L)
  559. {
  560. *H = m_H;
  561. *S = m_S;
  562. *L = m_L;
  563. return m_bUseHSL;
  564. }
  565. void CPaintManagerUI::SetHSL(bool bUseHSL, short H, short S, short L)
  566. {
  567. if (m_bUseHSL || m_bUseHSL != bUseHSL)
  568. {
  569. m_bUseHSL = bUseHSL;
  570. if (H == m_H && S == m_S && L == m_L) return;
  571. m_H = CLAMP(H, 0, 360);
  572. m_S = CLAMP(S, 0, 200);
  573. m_L = CLAMP(L, 0, 200);
  574. AdjustSharedImagesHSL();
  575. for (int i = 0; i < m_aPreMessages.GetSize(); i++)
  576. {
  577. CPaintManagerUI* pManager = static_cast<CPaintManagerUI*>(m_aPreMessages[i]);
  578. if (pManager != NULL) pManager->AdjustImagesHSL();
  579. }
  580. }
  581. }
  582. void CPaintManagerUI::ReloadSkin()
  583. {
  584. ReloadSharedImages();
  585. for (int i = 0; i < m_aPreMessages.GetSize(); i++)
  586. {
  587. CPaintManagerUI* pManager = static_cast<CPaintManagerUI*>(m_aPreMessages[i]);
  588. pManager->ReloadImages();
  589. }
  590. }
  591. CPaintManagerUI* CPaintManagerUI::GetPaintManager(LPCTSTR pstrName)
  592. {
  593. if (pstrName == NULL) return NULL;
  594. CDuiString sName = pstrName;
  595. if (sName.IsEmpty()) return NULL;
  596. for (int i = 0; i < m_aPreMessages.GetSize(); i++)
  597. {
  598. CPaintManagerUI* pManager = static_cast<CPaintManagerUI*>(m_aPreMessages[i]);
  599. if (pManager != NULL && sName == pManager->GetName()) return pManager;
  600. }
  601. return NULL;
  602. }
  603. CStdPtrArray* CPaintManagerUI::GetPaintManagers()
  604. {
  605. return &m_aPreMessages;
  606. }
  607. bool CPaintManagerUI::LoadPlugin(LPCTSTR pstrModuleName)
  608. {
  609. ASSERT(!::IsBadStringPtr(pstrModuleName, -1) || pstrModuleName == NULL);
  610. if (pstrModuleName == NULL) return false;
  611. HMODULE hModule = ::LoadLibrary(pstrModuleName);
  612. if (hModule != NULL)
  613. {
  614. LPCREATECONTROL lpCreateControl = (LPCREATECONTROL)::GetProcAddress(hModule, "CreateControl");
  615. if (lpCreateControl != NULL)
  616. {
  617. if (m_aPlugins.Find(lpCreateControl) >= 0) return true;
  618. m_aPlugins.Add(lpCreateControl);
  619. return true;
  620. }
  621. }
  622. return false;
  623. }
  624. CStdPtrArray* CPaintManagerUI::GetPlugins()
  625. {
  626. return &m_aPlugins;
  627. }
  628. HWND CPaintManagerUI::GetPaintWindow() const
  629. {
  630. return m_hWndPaint;
  631. }
  632. HWND CPaintManagerUI::GetTooltipWindow() const
  633. {
  634. return m_hwndTooltip;
  635. }
  636. int CPaintManagerUI::GetHoverTime() const
  637. {
  638. return m_iHoverTime;
  639. }
  640. void CPaintManagerUI::SetHoverTime(int iTime)
  641. {
  642. m_iHoverTime = iTime;
  643. }
  644. LPCTSTR CPaintManagerUI::GetName() const
  645. {
  646. return m_sName;
  647. }
  648. HDC CPaintManagerUI::GetPaintDC() const
  649. {
  650. return m_hDcPaint;
  651. }
  652. POINT CPaintManagerUI::GetMousePos() const
  653. {
  654. return m_ptLastMousePos;
  655. }
  656. SIZE CPaintManagerUI::GetClientSize() const
  657. {
  658. RECT rcClient = { 0 };
  659. ::GetClientRect(m_hWndPaint, &rcClient);
  660. return CDuiSize(rcClient.right - rcClient.left, rcClient.bottom - rcClient.top);
  661. }
  662. SIZE CPaintManagerUI::GetInitSize()
  663. {
  664. return m_szInitWindowSize;
  665. }
  666. void CPaintManagerUI::SetInitSize(int cx, int cy)
  667. {
  668. m_szInitWindowSize.cx = cx;
  669. m_szInitWindowSize.cy = cy;
  670. if (m_pRoot == NULL && m_hWndPaint != NULL)
  671. {
  672. ::SetWindowPos(m_hWndPaint, NULL, 0, 0, cx, cy, SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
  673. }
  674. }
  675. RECT CPaintManagerUI::GetSizeBox()
  676. {
  677. return GetDPIObj()->Scale(m_rcSizeBox);
  678. }
  679. void CPaintManagerUI::SetSizeBox(RECT& rcSizeBox)
  680. {
  681. m_rcSizeBox = rcSizeBox;
  682. }
  683. RECT CPaintManagerUI::GetCaptionRect()
  684. {
  685. return GetDPIObj()->Scale(m_rcCaption);
  686. }
  687. void CPaintManagerUI::SetCaptionRect(RECT& rcCaption)
  688. {
  689. m_rcCaption = rcCaption;
  690. }
  691. SIZE CPaintManagerUI::GetRoundCorner()
  692. {
  693. return GetDPIObj()->Scale(m_szRoundCorner);
  694. }
  695. void CPaintManagerUI::SetRoundCorner(int cx, int cy)
  696. {
  697. m_szRoundCorner.cx = cx;
  698. m_szRoundCorner.cy = cy;
  699. }
  700. SIZE CPaintManagerUI::GetMinInfo()
  701. {
  702. return GetDPIObj()->Scale(m_szMinWindow);
  703. }
  704. void CPaintManagerUI::SetMinInfo(int cx, int cy)
  705. {
  706. ASSERT(cx >= 0 && cy >= 0);
  707. m_szMinWindow.cx = cx;
  708. m_szMinWindow.cy = cy;
  709. }
  710. SIZE CPaintManagerUI::GetMaxInfo()
  711. {
  712. return GetDPIObj()->Scale(m_szMaxWindow);
  713. }
  714. void CPaintManagerUI::SetMaxInfo(int cx, int cy)
  715. {
  716. ASSERT(cx >= 0 && cy >= 0);
  717. m_szMaxWindow.cx = cx;
  718. m_szMaxWindow.cy = cy;
  719. }
  720. bool CPaintManagerUI::IsShowUpdateRect()
  721. {
  722. return m_bShowUpdateRect;
  723. }
  724. void CPaintManagerUI::SetShowUpdateRect(bool show)
  725. {
  726. m_bShowUpdateRect = show;
  727. }
  728. bool CPaintManagerUI::IsNoActivate()
  729. {
  730. return m_bNoActivate;
  731. }
  732. void CPaintManagerUI::SetNoActivate(bool bNoActivate)
  733. {
  734. m_bNoActivate = bNoActivate;
  735. }
  736. BYTE CPaintManagerUI::GetOpacity() const
  737. {
  738. return m_nOpacity;
  739. }
  740. void CPaintManagerUI::SetOpacity(BYTE nOpacity)
  741. {
  742. m_nOpacity = nOpacity;
  743. if (m_hWndPaint != NULL)
  744. {
  745. typedef BOOL(__stdcall* PFUNCSETLAYEREDWINDOWATTR)(HWND, COLORREF, BYTE, DWORD);
  746. PFUNCSETLAYEREDWINDOWATTR fSetLayeredWindowAttributes = NULL;
  747. HMODULE hUser32 = ::GetModuleHandle(_T("User32.dll"));
  748. if (hUser32)
  749. {
  750. fSetLayeredWindowAttributes =
  751. (PFUNCSETLAYEREDWINDOWATTR)::GetProcAddress(hUser32, "SetLayeredWindowAttributes");
  752. if (fSetLayeredWindowAttributes == NULL) return;
  753. }
  754. DWORD dwStyle = ::GetWindowLong(m_hWndPaint, GWL_EXSTYLE);
  755. DWORD dwNewStyle = dwStyle;
  756. if (nOpacity >= 0 && nOpacity < 256) dwNewStyle |= WS_EX_LAYERED;
  757. else dwNewStyle &= ~WS_EX_LAYERED;
  758. if (dwStyle != dwNewStyle) ::SetWindowLong(m_hWndPaint, GWL_EXSTYLE, dwNewStyle);
  759. fSetLayeredWindowAttributes(m_hWndPaint, 0, nOpacity, LWA_ALPHA);
  760. }
  761. }
  762. bool CPaintManagerUI::IsLayered()
  763. {
  764. return m_bLayered;
  765. }
  766. void CPaintManagerUI::SetLayered(bool bLayered)
  767. {
  768. if (m_hWndPaint != NULL && bLayered != m_bLayered)
  769. {
  770. UINT uStyle = GetWindowStyle(m_hWndPaint);
  771. if ((uStyle & WS_CHILD) != 0) return;
  772. if (g_fUpdateLayeredWindow == NULL)
  773. {
  774. HMODULE hUser32 = ::GetModuleHandle(_T("User32.dll"));
  775. if (hUser32)
  776. {
  777. g_fUpdateLayeredWindow =
  778. (PFUNCUPDATELAYEREDWINDOW)::GetProcAddress(hUser32, "UpdateLayeredWindow");
  779. if (g_fUpdateLayeredWindow == NULL) return;
  780. }
  781. }
  782. m_bLayered = bLayered;
  783. if (m_pRoot != NULL) m_pRoot->NeedUpdate();
  784. Invalidate();
  785. }
  786. }
  787. RECT& CPaintManagerUI::GetLayeredInset()
  788. {
  789. return m_rcLayeredInset;
  790. }
  791. void CPaintManagerUI::SetLayeredInset(RECT& rcLayeredInset)
  792. {
  793. m_rcLayeredInset = rcLayeredInset;
  794. m_bLayeredChanged = true;
  795. Invalidate();
  796. }
  797. BYTE CPaintManagerUI::GetLayeredOpacity()
  798. {
  799. return m_nOpacity;
  800. }
  801. void CPaintManagerUI::SetLayeredOpacity(BYTE nOpacity)
  802. {
  803. m_nOpacity = nOpacity;
  804. m_bLayeredChanged = true;
  805. Invalidate();
  806. }
  807. LPCTSTR CPaintManagerUI::GetLayeredImage()
  808. {
  809. return m_diLayered.sDrawString;
  810. }
  811. void CPaintManagerUI::SetLayeredImage(LPCTSTR pstrImage)
  812. {
  813. m_diLayered.sDrawString = pstrImage;
  814. RECT rcNull = { 0 };
  815. CRenderEngine::DrawImageInfo(NULL, this, rcNull, rcNull, &m_diLayered);
  816. m_bLayeredChanged = true;
  817. Invalidate();
  818. }
  819. CShadowUI* CPaintManagerUI::GetShadow()
  820. {
  821. return &m_shadow;
  822. }
  823. void CPaintManagerUI::SetUseGdiplusText(bool bUse)
  824. {
  825. m_bUseGdiplusText = bUse;
  826. }
  827. bool CPaintManagerUI::IsUseGdiplusText() const
  828. {
  829. return m_bUseGdiplusText;
  830. }
  831. void CPaintManagerUI::SetGdiplusTextRenderingHint(int trh)
  832. {
  833. m_trh = trh;
  834. }
  835. int CPaintManagerUI::GetGdiplusTextRenderingHint() const
  836. {
  837. return m_trh;
  838. }
  839. bool CPaintManagerUI::PreMessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT& lRes)
  840. {
  841. for (int i = 0; i < m_aPreMessageFilters.GetSize(); i++)
  842. {
  843. bool bHandled = false;
  844. LRESULT lResult = static_cast<IMessageFilterUI*>(m_aPreMessageFilters[i])->MessageHandler(uMsg, wParam, lParam, bHandled);
  845. if (bHandled)
  846. {
  847. lRes = lResult;
  848. return true;
  849. }
  850. }
  851. switch (uMsg)
  852. {
  853. case WM_KEYDOWN:
  854. {
  855. // Tabbing between controls
  856. if (wParam == VK_TAB)
  857. {
  858. if (m_pFocus && m_pFocus->IsVisible() && m_pFocus->IsEnabled() && _tcsstr(m_pFocus->GetClass(), _T("RichEditUI")) != NULL)
  859. {
  860. if (static_cast<CRichEditUI*>(m_pFocus)->IsWantTab()) return false;
  861. }
  862. if (m_pFocus && m_pFocus->IsVisible() && m_pFocus->IsEnabled() && _tcsstr(m_pFocus->GetClass(), _T("WkeWebkitUI")) != NULL)
  863. {
  864. return false;
  865. }
  866. SetNextTabControl(::GetKeyState(VK_SHIFT) >= 0);
  867. return false;
  868. }
  869. }
  870. break;
  871. case WM_SYSCHAR:
  872. {
  873. // Handle ALT-shortcut key-combinations
  874. FINDSHORTCUT fs = { 0 };
  875. fs.ch = toupper((int)wParam);
  876. CControlUI* pControl = m_pRoot->FindControl(__FindControlFromShortcut, &fs, UIFIND_ENABLED | UIFIND_ME_FIRST | UIFIND_TOP_FIRST);
  877. if (pControl != NULL)
  878. {
  879. pControl->SetFocus();
  880. pControl->Activate();
  881. return true;
  882. }
  883. }
  884. break;
  885. case WM_SYSKEYDOWN:
  886. {
  887. if (m_pFocus != NULL)
  888. {
  889. TEventUI event = { 0 };
  890. event.Type = UIEVENT_SYSKEY;
  891. event.chKey = (TCHAR)wParam;
  892. event.ptMouse = m_ptLastMousePos;
  893. event.wKeyState = MapKeyState();
  894. event.dwTimestamp = ::GetTickCount();
  895. m_pFocus->Event(event);
  896. }
  897. }
  898. break;
  899. }
  900. return false;
  901. }
  902. bool CPaintManagerUI::MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT& lRes)
  903. {
  904. if (m_hWndPaint == NULL) return false;
  905. // [触屏兼容修复] 过滤 Windows 为“触摸手势”模拟出来的鼠标消息(ExtraInfo 带 MOUSEEVENTF_FROMTOUCH 标记)。
  906. // 背景:调用 RegisterTouchWindow 后,Windows 在把 WM_TOUCH 交给我们的同时,还会“模拟”出一套
  907. // WM_LBUTTONDOWN / WM_LBUTTONMOVE / WM_LBUTTONUP(以及可能的 WM_LBUTTONDBLCLK)。
  908. // 这些模拟消息若进入 DuiLib,会导致:
  909. // * 手指刚按下准备滑动就被当成“点击” —— 误把商品加入购物车;
  910. // * 滑动时经过的每个商品 item 都被置上悬浮态(UISTATE_HOT) 且无人清除 —— 多个 item 同时悬浮;
  911. // * 抬起后悬浮态卡死不消失。
  912. // 触摸手势的实际处理(滚动 / 轻触判定 / 惯性)由 CTouchWindowBase 通过 WM_TOUCH 完成,
  913. // 轻触时它会以“纯净鼠标消息”(ExtraInfo=0) 重新发一次 down+up 给真正需要点击的控件。
  914. //
  915. // 作用域天然正确:只有调用过 RegisterTouchWindow 的窗口(主窗口已在 OnCreate 注册)才会产生带
  916. // FROMTOUCH 标记的模拟鼠标;DuiLib 的下拉框/菜单等未注册触摸的弹出窗口不会产生该标记,照常进入
  917. // DuiLib,触摸点选不受影响。因此不必再用窗口属性做额外限定。
  918. // 注:未用 IsTouchWindow,因其声明要求 _WIN32_WINNT>=0x0601,本项目部分目标 SDK 没有该符号。
  919. if ((uMsg == WM_LBUTTONDOWN || uMsg == WM_LBUTTONUP || uMsg == WM_LBUTTONDBLCLK
  920. || uMsg == WM_MOUSEMOVE)
  921. && (::GetMessageExtraInfo() & 0xFF515700) == 0xFF515700)
  922. {
  923. lRes = 0;
  924. return true; // 标记为已处理,阻止 DuiLib 继续处理
  925. }
  926. // Cycle through listeners
  927. for (int i = 0; i < m_aMessageFilters.GetSize(); i++)
  928. {
  929. bool bHandled = false;
  930. LRESULT lResult = static_cast<IMessageFilterUI*>(m_aMessageFilters[i])->MessageHandler(uMsg, wParam, lParam, bHandled);
  931. if (bHandled)
  932. {
  933. lRes = lResult;
  934. switch (uMsg)
  935. {
  936. case WM_MOUSEMOVE:
  937. case WM_LBUTTONDOWN:
  938. case WM_LBUTTONDBLCLK:
  939. case WM_LBUTTONUP:
  940. {
  941. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  942. m_ptLastMousePos = pt;
  943. }
  944. break;
  945. case WM_CONTEXTMENU:
  946. case WM_MOUSEWHEEL:
  947. {
  948. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  949. ::ScreenToClient(m_hWndPaint, &pt);
  950. m_ptLastMousePos = pt;
  951. }
  952. break;
  953. }
  954. return true;
  955. }
  956. }
  957. if (m_bLayered)
  958. {
  959. switch (uMsg)
  960. {
  961. case WM_NCACTIVATE:
  962. if (!::IsIconic(m_hWndPaint))
  963. {
  964. lRes = (wParam == 0) ? TRUE : FALSE;
  965. return true;
  966. }
  967. break;
  968. case WM_NCCALCSIZE:
  969. case WM_NCPAINT:
  970. lRes = 0;
  971. return true;
  972. }
  973. }
  974. // Custom handling of events
  975. switch (uMsg)
  976. {
  977. case WM_APP + 1:
  978. {
  979. for (int i = 0; i < m_aDelayedCleanup.GetSize(); i++)
  980. delete static_cast<CControlUI*>(m_aDelayedCleanup[i]);
  981. m_aDelayedCleanup.Empty();
  982. m_bAsyncNotifyPosted = false;
  983. TNotifyUI* pMsg = NULL;
  984. while (pMsg = static_cast<TNotifyUI*>(m_aAsyncNotify.GetAt(0)))
  985. {
  986. m_aAsyncNotify.Remove(0);
  987. if (pMsg->pSender != NULL)
  988. {
  989. if (pMsg->pSender->OnNotify) pMsg->pSender->OnNotify(pMsg);
  990. }
  991. for (int j = 0; j < m_aNotifiers.GetSize(); j++)
  992. {
  993. static_cast<INotifyUI*>(m_aNotifiers[j])->Notify(*pMsg);
  994. }
  995. delete pMsg;
  996. }
  997. }
  998. break;
  999. case WM_CLOSE:
  1000. {
  1001. // Make sure all matching "closing" events are sent
  1002. TEventUI event = { 0 };
  1003. event.ptMouse = m_ptLastMousePos;
  1004. event.wKeyState = MapKeyState();
  1005. event.dwTimestamp = ::GetTickCount();
  1006. if (m_pEventHover != NULL)
  1007. {
  1008. event.Type = UIEVENT_MOUSELEAVE;
  1009. event.pSender = m_pEventHover;
  1010. m_pEventHover->Event(event);
  1011. }
  1012. if (m_pEventClick != NULL)
  1013. {
  1014. event.Type = UIEVENT_BUTTONUP;
  1015. event.pSender = m_pEventClick;
  1016. m_pEventClick->Event(event);
  1017. }
  1018. if (m_pEventRClick != NULL)
  1019. {
  1020. event.Type = UIEVENT_RBUTTONUP;
  1021. event.pSender = m_pEventClick;
  1022. m_pEventRClick->Event(event);
  1023. }
  1024. SetFocus(NULL);
  1025. if (::GetActiveWindow() == m_hWndPaint)
  1026. {
  1027. HWND hwndParent = GetWindowOwner(m_hWndPaint);
  1028. if (hwndParent != NULL) ::SetFocus(hwndParent);
  1029. }
  1030. if (m_hwndTooltip != NULL)
  1031. {
  1032. ::DestroyWindow(m_hwndTooltip);
  1033. m_hwndTooltip = NULL;
  1034. }
  1035. }
  1036. break;
  1037. case WM_ERASEBKGND:
  1038. {
  1039. // We'll do the painting here...
  1040. lRes = 1;
  1041. }
  1042. return true;
  1043. case WM_PAINT:
  1044. {
  1045. if (m_pRoot == NULL)
  1046. {
  1047. PAINTSTRUCT ps = { 0 };
  1048. ::BeginPaint(m_hWndPaint, &ps);
  1049. CRenderEngine::DrawColor(m_hDcPaint, ps.rcPaint, 0xFF000000);
  1050. ::EndPaint(m_hWndPaint, &ps);
  1051. return true;
  1052. }
  1053. RECT rcClient = { 0 };
  1054. ::GetClientRect(m_hWndPaint, &rcClient);
  1055. RECT rcPaint = { 0 };
  1056. if (!::GetUpdateRect(m_hWndPaint, &rcPaint, FALSE)) return true;
  1057. //if( m_bLayered ) {
  1058. // m_bOffscreenPaint = true;
  1059. // rcPaint = m_rcLayeredUpdate;
  1060. // if( ::IsRectEmpty(&m_rcLayeredUpdate) ) {
  1061. // PAINTSTRUCT ps = { 0 };
  1062. // ::BeginPaint(m_hWndPaint, &ps);
  1063. // ::EndPaint(m_hWndPaint, &ps);
  1064. // return true;
  1065. // }
  1066. // if( rcPaint.right > rcClient.right ) rcPaint.right = rcClient.right;
  1067. // if( rcPaint.bottom > rcClient.bottom ) rcPaint.bottom = rcClient.bottom;
  1068. // ::ZeroMemory(&m_rcLayeredUpdate, sizeof(m_rcLayeredUpdate));
  1069. //}
  1070. //else {
  1071. // if( !::GetUpdateRect(m_hWndPaint, &rcPaint, FALSE) ) return true;
  1072. //}
  1073. // Set focus to first control?
  1074. if (m_bFocusNeeded)
  1075. {
  1076. //修复新窗口自动切换焦点的问题
  1077. //SetNextTabControl();
  1078. m_bFocusNeeded = false;
  1079. }
  1080. SetPainting(true);
  1081. bool bNeedSizeMsg = false;
  1082. DWORD dwWidth = rcClient.right - rcClient.left;
  1083. DWORD dwHeight = rcClient.bottom - rcClient.top;
  1084. SetPainting(true);
  1085. if (m_bUpdateNeeded)
  1086. {
  1087. m_bUpdateNeeded = false;
  1088. if (!::IsRectEmpty(&rcClient) && !::IsIconic(m_hWndPaint))
  1089. {
  1090. if (m_pRoot->IsUpdateNeeded())
  1091. {
  1092. RECT rcRoot = rcClient;
  1093. if (m_hDcOffscreen != NULL) ::DeleteDC(m_hDcOffscreen);
  1094. if (m_hDcBackground != NULL) ::DeleteDC(m_hDcBackground);
  1095. if (m_hbmpOffscreen != NULL) ::DeleteObject(m_hbmpOffscreen);
  1096. if (m_hbmpBackground != NULL) ::DeleteObject(m_hbmpBackground);
  1097. m_hDcOffscreen = NULL;
  1098. m_hDcBackground = NULL;
  1099. m_hbmpOffscreen = NULL;
  1100. m_hbmpBackground = NULL;
  1101. if (m_bLayered)
  1102. {
  1103. rcRoot.left += m_rcLayeredInset.left;
  1104. rcRoot.top += m_rcLayeredInset.top;
  1105. rcRoot.right -= m_rcLayeredInset.right;
  1106. rcRoot.bottom -= m_rcLayeredInset.bottom;
  1107. }
  1108. m_pRoot->SetPos(rcRoot, true);
  1109. bNeedSizeMsg = true;
  1110. }
  1111. else
  1112. {
  1113. CControlUI* pControl = NULL;
  1114. m_aFoundControls.Empty();
  1115. m_pRoot->FindControl(__FindControlsFromUpdate, NULL, UIFIND_VISIBLE | UIFIND_ME_FIRST | UIFIND_UPDATETEST);
  1116. for (int it = 0; it < m_aFoundControls.GetSize(); it++)
  1117. {
  1118. pControl = static_cast<CControlUI*>(m_aFoundControls[it]);
  1119. pControl->SetPos(pControl->GetPos(), true);
  1120. }
  1121. bNeedSizeMsg = true;
  1122. }
  1123. // We'll want to notify the window when it is first initialized
  1124. // with the correct layout. The window form would take the time
  1125. // to submit swipes/animations.
  1126. if (m_bFirstLayout)
  1127. {
  1128. m_bFirstLayout = false;
  1129. SendNotify(m_pRoot, DUI_MSGTYPE_WINDOWINIT, 0, 0, false);
  1130. if (m_bLayered && m_bLayeredChanged)
  1131. {
  1132. Invalidate();
  1133. SetPainting(false);
  1134. return true;
  1135. }
  1136. // 更新阴影窗口显示
  1137. m_shadow.Update(m_hWndPaint);
  1138. }
  1139. }
  1140. }
  1141. else if (m_bLayered && m_bLayeredChanged)
  1142. {
  1143. RECT rcRoot = rcClient;
  1144. if (m_pOffscreenBits) ::ZeroMemory(m_pOffscreenBits, (rcRoot.right - rcRoot.left)
  1145. * (rcRoot.bottom - rcRoot.top) * 4);
  1146. rcRoot.left += m_rcLayeredInset.left;
  1147. rcRoot.top += m_rcLayeredInset.top;
  1148. rcRoot.right -= m_rcLayeredInset.right;
  1149. rcRoot.bottom -= m_rcLayeredInset.bottom;
  1150. m_pRoot->SetPos(rcRoot, true);
  1151. }
  1152. if (m_bLayered)
  1153. {
  1154. DWORD dwExStyle = ::GetWindowLong(m_hWndPaint, GWL_EXSTYLE);
  1155. DWORD dwNewExStyle = dwExStyle | WS_EX_LAYERED;
  1156. if (dwExStyle != dwNewExStyle) ::SetWindowLong(m_hWndPaint, GWL_EXSTYLE, dwNewExStyle);
  1157. m_bOffscreenPaint = true;
  1158. UnionRect(&rcPaint, &rcPaint, &m_rcLayeredUpdate);
  1159. if (rcPaint.right > rcClient.right) rcPaint.right = rcClient.right;
  1160. if (rcPaint.bottom > rcClient.bottom) rcPaint.bottom = rcClient.bottom;
  1161. ::ZeroMemory(&m_rcLayeredUpdate, sizeof(m_rcLayeredUpdate));
  1162. }
  1163. //
  1164. // Render screen
  1165. //
  1166. // Prepare offscreen bitmap
  1167. if (m_bOffscreenPaint && m_hbmpOffscreen == NULL)
  1168. {
  1169. m_hDcOffscreen = ::CreateCompatibleDC(m_hDcPaint);
  1170. m_hbmpOffscreen = CRenderEngine::CreateARGB32Bitmap(m_hDcPaint, dwWidth, dwHeight, (LPBYTE*)&m_pOffscreenBits);
  1171. ASSERT(m_hDcOffscreen);
  1172. ASSERT(m_hbmpOffscreen);
  1173. }
  1174. // Begin Windows paint
  1175. PAINTSTRUCT ps = { 0 };
  1176. ::BeginPaint(m_hWndPaint, &ps);
  1177. if (m_bOffscreenPaint)
  1178. {
  1179. HBITMAP hOldBitmap = (HBITMAP) ::SelectObject(m_hDcOffscreen, m_hbmpOffscreen);
  1180. int iSaveDC = ::SaveDC(m_hDcOffscreen);
  1181. if (m_bLayered)
  1182. {
  1183. for (LONG y = rcClient.bottom - rcPaint.bottom; y < rcClient.bottom - rcPaint.top; ++y)
  1184. {
  1185. for (LONG x = rcPaint.left; x < rcPaint.right; ++x)
  1186. {
  1187. int i = (y * dwWidth + x) * 4;
  1188. *(DWORD*)(&m_pOffscreenBits[i]) = 0;
  1189. }
  1190. }
  1191. }
  1192. m_pRoot->Paint(m_hDcOffscreen, rcPaint, NULL);
  1193. if (m_bLayered)
  1194. {
  1195. for (int i = 0; i < m_aNativeWindow.GetSize(); )
  1196. {
  1197. HWND hChildWnd = static_cast<HWND>(m_aNativeWindow[i]);
  1198. if (!::IsWindow(hChildWnd))
  1199. {
  1200. m_aNativeWindow.Remove(i);
  1201. m_aNativeWindowControl.Remove(i);
  1202. continue;
  1203. }
  1204. ++i;
  1205. if (!::IsWindowVisible(hChildWnd)) continue;
  1206. RECT rcChildWnd = GetNativeWindowRect(hChildWnd);
  1207. RECT rcTemp = { 0 };
  1208. if (!::IntersectRect(&rcTemp, &rcPaint, &rcChildWnd)) continue;
  1209. COLORREF* pChildBitmapBits = NULL;
  1210. HDC hChildMemDC = ::CreateCompatibleDC(m_hDcOffscreen);
  1211. HBITMAP hChildBitmap = CRenderEngine::CreateARGB32Bitmap(hChildMemDC, rcChildWnd.right - rcChildWnd.left, rcChildWnd.bottom - rcChildWnd.top, (BYTE**)&pChildBitmapBits);
  1212. ::ZeroMemory(pChildBitmapBits, (rcChildWnd.right - rcChildWnd.left) * (rcChildWnd.bottom - rcChildWnd.top) * 4);
  1213. HBITMAP hOldChildBitmap = (HBITMAP) ::SelectObject(hChildMemDC, hChildBitmap);
  1214. ::SendMessage(hChildWnd, WM_PRINT, (WPARAM)hChildMemDC, (LPARAM)(PRF_CHECKVISIBLE | PRF_CHILDREN | PRF_CLIENT | PRF_OWNED));
  1215. COLORREF* pChildBitmapBit;
  1216. for (LONG y = 0; y < rcChildWnd.bottom - rcChildWnd.top; y++)
  1217. {
  1218. for (LONG x = 0; x < rcChildWnd.right - rcChildWnd.left; x++)
  1219. {
  1220. pChildBitmapBit = pChildBitmapBits + y * (rcChildWnd.right - rcChildWnd.left) + x;
  1221. if (*pChildBitmapBit != 0x00000000) *pChildBitmapBit |= 0xff000000;
  1222. }
  1223. }
  1224. ::BitBlt(m_hDcOffscreen, rcChildWnd.left, rcChildWnd.top, rcChildWnd.right - rcChildWnd.left,
  1225. rcChildWnd.bottom - rcChildWnd.top, hChildMemDC, 0, 0, SRCCOPY);
  1226. ::SelectObject(hChildMemDC, hOldChildBitmap);
  1227. ::DeleteObject(hChildBitmap);
  1228. ::DeleteDC(hChildMemDC);
  1229. }
  1230. }
  1231. for (int i = 0; i < m_aPostPaintControls.GetSize(); i++)
  1232. {
  1233. CControlUI* pPostPaintControl = static_cast<CControlUI*>(m_aPostPaintControls[i]);
  1234. pPostPaintControl->DoPostPaint(m_hDcOffscreen, rcPaint);
  1235. }
  1236. ::RestoreDC(m_hDcOffscreen, iSaveDC);
  1237. if (m_bLayered)
  1238. {
  1239. RECT rcWnd = { 0 };
  1240. ::GetWindowRect(m_hWndPaint, &rcWnd);
  1241. if (!m_diLayered.sDrawString.IsEmpty())
  1242. {
  1243. DWORD dwWidth = rcClient.right - rcClient.left;
  1244. DWORD dwHeight = rcClient.bottom - rcClient.top;
  1245. RECT rcLayeredClient = rcClient;
  1246. rcLayeredClient.left += m_rcLayeredInset.left;
  1247. rcLayeredClient.top += m_rcLayeredInset.top;
  1248. rcLayeredClient.right -= m_rcLayeredInset.right;
  1249. rcLayeredClient.bottom -= m_rcLayeredInset.bottom;
  1250. COLORREF* pOffscreenBits = (COLORREF*)m_pOffscreenBits;
  1251. COLORREF* pBackgroundBits = m_pBackgroundBits;
  1252. BYTE A = 0;
  1253. BYTE R = 0;
  1254. BYTE G = 0;
  1255. BYTE B = 0;
  1256. if (!m_diLayered.sDrawString.IsEmpty())
  1257. {
  1258. if (m_hbmpBackground == NULL)
  1259. {
  1260. m_hDcBackground = ::CreateCompatibleDC(m_hDcPaint);
  1261. m_hbmpBackground = CRenderEngine::CreateARGB32Bitmap(m_hDcPaint, dwWidth, dwHeight, (BYTE**)&m_pBackgroundBits);
  1262. ::ZeroMemory(m_pBackgroundBits, dwWidth * dwHeight * 4);
  1263. ::SelectObject(m_hDcBackground, m_hbmpBackground);
  1264. CRenderClip clip;
  1265. CRenderClip::GenerateClip(m_hDcBackground, rcLayeredClient, clip);
  1266. CRenderEngine::DrawImageInfo(m_hDcBackground, this, rcLayeredClient, rcLayeredClient, &m_diLayered);
  1267. }
  1268. else if (m_bLayeredChanged)
  1269. {
  1270. ::ZeroMemory(m_pBackgroundBits, dwWidth * dwHeight * 4);
  1271. CRenderClip clip;
  1272. CRenderClip::GenerateClip(m_hDcBackground, rcLayeredClient, clip);
  1273. CRenderEngine::DrawImageInfo(m_hDcBackground, this, rcLayeredClient, rcLayeredClient, &m_diLayered);
  1274. }
  1275. for (LONG y = rcClient.bottom - rcPaint.bottom; y < rcClient.bottom - rcPaint.top; ++y)
  1276. {
  1277. for (LONG x = rcPaint.left; x < rcPaint.right; ++x)
  1278. {
  1279. pOffscreenBits = (COLORREF*)(m_pOffscreenBits + y * dwWidth + x);
  1280. pBackgroundBits = m_pBackgroundBits + y * dwWidth + x;
  1281. A = (BYTE)((*pBackgroundBits) >> 24);
  1282. R = (BYTE)((*pOffscreenBits) >> 16) * A / 255;
  1283. G = (BYTE)((*pOffscreenBits) >> 8) * A / 255;
  1284. B = (BYTE)(*pOffscreenBits) * A / 255;
  1285. *pOffscreenBits = RGB(B, G, R) + ((DWORD)A << 24);
  1286. }
  1287. }
  1288. }
  1289. }
  1290. else
  1291. {
  1292. for (LONG y = rcClient.bottom - rcPaint.bottom; y < rcClient.bottom - rcPaint.top; ++y)
  1293. {
  1294. for (LONG x = rcPaint.left; x < rcPaint.right; ++x)
  1295. {
  1296. int i = (y * dwWidth + x) * 4;
  1297. if ((m_pOffscreenBits[i + 3] == 0) && (m_pOffscreenBits[i + 0] != 0 || m_pOffscreenBits[i + 1] != 0 || m_pOffscreenBits[i + 2] != 0))
  1298. m_pOffscreenBits[i + 3] = 255;
  1299. }
  1300. }
  1301. }
  1302. BLENDFUNCTION bf = { AC_SRC_OVER, 0, m_nOpacity, AC_SRC_ALPHA };
  1303. POINT ptPos = { rcWnd.left, rcWnd.top };
  1304. SIZE sizeWnd = { dwWidth, dwHeight };
  1305. POINT ptSrc = { 0, 0 };
  1306. g_fUpdateLayeredWindow(m_hWndPaint, m_hDcPaint, &ptPos, &sizeWnd, m_hDcOffscreen, &ptSrc, 0, &bf, ULW_ALPHA);
  1307. }
  1308. else
  1309. {
  1310. ::BitBlt(m_hDcPaint, rcPaint.left, rcPaint.top, rcPaint.right - rcPaint.left, rcPaint.bottom - rcPaint.top, m_hDcOffscreen, rcPaint.left, rcPaint.top, SRCCOPY);
  1311. }
  1312. ::SelectObject(m_hDcOffscreen, hOldBitmap);
  1313. if (m_bShowUpdateRect && !m_bLayered)
  1314. {
  1315. HPEN hOldPen = (HPEN)::SelectObject(m_hDcPaint, m_hUpdateRectPen);
  1316. ::SelectObject(m_hDcPaint, ::GetStockObject(HOLLOW_BRUSH));
  1317. ::Rectangle(m_hDcPaint, rcPaint.left, rcPaint.top, rcPaint.right, rcPaint.bottom);
  1318. ::SelectObject(m_hDcPaint, hOldPen);
  1319. }
  1320. }
  1321. else
  1322. {
  1323. // A standard paint job
  1324. int iSaveDC = ::SaveDC(m_hDcPaint);
  1325. m_pRoot->Paint(m_hDcPaint, rcPaint, NULL);
  1326. for (int i = 0; i < m_aPostPaintControls.GetSize(); i++)
  1327. {
  1328. CControlUI* pPostPaintControl = static_cast<CControlUI*>(m_aPostPaintControls[i]);
  1329. pPostPaintControl->DoPostPaint(m_hDcPaint, rcPaint);
  1330. }
  1331. ::RestoreDC(m_hDcPaint, iSaveDC);
  1332. }
  1333. // All Done!
  1334. ::EndPaint(m_hWndPaint, &ps);
  1335. // 绘制结束
  1336. SetPainting(false);
  1337. m_bLayeredChanged = false;
  1338. if (m_bUpdateNeeded) Invalidate();
  1339. // 发送窗口大小改变消息
  1340. if (bNeedSizeMsg)
  1341. {
  1342. this->SendNotify(m_pRoot, DUI_MSGTYPE_WINDOWSIZE, 0, 0, true);
  1343. }
  1344. return true;
  1345. }
  1346. case WM_PRINTCLIENT:
  1347. {
  1348. if (m_pRoot == NULL) break;
  1349. RECT rcClient;
  1350. ::GetClientRect(m_hWndPaint, &rcClient);
  1351. HDC hDC = (HDC)wParam;
  1352. int save = ::SaveDC(hDC);
  1353. m_pRoot->Paint(hDC, rcClient, NULL);
  1354. if ((lParam & PRF_CHILDREN) != 0)
  1355. {
  1356. HWND hWndChild = ::GetWindow(m_hWndPaint, GW_CHILD);
  1357. while (hWndChild != NULL)
  1358. {
  1359. RECT rcPos = { 0 };
  1360. ::GetWindowRect(hWndChild, &rcPos);
  1361. ::MapWindowPoints(HWND_DESKTOP, m_hWndPaint, reinterpret_cast<LPPOINT>(&rcPos), 2);
  1362. ::SetWindowOrgEx(hDC, -rcPos.left, -rcPos.top, NULL);
  1363. ::SendMessage(hWndChild, WM_PRINT, wParam, lParam | PRF_NONCLIENT);
  1364. hWndChild = ::GetWindow(hWndChild, GW_HWNDNEXT);
  1365. }
  1366. }
  1367. ::RestoreDC(hDC, save);
  1368. }
  1369. break;
  1370. case WM_GETMINMAXINFO:
  1371. {
  1372. MONITORINFO Monitor = {};
  1373. Monitor.cbSize = sizeof(Monitor);
  1374. ::GetMonitorInfo(::MonitorFromWindow(m_hWndPaint, MONITOR_DEFAULTTOPRIMARY), &Monitor);
  1375. RECT rcWork = Monitor.rcWork;
  1376. if (Monitor.dwFlags != MONITORINFOF_PRIMARY)
  1377. {
  1378. ::OffsetRect(&rcWork, -rcWork.left, -rcWork.top);
  1379. }
  1380. LPMINMAXINFO lpMMI = (LPMINMAXINFO)lParam;
  1381. if (m_szMinWindow.cx > 0) lpMMI->ptMinTrackSize.x = m_szMinWindow.cx;
  1382. if (m_szMinWindow.cy > 0) lpMMI->ptMinTrackSize.y = m_szMinWindow.cy;
  1383. if (m_szMaxWindow.cx > 0) lpMMI->ptMaxTrackSize.x = m_szMaxWindow.cx;
  1384. if (m_szMaxWindow.cy > 0) lpMMI->ptMaxTrackSize.y = m_szMaxWindow.cy;
  1385. if (m_szMaxWindow.cx > 0) lpMMI->ptMaxSize.x = m_szMaxWindow.cx;
  1386. if (m_szMaxWindow.cy > 0) lpMMI->ptMaxSize.y = m_szMaxWindow.cy;
  1387. }
  1388. break;
  1389. case WM_SIZE:
  1390. {
  1391. if (m_pFocus != NULL)
  1392. {
  1393. TEventUI event = { 0 };
  1394. event.Type = UIEVENT_WINDOWSIZE;
  1395. event.pSender = m_pFocus;
  1396. event.dwTimestamp = ::GetTickCount();
  1397. m_pFocus->Event(event);
  1398. }
  1399. if (m_pRoot != NULL) m_pRoot->NeedUpdate();
  1400. }
  1401. return true;
  1402. case WM_TIMER:
  1403. {
  1404. for (int i = 0; i < m_aTimers.GetSize(); i++)
  1405. {
  1406. const TIMERINFO* pTimer = static_cast<TIMERINFO*>(m_aTimers[i]);
  1407. if (pTimer->hWnd == m_hWndPaint &&
  1408. pTimer->uWinTimer == LOWORD(wParam) &&
  1409. pTimer->bKilled == false)
  1410. {
  1411. TEventUI event = { 0 };
  1412. event.Type = UIEVENT_TIMER;
  1413. event.pSender = pTimer->pSender;
  1414. event.dwTimestamp = ::GetTickCount();
  1415. event.ptMouse = m_ptLastMousePos;
  1416. event.wKeyState = MapKeyState();
  1417. event.wParam = pTimer->nLocalID;
  1418. event.lParam = lParam;
  1419. pTimer->pSender->Event(event);
  1420. break;
  1421. }
  1422. }
  1423. }
  1424. break;
  1425. case WM_MOUSEHOVER:
  1426. {
  1427. m_bMouseTracking = false;
  1428. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  1429. CControlUI* pHover = FindControl(pt);
  1430. if (pHover == NULL) break;
  1431. // Generate mouse hover event
  1432. if (m_pEventHover != NULL)
  1433. {
  1434. TEventUI event = { 0 };
  1435. event.Type = UIEVENT_MOUSEHOVER;
  1436. event.pSender = m_pEventHover;
  1437. event.wParam = wParam;
  1438. event.lParam = lParam;
  1439. event.dwTimestamp = ::GetTickCount();
  1440. event.ptMouse = pt;
  1441. event.wKeyState = MapKeyState();
  1442. m_pEventHover->Event(event);
  1443. }
  1444. // Create tooltip information
  1445. CDuiString sToolTip = pHover->GetToolTip();
  1446. if (sToolTip.IsEmpty()) return true;
  1447. ::ZeroMemory(&m_ToolTip, sizeof(TOOLINFO));
  1448. m_ToolTip.cbSize = sizeof(TOOLINFO);
  1449. m_ToolTip.uFlags = TTF_IDISHWND;
  1450. m_ToolTip.hwnd = m_hWndPaint;
  1451. m_ToolTip.uId = (UINT_PTR)m_hWndPaint;
  1452. m_ToolTip.hinst = m_hInstance;
  1453. m_ToolTip.lpszText = const_cast<LPTSTR>((LPCTSTR)sToolTip);
  1454. m_ToolTip.rect = pHover->GetPos();
  1455. if (m_hwndTooltip == NULL)
  1456. {
  1457. m_hwndTooltip = ::CreateWindowEx(0, TOOLTIPS_CLASS, NULL, WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, m_hWndPaint, NULL, m_hInstance, NULL);
  1458. ::SendMessage(m_hwndTooltip, TTM_ADDTOOL, 0, (LPARAM)&m_ToolTip);
  1459. ::SendMessage(m_hwndTooltip, TTM_SETMAXTIPWIDTH, 0, pHover->GetToolTipWidth());
  1460. }
  1461. if (!::IsWindowVisible(m_hwndTooltip))
  1462. {
  1463. ::SendMessage(m_hwndTooltip, TTM_SETTOOLINFO, 0, (LPARAM)&m_ToolTip);
  1464. ::SendMessage(m_hwndTooltip, TTM_TRACKACTIVATE, TRUE, (LPARAM)&m_ToolTip);
  1465. }
  1466. }
  1467. return true;
  1468. case WM_MOUSELEAVE:
  1469. {
  1470. if (m_hwndTooltip != NULL) ::SendMessage(m_hwndTooltip, TTM_TRACKACTIVATE, FALSE, (LPARAM)&m_ToolTip);
  1471. if (m_bMouseTracking)
  1472. {
  1473. POINT pt = { 0 };
  1474. RECT rcWnd = { 0 };
  1475. ::GetCursorPos(&pt);
  1476. ::GetWindowRect(m_hWndPaint, &rcWnd);
  1477. if (!::IsIconic(m_hWndPaint) && ::GetActiveWindow() == m_hWndPaint && ::PtInRect(&rcWnd, pt))
  1478. {
  1479. if (::SendMessage(m_hWndPaint, WM_NCHITTEST, 0, MAKELPARAM(pt.x, pt.y)) == HTCLIENT)
  1480. {
  1481. ::ScreenToClient(m_hWndPaint, &pt);
  1482. ::SendMessage(m_hWndPaint, WM_MOUSEMOVE, 0, MAKELPARAM(pt.x, pt.y));
  1483. }
  1484. else
  1485. ::SendMessage(m_hWndPaint, WM_MOUSEMOVE, 0, (LPARAM)-1);
  1486. }
  1487. else
  1488. ::SendMessage(m_hWndPaint, WM_MOUSEMOVE, 0, (LPARAM)-1);
  1489. }
  1490. m_bMouseTracking = false;
  1491. }
  1492. break;
  1493. case WM_MOUSEMOVE:
  1494. {
  1495. // Start tracking this entire window again...
  1496. if (!m_bMouseTracking)
  1497. {
  1498. TRACKMOUSEEVENT tme = { 0 };
  1499. tme.cbSize = sizeof(TRACKMOUSEEVENT);
  1500. tme.dwFlags = TME_HOVER | TME_LEAVE;
  1501. tme.hwndTrack = m_hWndPaint;
  1502. tme.dwHoverTime = m_hwndTooltip == NULL ? m_iHoverTime : (DWORD) ::SendMessage(m_hwndTooltip, TTM_GETDELAYTIME, TTDT_INITIAL, 0L);
  1503. _TrackMouseEvent(&tme);
  1504. m_bMouseTracking = true;
  1505. }
  1506. // Generate the appropriate mouse messages
  1507. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  1508. // 是否移动
  1509. bool bNeedDrag = true;
  1510. if (m_ptLastMousePos.x == pt.x && m_ptLastMousePos.y == pt.y)
  1511. {
  1512. bNeedDrag = false;
  1513. }
  1514. // 记录鼠标位置
  1515. m_ptLastMousePos = pt;
  1516. CControlUI* pNewHover = FindControl(pt);
  1517. if (pNewHover != NULL && pNewHover->GetManager() != this) break;
  1518. // 拖拽事件
  1519. if (bNeedDrag && m_bDragMode && wParam == MK_LBUTTON)
  1520. {
  1521. // 释放Capture
  1522. ::ReleaseCapture();
  1523. // 接口
  1524. if (m_pDragDrop != NULL && m_pDragDrop->OnDragDrop(m_pEventClick))
  1525. {
  1526. m_bDragMode = false;
  1527. break;
  1528. }
  1529. CIDropSource* pdsrc = new CIDropSource;
  1530. if (pdsrc == NULL) return 0;
  1531. pdsrc->AddRef();
  1532. CIDataObject* pdobj = new CIDataObject(pdsrc);
  1533. if (pdobj == NULL) return 0;
  1534. pdobj->AddRef();
  1535. FORMATETC fmtetc = { 0 };
  1536. STGMEDIUM medium = { 0 };
  1537. fmtetc.dwAspect = DVASPECT_CONTENT;
  1538. fmtetc.lindex = -1;
  1539. fmtetc.cfFormat = CF_BITMAP;
  1540. fmtetc.tymed = TYMED_GDI;
  1541. //////////////////////////////////////
  1542. HBITMAP hBitmap = (HBITMAP)OleDuplicateData(m_hDragBitmap, fmtetc.cfFormat, NULL);
  1543. medium.hBitmap = hBitmap;
  1544. pdobj->SetData(&fmtetc, &medium, FALSE);
  1545. //////////////////////////////////////
  1546. BITMAP bmap;
  1547. GetObject(hBitmap, sizeof(BITMAP), &bmap);
  1548. RECT rc = { 0, 0, bmap.bmWidth, bmap.bmHeight };
  1549. fmtetc.cfFormat = CF_ENHMETAFILE;
  1550. fmtetc.tymed = TYMED_ENHMF;
  1551. HDC hMetaDC = CreateEnhMetaFile(m_hDcPaint, NULL, NULL, NULL);
  1552. HDC hdcMem = CreateCompatibleDC(m_hDcPaint);
  1553. HGDIOBJ hOldBmp = ::SelectObject(hdcMem, hBitmap);
  1554. ::BitBlt(hMetaDC, 0, 0, rc.right, rc.bottom, hdcMem, 0, 0, SRCCOPY);
  1555. ::SelectObject(hdcMem, hOldBmp);
  1556. medium.hEnhMetaFile = CloseEnhMetaFile(hMetaDC);
  1557. DeleteDC(hdcMem);
  1558. medium.tymed = TYMED_ENHMF;
  1559. pdobj->SetData(&fmtetc, &medium, TRUE);
  1560. //////////////////////////////////////
  1561. CDragSourceHelper dragSrcHelper;
  1562. POINT ptDrag = { 0 };
  1563. ptDrag.x = bmap.bmWidth / 2;
  1564. ptDrag.y = bmap.bmHeight / 2;
  1565. dragSrcHelper.InitializeFromBitmap(hBitmap, ptDrag, rc, pdobj); //will own the bmp
  1566. DWORD dwEffect;
  1567. HRESULT hr = ::DoDragDrop(pdobj, pdsrc, DROPEFFECT_COPY | DROPEFFECT_MOVE, &dwEffect);
  1568. if (dwEffect) pdsrc->Release();
  1569. else delete pdsrc;
  1570. pdobj->Release();
  1571. m_bDragMode = false;
  1572. break;
  1573. }
  1574. TEventUI event = { 0 };
  1575. event.ptMouse = pt;
  1576. event.wParam = wParam;
  1577. event.lParam = lParam;
  1578. event.dwTimestamp = ::GetTickCount();
  1579. event.wKeyState = MapKeyState();
  1580. if (!IsCaptured())
  1581. {
  1582. pNewHover = FindControl(pt);
  1583. if (pNewHover != NULL && pNewHover->GetManager() != this) break;
  1584. if (pNewHover != m_pEventHover && m_pEventHover != NULL)
  1585. {
  1586. event.Type = UIEVENT_MOUSELEAVE;
  1587. event.pSender = m_pEventHover;
  1588. CStdPtrArray aNeedMouseLeaveNeeded(m_aNeedMouseLeaveNeeded.GetSize());
  1589. aNeedMouseLeaveNeeded.Resize(m_aNeedMouseLeaveNeeded.GetSize());
  1590. ::CopyMemory(aNeedMouseLeaveNeeded.GetData(), m_aNeedMouseLeaveNeeded.GetData(), m_aNeedMouseLeaveNeeded.GetSize() * sizeof(LPVOID));
  1591. for (int i = 0; i < aNeedMouseLeaveNeeded.GetSize(); i++)
  1592. {
  1593. static_cast<CControlUI*>(aNeedMouseLeaveNeeded[i])->Event(event);
  1594. }
  1595. m_pEventHover->Event(event);
  1596. m_pEventHover = NULL;
  1597. if (m_hwndTooltip != NULL) ::SendMessage(m_hwndTooltip, TTM_TRACKACTIVATE, FALSE, (LPARAM)&m_ToolTip);
  1598. }
  1599. if (pNewHover != m_pEventHover && pNewHover != NULL)
  1600. {
  1601. event.Type = UIEVENT_MOUSEENTER;
  1602. event.pSender = pNewHover;
  1603. pNewHover->Event(event);
  1604. m_pEventHover = pNewHover;
  1605. }
  1606. }
  1607. if (m_pEventClick != NULL)
  1608. {
  1609. event.Type = UIEVENT_MOUSEMOVE;
  1610. event.pSender = m_pEventClick;
  1611. m_pEventClick->Event(event);
  1612. }
  1613. else if (pNewHover != NULL)
  1614. {
  1615. event.Type = UIEVENT_MOUSEMOVE;
  1616. event.pSender = pNewHover;
  1617. pNewHover->Event(event);
  1618. }
  1619. }
  1620. break;
  1621. case WM_LBUTTONDOWN:
  1622. {
  1623. // We alway set focus back to our app (this helps
  1624. // when Win32 child windows are placed on the dialog
  1625. // and we need to remove them on focus change).
  1626. if (!m_bNoActivate) ::SetFocus(m_hWndPaint);
  1627. if (m_pRoot == NULL) break;
  1628. // 查找控件
  1629. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  1630. m_ptLastMousePos = pt;
  1631. CControlUI* pControl = FindControl(pt);
  1632. if (pControl == NULL) break;
  1633. if (pControl->GetManager() != this) break;
  1634. // 准备拖拽
  1635. if (m_bDragDrop && pControl->IsDragEnabled())
  1636. {
  1637. m_bDragMode = true;
  1638. if (m_hDragBitmap != NULL)
  1639. {
  1640. ::DeleteObject(m_hDragBitmap);
  1641. m_hDragBitmap = NULL;
  1642. }
  1643. m_hDragBitmap = CRenderEngine::GenerateBitmap(this, pControl, pControl->GetPos());
  1644. }
  1645. // 开启捕获
  1646. SetCapture();
  1647. // 事件处理
  1648. m_pEventClick = pControl;
  1649. pControl->SetFocus();
  1650. TEventUI event = { 0 };
  1651. event.Type = UIEVENT_BUTTONDOWN;
  1652. event.pSender = pControl;
  1653. event.wParam = wParam;
  1654. event.lParam = lParam;
  1655. event.ptMouse = pt;
  1656. event.wKeyState = (WORD)wParam;
  1657. event.dwTimestamp = ::GetTickCount();
  1658. pControl->Event(event);
  1659. }
  1660. break;
  1661. case WM_LBUTTONDBLCLK:
  1662. {
  1663. if (!m_bNoActivate) ::SetFocus(m_hWndPaint);
  1664. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  1665. m_ptLastMousePos = pt;
  1666. CControlUI* pControl = FindControl(pt);
  1667. if (pControl == NULL) break;
  1668. if (pControl->GetManager() != this) break;
  1669. //SetCapture();
  1670. TEventUI event = { 0 };
  1671. event.Type = UIEVENT_DBLCLICK;
  1672. event.pSender = pControl;
  1673. event.ptMouse = pt;
  1674. event.wParam = wParam;
  1675. event.lParam = lParam;
  1676. event.wKeyState = (WORD)wParam;
  1677. event.dwTimestamp = ::GetTickCount();
  1678. pControl->Event(event);
  1679. m_pEventClick = pControl;
  1680. }
  1681. break;
  1682. case WM_LBUTTONUP:
  1683. {
  1684. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  1685. m_ptLastMousePos = pt;
  1686. if (m_pEventClick == NULL) break;
  1687. ReleaseCapture();
  1688. TEventUI event = { 0 };
  1689. event.Type = UIEVENT_BUTTONUP;
  1690. event.pSender = m_pEventClick;
  1691. event.wParam = wParam;
  1692. event.lParam = lParam;
  1693. event.ptMouse = pt;
  1694. event.wKeyState = (WORD)wParam;
  1695. event.dwTimestamp = ::GetTickCount();
  1696. CControlUI* pClick = m_pEventClick;
  1697. m_pEventClick = NULL;
  1698. pClick->Event(event);
  1699. }
  1700. break;
  1701. case WM_RBUTTONDOWN:
  1702. {
  1703. if (!m_bNoActivate) ::SetFocus(m_hWndPaint);
  1704. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  1705. m_ptLastMousePos = pt;
  1706. CControlUI* pControl = FindControl(pt);
  1707. if (pControl == NULL) break;
  1708. if (pControl->GetManager() != this) break;
  1709. pControl->SetFocus();
  1710. SetCapture();
  1711. TEventUI event = { 0 };
  1712. event.Type = UIEVENT_RBUTTONDOWN;
  1713. event.pSender = pControl;
  1714. event.wParam = wParam;
  1715. event.lParam = lParam;
  1716. event.ptMouse = pt;
  1717. event.wKeyState = (WORD)wParam;
  1718. event.dwTimestamp = ::GetTickCount();
  1719. pControl->Event(event);
  1720. m_pEventRClick = pControl;
  1721. }
  1722. break;
  1723. case WM_RBUTTONUP:
  1724. {
  1725. if (m_bMouseCapture) ReleaseCapture();
  1726. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  1727. m_ptLastMousePos = pt;
  1728. m_pEventRClick = FindControl(pt);
  1729. if (m_pEventRClick == NULL) break;
  1730. TEventUI event = { 0 };
  1731. event.Type = UIEVENT_RBUTTONUP;
  1732. event.pSender = m_pEventRClick;
  1733. event.wParam = wParam;
  1734. event.lParam = lParam;
  1735. event.ptMouse = pt;
  1736. event.wKeyState = (WORD)wParam;
  1737. event.dwTimestamp = ::GetTickCount();
  1738. m_pEventRClick->Event(event);
  1739. }
  1740. break;
  1741. case WM_MBUTTONDOWN:
  1742. {
  1743. if (!m_bNoActivate) ::SetFocus(m_hWndPaint);
  1744. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  1745. m_ptLastMousePos = pt;
  1746. CControlUI* pControl = FindControl(pt);
  1747. if (pControl == NULL) break;
  1748. if (pControl->GetManager() != this) break;
  1749. pControl->SetFocus();
  1750. SetCapture();
  1751. TEventUI event = { 0 };
  1752. event.Type = UIEVENT_MBUTTONDOWN;
  1753. event.pSender = pControl;
  1754. event.wParam = wParam;
  1755. event.lParam = lParam;
  1756. event.ptMouse = pt;
  1757. event.wKeyState = (WORD)wParam;
  1758. event.dwTimestamp = ::GetTickCount();
  1759. pControl->Event(event);
  1760. m_pEventClick = pControl;
  1761. }
  1762. break;
  1763. case WM_MBUTTONUP:
  1764. {
  1765. if (m_bMouseCapture) ReleaseCapture();
  1766. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  1767. m_ptLastMousePos = pt;
  1768. m_pEventClick = FindControl(pt);
  1769. if (m_pEventClick == NULL) break;
  1770. TEventUI event = { 0 };
  1771. event.Type = UIEVENT_MBUTTONUP;
  1772. event.pSender = m_pEventClick;
  1773. event.wParam = wParam;
  1774. event.lParam = lParam;
  1775. event.ptMouse = pt;
  1776. event.wKeyState = (WORD)wParam;
  1777. event.dwTimestamp = ::GetTickCount();
  1778. m_pEventClick->Event(event);
  1779. }
  1780. break;
  1781. case WM_CONTEXTMENU:
  1782. {
  1783. if (m_pRoot == NULL) break;
  1784. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  1785. ::ScreenToClient(m_hWndPaint, &pt);
  1786. m_ptLastMousePos = pt;
  1787. if (m_pEventRClick == NULL) break;
  1788. ReleaseCapture();
  1789. TEventUI event = { 0 };
  1790. event.Type = UIEVENT_CONTEXTMENU;
  1791. event.pSender = m_pEventRClick;
  1792. event.wParam = wParam;
  1793. event.lParam = lParam;
  1794. event.ptMouse = pt;
  1795. event.wKeyState = (WORD)wParam;
  1796. event.lParam = (LPARAM)m_pEventRClick;
  1797. event.dwTimestamp = ::GetTickCount();
  1798. m_pEventRClick->Event(event);
  1799. m_pEventRClick = NULL;
  1800. }
  1801. break;
  1802. case WM_MOUSEWHEEL:
  1803. {
  1804. if (m_pRoot == NULL) break;
  1805. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  1806. ::ScreenToClient(m_hWndPaint, &pt);
  1807. m_ptLastMousePos = pt;
  1808. CControlUI* pControl = FindControl(pt);
  1809. if (pControl == NULL) break;
  1810. if (pControl->GetManager() != this) break;
  1811. int zDelta = (int)(short)HIWORD(wParam);
  1812. TEventUI event = { 0 };
  1813. event.Type = UIEVENT_SCROLLWHEEL;
  1814. event.pSender = pControl;
  1815. event.wParam = MAKEWPARAM(zDelta < 0 ? SB_LINEDOWN : SB_LINEUP, zDelta);
  1816. event.lParam = lParam;
  1817. event.ptMouse = pt;
  1818. event.wKeyState = MapKeyState();
  1819. event.dwTimestamp = ::GetTickCount();
  1820. pControl->Event(event);
  1821. // Let's make sure that the scroll item below the cursor is the same as before...
  1822. ::SendMessage(m_hWndPaint, WM_MOUSEMOVE, 0, (LPARAM)MAKELPARAM(m_ptLastMousePos.x, m_ptLastMousePos.y));
  1823. }
  1824. break;
  1825. case WM_CHAR:
  1826. {
  1827. if (m_pRoot == NULL) break;
  1828. if (m_pFocus == NULL) break;
  1829. TEventUI event = { 0 };
  1830. event.Type = UIEVENT_CHAR;
  1831. event.pSender = m_pFocus;
  1832. event.wParam = wParam;
  1833. event.lParam = lParam;
  1834. event.chKey = (TCHAR)wParam;
  1835. event.ptMouse = m_ptLastMousePos;
  1836. event.wKeyState = MapKeyState();
  1837. event.dwTimestamp = ::GetTickCount();
  1838. m_pFocus->Event(event);
  1839. }
  1840. break;
  1841. case WM_KEYDOWN:
  1842. {
  1843. if (m_pRoot == NULL) break;
  1844. if (m_pFocus == NULL) break;
  1845. TEventUI event = { 0 };
  1846. event.Type = UIEVENT_KEYDOWN;
  1847. event.pSender = m_pFocus;
  1848. event.wParam = wParam;
  1849. event.lParam = lParam;
  1850. event.chKey = (TCHAR)wParam;
  1851. event.ptMouse = m_ptLastMousePos;
  1852. event.wKeyState = MapKeyState();
  1853. event.dwTimestamp = ::GetTickCount();
  1854. m_pFocus->Event(event);
  1855. m_pEventKey = m_pFocus;
  1856. }
  1857. break;
  1858. case WM_KEYUP:
  1859. {
  1860. if (m_pRoot == NULL) break;
  1861. if (m_pEventKey == NULL) break;
  1862. TEventUI event = { 0 };
  1863. event.Type = UIEVENT_KEYUP;
  1864. event.pSender = m_pEventKey;
  1865. event.wParam = wParam;
  1866. event.lParam = lParam;
  1867. event.chKey = (TCHAR)wParam;
  1868. event.ptMouse = m_ptLastMousePos;
  1869. event.wKeyState = MapKeyState();
  1870. event.dwTimestamp = ::GetTickCount();
  1871. m_pEventKey->Event(event);
  1872. m_pEventKey = NULL;
  1873. }
  1874. break;
  1875. case WM_SETCURSOR:
  1876. {
  1877. if (m_pRoot == NULL) break;
  1878. if (LOWORD(lParam) != HTCLIENT) break;
  1879. if (m_bMouseCapture) return true;
  1880. POINT pt = { 0 };
  1881. ::GetCursorPos(&pt);
  1882. ::ScreenToClient(m_hWndPaint, &pt);
  1883. CControlUI* pControl = FindControl(pt);
  1884. if (pControl == NULL) break;
  1885. if ((pControl->GetControlFlags() & UIFLAG_SETCURSOR) == 0) break;
  1886. TEventUI event = { 0 };
  1887. event.Type = UIEVENT_SETCURSOR;
  1888. event.pSender = pControl;
  1889. event.wParam = wParam;
  1890. event.lParam = lParam;
  1891. event.ptMouse = pt;
  1892. event.wKeyState = MapKeyState();
  1893. event.dwTimestamp = ::GetTickCount();
  1894. pControl->Event(event);
  1895. }
  1896. return true;
  1897. case WM_SETFOCUS:
  1898. {
  1899. if (m_pFocus != NULL)
  1900. {
  1901. TEventUI event = { 0 };
  1902. event.Type = UIEVENT_SETFOCUS;
  1903. event.wParam = wParam;
  1904. event.lParam = lParam;
  1905. event.pSender = m_pFocus;
  1906. event.dwTimestamp = ::GetTickCount();
  1907. m_pFocus->Event(event);
  1908. }
  1909. break;
  1910. }
  1911. case WM_KILLFOCUS:
  1912. {
  1913. if (IsCaptured()) ReleaseCapture();
  1914. break;
  1915. }
  1916. case WM_NOTIFY:
  1917. {
  1918. if (lParam == 0) break;
  1919. LPNMHDR lpNMHDR = (LPNMHDR)lParam;
  1920. if (lpNMHDR != NULL) lRes = ::SendMessage(lpNMHDR->hwndFrom, OCM__BASE + uMsg, wParam, lParam);
  1921. return true;
  1922. }
  1923. break;
  1924. case WM_COMMAND:
  1925. {
  1926. if (lParam == 0) break;
  1927. HWND hWndChild = (HWND)lParam;
  1928. lRes = ::SendMessage(hWndChild, OCM__BASE + uMsg, wParam, lParam);
  1929. if (lRes != 0) return true;
  1930. }
  1931. break;
  1932. case WM_CTLCOLOREDIT:
  1933. case WM_CTLCOLORSTATIC:
  1934. {
  1935. // Refer To: http://msdn.microsoft.com/en-us/library/bb761691(v=vs.85).aspx
  1936. // Read-only or disabled edit controls do not send the WM_CTLCOLOREDIT message; instead, they send the WM_CTLCOLORSTATIC message.
  1937. if (lParam == 0) break;
  1938. HWND hWndChild = (HWND)lParam;
  1939. lRes = ::SendMessage(hWndChild, OCM__BASE + uMsg, wParam, lParam);
  1940. if (lRes != 0) return true;
  1941. }
  1942. break;
  1943. default:
  1944. break;
  1945. }
  1946. return false;
  1947. }
  1948. bool CPaintManagerUI::IsUpdateNeeded() const
  1949. {
  1950. return m_bUpdateNeeded;
  1951. }
  1952. void CPaintManagerUI::NeedUpdate()
  1953. {
  1954. m_bUpdateNeeded = true;
  1955. }
  1956. void CPaintManagerUI::Invalidate()
  1957. {
  1958. RECT rcClient = { 0 };
  1959. ::GetClientRect(m_hWndPaint, &rcClient);
  1960. ::UnionRect(&m_rcLayeredUpdate, &m_rcLayeredUpdate, &rcClient);
  1961. ::InvalidateRect(m_hWndPaint, NULL, FALSE);
  1962. }
  1963. void CPaintManagerUI::Invalidate(RECT& rcItem)
  1964. {
  1965. if (rcItem.left < 0) rcItem.left = 0;
  1966. if (rcItem.top < 0) rcItem.top = 0;
  1967. if (rcItem.right < rcItem.left) rcItem.right = rcItem.left;
  1968. if (rcItem.bottom < rcItem.top) rcItem.bottom = rcItem.top;
  1969. ::UnionRect(&m_rcLayeredUpdate, &m_rcLayeredUpdate, &rcItem);
  1970. ::InvalidateRect(m_hWndPaint, &rcItem, FALSE);
  1971. }
  1972. bool CPaintManagerUI::IsValid()
  1973. {
  1974. return m_hWndPaint != NULL && m_pRoot != NULL;
  1975. }
  1976. bool CPaintManagerUI::AttachDialog(CControlUI* pControl)
  1977. {
  1978. ASSERT(::IsWindow(m_hWndPaint));
  1979. // 创建阴影窗口
  1980. m_shadow.Create(this);
  1981. // Reset any previous attachment
  1982. SetFocus(NULL);
  1983. m_pEventKey = NULL;
  1984. m_pEventHover = NULL;
  1985. m_pEventClick = NULL;
  1986. m_pEventRClick = NULL;
  1987. // Remove the existing control-tree. We might have gotten inside this function as
  1988. // a result of an event fired or similar, so we cannot just delete the objects and
  1989. // pull the internal memory of the calling code. We'll delay the cleanup.
  1990. if (m_pRoot != NULL)
  1991. {
  1992. m_aPostPaintControls.Empty();
  1993. AddDelayedCleanup(m_pRoot);
  1994. }
  1995. // Set the dialog root element
  1996. m_pRoot = pControl;
  1997. // Go ahead...
  1998. m_bUpdateNeeded = true;
  1999. m_bFirstLayout = true;
  2000. m_bFocusNeeded = true;
  2001. // Initiate all control
  2002. return InitControls(pControl);
  2003. }
  2004. bool CPaintManagerUI::InitControls(CControlUI* pControl, CControlUI* pParent /*= NULL*/)
  2005. {
  2006. ASSERT(pControl);
  2007. if (pControl == NULL) return false;
  2008. pControl->SetManager(this, pParent != NULL ? pParent : pControl->GetParent(), true);
  2009. pControl->FindControl(__FindControlFromNameHash, this, UIFIND_ALL);
  2010. return true;
  2011. }
  2012. void CPaintManagerUI::ReapObjects(CControlUI* pControl)
  2013. {
  2014. if (pControl == m_pEventKey) m_pEventKey = NULL;
  2015. if (pControl == m_pEventHover) m_pEventHover = NULL;
  2016. if (pControl == m_pEventClick) m_pEventClick = NULL;
  2017. if (pControl == m_pEventRClick) m_pEventRClick = NULL;
  2018. if (pControl == m_pFocus) m_pFocus = NULL;
  2019. KillTimer(pControl);
  2020. const CDuiString& sName = pControl->GetName();
  2021. if (!sName.IsEmpty())
  2022. {
  2023. if (pControl == FindControl(sName)) m_mNameHash.Remove(sName);
  2024. }
  2025. for (int i = 0; i < m_aAsyncNotify.GetSize(); i++)
  2026. {
  2027. TNotifyUI* pMsg = static_cast<TNotifyUI*>(m_aAsyncNotify[i]);
  2028. if (pMsg->pSender == pControl) pMsg->pSender = NULL;
  2029. }
  2030. }
  2031. bool CPaintManagerUI::AddOptionGroup(LPCTSTR pStrGroupName, CControlUI* pControl)
  2032. {
  2033. LPVOID lp = m_mOptionGroup.Find(pStrGroupName);
  2034. if (lp)
  2035. {
  2036. CStdPtrArray* aOptionGroup = static_cast<CStdPtrArray*>(lp);
  2037. for (int i = 0; i < aOptionGroup->GetSize(); i++)
  2038. {
  2039. if (static_cast<CControlUI*>(aOptionGroup->GetAt(i)) == pControl)
  2040. {
  2041. return false;
  2042. }
  2043. }
  2044. aOptionGroup->Add(pControl);
  2045. }
  2046. else
  2047. {
  2048. CStdPtrArray* aOptionGroup = new CStdPtrArray(6);
  2049. aOptionGroup->Add(pControl);
  2050. m_mOptionGroup.Insert(pStrGroupName, aOptionGroup);
  2051. }
  2052. return true;
  2053. }
  2054. CStdPtrArray* CPaintManagerUI::GetOptionGroup(LPCTSTR pStrGroupName)
  2055. {
  2056. LPVOID lp = m_mOptionGroup.Find(pStrGroupName);
  2057. if (lp) return static_cast<CStdPtrArray*>(lp);
  2058. return NULL;
  2059. }
  2060. void CPaintManagerUI::RemoveOptionGroup(LPCTSTR pStrGroupName, CControlUI* pControl)
  2061. {
  2062. LPVOID lp = m_mOptionGroup.Find(pStrGroupName);
  2063. if (lp)
  2064. {
  2065. CStdPtrArray* aOptionGroup = static_cast<CStdPtrArray*>(lp);
  2066. if (aOptionGroup == NULL) return;
  2067. for (int i = 0; i < aOptionGroup->GetSize(); i++)
  2068. {
  2069. if (static_cast<CControlUI*>(aOptionGroup->GetAt(i)) == pControl)
  2070. {
  2071. aOptionGroup->Remove(i);
  2072. break;
  2073. }
  2074. }
  2075. if (aOptionGroup->IsEmpty())
  2076. {
  2077. delete aOptionGroup;
  2078. m_mOptionGroup.Remove(pStrGroupName);
  2079. }
  2080. }
  2081. }
  2082. void CPaintManagerUI::RemoveAllOptionGroups()
  2083. {
  2084. CStdPtrArray* aOptionGroup;
  2085. for (int i = 0; i < m_mOptionGroup.GetSize(); i++)
  2086. {
  2087. if (LPCTSTR key = m_mOptionGroup.GetAt(i))
  2088. {
  2089. aOptionGroup = static_cast<CStdPtrArray*>(m_mOptionGroup.Find(key));
  2090. delete aOptionGroup;
  2091. }
  2092. }
  2093. m_mOptionGroup.RemoveAll();
  2094. }
  2095. void CPaintManagerUI::MessageLoop()
  2096. {
  2097. MSG msg = { 0 };
  2098. while (::GetMessage(&msg, NULL, 0, 0))
  2099. {
  2100. if (!CPaintManagerUI::TranslateMessage(&msg))
  2101. {
  2102. ::TranslateMessage(&msg);
  2103. try
  2104. {
  2105. ::DispatchMessage(&msg);
  2106. }
  2107. catch (...)
  2108. {
  2109. DUITRACE(_T("EXCEPTION: %s(%d)\n"), __FILET__, __LINE__);
  2110. #ifdef _DEBUG
  2111. throw "CPaintManagerUI::MessageLoop";
  2112. #endif
  2113. }
  2114. }
  2115. }
  2116. }
  2117. void CPaintManagerUI::Term()
  2118. {
  2119. // 销毁资源管理器
  2120. CResourceManager::GetInstance()->Release();
  2121. CControlFactory::GetInstance()->Release();
  2122. // 清理共享资源
  2123. // 图片
  2124. TImageInfo* data;
  2125. for (int i = 0; i < m_SharedResInfo.m_ImageHash.GetSize(); i++)
  2126. {
  2127. if (LPCTSTR key = m_SharedResInfo.m_ImageHash.GetAt(i))
  2128. {
  2129. data = static_cast<TImageInfo*>(m_SharedResInfo.m_ImageHash.Find(key, false));
  2130. if (data)
  2131. {
  2132. CRenderEngine::FreeImage(data);
  2133. data = NULL;
  2134. }
  2135. }
  2136. }
  2137. m_SharedResInfo.m_ImageHash.RemoveAll();
  2138. // 字体
  2139. TFontInfo* pFontInfo;
  2140. for (int i = 0; i < m_SharedResInfo.m_CustomFonts.GetSize(); i++)
  2141. {
  2142. if (LPCTSTR key = m_SharedResInfo.m_CustomFonts.GetAt(i))
  2143. {
  2144. pFontInfo = static_cast<TFontInfo*>(m_SharedResInfo.m_CustomFonts.Find(key, false));
  2145. if (pFontInfo)
  2146. {
  2147. ::DeleteObject(pFontInfo->hFont);
  2148. delete pFontInfo;
  2149. pFontInfo = NULL;
  2150. }
  2151. }
  2152. }
  2153. m_SharedResInfo.m_CustomFonts.RemoveAll();
  2154. // 默认字体
  2155. if (m_SharedResInfo.m_DefaultFontInfo.hFont != NULL)
  2156. {
  2157. ::DeleteObject(m_SharedResInfo.m_DefaultFontInfo.hFont);
  2158. }
  2159. // 样式
  2160. CDuiString* pStyle;
  2161. for (int i = 0; i < m_SharedResInfo.m_StyleHash.GetSize(); i++)
  2162. {
  2163. if (LPCTSTR key = m_SharedResInfo.m_StyleHash.GetAt(i))
  2164. {
  2165. pStyle = static_cast<CDuiString*>(m_SharedResInfo.m_StyleHash.Find(key, false));
  2166. if (pStyle)
  2167. {
  2168. delete pStyle;
  2169. pStyle = NULL;
  2170. }
  2171. }
  2172. }
  2173. m_SharedResInfo.m_StyleHash.RemoveAll();
  2174. // 样式
  2175. CDuiString* pAttr;
  2176. for (int i = 0; i < m_SharedResInfo.m_AttrHash.GetSize(); i++)
  2177. {
  2178. if (LPCTSTR key = m_SharedResInfo.m_AttrHash.GetAt(i))
  2179. {
  2180. pAttr = static_cast<CDuiString*>(m_SharedResInfo.m_AttrHash.Find(key, false));
  2181. if (pAttr)
  2182. {
  2183. delete pAttr;
  2184. pAttr = NULL;
  2185. }
  2186. }
  2187. }
  2188. m_SharedResInfo.m_AttrHash.RemoveAll();
  2189. // 关闭ZIP
  2190. if (m_bCachedResourceZip && m_hResourceZip != NULL)
  2191. {
  2192. CloseZip((HZIP)m_hResourceZip);
  2193. m_hResourceZip = NULL;
  2194. }
  2195. if (m_cbZipBuf)
  2196. {
  2197. delete[] m_cbZipBuf;
  2198. m_cbZipBuf = nullptr;
  2199. }
  2200. }
  2201. CDPI* DuiLib::CPaintManagerUI::GetDPIObj()
  2202. {
  2203. if (m_pDPI == NULL)
  2204. {
  2205. m_pDPI = new CDPI;
  2206. }
  2207. return m_pDPI;
  2208. }
  2209. void DuiLib::CPaintManagerUI::SetDPI(int iDPI)
  2210. {
  2211. int scale1 = GetDPIObj()->GetScale();
  2212. GetDPIObj()->SetScale(iDPI);
  2213. int scale2 = GetDPIObj()->GetScale();
  2214. ResetDPIAssets();
  2215. RECT rcWnd = { 0 };
  2216. ::GetWindowRect(GetPaintWindow(), &rcWnd);
  2217. RECT* prcNewWindow = &rcWnd;
  2218. if (!::IsZoomed(GetPaintWindow()))
  2219. {
  2220. RECT rc = rcWnd;
  2221. rc.right = rcWnd.left + (rcWnd.right - rcWnd.left) * scale2 / scale1;
  2222. rc.bottom = rcWnd.top + (rcWnd.bottom - rcWnd.top) * scale2 / scale1;
  2223. prcNewWindow = &rc;
  2224. }
  2225. SetWindowPos(GetPaintWindow(), NULL, prcNewWindow->left, prcNewWindow->top, prcNewWindow->right - prcNewWindow->left, prcNewWindow->bottom - prcNewWindow->top, SWP_NOZORDER | SWP_NOACTIVATE);
  2226. if (GetRoot() != NULL) GetRoot()->NeedUpdate();
  2227. ::PostMessage(GetPaintWindow(), UIMSG_SET_DPI, 0, 0);
  2228. }
  2229. void DuiLib::CPaintManagerUI::SetAllDPI(int iDPI)
  2230. {
  2231. for (int i = 0; i < m_aPreMessages.GetSize(); i++)
  2232. {
  2233. CPaintManagerUI* pManager = static_cast<CPaintManagerUI*>(m_aPreMessages[i]);
  2234. pManager->SetDPI(iDPI);
  2235. }
  2236. }
  2237. void DuiLib::CPaintManagerUI::ResetDPIAssets()
  2238. {
  2239. RemoveAllDrawInfos();
  2240. RemoveAllImages();;
  2241. for (int it = 0; it < m_ResInfo.m_CustomFonts.GetSize(); it++)
  2242. {
  2243. TFontInfo* pFontInfo = static_cast<TFontInfo*>(m_ResInfo.m_CustomFonts.Find(m_ResInfo.m_CustomFonts[it]));
  2244. RebuildFont(pFontInfo);
  2245. }
  2246. RebuildFont(&m_ResInfo.m_DefaultFontInfo);
  2247. for (int it = 0; it < m_SharedResInfo.m_CustomFonts.GetSize(); it++)
  2248. {
  2249. TFontInfo* pFontInfo = static_cast<TFontInfo*>(m_SharedResInfo.m_CustomFonts.Find(m_SharedResInfo.m_CustomFonts[it]));
  2250. RebuildFont(pFontInfo);
  2251. }
  2252. RebuildFont(&m_SharedResInfo.m_DefaultFontInfo);
  2253. CStdPtrArray* richEditList = FindSubControlsByClass(GetRoot(), _T("RichEditUI"));
  2254. for (int i = 0; i < richEditList->GetSize(); i++)
  2255. {
  2256. CRichEditUI* pT = static_cast<CRichEditUI*>((*richEditList)[i]);
  2257. pT->SetFont(pT->GetFont());
  2258. }
  2259. }
  2260. void DuiLib::CPaintManagerUI::RebuildFont(TFontInfo* pFontInfo)
  2261. {
  2262. ::DeleteObject(pFontInfo->hFont);
  2263. LOGFONT lf = { 0 };
  2264. ::GetObject(::GetStockObject(DEFAULT_GUI_FONT), sizeof(LOGFONT), &lf);
  2265. _tcsncpy(lf.lfFaceName, pFontInfo->sFontName, LF_FACESIZE);
  2266. lf.lfCharSet = DEFAULT_CHARSET;
  2267. lf.lfHeight = -GetDPIObj()->Scale(pFontInfo->iSize);
  2268. lf.lfQuality = CLEARTYPE_QUALITY;
  2269. if (pFontInfo->bBold) lf.lfWeight += FW_BOLD;
  2270. if (pFontInfo->bUnderline) lf.lfUnderline = TRUE;
  2271. if (pFontInfo->bItalic) lf.lfItalic = TRUE;
  2272. HFONT hFont = ::CreateFontIndirect(&lf);
  2273. pFontInfo->hFont = hFont;
  2274. ::ZeroMemory(&(pFontInfo->tm), sizeof(pFontInfo->tm));
  2275. if (m_hDcPaint)
  2276. {
  2277. HFONT hOldFont = (HFONT) ::SelectObject(m_hDcPaint, hFont);
  2278. ::GetTextMetrics(m_hDcPaint, &pFontInfo->tm);
  2279. ::SelectObject(m_hDcPaint, hOldFont);
  2280. }
  2281. }
  2282. CControlUI* CPaintManagerUI::GetFocus() const
  2283. {
  2284. return m_pFocus;
  2285. }
  2286. void CPaintManagerUI::SetFocus(CControlUI* pControl)
  2287. {
  2288. // Paint manager window has focus?
  2289. HWND hFocusWnd = ::GetFocus();
  2290. if (!m_bNoActivate && hFocusWnd != m_hWndPaint && pControl != m_pFocus) ::SetFocus(m_hWndPaint);
  2291. // Already has focus?
  2292. if (pControl == m_pFocus) return;
  2293. // Remove focus from old control
  2294. if (m_pFocus != NULL)
  2295. {
  2296. TEventUI event = { 0 };
  2297. event.Type = UIEVENT_KILLFOCUS;
  2298. event.pSender = pControl;
  2299. event.dwTimestamp = ::GetTickCount();
  2300. m_pFocus->Event(event);
  2301. SendNotify(m_pFocus, DUI_MSGTYPE_KILLFOCUS);
  2302. m_pFocus = NULL;
  2303. }
  2304. if (pControl == NULL) return;
  2305. // Set focus to new control
  2306. if (pControl != NULL
  2307. && pControl->GetManager() == this
  2308. && pControl->IsVisible()
  2309. && pControl->IsEnabled())
  2310. {
  2311. m_pFocus = pControl;
  2312. TEventUI event = { 0 };
  2313. event.Type = UIEVENT_SETFOCUS;
  2314. event.pSender = pControl;
  2315. event.dwTimestamp = ::GetTickCount();
  2316. m_pFocus->Event(event);
  2317. SendNotify(m_pFocus, DUI_MSGTYPE_SETFOCUS);
  2318. }
  2319. }
  2320. void CPaintManagerUI::SetFocusNeeded(CControlUI* pControl)
  2321. {
  2322. if (!m_bNoActivate) ::SetFocus(m_hWndPaint);
  2323. if (pControl == NULL) return;
  2324. if (m_pFocus != NULL)
  2325. {
  2326. TEventUI event = { 0 };
  2327. event.Type = UIEVENT_KILLFOCUS;
  2328. event.pSender = pControl;
  2329. event.dwTimestamp = ::GetTickCount();
  2330. m_pFocus->Event(event);
  2331. SendNotify(m_pFocus, DUI_MSGTYPE_KILLFOCUS);
  2332. m_pFocus = NULL;
  2333. }
  2334. FINDTABINFO info = { 0 };
  2335. info.pFocus = pControl;
  2336. info.bForward = false;
  2337. m_pFocus = m_pRoot->FindControl(__FindControlFromTab, &info, UIFIND_VISIBLE | UIFIND_ENABLED | UIFIND_ME_FIRST);
  2338. m_bFocusNeeded = true;
  2339. if (m_pRoot != NULL) m_pRoot->NeedUpdate();
  2340. }
  2341. bool CPaintManagerUI::SetTimer(CControlUI* pControl, UINT nTimerID, UINT uElapse)
  2342. {
  2343. ASSERT(pControl != NULL);
  2344. ASSERT(uElapse > 0);
  2345. for (int i = 0; i < m_aTimers.GetSize(); i++)
  2346. {
  2347. TIMERINFO* pTimer = static_cast<TIMERINFO*>(m_aTimers[i]);
  2348. if (pTimer->pSender == pControl
  2349. && pTimer->hWnd == m_hWndPaint
  2350. && pTimer->nLocalID == nTimerID)
  2351. {
  2352. if (pTimer->bKilled == true)
  2353. {
  2354. if (::SetTimer(m_hWndPaint, pTimer->uWinTimer, uElapse, NULL))
  2355. {
  2356. pTimer->bKilled = false;
  2357. return true;
  2358. }
  2359. return false;
  2360. }
  2361. return false;
  2362. }
  2363. }
  2364. m_uTimerID = (++m_uTimerID) % 0xF0; //0xf1-0xfe特殊用途
  2365. if (!::SetTimer(m_hWndPaint, m_uTimerID, uElapse, NULL)) return FALSE;
  2366. TIMERINFO* pTimer = new TIMERINFO;
  2367. if (pTimer == NULL) return FALSE;
  2368. pTimer->hWnd = m_hWndPaint;
  2369. pTimer->pSender = pControl;
  2370. pTimer->nLocalID = nTimerID;
  2371. pTimer->uWinTimer = m_uTimerID;
  2372. pTimer->bKilled = false;
  2373. return m_aTimers.Add(pTimer);
  2374. }
  2375. bool CPaintManagerUI::KillTimer(CControlUI* pControl, UINT nTimerID)
  2376. {
  2377. ASSERT(pControl != NULL);
  2378. for (int i = 0; i < m_aTimers.GetSize(); i++)
  2379. {
  2380. TIMERINFO* pTimer = static_cast<TIMERINFO*>(m_aTimers[i]);
  2381. if (pTimer->pSender == pControl
  2382. && pTimer->hWnd == m_hWndPaint
  2383. && pTimer->nLocalID == nTimerID)
  2384. {
  2385. if (pTimer->bKilled == false)
  2386. {
  2387. if (::IsWindow(m_hWndPaint)) ::KillTimer(pTimer->hWnd, pTimer->uWinTimer);
  2388. pTimer->bKilled = true;
  2389. return true;
  2390. }
  2391. }
  2392. }
  2393. return false;
  2394. }
  2395. void CPaintManagerUI::KillTimer(CControlUI* pControl)
  2396. {
  2397. ASSERT(pControl != NULL);
  2398. int count = m_aTimers.GetSize();
  2399. for (int i = 0, j = 0; i < count; i++)
  2400. {
  2401. TIMERINFO* pTimer = static_cast<TIMERINFO*>(m_aTimers[i - j]);
  2402. if (pTimer->pSender == pControl && pTimer->hWnd == m_hWndPaint)
  2403. {
  2404. if (pTimer->bKilled == false) ::KillTimer(pTimer->hWnd, pTimer->uWinTimer);
  2405. delete pTimer;
  2406. m_aTimers.Remove(i - j);
  2407. j++;
  2408. }
  2409. }
  2410. }
  2411. void CPaintManagerUI::RemoveAllTimers()
  2412. {
  2413. for (int i = 0; i < m_aTimers.GetSize(); i++)
  2414. {
  2415. TIMERINFO* pTimer = static_cast<TIMERINFO*>(m_aTimers[i]);
  2416. if (pTimer->hWnd == m_hWndPaint)
  2417. {
  2418. if (pTimer->bKilled == false)
  2419. {
  2420. if (::IsWindow(m_hWndPaint)) ::KillTimer(m_hWndPaint, pTimer->uWinTimer);
  2421. }
  2422. delete pTimer;
  2423. }
  2424. }
  2425. m_aTimers.Empty();
  2426. }
  2427. void CPaintManagerUI::SetCapture()
  2428. {
  2429. ::SetCapture(m_hWndPaint);
  2430. m_bMouseCapture = true;
  2431. }
  2432. void CPaintManagerUI::ReleaseCapture()
  2433. {
  2434. ::ReleaseCapture();
  2435. m_bMouseCapture = false;
  2436. m_bDragMode = false;
  2437. }
  2438. bool CPaintManagerUI::IsCaptured()
  2439. {
  2440. return m_bMouseCapture;
  2441. }
  2442. bool CPaintManagerUI::IsPainting()
  2443. {
  2444. return m_bIsPainting;
  2445. }
  2446. void CPaintManagerUI::SetPainting(bool bIsPainting)
  2447. {
  2448. m_bIsPainting = bIsPainting;
  2449. }
  2450. bool CPaintManagerUI::SetNextTabControl(bool bForward)
  2451. {
  2452. // If we're in the process of restructuring the layout we can delay the
  2453. // focus calulation until the next repaint.
  2454. if (m_bUpdateNeeded && bForward)
  2455. {
  2456. m_bFocusNeeded = true;
  2457. ::InvalidateRect(m_hWndPaint, NULL, FALSE);
  2458. return true;
  2459. }
  2460. // Find next/previous tabbable control
  2461. FINDTABINFO info1 = { 0 };
  2462. info1.pFocus = m_pFocus;
  2463. info1.bForward = bForward;
  2464. CControlUI* pControl = m_pRoot->FindControl(__FindControlFromTab, &info1, UIFIND_VISIBLE | UIFIND_ENABLED | UIFIND_ME_FIRST);
  2465. if (pControl == NULL)
  2466. {
  2467. if (bForward)
  2468. {
  2469. // Wrap around
  2470. FINDTABINFO info2 = { 0 };
  2471. info2.pFocus = bForward ? NULL : info1.pLast;
  2472. info2.bForward = bForward;
  2473. pControl = m_pRoot->FindControl(__FindControlFromTab, &info2, UIFIND_VISIBLE | UIFIND_ENABLED | UIFIND_ME_FIRST);
  2474. }
  2475. else
  2476. {
  2477. pControl = info1.pLast;
  2478. }
  2479. }
  2480. if (pControl != NULL) SetFocus(pControl);
  2481. m_bFocusNeeded = false;
  2482. return true;
  2483. }
  2484. bool CPaintManagerUI::AddNotifier(INotifyUI* pNotifier)
  2485. {
  2486. ASSERT(m_aNotifiers.Find(pNotifier) < 0);
  2487. return m_aNotifiers.Add(pNotifier);
  2488. }
  2489. bool CPaintManagerUI::RemoveNotifier(INotifyUI* pNotifier)
  2490. {
  2491. for (int i = 0; i < m_aNotifiers.GetSize(); i++)
  2492. {
  2493. if (static_cast<INotifyUI*>(m_aNotifiers[i]) == pNotifier)
  2494. {
  2495. return m_aNotifiers.Remove(i);
  2496. }
  2497. }
  2498. return false;
  2499. }
  2500. bool CPaintManagerUI::AddPreMessageFilter(IMessageFilterUI* pFilter)
  2501. {
  2502. ASSERT(m_aPreMessageFilters.Find(pFilter) < 0);
  2503. return m_aPreMessageFilters.Add(pFilter);
  2504. }
  2505. bool CPaintManagerUI::RemovePreMessageFilter(IMessageFilterUI* pFilter)
  2506. {
  2507. for (int i = 0; i < m_aPreMessageFilters.GetSize(); i++)
  2508. {
  2509. if (static_cast<IMessageFilterUI*>(m_aPreMessageFilters[i]) == pFilter)
  2510. {
  2511. return m_aPreMessageFilters.Remove(i);
  2512. }
  2513. }
  2514. return false;
  2515. }
  2516. bool CPaintManagerUI::AddMessageFilter(IMessageFilterUI* pFilter)
  2517. {
  2518. ASSERT(m_aMessageFilters.Find(pFilter) < 0);
  2519. return m_aMessageFilters.Add(pFilter);
  2520. }
  2521. bool CPaintManagerUI::RemoveMessageFilter(IMessageFilterUI* pFilter)
  2522. {
  2523. for (int i = 0; i < m_aMessageFilters.GetSize(); i++)
  2524. {
  2525. if (static_cast<IMessageFilterUI*>(m_aMessageFilters[i]) == pFilter)
  2526. {
  2527. return m_aMessageFilters.Remove(i);
  2528. }
  2529. }
  2530. return false;
  2531. }
  2532. int CPaintManagerUI::GetPostPaintCount() const
  2533. {
  2534. return m_aPostPaintControls.GetSize();
  2535. }
  2536. bool CPaintManagerUI::IsPostPaint(CControlUI* pControl)
  2537. {
  2538. return m_aPostPaintControls.Find(pControl) >= 0;
  2539. }
  2540. bool CPaintManagerUI::AddPostPaint(CControlUI* pControl)
  2541. {
  2542. ASSERT(m_aPostPaintControls.Find(pControl) < 0);
  2543. return m_aPostPaintControls.Add(pControl);
  2544. }
  2545. bool CPaintManagerUI::RemovePostPaint(CControlUI* pControl)
  2546. {
  2547. for (int i = 0; i < m_aPostPaintControls.GetSize(); i++)
  2548. {
  2549. if (static_cast<CControlUI*>(m_aPostPaintControls[i]) == pControl)
  2550. {
  2551. return m_aPostPaintControls.Remove(i);
  2552. }
  2553. }
  2554. return false;
  2555. }
  2556. bool CPaintManagerUI::SetPostPaintIndex(CControlUI* pControl, int iIndex)
  2557. {
  2558. RemovePostPaint(pControl);
  2559. return m_aPostPaintControls.InsertAt(iIndex, pControl);
  2560. }
  2561. int CPaintManagerUI::GetNativeWindowCount() const
  2562. {
  2563. return m_aNativeWindow.GetSize();
  2564. }
  2565. bool CPaintManagerUI::AddNativeWindow(CControlUI* pControl, HWND hChildWnd)
  2566. {
  2567. if (pControl == NULL || hChildWnd == NULL) return false;
  2568. RECT rcChildWnd = GetNativeWindowRect(hChildWnd);
  2569. Invalidate(rcChildWnd);
  2570. if (m_aNativeWindow.Find(hChildWnd) >= 0) return false;
  2571. if (m_aNativeWindow.Add(hChildWnd))
  2572. {
  2573. m_aNativeWindowControl.Add(pControl);
  2574. return true;
  2575. }
  2576. return false;
  2577. }
  2578. bool CPaintManagerUI::RemoveNativeWindow(HWND hChildWnd)
  2579. {
  2580. for (int i = 0; i < m_aNativeWindow.GetSize(); i++)
  2581. {
  2582. if (static_cast<HWND>(m_aNativeWindow[i]) == hChildWnd)
  2583. {
  2584. if (m_aNativeWindow.Remove(i))
  2585. {
  2586. m_aNativeWindowControl.Remove(i);
  2587. return true;
  2588. }
  2589. return false;
  2590. }
  2591. }
  2592. return false;
  2593. }
  2594. RECT CPaintManagerUI::GetNativeWindowRect(HWND hChildWnd)
  2595. {
  2596. RECT rcChildWnd;
  2597. ::GetWindowRect(hChildWnd, &rcChildWnd);
  2598. ::ScreenToClient(m_hWndPaint, (LPPOINT)(&rcChildWnd));
  2599. ::ScreenToClient(m_hWndPaint, (LPPOINT)(&rcChildWnd) + 1);
  2600. return rcChildWnd;
  2601. }
  2602. void CPaintManagerUI::AddDelayedCleanup(CControlUI* pControl)
  2603. {
  2604. if (pControl == NULL) return;
  2605. pControl->SetManager(this, NULL, false);
  2606. m_aDelayedCleanup.Add(pControl);
  2607. PostAsyncNotify();
  2608. }
  2609. void CPaintManagerUI::AddMouseLeaveNeeded(CControlUI* pControl)
  2610. {
  2611. if (pControl == NULL) return;
  2612. for (int i = 0; i < m_aNeedMouseLeaveNeeded.GetSize(); i++)
  2613. {
  2614. if (static_cast<CControlUI*>(m_aNeedMouseLeaveNeeded[i]) == pControl)
  2615. {
  2616. return;
  2617. }
  2618. }
  2619. m_aNeedMouseLeaveNeeded.Add(pControl);
  2620. }
  2621. bool CPaintManagerUI::RemoveMouseLeaveNeeded(CControlUI* pControl)
  2622. {
  2623. if (pControl == NULL) return false;
  2624. for (int i = 0; i < m_aNeedMouseLeaveNeeded.GetSize(); i++)
  2625. {
  2626. if (static_cast<CControlUI*>(m_aNeedMouseLeaveNeeded[i]) == pControl)
  2627. {
  2628. return m_aNeedMouseLeaveNeeded.Remove(i);
  2629. }
  2630. }
  2631. return false;
  2632. }
  2633. void CPaintManagerUI::SendNotify(CControlUI* pControl, LPCTSTR pstrMessage, WPARAM wParam /*= 0*/, LPARAM lParam /*= 0*/, bool bAsync /*= false*/)
  2634. {
  2635. TNotifyUI Msg;
  2636. Msg.pSender = pControl;
  2637. Msg.sType = pstrMessage;
  2638. Msg.wParam = wParam;
  2639. Msg.lParam = lParam;
  2640. SendNotify(Msg, bAsync);
  2641. }
  2642. void CPaintManagerUI::SendNotify(TNotifyUI& Msg, bool bAsync /*= false*/)
  2643. {
  2644. Msg.ptMouse = m_ptLastMousePos;
  2645. Msg.dwTimestamp = ::GetTickCount();
  2646. if (m_bUsedVirtualWnd)
  2647. {
  2648. Msg.sVirtualWnd = Msg.pSender->GetVirtualWnd();
  2649. }
  2650. if (!bAsync)
  2651. {
  2652. // Send to all listeners
  2653. if (Msg.pSender != NULL)
  2654. {
  2655. if (Msg.pSender->OnNotify) Msg.pSender->OnNotify(&Msg);
  2656. }
  2657. for (int i = 0; i < m_aNotifiers.GetSize(); i++)
  2658. {
  2659. static_cast<INotifyUI*>(m_aNotifiers[i])->Notify(Msg);
  2660. }
  2661. }
  2662. else
  2663. {
  2664. TNotifyUI* pMsg = new TNotifyUI;
  2665. pMsg->sVirtualWnd = Msg.sVirtualWnd;
  2666. pMsg->pSender = Msg.pSender;
  2667. pMsg->sType = Msg.sType;
  2668. pMsg->wParam = Msg.wParam;
  2669. pMsg->lParam = Msg.lParam;
  2670. pMsg->ptMouse = Msg.ptMouse;
  2671. pMsg->dwTimestamp = Msg.dwTimestamp;
  2672. m_aAsyncNotify.Add(pMsg);
  2673. PostAsyncNotify();
  2674. }
  2675. }
  2676. bool CPaintManagerUI::IsForceUseSharedRes() const
  2677. {
  2678. return m_bForceUseSharedRes;
  2679. }
  2680. void CPaintManagerUI::SetForceUseSharedRes(bool bForce)
  2681. {
  2682. m_bForceUseSharedRes = bForce;
  2683. }
  2684. DWORD CPaintManagerUI::GetDefaultDisabledColor() const
  2685. {
  2686. return m_ResInfo.m_dwDefaultDisabledColor;
  2687. }
  2688. void CPaintManagerUI::SetDefaultDisabledColor(DWORD dwColor, bool bShared)
  2689. {
  2690. if (bShared)
  2691. {
  2692. if (m_ResInfo.m_dwDefaultDisabledColor == m_SharedResInfo.m_dwDefaultDisabledColor)
  2693. m_ResInfo.m_dwDefaultDisabledColor = dwColor;
  2694. m_SharedResInfo.m_dwDefaultDisabledColor = dwColor;
  2695. }
  2696. else
  2697. {
  2698. m_ResInfo.m_dwDefaultDisabledColor = dwColor;
  2699. }
  2700. }
  2701. DWORD CPaintManagerUI::GetDefaultFontColor() const
  2702. {
  2703. return m_ResInfo.m_dwDefaultFontColor;
  2704. }
  2705. void CPaintManagerUI::SetDefaultFontColor(DWORD dwColor, bool bShared)
  2706. {
  2707. if (bShared)
  2708. {
  2709. if (m_ResInfo.m_dwDefaultFontColor == m_SharedResInfo.m_dwDefaultFontColor)
  2710. m_ResInfo.m_dwDefaultFontColor = dwColor;
  2711. m_SharedResInfo.m_dwDefaultFontColor = dwColor;
  2712. }
  2713. else
  2714. {
  2715. m_ResInfo.m_dwDefaultFontColor = dwColor;
  2716. }
  2717. }
  2718. DWORD CPaintManagerUI::GetDefaultLinkFontColor() const
  2719. {
  2720. return m_ResInfo.m_dwDefaultLinkFontColor;
  2721. }
  2722. void CPaintManagerUI::SetDefaultLinkFontColor(DWORD dwColor, bool bShared)
  2723. {
  2724. if (bShared)
  2725. {
  2726. if (m_ResInfo.m_dwDefaultLinkFontColor == m_SharedResInfo.m_dwDefaultLinkFontColor)
  2727. m_ResInfo.m_dwDefaultLinkFontColor = dwColor;
  2728. m_SharedResInfo.m_dwDefaultLinkFontColor = dwColor;
  2729. }
  2730. else
  2731. {
  2732. m_ResInfo.m_dwDefaultLinkFontColor = dwColor;
  2733. }
  2734. }
  2735. DWORD CPaintManagerUI::GetDefaultLinkHoverFontColor() const
  2736. {
  2737. return m_ResInfo.m_dwDefaultLinkHoverFontColor;
  2738. }
  2739. void CPaintManagerUI::SetDefaultLinkHoverFontColor(DWORD dwColor, bool bShared)
  2740. {
  2741. if (bShared)
  2742. {
  2743. if (m_ResInfo.m_dwDefaultLinkHoverFontColor == m_SharedResInfo.m_dwDefaultLinkHoverFontColor)
  2744. m_ResInfo.m_dwDefaultLinkHoverFontColor = dwColor;
  2745. m_SharedResInfo.m_dwDefaultLinkHoverFontColor = dwColor;
  2746. }
  2747. else
  2748. {
  2749. m_ResInfo.m_dwDefaultLinkHoverFontColor = dwColor;
  2750. }
  2751. }
  2752. DWORD CPaintManagerUI::GetDefaultSelectedBkColor() const
  2753. {
  2754. return m_ResInfo.m_dwDefaultSelectedBkColor;
  2755. }
  2756. void CPaintManagerUI::SetDefaultSelectedBkColor(DWORD dwColor, bool bShared)
  2757. {
  2758. if (bShared)
  2759. {
  2760. if (m_ResInfo.m_dwDefaultSelectedBkColor == m_SharedResInfo.m_dwDefaultSelectedBkColor)
  2761. m_ResInfo.m_dwDefaultSelectedBkColor = dwColor;
  2762. m_SharedResInfo.m_dwDefaultSelectedBkColor = dwColor;
  2763. }
  2764. else
  2765. {
  2766. m_ResInfo.m_dwDefaultSelectedBkColor = dwColor;
  2767. }
  2768. }
  2769. TFontInfo* CPaintManagerUI::GetDefaultFontInfo()
  2770. {
  2771. if (m_ResInfo.m_DefaultFontInfo.sFontName.IsEmpty())
  2772. {
  2773. if (m_SharedResInfo.m_DefaultFontInfo.tm.tmHeight == 0)
  2774. {
  2775. HFONT hOldFont = (HFONT) ::SelectObject(m_hDcPaint, m_SharedResInfo.m_DefaultFontInfo.hFont);
  2776. ::GetTextMetrics(m_hDcPaint, &m_SharedResInfo.m_DefaultFontInfo.tm);
  2777. ::SelectObject(m_hDcPaint, hOldFont);
  2778. }
  2779. return &m_SharedResInfo.m_DefaultFontInfo;
  2780. }
  2781. else
  2782. {
  2783. if (m_ResInfo.m_DefaultFontInfo.tm.tmHeight == 0)
  2784. {
  2785. HFONT hOldFont = (HFONT) ::SelectObject(m_hDcPaint, m_ResInfo.m_DefaultFontInfo.hFont);
  2786. ::GetTextMetrics(m_hDcPaint, &m_ResInfo.m_DefaultFontInfo.tm);
  2787. ::SelectObject(m_hDcPaint, hOldFont);
  2788. }
  2789. return &m_ResInfo.m_DefaultFontInfo;
  2790. }
  2791. }
  2792. void CPaintManagerUI::SetDefaultFont(LPCTSTR pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic, bool bStrikeout, bool bShared)
  2793. {
  2794. LOGFONT lf = { 0 };
  2795. ::GetObject(::GetStockObject(DEFAULT_GUI_FONT), sizeof(LOGFONT), &lf);
  2796. if (lstrlen(pStrFontName) > 0)
  2797. {
  2798. TCHAR szFaceName[32] = { 0 };//_T("@");
  2799. _tcsncat(szFaceName, pStrFontName, LF_FACESIZE);
  2800. _tcsncpy(lf.lfFaceName, szFaceName, LF_FACESIZE);
  2801. }
  2802. lf.lfCharSet = DEFAULT_CHARSET;
  2803. lf.lfHeight = -GetDPIObj()->Scale(nSize);;
  2804. if (bBold) lf.lfWeight += FW_BOLD;
  2805. if (bUnderline) lf.lfUnderline = TRUE;
  2806. if (bItalic) lf.lfItalic = TRUE;
  2807. if (bStrikeout) lf.lfStrikeOut = TRUE;
  2808. HFONT hFont = ::CreateFontIndirect(&lf);
  2809. if (hFont == NULL) return;
  2810. if (bShared)
  2811. {
  2812. ::DeleteObject(m_SharedResInfo.m_DefaultFontInfo.hFont);
  2813. m_SharedResInfo.m_DefaultFontInfo.hFont = hFont;
  2814. m_SharedResInfo.m_DefaultFontInfo.sFontName = lf.lfFaceName;
  2815. m_SharedResInfo.m_DefaultFontInfo.iSize = nSize;
  2816. m_SharedResInfo.m_DefaultFontInfo.bBold = bBold;
  2817. m_SharedResInfo.m_DefaultFontInfo.bUnderline = bUnderline;
  2818. m_SharedResInfo.m_DefaultFontInfo.bItalic = bItalic;
  2819. m_SharedResInfo.m_DefaultFontInfo.bStrikeout = bStrikeout;
  2820. ::ZeroMemory(&m_SharedResInfo.m_DefaultFontInfo.tm, sizeof(m_SharedResInfo.m_DefaultFontInfo.tm));
  2821. if (m_hDcPaint)
  2822. {
  2823. HFONT hOldFont = (HFONT) ::SelectObject(m_hDcPaint, hFont);
  2824. ::GetTextMetrics(m_hDcPaint, &m_SharedResInfo.m_DefaultFontInfo.tm);
  2825. ::SelectObject(m_hDcPaint, hOldFont);
  2826. }
  2827. }
  2828. else
  2829. {
  2830. ::DeleteObject(m_ResInfo.m_DefaultFontInfo.hFont);
  2831. m_ResInfo.m_DefaultFontInfo.hFont = hFont;
  2832. m_ResInfo.m_DefaultFontInfo.sFontName = lf.lfFaceName;
  2833. m_ResInfo.m_DefaultFontInfo.iSize = nSize;
  2834. m_ResInfo.m_DefaultFontInfo.bBold = bBold;
  2835. m_ResInfo.m_DefaultFontInfo.bUnderline = bUnderline;
  2836. m_ResInfo.m_DefaultFontInfo.bItalic = bItalic;
  2837. m_ResInfo.m_DefaultFontInfo.bStrikeout = bStrikeout;
  2838. ::ZeroMemory(&m_ResInfo.m_DefaultFontInfo.tm, sizeof(m_ResInfo.m_DefaultFontInfo.tm));
  2839. if (m_hDcPaint)
  2840. {
  2841. HFONT hOldFont = (HFONT) ::SelectObject(m_hDcPaint, hFont);
  2842. ::GetTextMetrics(m_hDcPaint, &m_ResInfo.m_DefaultFontInfo.tm);
  2843. ::SelectObject(m_hDcPaint, hOldFont);
  2844. }
  2845. }
  2846. }
  2847. DWORD CPaintManagerUI::GetCustomFontCount(bool bShared) const
  2848. {
  2849. if (bShared)
  2850. return m_SharedResInfo.m_CustomFonts.GetSize();
  2851. else
  2852. return m_ResInfo.m_CustomFonts.GetSize();
  2853. }
  2854. HFONT CPaintManagerUI::AddFont(int id, LPCTSTR pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic, bool bStrikeout, bool bShared)
  2855. {
  2856. LOGFONT lf = { 0 };
  2857. ::GetObject(::GetStockObject(DEFAULT_GUI_FONT), sizeof(LOGFONT), &lf);
  2858. if (lstrlen(pStrFontName) > 0)
  2859. {
  2860. TCHAR szFaceName[32] = { 0 };//_T("@");
  2861. _tcsncat(szFaceName, pStrFontName, LF_FACESIZE);
  2862. _tcsncpy(lf.lfFaceName, szFaceName, LF_FACESIZE);
  2863. }
  2864. lf.lfCharSet = DEFAULT_CHARSET;
  2865. lf.lfHeight = -GetDPIObj()->Scale(nSize);
  2866. if (bBold) lf.lfWeight = FW_BOLD;
  2867. if (bUnderline) lf.lfUnderline = TRUE;
  2868. if (bItalic) lf.lfItalic = TRUE;
  2869. if (bStrikeout) lf.lfStrikeOut = TRUE;
  2870. HFONT hFont = ::CreateFontIndirect(&lf);
  2871. if (hFont == NULL) return NULL;
  2872. TFontInfo* pFontInfo = new TFontInfo;
  2873. if (!pFontInfo) return false;
  2874. ::ZeroMemory(pFontInfo, sizeof(TFontInfo));
  2875. pFontInfo->hFont = hFont;
  2876. pFontInfo->sFontName = lf.lfFaceName;
  2877. pFontInfo->iSize = nSize;
  2878. pFontInfo->bBold = bBold;
  2879. pFontInfo->bUnderline = bUnderline;
  2880. pFontInfo->bItalic = bItalic;
  2881. pFontInfo->bStrikeout = bStrikeout;
  2882. if (m_hDcPaint)
  2883. {
  2884. HFONT hOldFont = (HFONT) ::SelectObject(m_hDcPaint, hFont);
  2885. ::GetTextMetrics(m_hDcPaint, &pFontInfo->tm);
  2886. ::SelectObject(m_hDcPaint, hOldFont);
  2887. }
  2888. TCHAR idBuffer[16];
  2889. ::ZeroMemory(idBuffer, sizeof(idBuffer));
  2890. _itot(id, idBuffer, 10);
  2891. if (bShared || m_bForceUseSharedRes)
  2892. {
  2893. TFontInfo* pOldFontInfo = static_cast<TFontInfo*>(m_SharedResInfo.m_CustomFonts.Find(idBuffer));
  2894. if (pOldFontInfo)
  2895. {
  2896. ::DeleteObject(pOldFontInfo->hFont);
  2897. delete pOldFontInfo;
  2898. m_SharedResInfo.m_CustomFonts.Remove(idBuffer);
  2899. }
  2900. if (!m_SharedResInfo.m_CustomFonts.Insert(idBuffer, pFontInfo))
  2901. {
  2902. ::DeleteObject(hFont);
  2903. delete pFontInfo;
  2904. return NULL;
  2905. }
  2906. }
  2907. else
  2908. {
  2909. TFontInfo* pOldFontInfo = static_cast<TFontInfo*>(m_ResInfo.m_CustomFonts.Find(idBuffer));
  2910. if (pOldFontInfo)
  2911. {
  2912. ::DeleteObject(pOldFontInfo->hFont);
  2913. delete pOldFontInfo;
  2914. m_ResInfo.m_CustomFonts.Remove(idBuffer);
  2915. }
  2916. if (!m_ResInfo.m_CustomFonts.Insert(idBuffer, pFontInfo))
  2917. {
  2918. ::DeleteObject(hFont);
  2919. delete pFontInfo;
  2920. return NULL;
  2921. }
  2922. }
  2923. return hFont;
  2924. }
  2925. void CPaintManagerUI::AddFontArray(LPCTSTR pstrPath)
  2926. {
  2927. LPBYTE pData = NULL;
  2928. DWORD dwSize = 0;
  2929. do
  2930. {
  2931. CDuiString sFile = CPaintManagerUI::GetResourcePath();
  2932. if (CPaintManagerUI::GetResourceZip().IsEmpty())
  2933. {
  2934. sFile += pstrPath;
  2935. HANDLE hFile = ::CreateFile(sFile.GetData(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, \
  2936. FILE_ATTRIBUTE_NORMAL, NULL);
  2937. if (hFile == INVALID_HANDLE_VALUE) break;
  2938. dwSize = ::GetFileSize(hFile, NULL);
  2939. if (dwSize == 0) break;
  2940. DWORD dwRead = 0;
  2941. pData = new BYTE[dwSize];
  2942. ::ReadFile(hFile, pData, dwSize, &dwRead, NULL);
  2943. ::CloseHandle(hFile);
  2944. if (dwRead != dwSize)
  2945. {
  2946. delete[] pData;
  2947. pData = NULL;
  2948. break;
  2949. }
  2950. }
  2951. else
  2952. {
  2953. sFile += CPaintManagerUI::GetResourceZip();
  2954. HZIP hz = NULL;
  2955. if (CPaintManagerUI::IsCachedResourceZip()) hz = (HZIP)CPaintManagerUI::GetResourceZipHandle();
  2956. else
  2957. {
  2958. CDuiString sFilePwd = CPaintManagerUI::GetResourceZipPwd();
  2959. #ifdef UNICODE
  2960. char* pwd = w2a((wchar_t*)sFilePwd.GetData());
  2961. hz = OpenZip(sFile.GetData(), pwd);
  2962. if (pwd) delete[] pwd;
  2963. #else
  2964. hz = OpenZip(sFile.GetData(), sFilePwd.GetData());
  2965. #endif
  2966. }
  2967. if (hz == NULL) break;
  2968. ZIPENTRY ze;
  2969. int i = 0;
  2970. CDuiString key = pstrPath;
  2971. key.Replace(_T("\\"), _T("/"));
  2972. if (FindZipItem(hz, key, true, &i, &ze) != 0) break;
  2973. dwSize = ze.unc_size;
  2974. if (dwSize == 0) break;
  2975. pData = new BYTE[dwSize];
  2976. int res = UnzipItem(hz, i, pData, dwSize);
  2977. if (res != 0x00000000 && res != 0x00000600)
  2978. {
  2979. delete[] pData;
  2980. pData = NULL;
  2981. if (!CPaintManagerUI::IsCachedResourceZip()) CloseZip(hz);
  2982. break;
  2983. }
  2984. if (!CPaintManagerUI::IsCachedResourceZip()) CloseZip(hz);
  2985. }
  2986. } while (0);
  2987. while (!pData)
  2988. {
  2989. //读不到图片, 则直接去读取bitmap.m_lpstr指向的路径
  2990. HANDLE hFile = ::CreateFile(pstrPath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  2991. if (hFile == INVALID_HANDLE_VALUE) break;
  2992. dwSize = ::GetFileSize(hFile, NULL);
  2993. if (dwSize == 0) break;
  2994. DWORD dwRead = 0;
  2995. pData = new BYTE[dwSize];
  2996. ::ReadFile(hFile, pData, dwSize, &dwRead, NULL);
  2997. ::CloseHandle(hFile);
  2998. if (dwRead != dwSize)
  2999. {
  3000. delete[] pData;
  3001. pData = NULL;
  3002. }
  3003. break;
  3004. }
  3005. DWORD nFonts;
  3006. HANDLE hFont = ::AddFontMemResourceEx(pData, dwSize, NULL, &nFonts);
  3007. delete[] pData;
  3008. pData = NULL;
  3009. m_aFonts.Add(hFont);
  3010. }
  3011. HFONT CPaintManagerUI::GetFont(int id)
  3012. {
  3013. if (id < 0) return GetDefaultFontInfo()->hFont;
  3014. TCHAR idBuffer[16];
  3015. ::ZeroMemory(idBuffer, sizeof(idBuffer));
  3016. _itot(id, idBuffer, 10);
  3017. TFontInfo* pFontInfo = static_cast<TFontInfo*>(m_ResInfo.m_CustomFonts.Find(idBuffer));
  3018. if (!pFontInfo) pFontInfo = static_cast<TFontInfo*>(m_SharedResInfo.m_CustomFonts.Find(idBuffer));
  3019. if (!pFontInfo) return GetDefaultFontInfo()->hFont;
  3020. return pFontInfo->hFont;
  3021. }
  3022. HFONT CPaintManagerUI::GetFont(LPCTSTR pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic, bool bStrikeout)
  3023. {
  3024. TFontInfo* pFontInfo = NULL;
  3025. for (int i = 0; i < m_ResInfo.m_CustomFonts.GetSize(); i++)
  3026. {
  3027. if (LPCTSTR key = m_ResInfo.m_CustomFonts.GetAt(i))
  3028. {
  3029. pFontInfo = static_cast<TFontInfo*>(m_ResInfo.m_CustomFonts.Find(key));
  3030. if (pFontInfo && pFontInfo->sFontName == pStrFontName && pFontInfo->iSize == nSize &&
  3031. pFontInfo->bBold == bBold && pFontInfo->bUnderline == bUnderline && pFontInfo->bItalic == bItalic
  3032. && pFontInfo->bStrikeout == bStrikeout)
  3033. return pFontInfo->hFont;
  3034. }
  3035. }
  3036. for (int i = 0; i < m_SharedResInfo.m_CustomFonts.GetSize(); i++)
  3037. {
  3038. if (LPCTSTR key = m_SharedResInfo.m_CustomFonts.GetAt(i))
  3039. {
  3040. pFontInfo = static_cast<TFontInfo*>(m_SharedResInfo.m_CustomFonts.Find(key));
  3041. if (pFontInfo && pFontInfo->sFontName == pStrFontName && pFontInfo->iSize == nSize &&
  3042. pFontInfo->bBold == bBold && pFontInfo->bUnderline == bUnderline && pFontInfo->bItalic == bItalic
  3043. && pFontInfo->bStrikeout == bStrikeout)
  3044. return pFontInfo->hFont;
  3045. }
  3046. }
  3047. return NULL;
  3048. }
  3049. int CPaintManagerUI::GetFontIndex(HFONT hFont, bool bShared)
  3050. {
  3051. TFontInfo* pFontInfo = NULL;
  3052. if (bShared)
  3053. {
  3054. for (int i = 0; i < m_SharedResInfo.m_CustomFonts.GetSize(); i++)
  3055. {
  3056. if (LPCTSTR key = m_SharedResInfo.m_CustomFonts.GetAt(i))
  3057. {
  3058. pFontInfo = static_cast<TFontInfo*>(m_SharedResInfo.m_CustomFonts.Find(key));
  3059. if (pFontInfo && pFontInfo->hFont == hFont) return _ttoi(key);
  3060. }
  3061. }
  3062. }
  3063. else
  3064. {
  3065. for (int i = 0; i < m_ResInfo.m_CustomFonts.GetSize(); i++)
  3066. {
  3067. if (LPCTSTR key = m_ResInfo.m_CustomFonts.GetAt(i))
  3068. {
  3069. pFontInfo = static_cast<TFontInfo*>(m_ResInfo.m_CustomFonts.Find(key));
  3070. if (pFontInfo && pFontInfo->hFont == hFont) return _ttoi(key);
  3071. }
  3072. }
  3073. }
  3074. return -1;
  3075. }
  3076. int CPaintManagerUI::GetFontIndex(LPCTSTR pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic, bool bStrikeout, bool bShared)
  3077. {
  3078. TFontInfo* pFontInfo = NULL;
  3079. if (bShared)
  3080. {
  3081. for (int i = 0; i < m_SharedResInfo.m_CustomFonts.GetSize(); i++)
  3082. {
  3083. if (LPCTSTR key = m_SharedResInfo.m_CustomFonts.GetAt(i))
  3084. {
  3085. pFontInfo = static_cast<TFontInfo*>(m_SharedResInfo.m_CustomFonts.Find(key));
  3086. if (pFontInfo && pFontInfo->sFontName == pStrFontName && pFontInfo->iSize == nSize &&
  3087. pFontInfo->bBold == bBold && pFontInfo->bUnderline == bUnderline && pFontInfo->bItalic == bItalic
  3088. && pFontInfo->bStrikeout == bStrikeout)
  3089. return _ttoi(key);
  3090. }
  3091. }
  3092. }
  3093. else
  3094. {
  3095. for (int i = 0; i < m_ResInfo.m_CustomFonts.GetSize(); i++)
  3096. {
  3097. if (LPCTSTR key = m_ResInfo.m_CustomFonts.GetAt(i))
  3098. {
  3099. pFontInfo = static_cast<TFontInfo*>(m_ResInfo.m_CustomFonts.Find(key));
  3100. if (pFontInfo && pFontInfo->sFontName == pStrFontName && pFontInfo->iSize == nSize &&
  3101. pFontInfo->bBold == bBold && pFontInfo->bUnderline == bUnderline && pFontInfo->bItalic == bItalic
  3102. && pFontInfo->bStrikeout == bStrikeout)
  3103. return _ttoi(key);
  3104. }
  3105. }
  3106. }
  3107. return -1;
  3108. }
  3109. void CPaintManagerUI::RemoveFont(HFONT hFont, bool bShared)
  3110. {
  3111. TFontInfo* pFontInfo = NULL;
  3112. if (bShared)
  3113. {
  3114. for (int i = 0; i < m_SharedResInfo.m_CustomFonts.GetSize(); i++)
  3115. {
  3116. if (LPCTSTR key = m_SharedResInfo.m_CustomFonts.GetAt(i))
  3117. {
  3118. pFontInfo = static_cast<TFontInfo*>(m_SharedResInfo.m_CustomFonts.Find(key));
  3119. if (pFontInfo && pFontInfo->hFont == hFont)
  3120. {
  3121. ::DeleteObject(pFontInfo->hFont);
  3122. delete pFontInfo;
  3123. m_SharedResInfo.m_CustomFonts.Remove(key);
  3124. return;
  3125. }
  3126. }
  3127. }
  3128. }
  3129. else
  3130. {
  3131. for (int i = 0; i < m_ResInfo.m_CustomFonts.GetSize(); i++)
  3132. {
  3133. if (LPCTSTR key = m_ResInfo.m_CustomFonts.GetAt(i))
  3134. {
  3135. pFontInfo = static_cast<TFontInfo*>(m_ResInfo.m_CustomFonts.Find(key));
  3136. if (pFontInfo && pFontInfo->hFont == hFont)
  3137. {
  3138. ::DeleteObject(pFontInfo->hFont);
  3139. delete pFontInfo;
  3140. m_ResInfo.m_CustomFonts.Remove(key);
  3141. return;
  3142. }
  3143. }
  3144. }
  3145. }
  3146. }
  3147. void CPaintManagerUI::RemoveFont(int id, bool bShared)
  3148. {
  3149. TCHAR idBuffer[16];
  3150. ::ZeroMemory(idBuffer, sizeof(idBuffer));
  3151. _itot(id, idBuffer, 10);
  3152. TFontInfo* pFontInfo = NULL;
  3153. if (bShared)
  3154. {
  3155. pFontInfo = static_cast<TFontInfo*>(m_SharedResInfo.m_CustomFonts.Find(idBuffer));
  3156. if (pFontInfo)
  3157. {
  3158. ::DeleteObject(pFontInfo->hFont);
  3159. delete pFontInfo;
  3160. m_SharedResInfo.m_CustomFonts.Remove(idBuffer);
  3161. }
  3162. }
  3163. else
  3164. {
  3165. pFontInfo = static_cast<TFontInfo*>(m_ResInfo.m_CustomFonts.Find(idBuffer));
  3166. if (pFontInfo)
  3167. {
  3168. ::DeleteObject(pFontInfo->hFont);
  3169. delete pFontInfo;
  3170. m_ResInfo.m_CustomFonts.Remove(idBuffer);
  3171. }
  3172. }
  3173. }
  3174. void CPaintManagerUI::RemoveAllFonts(bool bShared)
  3175. {
  3176. TFontInfo* pFontInfo;
  3177. if (bShared)
  3178. {
  3179. for (int i = 0; i < m_SharedResInfo.m_CustomFonts.GetSize(); i++)
  3180. {
  3181. if (LPCTSTR key = m_SharedResInfo.m_CustomFonts.GetAt(i))
  3182. {
  3183. pFontInfo = static_cast<TFontInfo*>(m_SharedResInfo.m_CustomFonts.Find(key, false));
  3184. if (pFontInfo)
  3185. {
  3186. ::DeleteObject(pFontInfo->hFont);
  3187. delete pFontInfo;
  3188. }
  3189. }
  3190. }
  3191. m_SharedResInfo.m_CustomFonts.RemoveAll();
  3192. }
  3193. else
  3194. {
  3195. for (int i = 0; i < m_ResInfo.m_CustomFonts.GetSize(); i++)
  3196. {
  3197. if (LPCTSTR key = m_ResInfo.m_CustomFonts.GetAt(i))
  3198. {
  3199. pFontInfo = static_cast<TFontInfo*>(m_ResInfo.m_CustomFonts.Find(key, false));
  3200. if (pFontInfo)
  3201. {
  3202. ::DeleteObject(pFontInfo->hFont);
  3203. delete pFontInfo;
  3204. }
  3205. }
  3206. }
  3207. m_ResInfo.m_CustomFonts.RemoveAll();
  3208. }
  3209. }
  3210. TFontInfo* CPaintManagerUI::GetFontInfo(int id)
  3211. {
  3212. if (id < 0) return GetDefaultFontInfo();
  3213. TCHAR idBuffer[16];
  3214. ::ZeroMemory(idBuffer, sizeof(idBuffer));
  3215. _itot(id, idBuffer, 10);
  3216. TFontInfo* pFontInfo = static_cast<TFontInfo*>(m_ResInfo.m_CustomFonts.Find(idBuffer));
  3217. if (!pFontInfo) pFontInfo = static_cast<TFontInfo*>(m_SharedResInfo.m_CustomFonts.Find(idBuffer));
  3218. if (!pFontInfo) pFontInfo = GetDefaultFontInfo();
  3219. if (pFontInfo->tm.tmHeight == 0)
  3220. {
  3221. HFONT hOldFont = (HFONT) ::SelectObject(m_hDcPaint, pFontInfo->hFont);
  3222. ::GetTextMetrics(m_hDcPaint, &pFontInfo->tm);
  3223. ::SelectObject(m_hDcPaint, hOldFont);
  3224. }
  3225. return pFontInfo;
  3226. }
  3227. TFontInfo* CPaintManagerUI::GetFontInfo(HFONT hFont)
  3228. {
  3229. TFontInfo* pFontInfo = NULL;
  3230. for (int i = 0; i < m_ResInfo.m_CustomFonts.GetSize(); i++)
  3231. {
  3232. if (LPCTSTR key = m_ResInfo.m_CustomFonts.GetAt(i))
  3233. {
  3234. pFontInfo = static_cast<TFontInfo*>(m_ResInfo.m_CustomFonts.Find(key));
  3235. if (pFontInfo && pFontInfo->hFont == hFont) break;
  3236. }
  3237. }
  3238. if (!pFontInfo)
  3239. {
  3240. for (int i = 0; i < m_SharedResInfo.m_CustomFonts.GetSize(); i++)
  3241. {
  3242. if (LPCTSTR key = m_SharedResInfo.m_CustomFonts.GetAt(i))
  3243. {
  3244. pFontInfo = static_cast<TFontInfo*>(m_SharedResInfo.m_CustomFonts.Find(key));
  3245. if (pFontInfo && pFontInfo->hFont == hFont) break;
  3246. }
  3247. }
  3248. }
  3249. if (!pFontInfo) pFontInfo = GetDefaultFontInfo();
  3250. if (pFontInfo->tm.tmHeight == 0)
  3251. {
  3252. HFONT hOldFont = (HFONT) ::SelectObject(m_hDcPaint, pFontInfo->hFont);
  3253. ::GetTextMetrics(m_hDcPaint, &pFontInfo->tm);
  3254. ::SelectObject(m_hDcPaint, hOldFont);
  3255. }
  3256. return pFontInfo;
  3257. }
  3258. const TImageInfo* CPaintManagerUI::GetImage(LPCTSTR bitmap)
  3259. {
  3260. TImageInfo* data = static_cast<TImageInfo*>(m_ResInfo.m_ImageHash.Find(bitmap));
  3261. if (!data) data = static_cast<TImageInfo*>(m_SharedResInfo.m_ImageHash.Find(bitmap));
  3262. return data;
  3263. }
  3264. const TImageInfo* CPaintManagerUI::GetImageEx(LPCTSTR bitmap, LPCTSTR type, DWORD mask, bool bUseHSL, bool bGdiplus, HINSTANCE instance)
  3265. {
  3266. const TImageInfo* data = GetImage(bitmap);
  3267. if (!data)
  3268. {
  3269. if (AddImage(bitmap, type, mask, bUseHSL, bGdiplus, false, instance))
  3270. {
  3271. if (m_bForceUseSharedRes) data = static_cast<TImageInfo*>(m_SharedResInfo.m_ImageHash.Find(bitmap));
  3272. else data = static_cast<TImageInfo*>(m_ResInfo.m_ImageHash.Find(bitmap));
  3273. }
  3274. }
  3275. return data;
  3276. }
  3277. const TImageInfo* CPaintManagerUI::AddImage(LPCTSTR bitmap, LPCTSTR type, DWORD mask, bool bUseHSL, bool bGdiplus, bool bShared, HINSTANCE instance)
  3278. {
  3279. if (bitmap == NULL || bitmap[0] == _T('\0')) return NULL;
  3280. TImageInfo* data = NULL;
  3281. if (type != NULL && lstrlen(type) > 0)
  3282. {
  3283. if (isdigit(*bitmap))
  3284. {
  3285. LPTSTR pstr = NULL;
  3286. int iIndex = _tcstol(bitmap, &pstr, 10);
  3287. data = bGdiplus ? CRenderEngine::GdiplusLoadImage(iIndex, type, mask, instance) : CRenderEngine::LoadImage(iIndex, type, mask, instance);
  3288. }
  3289. }
  3290. else
  3291. {
  3292. data = bGdiplus ? CRenderEngine::GdiplusLoadImage(bitmap, NULL, mask, instance) : CRenderEngine::LoadImage(bitmap, NULL, mask, instance);
  3293. if (!data)
  3294. {
  3295. CDuiString sImageName = bitmap;
  3296. int iAtIdx = sImageName.ReverseFind(_T('@'));
  3297. int iDotIdx = sImageName.ReverseFind(_T('.'));
  3298. if (iAtIdx != -1 && iDotIdx != -1)
  3299. {
  3300. CDuiString sExe = sImageName.Mid(iDotIdx);
  3301. sImageName = sImageName.Left(iAtIdx) + sExe;
  3302. data = bGdiplus ? CRenderEngine::GdiplusLoadImage(sImageName.GetData(), NULL, mask, instance) : CRenderEngine::LoadImage(sImageName.GetData(), NULL, mask, instance);
  3303. }
  3304. }
  3305. }
  3306. if (data == NULL)
  3307. {
  3308. return NULL;
  3309. }
  3310. data->bUseHSL = bUseHSL;
  3311. if (type != NULL) data->sResType = type;
  3312. data->dwMask = mask;
  3313. if (data->bUseHSL)
  3314. {
  3315. data->pSrcBits = new BYTE[data->nX * data->nY * 4];
  3316. ::CopyMemory(data->pSrcBits, data->pBits, data->nX * data->nY * 4);
  3317. }
  3318. else data->pSrcBits = NULL;
  3319. if (m_bUseHSL) CRenderEngine::AdjustImage(true, data, m_H, m_S, m_L);
  3320. if (data)
  3321. {
  3322. if (bShared || m_bForceUseSharedRes)
  3323. {
  3324. TImageInfo* pOldImageInfo = static_cast<TImageInfo*>(m_SharedResInfo.m_ImageHash.Find(bitmap));
  3325. if (pOldImageInfo)
  3326. {
  3327. CRenderEngine::FreeImage(pOldImageInfo);
  3328. m_SharedResInfo.m_ImageHash.Remove(bitmap);
  3329. }
  3330. if (!m_SharedResInfo.m_ImageHash.Insert(bitmap, data))
  3331. {
  3332. CRenderEngine::FreeImage(data);
  3333. data = NULL;
  3334. }
  3335. }
  3336. else
  3337. {
  3338. TImageInfo* pOldImageInfo = static_cast<TImageInfo*>(m_ResInfo.m_ImageHash.Find(bitmap));
  3339. if (pOldImageInfo)
  3340. {
  3341. CRenderEngine::FreeImage(pOldImageInfo);
  3342. m_ResInfo.m_ImageHash.Remove(bitmap);
  3343. }
  3344. if (!m_ResInfo.m_ImageHash.Insert(bitmap, data))
  3345. {
  3346. CRenderEngine::FreeImage(data);
  3347. data = NULL;
  3348. }
  3349. }
  3350. }
  3351. return data;
  3352. }
  3353. const TImageInfo* CPaintManagerUI::AddImage(LPCTSTR bitmap, HBITMAP hBitmap, int iWidth, int iHeight, bool bAlpha, bool bShared)
  3354. {
  3355. // 因无法确定外部HBITMAP格式,不能使用hsl调整
  3356. if (bitmap == NULL || bitmap[0] == _T('\0')) return NULL;
  3357. if (hBitmap == NULL || iWidth <= 0 || iHeight <= 0) return NULL;
  3358. TImageInfo* data = new TImageInfo;
  3359. data->pBits = NULL;
  3360. data->pSrcBits = NULL;
  3361. data->hBitmap = hBitmap;
  3362. data->pBits = NULL;
  3363. data->nX = iWidth;
  3364. data->nY = iHeight;
  3365. data->bAlpha = bAlpha;
  3366. data->bUseHSL = false;
  3367. data->pSrcBits = NULL;
  3368. data->dwMask = 0;
  3369. if (bShared || m_bForceUseSharedRes)
  3370. {
  3371. if (!m_SharedResInfo.m_ImageHash.Insert(bitmap, data))
  3372. {
  3373. CRenderEngine::FreeImage(data);
  3374. data = NULL;
  3375. }
  3376. }
  3377. else
  3378. {
  3379. if (!m_ResInfo.m_ImageHash.Insert(bitmap, data))
  3380. {
  3381. CRenderEngine::FreeImage(data);
  3382. data = NULL;
  3383. }
  3384. }
  3385. return data;
  3386. }
  3387. void CPaintManagerUI::RemoveImage(LPCTSTR bitmap, bool bShared)
  3388. {
  3389. TImageInfo* data = NULL;
  3390. if (bShared)
  3391. {
  3392. data = static_cast<TImageInfo*>(m_SharedResInfo.m_ImageHash.Find(bitmap));
  3393. if (data)
  3394. {
  3395. CRenderEngine::FreeImage(data);
  3396. m_SharedResInfo.m_ImageHash.Remove(bitmap);
  3397. }
  3398. }
  3399. else
  3400. {
  3401. data = static_cast<TImageInfo*>(m_ResInfo.m_ImageHash.Find(bitmap));
  3402. if (data)
  3403. {
  3404. CRenderEngine::FreeImage(data);
  3405. m_ResInfo.m_ImageHash.Remove(bitmap);
  3406. }
  3407. }
  3408. }
  3409. void CPaintManagerUI::RemoveAllImages(bool bShared)
  3410. {
  3411. if (bShared)
  3412. {
  3413. TImageInfo* data;
  3414. for (int i = 0; i < m_SharedResInfo.m_ImageHash.GetSize(); i++)
  3415. {
  3416. if (LPCTSTR key = m_SharedResInfo.m_ImageHash.GetAt(i))
  3417. {
  3418. data = static_cast<TImageInfo*>(m_SharedResInfo.m_ImageHash.Find(key, false));
  3419. if (data)
  3420. {
  3421. CRenderEngine::FreeImage(data);
  3422. }
  3423. }
  3424. }
  3425. m_SharedResInfo.m_ImageHash.RemoveAll();
  3426. }
  3427. else
  3428. {
  3429. TImageInfo* data;
  3430. for (int i = 0; i < m_ResInfo.m_ImageHash.GetSize(); i++)
  3431. {
  3432. if (LPCTSTR key = m_ResInfo.m_ImageHash.GetAt(i))
  3433. {
  3434. data = static_cast<TImageInfo*>(m_ResInfo.m_ImageHash.Find(key, false));
  3435. if (data)
  3436. {
  3437. CRenderEngine::FreeImage(data);
  3438. }
  3439. }
  3440. }
  3441. m_ResInfo.m_ImageHash.RemoveAll();
  3442. }
  3443. }
  3444. void CPaintManagerUI::AdjustSharedImagesHSL()
  3445. {
  3446. TImageInfo* data;
  3447. for (int i = 0; i < m_SharedResInfo.m_ImageHash.GetSize(); i++)
  3448. {
  3449. if (LPCTSTR key = m_SharedResInfo.m_ImageHash.GetAt(i))
  3450. {
  3451. data = static_cast<TImageInfo*>(m_SharedResInfo.m_ImageHash.Find(key));
  3452. if (data && data->bUseHSL)
  3453. {
  3454. CRenderEngine::AdjustImage(m_bUseHSL, data, m_H, m_S, m_L);
  3455. }
  3456. }
  3457. }
  3458. }
  3459. void CPaintManagerUI::AdjustImagesHSL()
  3460. {
  3461. TImageInfo* data;
  3462. for (int i = 0; i < m_ResInfo.m_ImageHash.GetSize(); i++)
  3463. {
  3464. if (LPCTSTR key = m_ResInfo.m_ImageHash.GetAt(i))
  3465. {
  3466. data = static_cast<TImageInfo*>(m_ResInfo.m_ImageHash.Find(key));
  3467. if (data && data->bUseHSL)
  3468. {
  3469. CRenderEngine::AdjustImage(m_bUseHSL, data, m_H, m_S, m_L);
  3470. }
  3471. }
  3472. }
  3473. Invalidate();
  3474. }
  3475. void CPaintManagerUI::PostAsyncNotify()
  3476. {
  3477. if (!m_bAsyncNotifyPosted)
  3478. {
  3479. ::PostMessage(m_hWndPaint, WM_APP + 1, 0, 0L);
  3480. m_bAsyncNotifyPosted = true;
  3481. }
  3482. }
  3483. void CPaintManagerUI::ReloadSharedImages()
  3484. {
  3485. TImageInfo* data = NULL;
  3486. TImageInfo* pNewData = NULL;
  3487. for (int i = 0; i < m_SharedResInfo.m_ImageHash.GetSize(); i++)
  3488. {
  3489. if (LPCTSTR bitmap = m_SharedResInfo.m_ImageHash.GetAt(i))
  3490. {
  3491. data = static_cast<TImageInfo*>(m_SharedResInfo.m_ImageHash.Find(bitmap));
  3492. if (data != NULL)
  3493. {
  3494. if (!data->sResType.IsEmpty())
  3495. {
  3496. if (isdigit(*bitmap))
  3497. {
  3498. LPTSTR pstr = NULL;
  3499. int iIndex = _tcstol(bitmap, &pstr, 10);
  3500. pNewData = CRenderEngine::LoadImage(iIndex, data->sResType.GetData(), data->dwMask);
  3501. }
  3502. }
  3503. else
  3504. {
  3505. pNewData = CRenderEngine::LoadImage(bitmap, NULL, data->dwMask);
  3506. }
  3507. if (pNewData == NULL) continue;
  3508. CRenderEngine::FreeImage(data, false);
  3509. data->hBitmap = pNewData->hBitmap;
  3510. data->pImage = pNewData->pImage;
  3511. data->pBits = pNewData->pBits;
  3512. data->nX = pNewData->nX;
  3513. data->nY = pNewData->nY;
  3514. data->bAlpha = pNewData->bAlpha;
  3515. data->pSrcBits = NULL;
  3516. if (data->bUseHSL)
  3517. {
  3518. data->pSrcBits = new BYTE[data->nX * data->nY * 4];
  3519. ::CopyMemory(data->pSrcBits, data->pBits, data->nX * data->nY * 4);
  3520. }
  3521. else data->pSrcBits = NULL;
  3522. if (m_bUseHSL) CRenderEngine::AdjustImage(true, data, m_H, m_S, m_L);
  3523. delete pNewData;
  3524. }
  3525. }
  3526. }
  3527. }
  3528. void CPaintManagerUI::ReloadImages()
  3529. {
  3530. RemoveAllDrawInfos();
  3531. TImageInfo* data = NULL;
  3532. TImageInfo* pNewData = NULL;
  3533. for (int i = 0; i < m_ResInfo.m_ImageHash.GetSize(); i++)
  3534. {
  3535. if (LPCTSTR bitmap = m_ResInfo.m_ImageHash.GetAt(i))
  3536. {
  3537. data = static_cast<TImageInfo*>(m_ResInfo.m_ImageHash.Find(bitmap));
  3538. if (data != NULL)
  3539. {
  3540. if (!data->sResType.IsEmpty())
  3541. {
  3542. if (isdigit(*bitmap))
  3543. {
  3544. LPTSTR pstr = NULL;
  3545. int iIndex = _tcstol(bitmap, &pstr, 10);
  3546. pNewData = CRenderEngine::LoadImage(iIndex, data->sResType.GetData(), data->dwMask);
  3547. }
  3548. }
  3549. else
  3550. {
  3551. pNewData = CRenderEngine::LoadImage(bitmap, NULL, data->dwMask);
  3552. }
  3553. CRenderEngine::FreeImage(data, false);
  3554. if (pNewData == NULL)
  3555. {
  3556. m_ResInfo.m_ImageHash.Remove(bitmap);
  3557. continue;
  3558. }
  3559. data->hBitmap = pNewData->hBitmap;
  3560. data->pBits = pNewData->pBits;
  3561. data->nX = pNewData->nX;
  3562. data->nY = pNewData->nY;
  3563. data->bAlpha = pNewData->bAlpha;
  3564. data->pSrcBits = NULL;
  3565. if (data->bUseHSL)
  3566. {
  3567. data->pSrcBits = new BYTE[data->nX * data->nY * 4];
  3568. ::CopyMemory(data->pSrcBits, data->pBits, data->nX * data->nY * 4);
  3569. }
  3570. else data->pSrcBits = NULL;
  3571. if (m_bUseHSL) CRenderEngine::AdjustImage(true, data, m_H, m_S, m_L);
  3572. delete pNewData;
  3573. }
  3574. }
  3575. }
  3576. if (m_pRoot) m_pRoot->Invalidate();
  3577. }
  3578. const TDrawInfo* CPaintManagerUI::GetDrawInfo(LPCTSTR pStrImage, LPCTSTR pStrModify)
  3579. {
  3580. CDuiString sKey;
  3581. sKey.Format(_T("%s%s"), pStrImage == NULL ? _T("") : pStrImage, pStrModify == NULL ? _T("") : pStrModify);
  3582. TDrawInfo* pDrawInfo = static_cast<TDrawInfo*>(m_ResInfo.m_DrawInfoHash.Find(sKey));
  3583. if (pDrawInfo == NULL && !sKey.IsEmpty())
  3584. {
  3585. pDrawInfo = new TDrawInfo();
  3586. pDrawInfo->Parse(pStrImage, pStrModify, this);
  3587. m_ResInfo.m_DrawInfoHash.Insert(sKey, pDrawInfo);
  3588. }
  3589. return pDrawInfo;
  3590. }
  3591. void CPaintManagerUI::RemoveDrawInfo(LPCTSTR pStrImage, LPCTSTR pStrModify)
  3592. {
  3593. CDuiString sKey;
  3594. sKey.Format(_T("%s%s"), pStrImage == NULL ? _T("") : pStrImage, pStrModify == NULL ? _T("") : pStrModify);
  3595. TDrawInfo* pDrawInfo = static_cast<TDrawInfo*>(m_ResInfo.m_DrawInfoHash.Find(sKey));
  3596. if (pDrawInfo != NULL)
  3597. {
  3598. m_ResInfo.m_DrawInfoHash.Remove(sKey);
  3599. delete pDrawInfo;
  3600. pDrawInfo = NULL;
  3601. }
  3602. }
  3603. void CPaintManagerUI::RemoveAllDrawInfos()
  3604. {
  3605. TDrawInfo* pDrawInfo = NULL;
  3606. for (int i = 0; i < m_ResInfo.m_DrawInfoHash.GetSize(); i++)
  3607. {
  3608. LPCTSTR key = m_ResInfo.m_DrawInfoHash.GetAt(i);
  3609. if (key != NULL)
  3610. {
  3611. pDrawInfo = static_cast<TDrawInfo*>(m_ResInfo.m_DrawInfoHash.Find(key, false));
  3612. if (pDrawInfo)
  3613. {
  3614. delete pDrawInfo;
  3615. pDrawInfo = NULL;
  3616. }
  3617. }
  3618. }
  3619. m_ResInfo.m_DrawInfoHash.RemoveAll();
  3620. }
  3621. void CPaintManagerUI::AddDefaultAttributeList(LPCTSTR pStrControlName, LPCTSTR pStrControlAttrList, bool bShared)
  3622. {
  3623. if (bShared || m_bForceUseSharedRes)
  3624. {
  3625. CDuiString* pDefaultAttr = new CDuiString(pStrControlAttrList);
  3626. if (pDefaultAttr != NULL)
  3627. {
  3628. CDuiString* pOldDefaultAttr = static_cast<CDuiString*>(m_SharedResInfo.m_AttrHash.Set(pStrControlName, (LPVOID)pDefaultAttr));
  3629. if (pOldDefaultAttr) delete pOldDefaultAttr;
  3630. }
  3631. }
  3632. else
  3633. {
  3634. CDuiString* pDefaultAttr = new CDuiString(pStrControlAttrList);
  3635. if (pDefaultAttr != NULL)
  3636. {
  3637. CDuiString* pOldDefaultAttr = static_cast<CDuiString*>(m_ResInfo.m_AttrHash.Set(pStrControlName, (LPVOID)pDefaultAttr));
  3638. if (pOldDefaultAttr) delete pOldDefaultAttr;
  3639. }
  3640. }
  3641. }
  3642. LPCTSTR CPaintManagerUI::GetDefaultAttributeList(LPCTSTR pStrControlName) const
  3643. {
  3644. CDuiString* pDefaultAttr = static_cast<CDuiString*>(m_ResInfo.m_AttrHash.Find(pStrControlName));
  3645. if (!pDefaultAttr) pDefaultAttr = static_cast<CDuiString*>(m_SharedResInfo.m_AttrHash.Find(pStrControlName));
  3646. if (pDefaultAttr) return pDefaultAttr->GetData();
  3647. return NULL;
  3648. }
  3649. bool CPaintManagerUI::RemoveDefaultAttributeList(LPCTSTR pStrControlName, bool bShared)
  3650. {
  3651. if (bShared)
  3652. {
  3653. CDuiString* pDefaultAttr = static_cast<CDuiString*>(m_SharedResInfo.m_AttrHash.Find(pStrControlName));
  3654. if (!pDefaultAttr) return false;
  3655. delete pDefaultAttr;
  3656. return m_SharedResInfo.m_AttrHash.Remove(pStrControlName);
  3657. }
  3658. else
  3659. {
  3660. CDuiString* pDefaultAttr = static_cast<CDuiString*>(m_ResInfo.m_AttrHash.Find(pStrControlName));
  3661. if (!pDefaultAttr) return false;
  3662. delete pDefaultAttr;
  3663. return m_ResInfo.m_AttrHash.Remove(pStrControlName);
  3664. }
  3665. }
  3666. void CPaintManagerUI::RemoveAllDefaultAttributeList(bool bShared)
  3667. {
  3668. if (bShared)
  3669. {
  3670. CDuiString* pDefaultAttr;
  3671. for (int i = 0; i < m_SharedResInfo.m_AttrHash.GetSize(); i++)
  3672. {
  3673. if (LPCTSTR key = m_SharedResInfo.m_AttrHash.GetAt(i))
  3674. {
  3675. pDefaultAttr = static_cast<CDuiString*>(m_SharedResInfo.m_AttrHash.Find(key));
  3676. if (pDefaultAttr) delete pDefaultAttr;
  3677. }
  3678. }
  3679. m_SharedResInfo.m_AttrHash.RemoveAll();
  3680. }
  3681. else
  3682. {
  3683. CDuiString* pDefaultAttr;
  3684. for (int i = 0; i < m_ResInfo.m_AttrHash.GetSize(); i++)
  3685. {
  3686. if (LPCTSTR key = m_ResInfo.m_AttrHash.GetAt(i))
  3687. {
  3688. pDefaultAttr = static_cast<CDuiString*>(m_ResInfo.m_AttrHash.Find(key));
  3689. if (pDefaultAttr) delete pDefaultAttr;
  3690. }
  3691. }
  3692. m_ResInfo.m_AttrHash.RemoveAll();
  3693. }
  3694. }
  3695. void CPaintManagerUI::AddWindowCustomAttribute(LPCTSTR pstrName, LPCTSTR pstrAttr)
  3696. {
  3697. if (pstrName == NULL || pstrName[0] == _T('\0') || pstrAttr == NULL || pstrAttr[0] == _T('\0')) return;
  3698. CDuiString* pCostomAttr = new CDuiString(pstrAttr);
  3699. if (pCostomAttr != NULL)
  3700. {
  3701. if (m_mWindowCustomAttrHash.Find(pstrName) == NULL)
  3702. m_mWindowCustomAttrHash.Set(pstrName, (LPVOID)pCostomAttr);
  3703. else
  3704. delete pCostomAttr;
  3705. }
  3706. }
  3707. LPCTSTR CPaintManagerUI::GetWindowCustomAttribute(LPCTSTR pstrName) const
  3708. {
  3709. if (pstrName == NULL || pstrName[0] == _T('\0')) return NULL;
  3710. CDuiString* pCostomAttr = static_cast<CDuiString*>(m_mWindowCustomAttrHash.Find(pstrName));
  3711. if (pCostomAttr) return pCostomAttr->GetData();
  3712. return NULL;
  3713. }
  3714. bool CPaintManagerUI::RemoveWindowCustomAttribute(LPCTSTR pstrName)
  3715. {
  3716. if (pstrName == NULL || pstrName[0] == _T('\0')) return NULL;
  3717. CDuiString* pCostomAttr = static_cast<CDuiString*>(m_mWindowCustomAttrHash.Find(pstrName));
  3718. if (!pCostomAttr) return false;
  3719. delete pCostomAttr;
  3720. return m_mWindowCustomAttrHash.Remove(pstrName);
  3721. }
  3722. void CPaintManagerUI::RemoveAllWindowCustomAttribute()
  3723. {
  3724. CDuiString* pCostomAttr;
  3725. for (int i = 0; i < m_mWindowCustomAttrHash.GetSize(); i++)
  3726. {
  3727. if (LPCTSTR key = m_mWindowCustomAttrHash.GetAt(i))
  3728. {
  3729. pCostomAttr = static_cast<CDuiString*>(m_mWindowCustomAttrHash.Find(key));
  3730. delete pCostomAttr;
  3731. }
  3732. }
  3733. m_mWindowCustomAttrHash.Resize();
  3734. }
  3735. CControlUI* CPaintManagerUI::GetRoot() const
  3736. {
  3737. ASSERT(m_pRoot);
  3738. return m_pRoot;
  3739. }
  3740. CControlUI* CPaintManagerUI::FindControl(POINT pt) const
  3741. {
  3742. ASSERT(m_pRoot);
  3743. return m_pRoot->FindControl(__FindControlFromPoint, &pt, UIFIND_VISIBLE | UIFIND_HITTEST | UIFIND_TOP_FIRST);
  3744. }
  3745. CControlUI* CPaintManagerUI::FindControl(LPCTSTR pstrName) const
  3746. {
  3747. ASSERT(m_pRoot);
  3748. return static_cast<CControlUI*>(m_mNameHash.Find(pstrName));
  3749. }
  3750. CControlUI* CPaintManagerUI::FindSubControlByPoint(CControlUI* pParent, POINT pt) const
  3751. {
  3752. if (pParent == NULL) pParent = GetRoot();
  3753. ASSERT(pParent);
  3754. return pParent->FindControl(__FindControlFromPoint, &pt, UIFIND_VISIBLE | UIFIND_HITTEST | UIFIND_TOP_FIRST);
  3755. }
  3756. CControlUI* CPaintManagerUI::FindSubControlByName(CControlUI* pParent, LPCTSTR pstrName) const
  3757. {
  3758. if (pParent == NULL) pParent = GetRoot();
  3759. ASSERT(pParent);
  3760. return pParent->FindControl(__FindControlFromName, (LPVOID)pstrName, UIFIND_ALL);
  3761. }
  3762. CControlUI* CPaintManagerUI::FindSubControlByClass(CControlUI* pParent, LPCTSTR pstrClass, int iIndex)
  3763. {
  3764. if (pParent == NULL) pParent = GetRoot();
  3765. ASSERT(pParent);
  3766. m_aFoundControls.Resize(iIndex + 1);
  3767. return pParent->FindControl(__FindControlFromClass, (LPVOID)pstrClass, UIFIND_ALL);
  3768. }
  3769. CStdPtrArray* CPaintManagerUI::FindSubControlsByClass(CControlUI* pParent, LPCTSTR pstrClass)
  3770. {
  3771. if (pParent == NULL) pParent = GetRoot();
  3772. ASSERT(pParent);
  3773. m_aFoundControls.Empty();
  3774. pParent->FindControl(__FindControlsFromClass, (LPVOID)pstrClass, UIFIND_ALL);
  3775. return &m_aFoundControls;
  3776. }
  3777. CStdPtrArray* CPaintManagerUI::GetFoundControls()
  3778. {
  3779. return &m_aFoundControls;
  3780. }
  3781. CControlUI* CALLBACK CPaintManagerUI::__FindControlFromNameHash(CControlUI* pThis, LPVOID pData)
  3782. {
  3783. CPaintManagerUI* pManager = static_cast<CPaintManagerUI*>(pData);
  3784. const CDuiString& sName = pThis->GetName();
  3785. if (sName.IsEmpty()) return NULL;
  3786. // Add this control to the hash list
  3787. pManager->m_mNameHash.Set(sName, pThis);
  3788. return NULL; // Attempt to add all controls
  3789. }
  3790. CControlUI* CALLBACK CPaintManagerUI::__FindControlFromCount(CControlUI* /*pThis*/, LPVOID pData)
  3791. {
  3792. int* pnCount = static_cast<int*>(pData);
  3793. (*pnCount)++;
  3794. return NULL; // Count all controls
  3795. }
  3796. CControlUI* CALLBACK CPaintManagerUI::__FindControlFromPoint(CControlUI* pThis, LPVOID pData)
  3797. {
  3798. LPPOINT pPoint = static_cast<LPPOINT>(pData);
  3799. return ::PtInRect(&pThis->GetPos(), *pPoint) ? pThis : NULL;
  3800. }
  3801. CControlUI* CALLBACK CPaintManagerUI::__FindControlFromTab(CControlUI* pThis, LPVOID pData)
  3802. {
  3803. FINDTABINFO* pInfo = static_cast<FINDTABINFO*>(pData);
  3804. if (pInfo->pFocus == pThis)
  3805. {
  3806. if (pInfo->bForward) pInfo->bNextIsIt = true;
  3807. return pInfo->bForward ? NULL : pInfo->pLast;
  3808. }
  3809. if ((pThis->GetControlFlags() & UIFLAG_TABSTOP) == 0) return NULL;
  3810. pInfo->pLast = pThis;
  3811. if (pInfo->bNextIsIt) return pThis;
  3812. if (pInfo->pFocus == NULL) return pThis;
  3813. return NULL; // Examine all controls
  3814. }
  3815. CControlUI* CALLBACK CPaintManagerUI::__FindControlFromShortcut(CControlUI* pThis, LPVOID pData)
  3816. {
  3817. if (!pThis->IsVisible()) return NULL;
  3818. FINDSHORTCUT* pFS = static_cast<FINDSHORTCUT*>(pData);
  3819. if (pFS->ch == toupper(pThis->GetShortcut())) pFS->bPickNext = true;
  3820. if (_tcsstr(pThis->GetClass(), _T("LabelUI")) != NULL) return NULL; // Labels never get focus!
  3821. return pFS->bPickNext ? pThis : NULL;
  3822. }
  3823. CControlUI* CALLBACK CPaintManagerUI::__FindControlFromName(CControlUI* pThis, LPVOID pData)
  3824. {
  3825. LPCTSTR pstrName = static_cast<LPCTSTR>(pData);
  3826. const CDuiString& sName = pThis->GetName();
  3827. if (sName.IsEmpty()) return NULL;
  3828. return (_tcsicmp(sName, pstrName) == 0) ? pThis : NULL;
  3829. }
  3830. CControlUI* CALLBACK CPaintManagerUI::__FindControlFromClass(CControlUI* pThis, LPVOID pData)
  3831. {
  3832. LPCTSTR pstrType = static_cast<LPCTSTR>(pData);
  3833. LPCTSTR pType = pThis->GetClass();
  3834. CStdPtrArray* pFoundControls = pThis->GetManager()->GetFoundControls();
  3835. if (_tcscmp(pstrType, _T("*")) == 0 || _tcscmp(pstrType, pType) == 0)
  3836. {
  3837. int iIndex = -1;
  3838. while (pFoundControls->GetAt(++iIndex) != NULL);
  3839. if (iIndex < pFoundControls->GetSize()) pFoundControls->SetAt(iIndex, pThis);
  3840. }
  3841. if (pFoundControls->GetAt(pFoundControls->GetSize() - 1) != NULL) return pThis;
  3842. return NULL;
  3843. }
  3844. CControlUI* CALLBACK CPaintManagerUI::__FindControlsFromClass(CControlUI* pThis, LPVOID pData)
  3845. {
  3846. LPCTSTR pstrType = static_cast<LPCTSTR>(pData);
  3847. LPCTSTR pType = pThis->GetClass();
  3848. if (_tcscmp(pstrType, _T("*")) == 0 || _tcscmp(pstrType, pType) == 0)
  3849. pThis->GetManager()->GetFoundControls()->Add((LPVOID)pThis);
  3850. return NULL;
  3851. }
  3852. CControlUI* CALLBACK CPaintManagerUI::__FindControlsFromUpdate(CControlUI* pThis, LPVOID pData)
  3853. {
  3854. if (pThis->IsUpdateNeeded())
  3855. {
  3856. pThis->GetManager()->GetFoundControls()->Add((LPVOID)pThis);
  3857. return pThis;
  3858. }
  3859. return NULL;
  3860. }
  3861. bool CPaintManagerUI::TranslateAccelerator(LPMSG pMsg)
  3862. {
  3863. for (int i = 0; i < m_aTranslateAccelerator.GetSize(); i++)
  3864. {
  3865. LRESULT lResult = static_cast<ITranslateAccelerator*>(m_aTranslateAccelerator[i])->TranslateAccelerator(pMsg);
  3866. if (lResult == S_OK) return true;
  3867. }
  3868. return false;
  3869. }
  3870. bool CPaintManagerUI::TranslateMessage(const LPMSG pMsg)
  3871. {
  3872. // Pretranslate Message takes care of system-wide messages, such as
  3873. // tabbing and shortcut key-combos. We'll look for all messages for
  3874. // each window and any child control attached.
  3875. UINT uStyle = GetWindowStyle(pMsg->hwnd);
  3876. UINT uChildRes = uStyle & WS_CHILD;
  3877. LRESULT lRes = 0;
  3878. if (uChildRes != 0)
  3879. {
  3880. HWND hWndParent = ::GetParent(pMsg->hwnd);
  3881. for (int i = 0; i < m_aPreMessages.GetSize(); i++)
  3882. {
  3883. CPaintManagerUI* pT = static_cast<CPaintManagerUI*>(m_aPreMessages[i]);
  3884. HWND hTempParent = hWndParent;
  3885. while (hTempParent)
  3886. {
  3887. if (pMsg->hwnd == pT->GetPaintWindow() || hTempParent == pT->GetPaintWindow())
  3888. {
  3889. if (pT->TranslateAccelerator(pMsg))
  3890. return true;
  3891. pT->PreMessageHandler(pMsg->message, pMsg->wParam, pMsg->lParam, lRes);
  3892. }
  3893. hTempParent = GetParent(hTempParent);
  3894. }
  3895. }
  3896. }
  3897. else
  3898. {
  3899. for (int i = 0; i < m_aPreMessages.GetSize(); i++)
  3900. {
  3901. CPaintManagerUI* pT = static_cast<CPaintManagerUI*>(m_aPreMessages[i]);
  3902. if (pMsg->hwnd == pT->GetPaintWindow())
  3903. {
  3904. if (pT->TranslateAccelerator(pMsg))
  3905. return true;
  3906. if (pT->PreMessageHandler(pMsg->message, pMsg->wParam, pMsg->lParam, lRes))
  3907. return true;
  3908. return false;
  3909. }
  3910. }
  3911. }
  3912. return false;
  3913. }
  3914. bool CPaintManagerUI::AddTranslateAccelerator(ITranslateAccelerator* pTranslateAccelerator)
  3915. {
  3916. ASSERT(m_aTranslateAccelerator.Find(pTranslateAccelerator) < 0);
  3917. return m_aTranslateAccelerator.Add(pTranslateAccelerator);
  3918. }
  3919. bool CPaintManagerUI::RemoveTranslateAccelerator(ITranslateAccelerator* pTranslateAccelerator)
  3920. {
  3921. for (int i = 0; i < m_aTranslateAccelerator.GetSize(); i++)
  3922. {
  3923. if (static_cast<ITranslateAccelerator*>(m_aTranslateAccelerator[i]) == pTranslateAccelerator)
  3924. {
  3925. return m_aTranslateAccelerator.Remove(i);
  3926. }
  3927. }
  3928. return false;
  3929. }
  3930. void CPaintManagerUI::UsedVirtualWnd(bool bUsed)
  3931. {
  3932. m_bUsedVirtualWnd = bUsed;
  3933. }
  3934. // 样式管理
  3935. void CPaintManagerUI::AddStyle(LPCTSTR pName, LPCTSTR pDeclarationList, bool bShared)
  3936. {
  3937. CDuiString* pStyle = new CDuiString(pDeclarationList);
  3938. if (bShared || m_bForceUseSharedRes)
  3939. {
  3940. if (!m_SharedResInfo.m_StyleHash.Insert(pName, pStyle))
  3941. {
  3942. delete pStyle;
  3943. }
  3944. }
  3945. else
  3946. {
  3947. if (!m_ResInfo.m_StyleHash.Insert(pName, pStyle))
  3948. {
  3949. delete pStyle;
  3950. }
  3951. }
  3952. }
  3953. LPCTSTR CPaintManagerUI::GetStyle(LPCTSTR pName) const
  3954. {
  3955. CDuiString* pStyle = static_cast<CDuiString*>(m_ResInfo.m_StyleHash.Find(pName));
  3956. if (!pStyle) pStyle = static_cast<CDuiString*>(m_SharedResInfo.m_StyleHash.Find(pName));
  3957. if (pStyle) return pStyle->GetData();
  3958. else return NULL;
  3959. }
  3960. BOOL CPaintManagerUI::RemoveStyle(LPCTSTR pName, bool bShared)
  3961. {
  3962. CDuiString* pStyle = NULL;
  3963. if (bShared)
  3964. {
  3965. pStyle = static_cast<CDuiString*>(m_SharedResInfo.m_StyleHash.Find(pName));
  3966. if (pStyle)
  3967. {
  3968. delete pStyle;
  3969. m_SharedResInfo.m_StyleHash.Remove(pName);
  3970. }
  3971. }
  3972. else
  3973. {
  3974. pStyle = static_cast<CDuiString*>(m_ResInfo.m_StyleHash.Find(pName));
  3975. if (pStyle)
  3976. {
  3977. delete pStyle;
  3978. m_ResInfo.m_StyleHash.Remove(pName);
  3979. }
  3980. }
  3981. return true;
  3982. }
  3983. const CStdStringPtrMap& CPaintManagerUI::GetStyles(bool bShared) const
  3984. {
  3985. if (bShared) return m_SharedResInfo.m_StyleHash;
  3986. else return m_ResInfo.m_StyleHash;
  3987. }
  3988. void CPaintManagerUI::RemoveAllStyle(bool bShared)
  3989. {
  3990. if (bShared)
  3991. {
  3992. CDuiString* pStyle;
  3993. for (int i = 0; i < m_SharedResInfo.m_StyleHash.GetSize(); i++)
  3994. {
  3995. if (LPCTSTR key = m_SharedResInfo.m_StyleHash.GetAt(i))
  3996. {
  3997. pStyle = static_cast<CDuiString*>(m_SharedResInfo.m_StyleHash.Find(key));
  3998. delete pStyle;
  3999. }
  4000. }
  4001. m_SharedResInfo.m_StyleHash.RemoveAll();
  4002. }
  4003. else
  4004. {
  4005. CDuiString* pStyle;
  4006. for (int i = 0; i < m_ResInfo.m_StyleHash.GetSize(); i++)
  4007. {
  4008. if (LPCTSTR key = m_ResInfo.m_StyleHash.GetAt(i))
  4009. {
  4010. pStyle = static_cast<CDuiString*>(m_ResInfo.m_StyleHash.Find(key));
  4011. delete pStyle;
  4012. }
  4013. }
  4014. m_ResInfo.m_StyleHash.RemoveAll();
  4015. }
  4016. }
  4017. const TImageInfo* CPaintManagerUI::GetImageString(LPCTSTR pStrImage, LPCTSTR pStrModify)
  4018. {
  4019. CDuiString sImageName = pStrImage;
  4020. CDuiString sImageResType = _T("");
  4021. DWORD dwMask = 0;
  4022. CDuiString sItem;
  4023. CDuiString sValue;
  4024. LPTSTR pstr = NULL;
  4025. for (int i = 0; i < 2; ++i)
  4026. {
  4027. if (i == 1)
  4028. pStrImage = pStrModify;
  4029. if (!pStrImage) continue;
  4030. while (*pStrImage != _T('\0'))
  4031. {
  4032. sItem.Empty();
  4033. sValue.Empty();
  4034. while (*pStrImage > _T('\0') && *pStrImage <= _T(' ')) pStrImage = ::CharNext(pStrImage);
  4035. while (*pStrImage != _T('\0') && *pStrImage != _T('=') && *pStrImage > _T(' '))
  4036. {
  4037. LPTSTR pstrTemp = ::CharNext(pStrImage);
  4038. while (pStrImage < pstrTemp)
  4039. {
  4040. sItem += *pStrImage++;
  4041. }
  4042. }
  4043. while (*pStrImage > _T('\0') && *pStrImage <= _T(' ')) pStrImage = ::CharNext(pStrImage);
  4044. if (*pStrImage++ != _T('=')) break;
  4045. while (*pStrImage > _T('\0') && *pStrImage <= _T(' ')) pStrImage = ::CharNext(pStrImage);
  4046. if (*pStrImage++ != _T('\'')) break;
  4047. while (*pStrImage != _T('\0') && *pStrImage != _T('\''))
  4048. {
  4049. LPTSTR pstrTemp = ::CharNext(pStrImage);
  4050. while (pStrImage < pstrTemp)
  4051. {
  4052. sValue += *pStrImage++;
  4053. }
  4054. }
  4055. if (*pStrImage++ != _T('\'')) break;
  4056. if (!sValue.IsEmpty())
  4057. {
  4058. if (sItem == _T("file") || sItem == _T("res"))
  4059. {
  4060. sImageName = sValue;
  4061. }
  4062. else if (sItem == _T("restype"))
  4063. {
  4064. sImageResType = sValue;
  4065. }
  4066. else if (sItem == _T("mask"))
  4067. {
  4068. if (sValue[0] == _T('#')) dwMask = _tcstoul(sValue.GetData() + 1, &pstr, 16);
  4069. else dwMask = _tcstoul(sValue.GetData(), &pstr, 16);
  4070. }
  4071. }
  4072. if (*pStrImage++ != _T(' ')) break;
  4073. }
  4074. }
  4075. return GetImageEx(sImageName, sImageResType, dwMask);
  4076. }
  4077. bool CPaintManagerUI::EnableDragDrop(bool bEnable)
  4078. {
  4079. if (m_bDragDrop == bEnable) return false;
  4080. m_bDragDrop = bEnable;
  4081. if (bEnable)
  4082. {
  4083. AddRef();
  4084. if (FAILED(RegisterDragDrop(m_hWndPaint, this)))
  4085. {
  4086. return false;
  4087. }
  4088. SetTargetWnd(m_hWndPaint);
  4089. FORMATETC ftetc = { 0 };
  4090. ftetc.cfFormat = CF_BITMAP;
  4091. ftetc.dwAspect = DVASPECT_CONTENT;
  4092. ftetc.lindex = -1;
  4093. ftetc.tymed = TYMED_GDI;
  4094. AddSuportedFormat(ftetc);
  4095. ftetc.cfFormat = CF_DIB;
  4096. ftetc.tymed = TYMED_HGLOBAL;
  4097. AddSuportedFormat(ftetc);
  4098. ftetc.cfFormat = CF_HDROP;
  4099. ftetc.tymed = TYMED_HGLOBAL;
  4100. AddSuportedFormat(ftetc);
  4101. ftetc.cfFormat = CF_ENHMETAFILE;
  4102. ftetc.tymed = TYMED_ENHMF;
  4103. AddSuportedFormat(ftetc);
  4104. }
  4105. else
  4106. {
  4107. Release();
  4108. if (FAILED(RevokeDragDrop(m_hWndPaint)))
  4109. {
  4110. return false;
  4111. }
  4112. }
  4113. return true;
  4114. }
  4115. void CPaintManagerUI::SetDragDrop(IDragDropUI* pDragDrop)
  4116. {
  4117. m_pDragDrop = pDragDrop;
  4118. }
  4119. static WORD DIBNumColors(void* pv)
  4120. {
  4121. int bits;
  4122. LPBITMAPINFOHEADER lpbi;
  4123. LPBITMAPCOREHEADER lpbc;
  4124. lpbi = ((LPBITMAPINFOHEADER)pv);
  4125. lpbc = ((LPBITMAPCOREHEADER)pv);
  4126. /* With the BITMAPINFO format headers, the size of the palette
  4127. * is in biClrUsed, whereas in the BITMAPCORE - style headers, it
  4128. * is dependent on the bits per pixel ( = 2 raised to the power of
  4129. * bits/pixel).
  4130. */
  4131. if (lpbi->biSize != sizeof(BITMAPCOREHEADER))
  4132. {
  4133. if (lpbi->biClrUsed != 0)
  4134. return (WORD)lpbi->biClrUsed;
  4135. bits = lpbi->biBitCount;
  4136. }
  4137. else
  4138. bits = lpbc->bcBitCount;
  4139. switch (bits)
  4140. {
  4141. case 1:
  4142. return 2;
  4143. case 4:
  4144. return 16;
  4145. case 8:
  4146. return 256;
  4147. default:
  4148. /* A 24 bitcount DIB has no color table */
  4149. return 0;
  4150. }
  4151. }
  4152. //code taken from SEEDIB MSDN sample
  4153. static WORD ColorTableSize(LPVOID lpv)
  4154. {
  4155. LPBITMAPINFOHEADER lpbih = (LPBITMAPINFOHEADER)lpv;
  4156. if (lpbih->biSize != sizeof(BITMAPCOREHEADER))
  4157. {
  4158. if (((LPBITMAPINFOHEADER)(lpbih))->biCompression == BI_BITFIELDS)
  4159. /* Remember that 16/32bpp dibs can still have a color table */
  4160. return (sizeof(DWORD) * 3) + (DIBNumColors(lpbih) * sizeof(RGBQUAD));
  4161. else
  4162. return (WORD)(DIBNumColors(lpbih) * sizeof(RGBQUAD));
  4163. }
  4164. else
  4165. return (WORD)(DIBNumColors(lpbih) * sizeof(RGBTRIPLE));
  4166. }
  4167. bool CPaintManagerUI::OnDrop(FORMATETC* pFmtEtc, STGMEDIUM& medium, DWORD* pdwEffect)
  4168. {
  4169. POINT ptMouse = { 0 };
  4170. GetCursorPos(&ptMouse);
  4171. ::SendMessage(m_hTargetWnd, WM_LBUTTONUP, NULL, MAKELPARAM(ptMouse.x, ptMouse.y));
  4172. if (pFmtEtc->cfFormat == CF_DIB && medium.tymed == TYMED_HGLOBAL)
  4173. {
  4174. if (medium.hGlobal != NULL)
  4175. {
  4176. LPBITMAPINFOHEADER lpbi = (BITMAPINFOHEADER*)GlobalLock(medium.hGlobal);
  4177. if (lpbi != NULL)
  4178. {
  4179. HBITMAP hbm = NULL;
  4180. HDC hdc = GetDC(NULL);
  4181. if (hdc != NULL)
  4182. {
  4183. int i = ((BITMAPFILEHEADER*)lpbi)->bfOffBits;
  4184. hbm = CreateDIBitmap(hdc, (LPBITMAPINFOHEADER)lpbi,
  4185. (LONG)CBM_INIT,
  4186. (LPSTR)lpbi + lpbi->biSize + ColorTableSize(lpbi),
  4187. (LPBITMAPINFO)lpbi, DIB_RGB_COLORS);
  4188. ::ReleaseDC(NULL, hdc);
  4189. }
  4190. GlobalUnlock(medium.hGlobal);
  4191. if (hbm != NULL)
  4192. hbm = (HBITMAP)SendMessage(m_hTargetWnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hbm);
  4193. if (hbm != NULL)
  4194. DeleteObject(hbm);
  4195. return true; //release the medium
  4196. }
  4197. }
  4198. }
  4199. if (pFmtEtc->cfFormat == CF_BITMAP && medium.tymed == TYMED_GDI)
  4200. {
  4201. if (medium.hBitmap != NULL)
  4202. {
  4203. HBITMAP hBmp = (HBITMAP)SendMessage(m_hTargetWnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)medium.hBitmap);
  4204. if (hBmp != NULL)
  4205. DeleteObject(hBmp);
  4206. return false; //don't free the bitmap
  4207. }
  4208. }
  4209. if (pFmtEtc->cfFormat == CF_ENHMETAFILE && medium.tymed == TYMED_ENHMF)
  4210. {
  4211. ENHMETAHEADER emh;
  4212. GetEnhMetaFileHeader(medium.hEnhMetaFile, sizeof(ENHMETAHEADER), &emh);
  4213. RECT rc;//={0,0,EnhMetaHdr.rclBounds.right-EnhMetaHdr.rclBounds.left, EnhMetaHdr.rclBounds.bottom-EnhMetaHdr.rclBounds.top};
  4214. HDC hDC = GetDC(m_hTargetWnd);
  4215. //start code: taken from ENHMETA.EXE MSDN Sample
  4216. //*ALSO NEED to GET the pallete (select and RealizePalette it, but i was too lazy*
  4217. // Get the characteristics of the output device
  4218. float PixelsX = (float)GetDeviceCaps(hDC, HORZRES);
  4219. float PixelsY = (float)GetDeviceCaps(hDC, VERTRES);
  4220. float MMX = (float)GetDeviceCaps(hDC, HORZSIZE);
  4221. float MMY = (float)GetDeviceCaps(hDC, VERTSIZE);
  4222. // Calculate the rect in which to draw the metafile based on the
  4223. // intended size and the current output device resolution
  4224. // Remember that the intended size is given in 0.01mm units, so
  4225. // convert those to device units on the target device
  4226. rc.top = (int)((float)(emh.rclFrame.top) * PixelsY / (MMY * 100.0f));
  4227. rc.left = (int)((float)(emh.rclFrame.left) * PixelsX / (MMX * 100.0f));
  4228. rc.right = (int)((float)(emh.rclFrame.right) * PixelsX / (MMX * 100.0f));
  4229. rc.bottom = (int)((float)(emh.rclFrame.bottom) * PixelsY / (MMY * 100.0f));
  4230. //end code: taken from ENHMETA.EXE MSDN Sample
  4231. HDC hdcMem = CreateCompatibleDC(hDC);
  4232. HGDIOBJ hBmpMem = CreateCompatibleBitmap(hDC, emh.rclBounds.right, emh.rclBounds.bottom);
  4233. HGDIOBJ hOldBmp = ::SelectObject(hdcMem, hBmpMem);
  4234. PlayEnhMetaFile(hdcMem, medium.hEnhMetaFile, &rc);
  4235. HBITMAP hBmp = (HBITMAP)::SelectObject(hdcMem, hOldBmp);
  4236. DeleteDC(hdcMem);
  4237. ReleaseDC(m_hTargetWnd, hDC);
  4238. hBmp = (HBITMAP)SendMessage(m_hTargetWnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBmp);
  4239. if (hBmp != NULL)
  4240. DeleteObject(hBmp);
  4241. return true;
  4242. }
  4243. if (pFmtEtc->cfFormat == CF_HDROP && medium.tymed == TYMED_HGLOBAL)
  4244. {
  4245. HDROP hDrop = (HDROP)GlobalLock(medium.hGlobal);
  4246. if (hDrop != NULL)
  4247. {
  4248. TCHAR szFileName[MAX_PATH];
  4249. UINT cFiles = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0);
  4250. if (cFiles > 0)
  4251. {
  4252. DragQueryFile(hDrop, 0, szFileName, sizeof(szFileName));
  4253. HBITMAP hBitmap = (HBITMAP)LoadImage(NULL, szFileName, IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE | LR_LOADFROMFILE);
  4254. if (hBitmap)
  4255. {
  4256. HBITMAP hBmp = (HBITMAP)SendMessage(m_hTargetWnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmap);
  4257. if (hBmp != NULL)
  4258. DeleteObject(hBmp);
  4259. }
  4260. }
  4261. }
  4262. GlobalUnlock(medium.hGlobal);
  4263. }
  4264. return true; //let base free the medium
  4265. }
  4266. } // namespace DuiLib
  4267. #pragma warning(pop)