autorun.cpp 192 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437
  1. /*
  2. ** Command & Conquer Generals(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /****************************************************************************
  19. ** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ****************************************************************************
  21. * *
  22. * Project Name : Autorun *
  23. * *
  24. * File Name : AUTORUN.CPP *
  25. * *
  26. * Programmers: Maria del Mar McCready Legg *
  27. * *
  28. * Start Date : September 5, 1997 *
  29. * *
  30. * Last Update : October 15, 2001 [MML] *
  31. * *
  32. *--------------------------------------------------------------------------*
  33. * Functions: *
  34. * WinMain *
  35. * Main::MessageLoop *
  36. * MainWindow::Register *
  37. * MainWindow::MainWindow *
  38. * MainWindow::Window_Proc *
  39. * MainWindow::Is_Product_Registered *
  40. * MainWindow::Run_Explorer *
  41. * MainWindow::Run_Game *
  42. * MainWindow::Run_Setup *
  43. * MainWindow::Run_New_Account *
  44. * MainWindow::Run_Register *
  45. * MainWindow::Run_Auto_Update *
  46. * MainWindow::Run_Uninstall *
  47. * MainWindow::Create_Buttons *
  48. * Wnd_Proc *
  49. * Dialog_Box_Proc *
  50. * Stop_Sound_Playing *
  51. * Options *
  52. * Valid_Environment *
  53. * LoadResourceBitmap *
  54. * CreateDIBPalette *
  55. * LoadResourceButton *
  56. * Cant_Find_MessageBox *
  57. * Error_Message *
  58. * Path_Add_Back_Slash *
  59. * Path_Remove_Back_Slash *
  60. * PlugInProductName *
  61. * Fix_Single_Ampersands *
  62. * Fix_Double_Ampersands *
  63. * LaunchObjectClass::LaunchObjectClass *
  64. * LaunchObjectClass::SetPath *
  65. * LaunchObjectClass::SetArgs *
  66. * LaunchObjectClass::Launch *
  67. *--------------------------------------------------------------------------*/
  68. #define STRICT
  69. #include <windows.h>
  70. #include <windowsx.h>
  71. #include <assert.h>
  72. #include <ctype.h>
  73. #include <direct.h>
  74. #include <dos.h>
  75. #include <errno.h>
  76. #include <fcntl.h>
  77. #include <fstream.h>
  78. #include <io.h>
  79. #include <locale.h>
  80. #include <math.h>
  81. #include <mbctype.h>
  82. #include <mmsystem.h>
  83. #include <process.h>
  84. #include <stdlib.h>
  85. #include <string.h>
  86. #include <stdio.h>
  87. #include <strstrea.h>
  88. #include <sys\stat.h>
  89. #include <time.h>
  90. #include <winuser.h>
  91. #include "args.h"
  92. #include "autorun.h"
  93. #include "drawbutton.h"
  94. #include "resource.h"
  95. #include "wnd_file.h"
  96. //#include "visualc.h"
  97. #include "winfix.h"
  98. #include "cdcntrl.h"
  99. #include "igr.h"
  100. #include "viewhtml.h"
  101. #include "utils.h"
  102. #include "locale_api.h"
  103. //#include "resources.h"
  104. #include "getcd.h"
  105. #include "WSYS_FileSystem.h"
  106. #include "WSYS_STDFileSystem.h"
  107. #include <string>
  108. #include "GameText.h"
  109. #include "leanAndMeanAutorun.h"
  110. #ifndef LEAN_AND_MEAN
  111. #include "Common/SubsystemInterface.h"
  112. #include "GameClient/GameText.h"
  113. #include "Common/UnicodeString.h"
  114. #include "Win32Device/Common/Win32LocalFileSystem.h"
  115. #include "Win32Device/Common/Win32BIGFileSystem.h"
  116. #endif
  117. //-----------------------------------------------------------------------------
  118. // DEFINES
  119. //-----------------------------------------------------------------------------
  120. #define PRETEND_ON_CD_TEST FALSE // should be FALSE
  121. //#define PRETEND_ON_CD_TEST TRUE // should be FALSE
  122. #define WINDOW_BRUSH FALSE
  123. #define BACKGROUND_BITMAP TRUE
  124. #define USE_MOUSE_MOVES TRUE
  125. #define DISABLE_KEYBOARD FALSE
  126. #define BUTTON_WIDTH 150
  127. #define BUTTON_HEIGHT 45
  128. #define NUM_BUTTONS 10
  129. #define NUM_ARGUMENTS 10
  130. #define NUM_SONGS 2 //32 //16
  131. #define NUM_FLICKER_FRAMES 1
  132. #define NUM_FLICKER_POSITIONS 15
  133. #define MOUSE_WAV "MouseMove"
  134. #define SOUND_FILE1 "SPEECH_FILE1"
  135. #define SOUND_FILE2 "SPEECH_FILE2"
  136. #define MOH_DEMO_PROGRAM "MOHAADEMO\\SETUP.EXE"
  137. #define SHOW_MOH_DEMO FALSE
  138. #define BFAVI_FILENAME "Autorun\\BF1942RTR.avi"
  139. #define SC4AVI_FILENAME "Autorun\\SimCity4.avi"
  140. #define HELP_FILENAME "HELP:FILENAME"//"Support\\eahelp.hlp"
  141. #define SHOW_GAMESPY_BUTTON FALSE
  142. #define GAMESPY_WEBSITE "http://www.gamespyarcade.com/features/launch.asp?svcname=ccrenegade&distID=391"
  143. #define RESOURCE_FILE "Autorun.loc"
  144. #define SETUP_INI_FILE1 "Setup\\Setup.ini"
  145. #define SETUP_INI_FILE2 "Setup.ini"
  146. //-----------------------------------------------------------------------------
  147. // These defines need the Product name from Setup.ini to complete.
  148. //-----------------------------------------------------------------------------
  149. #define SETUP_MAIN_WINDOW_NAME "%s Setup"
  150. #define CLASS_NAME "%s Autorun"
  151. #define GAME_MAIN_WINDOW_NAME "%s Game Window"
  152. //#define GAME_WEBSITE "http://www.westwood.com/"
  153. #define GAME_WEBSITE "http://generals.ea.com"
  154. #define AUTORUN_MUTEX_OBJECT "01AF9993-3492-11d3-8F6F-0060089C05B1"
  155. //#define GAME_MUTEX_OBJECT "C6D925A3-7A9B-4ca3-866D-8B4D506C3665"
  156. #define GAME_MUTEX_OBJECT "685EAFF2-3216-4265-B047-251C5F4B82F3"
  157. #define PRODUCT_VOLUME_CD1 "Generals1"
  158. #define PRODUCT_VOLUME_CD2 "Generals2"
  159. //-----------------------------------------------------------------------------
  160. // Global Variables
  161. //-----------------------------------------------------------------------------
  162. LaunchObjectClass LaunchObject;
  163. MainWindow *GlobalMainWindow = NULL;
  164. int Language = 0;
  165. int LanguageToUse = 0;
  166. DrawButton *ButtonList [ NUM_BUTTONS ];
  167. RECT ButtonSizes [ NUM_BUTTONS ];
  168. char ButtonImages [ NUM_BUTTONS ][ MAX_PATH ];
  169. CHAR szSongPath [ MAX_PATH ];
  170. char FocusedButtonImages [ NUM_BUTTONS ][ MAX_PATH ];
  171. char Arguments [ NUM_ARGUMENTS ][ 30 ];
  172. char szWavs [ NUM_SONGS][ _MAX_PATH ];
  173. char szBuffer [ MAX_PATH ];
  174. char szBuffer1 [ MAX_PATH ];
  175. char szBuffer2 [ MAX_PATH ];
  176. char szBuffer3 [ MAX_PATH * 2];
  177. char szInternetPath [_MAX_PATH];
  178. char szGamePath [_MAX_PATH];
  179. char szWorldbuilderPath [_MAX_PATH];
  180. char szPatchgetPath [_MAX_PATH];
  181. char szSetupPath [_MAX_PATH];
  182. char szUninstallPath [_MAX_PATH];
  183. char szRegisterPath [_MAX_PATH];
  184. char szButtonWav [_MAX_PATH ];
  185. char szSpeechWav [_MAX_PATH ];
  186. char szArgvPath [_MAX_PATH ];
  187. char drive [_MAX_DRIVE];
  188. char dir [_MAX_DIR ];
  189. char szSetupWindow [_MAX_PATH];
  190. char szGameWindow [_MAX_PATH];
  191. char szRegistryKey [_MAX_PATH];
  192. char szClassName [_MAX_PATH];
  193. char szVolumeName [_MAX_PATH];
  194. char szProduct_Name [ _MAX_PATH ];
  195. #ifdef LEAN_AND_MEAN
  196. wchar_t szWideBuffer [ _MAX_PATH ];
  197. wchar_t szWideBuffer0 [ _MAX_PATH ];
  198. wchar_t szWideBuffer2 [ _MAX_PATH ];
  199. wchar_t szWideBuffer3 [ _MAX_PATH ];
  200. wchar_t szProductName [ _MAX_PATH ];
  201. wchar_t szFullProductName [ _MAX_PATH ];
  202. /*
  203. enum
  204. {
  205. IDS_INSTALL,
  206. IDS_EXPLORE_CD,
  207. IDS_PREVIEWS,
  208. IDS_CANCEL,
  209. IDS_AUTORUN_TITLE,
  210. IDS_CANT_FIND_IEXPLORER,
  211. IDS_WINDOWS_VERSION_TEXT,
  212. IDS_WINDOWS_VERSION_TITLE,
  213. IDS_CANT_FIND,
  214. IDS_UNINSTALL,
  215. IDS_WEBSITE,
  216. IDS_CHECKFORUPDATES,
  217. IDS_WORLDBUILDER,
  218. IDS_PLAY,
  219. IDS_GAME_TITLE,
  220. IDS_FULL_GAME_TITLE,
  221. IDS_REGISTRY_KEY,
  222. IDS_MAIN_WINDOW,
  223. IDS_COUNT // keep this last
  224. };
  225. */
  226. #else
  227. UnicodeString wideBuffer;
  228. UnicodeString wideBuffer0;
  229. UnicodeString wideBuffer2;
  230. UnicodeString wideBuffer3;
  231. UnicodeString productName;
  232. UnicodeString fullProductName;
  233. #endif
  234. bool IsEnglish = FALSE;
  235. bool UseSounds = FALSE;
  236. bool b640X480 = FALSE;
  237. bool b800X600 = FALSE;
  238. BOOL OnCDRom = FALSE;
  239. BOOL IAmWindows95 = FALSE;
  240. BOOL InstallProduct = TRUE;
  241. BOOL UninstallAvailable = FALSE;
  242. BOOL IsUserRegistered = FALSE;
  243. BOOL DisplayRegisterButton = FALSE;
  244. BOOL IsWolapiAvailable = FALSE;
  245. BOOL CDLocked = FALSE;
  246. int WindowsVersion = 0;
  247. int NumberArguments = 0;
  248. int SongNumber = 0;
  249. HANDLE AppMutex = NULL;
  250. HANDLE GameAppMutex = NULL;
  251. HANDLE SetupAppMutex = NULL;
  252. #ifdef LEAN_AND_MEAN
  253. extern FileSystem *TheFileSystem;
  254. #else
  255. extern GameTextInterface *TheGameText;
  256. extern LocalFileSystem *TheLocalFileSystem;
  257. extern ArchiveFileSystem *TheArchiveFileSystem;
  258. #endif
  259. // stuff needed to compile.
  260. HWND ApplicationHWnd = NULL;
  261. HINSTANCE ApplicationHInstance; ///< main application instance
  262. const char *g_strFile = "Autorun.str";
  263. const char *g_csfFile = "Autorun.csf";
  264. char *gAppPrefix = "ar_"; // prefix to the debug log.
  265. int FlickerPositions[ NUM_FLICKER_POSITIONS ][2];
  266. #if( _DEBUG )
  267. char szCDDrive[ MAX_PATH ];
  268. #endif
  269. //-----------------------------------------------------------------------------
  270. // Global Function Definitions
  271. //-----------------------------------------------------------------------------
  272. void Cant_Find_MessageBox ( HINSTANCE hInstance, char *szPath );
  273. HPALETTE CreateDIBPalette ( LPBITMAPINFO lpbmi, LPINT lpiNumColors );
  274. void Debug_Date_And_Time_Stamp ( void );
  275. void Error_Message ( HINSTANCE hInstance, int title, int string, char *path );
  276. void Error_Message ( HINSTANCE hInstance, const char * title, const char * string, char *path );
  277. bool Is_On_CD ( char * );
  278. HBITMAP LoadResourceBitmap ( HMODULE hInstance, char *lpString, HPALETTE FAR *lphPalette, bool loading_a_button=FALSE );
  279. HBITMAP LoadResourceButton ( HMODULE hInstance, char *lpString, HPALETTE FAR lphPalette );
  280. BOOL Options ( Command_Line_Arguments *Orgs );
  281. void Prog_End ( void );
  282. bool Prompt_For_CD ( HWND window_handle, char *volume_name, const char * message1, const char * message2, int *cd_drive );
  283. void Reformat_Volume_Name ( char *volume_name, char *new_volume_name );
  284. int Show_Message ( HWND window_handle, const char * message_num1, const char * message_num2 );
  285. int Show_Message ( HWND window_handle, int message_num1 );
  286. void Stop_Sound_Playing ( void );
  287. BOOL Valid_Environment ( void );
  288. BOOL CALLBACK Dialog_Box_Proc ( HWND window_handle, UINT message, WPARAM w_param, LPARAM l_param );
  289. LRESULT CALLBACK Wnd_Proc ( HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam );
  290. //-----------------------------------------------------------------------------
  291. // Main & MainWindow Public Variables
  292. //-----------------------------------------------------------------------------
  293. HINSTANCE Main::hInstance = 0;
  294. HINSTANCE Main::hPrevInstance = 0;
  295. HMODULE Main::hModule = 0;
  296. int Main::nCmdShow = 0;
  297. char MainWindow::szClassName[] = CLASS_NAME;
  298. //*****************************************************************************
  299. // WinMain -- Main Program Loop.
  300. //
  301. // INPUT: HINSTANCE hInstance
  302. // HINSTANCE hPrevInstance
  303. // LPTSTR lpszCmdLine
  304. // int nCmdShow
  305. //
  306. // OUTPUT: int.
  307. //
  308. // WARNINGS: none.
  309. //
  310. // HISTORY:
  311. // 06/04/1996 MML : Created.
  312. //=============================================================================
  313. int PASCAL WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpszCmdLine, int nCmdShow )
  314. {
  315. int i = 0;
  316. char szPath[ _MAX_PATH ];
  317. char szIniPath[ _MAX_PATH ];
  318. HANDLE handle;
  319. WIN32_FIND_DATA FindFileData;
  320. Main::hInstance = hInstance;
  321. ApplicationHInstance = hInstance;
  322. Main::hPrevInstance = hPrevInstance;
  323. Main::nCmdShow = nCmdShow;
  324. Main::hModule = GetModuleHandle( NULL );
  325. memset( szSetupWindow, '\0', MAX_PATH );
  326. memset( szGameWindow, '\0', MAX_PATH );
  327. memset( szProductName, '\0', MAX_PATH );
  328. memset( szFullProductName, '\0', MAX_PATH );
  329. memset( szRegistryKey, '\0', MAX_PATH );
  330. memset( szClassName, '\0', MAX_PATH );
  331. memset( szVolumeName, '\0', MAX_PATH );
  332. Msg( __LINE__, __FILE__, "Entering WinMain." );
  333. //-------------------------------------------------------------------------
  334. // Set Cleanup function.
  335. //-------------------------------------------------------------------------
  336. atexit( Prog_End );
  337. //-------------------------------------------------------------------------
  338. // Clear Argument Array.
  339. //-------------------------------------------------------------------------
  340. for ( i = 0; i < NUM_ARGUMENTS; i++ ) {
  341. memset( Arguments[i], '\0', sizeof( Arguments[i] ));
  342. }
  343. for ( i = 0; i < NUM_SONGS; i++ ) {
  344. memset( szWavs[i], '\0', sizeof( szWavs[i] ));
  345. }
  346. //-------------------------------------------------------------------------
  347. // Init Args class.
  348. //-------------------------------------------------------------------------
  349. Args = new Command_Line_Arguments( hInstance, GetCommandLine());
  350. if ( Args == NULL ) {
  351. // Error_Message( hInstance, IDS_ERROR, IDS_COMMAND_LINE_ERR, NULL );
  352. Error_Message( hInstance, "Autorun:Error", "Autorun:CommandLineError", NULL );
  353. return( 0 );
  354. }
  355. Msg( __LINE__, __FILE__, "Args Created." );
  356. #if( PRETEND_ON_CD_TEST )
  357. strcpy( szCDDrive, "E:\\" );
  358. Options( Args );
  359. strcat( szCDDrive, "autorun.exe" );
  360. Msg( __LINE__, __FILE__, "szCDDrive = %s.", szCDDrive );
  361. Args->Set_argv( 0, szCDDrive );
  362. #endif
  363. //-------------------------------------------------------------------------
  364. // Get the CD volume to check on which CD in the product we are on.
  365. //-------------------------------------------------------------------------
  366. strcpy( szBuffer, Args->Get_argv(0));
  367. CDList.Get_Volume_For_This_CD_Drive( szBuffer, szVolumeName );
  368. Msg( __LINE__, __FILE__, "szVolumeName = %s.", szVolumeName );
  369. #ifdef LEAN_AND_MEAN
  370. TheFileSystem = new StdFileSystem;
  371. #else
  372. // create singletons
  373. TheFileSystem->init();
  374. TheLocalFileSystem = new Win32LocalFileSystem;
  375. TheArchiveFileSystem = new Win32BIGFileSystem;
  376. TheGameText = CreateGameTextInterface();
  377. TheGameText->init();
  378. #endif
  379. //=========================================================================
  380. // Make paths to .INI and .LOC files.
  381. //=========================================================================
  382. Make_Current_Path_To( RESOURCE_FILE, szPath );
  383. Make_Current_Path_To( SETUP_INI_FILE1, szIniPath );
  384. handle = FindFirstFile( szIniPath, &FindFileData );
  385. if ( handle == INVALID_HANDLE_VALUE ) {
  386. //---------------------------------------------------------------------
  387. // This might be a secondary CD.
  388. //---------------------------------------------------------------------
  389. Make_Current_Path_To( SETUP_INI_FILE2, szIniPath );
  390. }
  391. FindClose( handle );
  392. Msg( __LINE__, __FILE__, "Resource file = %s.", szPath );
  393. Msg( __LINE__, __FILE__, "Setup.ini file = %s.", szIniPath );
  394. //--------------------------------------------------------------------------
  395. // Get the language we are using from the Setup.ini file.
  396. //--------------------------------------------------------------------------
  397. Language = GetPrivateProfileInt( "Setup", "Language", 0, szIniPath );
  398. if( Language == 0 ) {
  399. IsEnglish = true;
  400. }
  401. Msg( __LINE__, __FILE__, "Language = %d.", Language );
  402. Msg( __LINE__, __FILE__, "IsEnglish = %d.", IsEnglish );
  403. //--------------------------------------------------------------------------
  404. // Set language to use.
  405. //--------------------------------------------------------------------------
  406. if( Locale_Use_Multi_Language_Files()) {
  407. if( IS_LANGUAGE_DBCS( Language ) && !IS_CODEPAGE_DBCS( CodePage )) {
  408. Language = LANG_USA;
  409. }
  410. /*switch( Language ) {
  411. case LANG_GER:
  412. LanguageToUse = IDL_GERMAN;
  413. break;
  414. case LANG_FRE:
  415. LanguageToUse = IDL_FRENCH;
  416. break;
  417. case LANG_JAP:
  418. LanguageToUse = IDL_JAPANESE;
  419. break;
  420. case LANG_KOR:
  421. LanguageToUse = IDL_KOREAN;
  422. break;
  423. case LANG_CHI:
  424. LanguageToUse = IDL_CHINESE;
  425. break;
  426. case LANG_USA:
  427. default:
  428. LanguageToUse = IDL_ENGLISH;
  429. break;
  430. }
  431. */
  432. LanguageToUse = Language;
  433. }
  434. Msg( __LINE__, __FILE__, "LanguageToUse = %d.", LanguageToUse );
  435. //-------------------------------------------------------------------------
  436. // Process the Command Line Options. This may change the language id.
  437. //-------------------------------------------------------------------------
  438. if ( !Options( Args )) {
  439. return( 0 );
  440. }
  441. //-------------------------------------------------------------------------
  442. // Save off the Current path for use by other stuff.
  443. //-------------------------------------------------------------------------
  444. _tcscpy( szArgvPath, Args->Get_argv(0));
  445. _tsplitpath( szArgvPath, drive, dir, NULL, NULL );
  446. _tmakepath ( szArgvPath, drive, dir, NULL, NULL );
  447. Path_Add_Back_Slash( szArgvPath );
  448. Msg( __LINE__, TEXT(__FILE__), TEXT("szArgvPath = %s."), szArgvPath );
  449. Msg( __LINE__, __FILE__, "About to Init text strings." );
  450. //=========================================================================
  451. // Init the strings chosen.
  452. //=========================================================================
  453. Locale_Init( LanguageToUse, szPath );
  454. /*
  455. if( !Locale_Init( LanguageToUse, szPath )) {
  456. LoadString( Main::hInstance, IDS_CANT_FIND_FILE, szBuffer1, _MAX_PATH );
  457. MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, szPath, _MAX_PATH, szWideBuffer0, _MAX_PATH );
  458. sprintf( szBuffer2, szBuffer1, szWideBuffer0 );
  459. MessageBox( NULL, szBuffer2, "Autorun", MB_APPLMODAL | MB_OK );
  460. return 0;
  461. }
  462. */
  463. //-------------------------------------------------------------------------
  464. // Get some pertinent strings.
  465. //-------------------------------------------------------------------------
  466. Locale_GetString( "Autorun:Title", szProductName );
  467. Locale_GetString( "Autorun:Command&ConquerGenerals", szFullProductName );
  468. //Locale_GetString( IDS_GAME_TITLE, szProductName );
  469. //Locale_GetString( IDS_FULL_GAME_TITLE, szFullProductName );
  470. // Locale_GetString( IDS_REGISTRY_KEY, szRegistryKey );
  471. // Locale_GetString( IDS_MAIN_WINDOW, szGameWindow );
  472. //-------------------------------------------------------------------------
  473. // Set other variables used through out.
  474. //-------------------------------------------------------------------------
  475. #ifdef LEAN_AND_MEAN
  476. //Fix_Single_Ampersands( &szProductName[0], false );
  477. //Fix_Single_Ampersands( &szFullProductName[0], false );
  478. Msg( __LINE__, __FILE__, "szProductName = %s.", szProductName );
  479. WideCharToMultiByte( CodePage, 0, szProductName, _MAX_PATH, szProduct_Name, _MAX_PATH, NULL, NULL );
  480. #else
  481. productName = TheGameText->fetch("Autorun:Generals");
  482. fullProductName = TheGameText->fetch("Autorun:Command&ConquerGenerals");
  483. Msg( __LINE__, __FILE__, "Product Name = %ls.", productName.str() );
  484. Msg( __LINE__, __FILE__, "Full Product Name = %ls.", fullProductName.str() );
  485. Msg( __LINE__, __FILE__, "szRegistryKey = %s.", szRegistryKey );
  486. Msg( __LINE__, __FILE__, "szGameWindow = %s.", szGameWindow );
  487. WideCharToMultiByte( CodePage, 0, productName.str(), productName.getLength()+1, szProduct_Name, _MAX_PATH, NULL, NULL );
  488. #endif
  489. sprintf( szClassName, CLASS_NAME, szProduct_Name );
  490. MainWindow::Reset_Class_Name( szClassName );
  491. sprintf( szSetupWindow, SETUP_MAIN_WINDOW_NAME, szProduct_Name );
  492. Msg( __LINE__, __FILE__, "szClassName = %s.", szClassName );
  493. Msg( __LINE__, __FILE__, "szSetupWindow = %s.", szSetupWindow );
  494. //=========================================================================
  495. // Create a mutex with a unique name to Autorun in order to determine if
  496. // our app is already running.
  497. //
  498. // Return Values:
  499. // If the function succeeds, the return value is a handle to the mutex object.
  500. // If the named mutex object existed before the function call, the function returns
  501. // a handle to the existing object and GetLastError returns ERROR_ALREADY_EXISTS.
  502. // Otherwise, the caller created the mutex.
  503. // If the function fails, the return value is NULL. To get extended error
  504. // information, call GetLastError.
  505. //
  506. // WARNING: DO NOT use this number for any other application except Autorun
  507. //=========================================================================
  508. if( WinVersion.Is_Win_XP() || WinVersion.Version() > 500 ) {
  509. strcat( strcpy( szBuffer, "Global\\" ), AUTORUN_MUTEX_OBJECT );
  510. } else {
  511. strcpy( szBuffer, AUTORUN_MUTEX_OBJECT );
  512. }
  513. AppMutex = CreateMutex( NULL, FALSE, szBuffer );
  514. if ( AppMutex != NULL && ( GetLastError() == ERROR_ALREADY_EXISTS )) {
  515. Msg( __LINE__, __FILE__, "AppMutex of %s already exists. Exit here.", szBuffer );
  516. //---------------------------------------------------------------------
  517. // Handle is closed in the ProgEnd().
  518. //---------------------------------------------------------------------
  519. //---------------------------------------------------------------------
  520. // Check if Game/Setup is already running, and is looking for the CDRom.
  521. //---------------------------------------------------------------------
  522. HWND prev = FindWindow( szClassName, NULL );
  523. if( prev ){
  524. //if( IsIconic( prev )){
  525. //ShowWindow( prev, SW_RESTORE );
  526. //}
  527. SetForegroundWindow( prev );
  528. }
  529. return 0;
  530. }
  531. Msg( __LINE__, __FILE__, "AppMutex of %s created.", szBuffer );
  532. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  533. // if AppMutex was NULL, let through. Perhaps in future we want to trap it?
  534. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  535. if ( AppMutex == NULL ) {
  536. }
  537. //=========================================================================
  538. // Create a mutex with a unique name to Game/Setup in order to
  539. // determine if our app is already running.
  540. //
  541. // Return Values
  542. // If the function succeeds, the return value is a handle to the mutex object.
  543. // If the function fails, the return value is NULL. To get extended error
  544. // information, call GetLastError.
  545. //
  546. // WARNING: DO NOT use this number for any other application except Game/Setup.
  547. //=========================================================================
  548. if( WinVersion.Is_Win_XP() || WinVersion.Version() > 500 ) {
  549. strcat( strcpy( szBuffer, "Global\\" ), GAME_MUTEX_OBJECT );
  550. } else {
  551. strcpy( szBuffer, GAME_MUTEX_OBJECT );
  552. }
  553. GameAppMutex = OpenMutex( MUTEX_ALL_ACCESS, FALSE, szBuffer );
  554. if ( GameAppMutex != NULL ) {
  555. Msg( __LINE__, TEXT(__FILE__), TEXT("Mutex Object of game found."));
  556. Msg( __LINE__, TEXT(__FILE__), TEXT("Looking for Game Window."));
  557. HWND ccwindow = FindWindow( szGameWindow, NULL );
  558. if ( ccwindow ) {
  559. Msg( __LINE__, TEXT(__FILE__), TEXT("Found Game Window."));
  560. if( IsIconic( ccwindow )){
  561. ShowWindow( ccwindow, SW_RESTORE );
  562. }
  563. SetForegroundWindow( ccwindow );
  564. } else {
  565. Msg( __LINE__, TEXT(__FILE__), TEXT("Looking for Setup Window."));
  566. ccwindow = FindWindow( szSetupWindow, NULL );
  567. if ( ccwindow ) {
  568. Msg( __LINE__, TEXT(__FILE__), TEXT("Found Setup Window."));
  569. if( IsIconic( ccwindow )){
  570. ShowWindow( ccwindow, SW_RESTORE );
  571. }
  572. BOOL result = SetForegroundWindow( ccwindow );
  573. Msg( __LINE__, TEXT(__FILE__), TEXT("SetForegroundWindow = %d."), result );
  574. }
  575. }
  576. //---------------------------------------------------------------------
  577. // Handle(s) are closed in the ProgEnd().
  578. //---------------------------------------------------------------------
  579. return 0;
  580. }
  581. //---------------------------------------------------------------------
  582. // Check if Game/Setup is already running, and is looking for the CDRom.
  583. //---------------------------------------------------------------------
  584. HWND prev = FindWindow( szClassName, NULL );
  585. if ( prev == NULL ) {
  586. prev = FindWindow( szGameWindow, NULL );
  587. if ( prev == NULL ) {
  588. prev = FindWindow( szSetupWindow, NULL );
  589. }
  590. }
  591. if( prev ){
  592. if( IsIconic( prev )){
  593. ShowWindow( prev, SW_RESTORE );
  594. }
  595. SetForegroundWindow( prev );
  596. Msg( __LINE__, __FILE__, "Either same app, game or setup was found. Exit and set window to foreground." );
  597. return 0;
  598. }
  599. //=========================================================================
  600. // Select Sounds.
  601. //=========================================================================
  602. memset( szButtonWav, '\0', _MAX_PATH );
  603. _tcscpy( szButtonWav, _TEXT( MOUSE_WAV ));
  604. // memset( szSpeechWav, '\0', _MAX_PATH );
  605. // _tcscpy( szSpeechWav, _TEXT( AUTORUN_WAV ));
  606. if( LanguageID == LANG_USA ) {
  607. strcpy( szWavs[0], SOUND_FILE1 );
  608. strcpy( szWavs[1], SOUND_FILE2 );
  609. // Pick a number between 0 and 1. ( NUM_SONGS - 1 )
  610. // Seed the random-number generator with current time so that
  611. // the numbers will be different every time we run.
  612. Msg( __LINE__, __FILE__, "szWav[0] = %s.", szWavs[0] );
  613. Msg( __LINE__, __FILE__, "szWav[1] = %s.", szWavs[1] );
  614. srand(( unsigned )time( NULL ));
  615. SongNumber = rand() & 1;
  616. // UseSounds = TRUE;
  617. Msg( __LINE__, __FILE__, "SongNumber = %d.", SongNumber );
  618. Msg( __LINE__, __FILE__, "UseSounds = %d.", UseSounds );
  619. }
  620. //-------------------------------------------------------------------------
  621. // Get the CD volume to check on which CD in the product we are on.
  622. //-------------------------------------------------------------------------
  623. // strcpy( szBuffer, Args->Get_argv(0));
  624. // CDList.Get_Volume_For_This_CD_Drive( szBuffer, szVolumeName );
  625. // Msg( __LINE__, __FILE__, "szVolumeName = %s.", szVolumeName );
  626. //-------------------------------------------------------------------------
  627. // Check if we are on the CD-ROM and in Windows 95.
  628. //-------------------------------------------------------------------------
  629. if ( !Valid_Environment( )) {
  630. return( -1 );
  631. }
  632. //=========================================================================
  633. // Lock the CD!
  634. //=========================================================================
  635. // memset( szPath, '\0', _MAX_PATH );
  636. // szPath[0] = (char)( toupper( szArgvPath[0] ));
  637. // strcat( szPath, ":\\" );
  638. //-------------------------------------------------------------------------
  639. // NOTE: Based on A=0, B=1, etc.
  640. //-------------------------------------------------------------------------
  641. //#if(!PRETEND_ON_CD_TEST)
  642. char driveLetter = Args->Get_argv(0)[0];
  643. Msg( __LINE__, TEXT(__FILE__), TEXT("About to lock on CD: %c:\\ "), toupper( driveLetter ));
  644. // CDLocked = CDControl.Lock_CD_Tray((unsigned)( toupper( szPath[0] ) - 'A' ));
  645. CDLocked = CDControl.Lock_CD_Tray((unsigned)( toupper( driveLetter ) - 'A' ));
  646. Msg( __LINE__, TEXT(__FILE__), TEXT("CDLocked = %d. "), CDLocked );
  647. //#endif
  648. //=========================================================================
  649. // Set the buttons images. Use when images are unique for each button.
  650. //=========================================================================
  651. strcpy( ButtonImages[0], BUTTON_REG );
  652. strcpy( ButtonImages[1], BUTTON_REG );
  653. strcpy( ButtonImages[2], BUTTON_REG );
  654. strcpy( ButtonImages[3], BUTTON_REG );
  655. strcpy( ButtonImages[4], BUTTON_REG );
  656. strcpy( ButtonImages[5], BUTTON_REG );
  657. strcpy( ButtonImages[6], BUTTON_REG );
  658. strcpy( ButtonImages[7], BUTTON_REG );
  659. strcpy( ButtonImages[8], BUTTON_REG );
  660. strcpy( ButtonImages[9], BUTTON_REG );
  661. strcpy( FocusedButtonImages[0], BUTTON_SEL );
  662. strcpy( FocusedButtonImages[1], BUTTON_SEL );
  663. strcpy( FocusedButtonImages[2], BUTTON_SEL );
  664. strcpy( FocusedButtonImages[3], BUTTON_SEL );
  665. strcpy( FocusedButtonImages[4], BUTTON_SEL );
  666. strcpy( FocusedButtonImages[5], BUTTON_SEL );
  667. strcpy( FocusedButtonImages[6], BUTTON_SEL );
  668. strcpy( FocusedButtonImages[7], BUTTON_SEL );
  669. strcpy( FocusedButtonImages[8], BUTTON_SEL );
  670. strcpy( FocusedButtonImages[9], BUTTON_SEL );
  671. //=========================================================================
  672. // A Windows class should be registered with Windows before any windows
  673. // of that type are created. Register here all Windows classes that
  674. // will be used in the program.
  675. //-------------------------------------------------------------------------
  676. // Register the class only AFTER WinMain assigns appropriate values to
  677. // static members of Main and only if no previous instances of the program
  678. // exist (a previous instance would have already performed the registration).
  679. //=========================================================================
  680. if ( !Main::hPrevInstance ) {
  681. MainWindow::Register();
  682. }
  683. //-------------------------------------------------------------------------
  684. // Create MainWnd, calls MainWindow Constructor.
  685. //-------------------------------------------------------------------------
  686. MainWindow MainWnd;
  687. //-------------------------------------------------------------------------
  688. // Begin processing Window Messages.
  689. //-------------------------------------------------------------------------
  690. return( Main::MessageLoop( ));
  691. }
  692. //*****************************************************************************
  693. // Prog_End -- Close all objects that were created.
  694. //
  695. // INPUT: none.
  696. //
  697. // OUTPUT: int.
  698. //
  699. // WARNINGS: none.
  700. //
  701. // HISTORY:
  702. // 01/22/2001 MML : Created.
  703. //=============================================================================
  704. void Prog_End ( void )
  705. {
  706. //==========================================================================
  707. // UnLock the CD!
  708. //==========================================================================
  709. if( CDLocked ) {
  710. CDControl.Unlock_CD_Tray((unsigned)( toupper( szArgvPath[0] ) - 'A' ));
  711. CDLocked = false;
  712. }
  713. if( Args != NULL ) {
  714. delete( Args );
  715. Args = NULL;
  716. Msg( __LINE__, __FILE__, "Args deleted." );
  717. }
  718. if ( AppMutex != NULL ) {
  719. CloseHandle( AppMutex );
  720. AppMutex = NULL;
  721. Msg( __LINE__, __FILE__, "AppMutex deleted." );
  722. }
  723. if ( GameAppMutex != NULL) {
  724. CloseHandle( GameAppMutex );
  725. GameAppMutex = NULL;
  726. }
  727. if ( FontManager != NULL ) {
  728. delete( FontManager );
  729. FontManager = NULL;
  730. Msg( __LINE__, __FILE__, "FontManager deleted." );
  731. }
  732. if ( OnlineOptions != NULL ) {
  733. delete( OnlineOptions );
  734. OnlineOptions = NULL;
  735. Msg( __LINE__, __FILE__, "OnlineOptions deleted." );
  736. }
  737. //-------------------------------------------------------------------------
  738. // Delete language resource file.
  739. //-------------------------------------------------------------------------
  740. Locale_Restore();
  741. Debug_Date_And_Time_Stamp();
  742. }
  743. //*****************************************************************************
  744. // Main::MessageLoop -- Dispatch Message Loop.
  745. //
  746. // INPUT: none.
  747. //
  748. // OUTPUT: int.
  749. //
  750. // WARNINGS: none.
  751. //
  752. // HISTORY:
  753. // 06/04/1996 MML : Created.
  754. //=============================================================================
  755. int Main::MessageLoop( void )
  756. {
  757. MSG msg;
  758. while( GetMessage( &msg, NULL, 0, 0 )) {
  759. TranslateMessage( &msg );
  760. DispatchMessage( &msg );
  761. }
  762. //--------------------------------------------------------------------------
  763. // Stop the sound if still going.
  764. //--------------------------------------------------------------------------
  765. Stop_Sound_Playing();
  766. //==========================================================================
  767. // UnLock the CD!
  768. //==========================================================================
  769. //#if(!PRETEND_ON_CD_TEST)
  770. if( CDLocked ) {
  771. CDControl.Unlock_CD_Tray((unsigned)( toupper( szArgvPath[0] ) - 'A' ));
  772. CDLocked = false;
  773. }
  774. //#endif
  775. //==========================================================================
  776. // Something to launch?
  777. //==========================================================================
  778. if( LaunchObject.Launch_A_Program()) {
  779. LaunchObject.Launch();
  780. }
  781. return( msg.wParam );
  782. }
  783. //*****************************************************************************
  784. // MainWindow::Register -- Register the Main Window.
  785. //
  786. // INPUT: none.
  787. //
  788. // OUTPUT: none.
  789. //
  790. // WARNINGS: none.
  791. //
  792. // HISTORY:
  793. // 06/04/1996 MML : Created.
  794. //=============================================================================
  795. void MainWindow::Register( void )
  796. {
  797. //--------------------------------------------------------------------------
  798. // Structure used to register Windows class.
  799. //--------------------------------------------------------------------------
  800. WNDCLASSEX wndclass;
  801. //--------------------------------------------------------------------------
  802. // set up and register window class
  803. //--------------------------------------------------------------------------
  804. wndclass.cbSize = sizeof(WNDCLASSEX);
  805. wndclass.style = CS_HREDRAW | CS_VREDRAW;
  806. wndclass.lpfnWndProc = Wnd_Proc;
  807. wndclass.cbClsExtra = 0;
  808. //--------------------------------------------------------------------------
  809. // Reserve extra bytes for each instance of the window. We will use these
  810. // bytes to store a pointer to the C++ (MainWindow) object corresponding
  811. // to the window. The size of a 'this' pointer depends on the memory model.
  812. //--------------------------------------------------------------------------
  813. wndclass.cbWndExtra = sizeof( MainWindow * );
  814. wndclass.hInstance = Main::hInstance;
  815. wndclass.hIcon = LoadIcon( Main::hInstance, MAKEINTRESOURCE(1));
  816. // strcpy( szBuffer, "C&C2.ICO" );
  817. // wndclass.hIcon = (HICON)LoadImage( NULL, szBuffer, IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_LOADFROMFILE );
  818. wndclass.hCursor = LoadCursor( Main::hInstance, MAKEINTRESOURCE(2) );
  819. wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  820. wndclass.lpszMenuName = szClassName;
  821. wndclass.lpszClassName = szClassName;
  822. wndclass.hIconSm = LoadIcon( Main::hInstance, MAKEINTRESOURCE(1));
  823. if ( !RegisterClassEx((const WNDCLASSEX *) &wndclass ) ) {
  824. #if(_DEBUG)
  825. LPVOID szMessage;
  826. FormatMessage(
  827. FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
  828. NULL,
  829. GetLastError(),
  830. MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ),
  831. (LPTSTR)&szMessage,
  832. 0,
  833. NULL );
  834. _stprintf( szBuffer, TEXT( "%s(%lx)" ), szMessage, GetLastError());
  835. Msg( __LINE__, TEXT(__FILE__), TEXT("GetLastError: %s"), szBuffer );
  836. #endif
  837. exit( FALSE );
  838. }
  839. }
  840. //*****************************************************************************
  841. // MainWindow::MainWindow -- Main Window Constructor function.
  842. //
  843. // INPUT: none.
  844. //
  845. // OUTPUT: none.
  846. //
  847. // WARNINGS: none.
  848. //
  849. // HISTORY:
  850. // 06/04/1996 MML : Created.
  851. //=============================================================================
  852. MainWindow::MainWindow( void )
  853. {
  854. char szTitle[ _MAX_PATH ];
  855. hWnd = 0;
  856. #ifdef LEAN_AND_MEAN
  857. WideCharToMultiByte( CodePage, 0, szFullProductName, _MAX_PATH, szBuffer, _MAX_PATH, NULL, NULL );
  858. #else
  859. WideCharToMultiByte( CodePage, 0, fullProductName.str(), fullProductName.getLength()+1, szBuffer, _MAX_PATH, NULL, NULL );
  860. #endif
  861. memset( szTitle, '\0', _MAX_PATH );
  862. sprintf( szTitle, CLASS_NAME, szBuffer );
  863. //--------------------------------------------------------------------------
  864. // Create the MainWindow.
  865. // Pass 'this' pointer in lpParam of CreateWindow().
  866. //--------------------------------------------------------------------------
  867. hWnd = CreateWindowEx(
  868. 0,
  869. szClassName,
  870. szClassName,
  871. WS_POPUPWINDOW | WS_MINIMIZE | !WS_VISIBLE,
  872. 0,
  873. 0,
  874. 640,
  875. 480,
  876. NULL,
  877. NULL,
  878. Main::hInstance,
  879. (LPTSTR) this );
  880. if ( !hWnd ) {
  881. Stop_Sound_Playing();
  882. exit( FALSE );
  883. }
  884. ApplicationHWnd = hWnd;
  885. //-------------------------------------------------------------------------
  886. // Save the pointer so we can access it globally.
  887. //-------------------------------------------------------------------------
  888. GlobalMainWindow = this;
  889. //--------------------------------------------------------------------------
  890. // If you want to see the Background Window, enable these.
  891. //--------------------------------------------------------------------------
  892. // Show( Main::nCmdShow );
  893. // Update();
  894. }
  895. //*****************************************************************************
  896. // MainWindow::Window_Proc -- Main Window Procedure fnc to process msgs.
  897. //
  898. // INPUT: none.
  899. //
  900. // OUTPUT: none.
  901. //
  902. // WARNINGS: none.
  903. //
  904. // HISTORY:
  905. // 06/04/1996 MML : Created.
  906. //=============================================================================
  907. LRESULT MainWindow::Window_Proc( HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam )
  908. {
  909. static RECT rect;
  910. static int cxChar, cyChar;
  911. static HBRUSH hBrush = 0;
  912. static POINT point;
  913. int decision;
  914. static int bits_pixel = 0;
  915. switch( iMessage ) {
  916. //-----------------------------------------------------------------------
  917. // Create Message.
  918. //-----------------------------------------------------------------------
  919. case WM_CREATE:
  920. #if(0)
  921. hBrush = CreateSolidBrush( GetSysColor( COLOR_WINDOW ));
  922. #endif
  923. GetClientRect( GetDesktopWindow(), &rect );
  924. SendMessage( hWnd, WM_GO, wParam, lParam );
  925. break;
  926. //-----------------------------------------------------------------------
  927. // Go!
  928. //-----------------------------------------------------------------------
  929. case WM_GO:
  930. decision = DialogBox( Main::hInstance, _TEXT( "BitmapDialog" ), hWnd, Dialog_Box_Proc );
  931. if ( Args ) {
  932. delete( Args );
  933. Args = NULL;
  934. }
  935. Stop_Sound_Playing();
  936. MoveWindow( hWnd, 0, 0, 0, 0, TRUE );
  937. SendMessage( hWnd, WM_DESTROY, wParam, lParam );
  938. Msg( __LINE__, TEXT(__FILE__), TEXT("---------------------- end of WM_GO ---------------------" ));
  939. break;
  940. //-----------------------------------------------------------------------
  941. // WM_CTLCOLOR Message.
  942. // wParam Handle to Child Window's device context
  943. // LOWORD( lParam ) Child Window handle
  944. // HIWORD( lParam ) Type of Window: CTLCOLOR_MSGBOX, _EDIT, _LISTBOX, _BTN, _DLG, _SCROLLBAR, _STATIC
  945. //-----------------------------------------------------------------------
  946. #if( WINDOW_BRUSH )
  947. case WM_CTLCOLOR:
  948. if ( HIWORD( lParam ) == CTLCOLOR_BTN ) {
  949. SetBkColor( (HDC)wParam, GetSysColor( COLOR_WINDOW ));
  950. SetTextColor( (HDC)wParam, GetSysColor( COLOR_WINDOWTEXT ));
  951. UnrealizeObject( hBrush ); // reset the origin of the brush next time used.
  952. point.x = point.y = 0; // create a point.
  953. ClientToScreen( hWnd, &point ); // translate into screen coordinates.
  954. SetBrushOrg( (HDC)wParam, point.x, point.y ); // New Origin to use when next selected.
  955. return ((DWORD) hBrush);
  956. }
  957. break;
  958. //-----------------------------------------------------------------------
  959. // WM_SYSCOLORCHANGE Message.
  960. //-----------------------------------------------------------------------
  961. case WM_SYSCOLORCHANGE:
  962. DeleteObject( hBrush );
  963. hBrush = CreateSolidBrush( GetSysColor( COLOR_WINDOW ));
  964. break;
  965. //-----------------------------------------------------------------------
  966. // WM_SIZE Message.
  967. //-----------------------------------------------------------------------
  968. case WM_SIZE:
  969. rect.left = 24 * cxChar;
  970. rect.top = 2 * cyChar;
  971. rect.right = LOWORD( lParam );
  972. rect.bottom = HIWORD( lParam );
  973. break;
  974. #endif
  975. //-----------------------------------------------------------------------
  976. // WM_COMMAND Message.
  977. // wParam Child Window ID
  978. // LOWORD( lParam ) Child Window handle
  979. // HIWORD( lParam ) Notification Code: BN_CLICKED, BN_PAINT, etc...
  980. //-----------------------------------------------------------------------
  981. case WM_COMMAND:
  982. break;
  983. //-----------------------------------------------------------------------
  984. // WM_DESTROY Message.
  985. //-----------------------------------------------------------------------
  986. case WM_DESTROY:
  987. #if(WINDOW_BRUSH)
  988. DeleteObject( hBrush );
  989. #endif
  990. PostQuitMessage( 0 );
  991. break;
  992. default:
  993. return DefWindowProc( hWnd, iMessage, wParam, lParam );
  994. }
  995. return 0;
  996. }
  997. //*****************************************************************************
  998. // MainWindow::Is_Product_Registered -- Check the Registration Table information.
  999. //
  1000. // INPUT: none.
  1001. //
  1002. // OUTPUT: BOOL - TRUE if product is already installed, FALSE if not.
  1003. //
  1004. // WARNINGS: none.
  1005. //
  1006. // HISTORY:
  1007. // 06/04/1996 MML : Created.
  1008. //=============================================================================
  1009. BOOL MainWindow::Is_Product_Registered( void )
  1010. {
  1011. HKEY phKey;
  1012. BOOL result = FALSE;
  1013. char key [_MAX_PATH];
  1014. wchar_t szPath [_MAX_PATH];
  1015. unsigned long Type;
  1016. unsigned long Size = _MAX_PATH;
  1017. HANDLE handle;
  1018. WIN32_FIND_DATA FindFileData;
  1019. memset( szPath, '\0', sizeof( szPath ));
  1020. memset( szGamePath, '\0', sizeof( szGamePath ));
  1021. memset( szSetupPath, '\0', sizeof( szSetupPath ));
  1022. memset( szRegisterPath, '\0', sizeof( szRegisterPath ));
  1023. memset( szInternetPath, '\0', sizeof( szInternetPath ));
  1024. memset( szUninstallPath, '\0', sizeof( szUninstallPath ));
  1025. memset( FindFileData.cFileName, '\0', sizeof( FindFileData.cFileName ));
  1026. memset( FindFileData.cAlternateFileName, '\0', sizeof( FindFileData.cAlternateFileName ));
  1027. InstallProduct = TRUE;
  1028. UninstallAvailable = FALSE;
  1029. DisplayRegisterButton = FALSE;
  1030. IsWolapiAvailable = FALSE;
  1031. IsUserRegistered = FALSE;
  1032. //==========================================================================
  1033. // Look for keys under the Game's Registry key.
  1034. //==========================================================================
  1035. // _tcscat( _tcscpy( key, SOFTWARE_EAGAMES_KEY ), szRegistryKey );
  1036. _tcscat( _tcscpy( key, EAGAMES_GENERALS_KEY ), szRegistryKey );
  1037. //--------------------------------------------------------------------------
  1038. // Try to open the key.
  1039. //--------------------------------------------------------------------------
  1040. if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE, key, 0, KEY_QUERY_VALUE, &phKey ) == ERROR_SUCCESS ) {
  1041. //-----------------------------------------------------------------------
  1042. // Get Full path\filename of product to execute ("Play").
  1043. //-----------------------------------------------------------------------
  1044. Size = _MAX_PATH;
  1045. if ( RegQueryValueEx( phKey, INSTALL_PATH_KEY, NULL, &Type, (unsigned char *)szGamePath, &Size ) == ERROR_SUCCESS ) {
  1046. _tcscpy(szWorldbuilderPath, szGamePath);
  1047. _tcscpy(szPatchgetPath, szGamePath);
  1048. _tcscat(szGamePath, LAUNCHER_FILENAME);
  1049. _tcscat(szWorldbuilderPath, WORLDBUILDER_FILENAME);
  1050. _tcscat(szPatchgetPath, PATCHGET_FILENAME);
  1051. handle = FindFirstFile( szGamePath, &FindFileData );
  1052. if ( handle != INVALID_HANDLE_VALUE ) {
  1053. InstallProduct = FALSE;
  1054. FindClose( handle );
  1055. }
  1056. }
  1057. Msg( __LINE__, TEXT(__FILE__), TEXT("GamePath = %s."), szGamePath );
  1058. RegCloseKey( phKey );
  1059. }
  1060. //==========================================================================
  1061. // Find Keys under "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall"
  1062. //==========================================================================
  1063. _tcscpy( key, SHELL_UNINSTALL_KEY );
  1064. Path_Add_Back_Slash( key );
  1065. _tcscat( key, szRegistryKey );
  1066. //--------------------------------------------------------------------------
  1067. // Query the Uninstall key "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall"
  1068. //--------------------------------------------------------------------------
  1069. if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE, key, 0, KEY_ALL_ACCESS, &phKey ) == ERROR_SUCCESS ) {
  1070. Size = _MAX_PATH;
  1071. if ( RegQueryValueEx( phKey, UNINSTALL_STRING_SUBKEY, NULL, &Type, (unsigned char *)szUninstallPath, &Size ) == ERROR_SUCCESS ) {
  1072. //--------------------------------------------------------------------
  1073. // Look for the uninstall program. If found, set flag.
  1074. //--------------------------------------------------------------------
  1075. handle = FindFirstFile( szUninstallPath, &FindFileData );
  1076. if ( handle != INVALID_HANDLE_VALUE ) {
  1077. UninstallAvailable = TRUE;
  1078. FindClose( handle );
  1079. }
  1080. }
  1081. RegCloseKey( phKey );
  1082. }
  1083. //==========================================================================
  1084. // Look for keys under Register. If available, we should show the "Register"
  1085. // button. WESTWOOD_REGISTER_KEY "Software\\Westwood\\Register"
  1086. //==========================================================================
  1087. // _tcscpy( key, WESTWOOD_REGISTER_KEY );
  1088. //-------------------------------------------------------------------------
  1089. // Create IGR Options Object.
  1090. //-------------------------------------------------------------------------
  1091. IGROptionsClass *OnlineOptions = new IGROptionsClass();
  1092. if ( OnlineOptions ) {
  1093. OnlineOptions->Init();
  1094. }
  1095. //--------------------------------------------------------------------------
  1096. // If "Options" is set under WOLAPI, then this is a Game Room Edition and
  1097. // registration should NOT be allowed.
  1098. //--------------------------------------------------------------------------
  1099. if ( OnlineOptions ) {
  1100. DisplayRegisterButton = OnlineOptions->Is_Running_Reg_App_Allowed();
  1101. }
  1102. //--------------------------------------------------------------------------
  1103. // If Registration is allowed...
  1104. //--------------------------------------------------------------------------
  1105. /*
  1106. if ( DisplayRegisterButton ) {
  1107. DisplayRegisterButton = false;
  1108. if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE, key, 0, KEY_QUERY_VALUE, &phKey ) == ERROR_SUCCESS ) {
  1109. //-----------------------------------------------------------------------
  1110. // Get Full path\filename of product to execute ("Register.exe").
  1111. //-----------------------------------------------------------------------
  1112. Size = _MAX_PATH;
  1113. if ( RegQueryValueEx( phKey, INSTALLPATH_SUBKEY, NULL, &Type, (unsigned char *)szRegisterPath, &Size ) == ERROR_SUCCESS ) {
  1114. //--------------------------------------------------------------------
  1115. // Check if this executable exists.
  1116. //--------------------------------------------------------------------
  1117. handle = FindFirstFile( szRegisterPath, &FindFileData );
  1118. if ( handle != INVALID_HANDLE_VALUE ) {
  1119. DisplayRegisterButton = TRUE;
  1120. FindClose( handle );
  1121. }
  1122. }
  1123. RegCloseKey( phKey );
  1124. }
  1125. }
  1126. */
  1127. //==========================================================================
  1128. // Is WOLAPI DLL installed?
  1129. //==========================================================================
  1130. /*
  1131. _tcscpy( key, WESTWOOD_WOLAPI_KEY );
  1132. if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE, key, 0, KEY_QUERY_VALUE, &phKey ) == ERROR_SUCCESS ) {
  1133. //-----------------------------------------------------------------------
  1134. // Get Full path\filename of product to execute ("Register.exe").
  1135. //-----------------------------------------------------------------------
  1136. Size = _MAX_PATH;
  1137. if ( RegQueryValueEx( phKey, INSTALLPATH_SUBKEY, NULL, &Type, (unsigned char *)szBuffer, &Size ) == ERROR_SUCCESS ) {
  1138. //--------------------------------------------------------------------
  1139. // Check if this executable exists.
  1140. //--------------------------------------------------------------------
  1141. handle = FindFirstFile( szBuffer, &FindFileData );
  1142. if ( handle != INVALID_HANDLE_VALUE ) {
  1143. IsWolapiAvailable = TRUE;
  1144. FindClose( handle );
  1145. }
  1146. }
  1147. RegCloseKey( phKey );
  1148. }
  1149. */
  1150. Msg( __LINE__, TEXT(__FILE__), TEXT("---------------- Is_Product_Registered---------------" ));
  1151. Msg( __LINE__, TEXT(__FILE__), TEXT(" InstallProduct = %d."), InstallProduct );
  1152. Msg( __LINE__, TEXT(__FILE__), TEXT(" UninstallAvailable = %d."), UninstallAvailable );
  1153. Msg( __LINE__, TEXT(__FILE__), TEXT(" IsUserRegistered = %d."), IsUserRegistered );
  1154. Msg( __LINE__, TEXT(__FILE__), TEXT(" DisplayRegisterButton = %d."), DisplayRegisterButton );
  1155. Msg( __LINE__, TEXT(__FILE__), TEXT(" szGamePath = %s."), szGamePath );
  1156. Msg( __LINE__, TEXT(__FILE__), TEXT(" szSetupPath = %s."), szSetupPath );
  1157. Msg( __LINE__, TEXT(__FILE__), TEXT(" szRegisterPath = %s."), szRegisterPath );
  1158. Msg( __LINE__, TEXT(__FILE__), TEXT(" szInternetPath = %s."), szInternetPath );
  1159. Msg( __LINE__, TEXT(__FILE__), TEXT(" szUninstallPath = %s."), szUninstallPath );
  1160. return( result );
  1161. }
  1162. //*****************************************************************************
  1163. // MainWindow::Run_Explorer
  1164. //
  1165. // Get the Current Dir from argv[0]. Open the Explorer Window with
  1166. // this dir. The Explorer will open and display everything in this dir.
  1167. //
  1168. // INPUT: none.
  1169. //
  1170. // OUTPUT: none.
  1171. //
  1172. // WARNINGS: none.
  1173. //
  1174. // HISTORY:
  1175. // 06/04/1996 MML : Created.
  1176. //=============================================================================
  1177. BOOL MainWindow::Run_Explorer( char *szString, HWND hWnd, RECT *rect )
  1178. {
  1179. char szWindowsPath [ _MAX_PATH ];
  1180. char szPath [ _MAX_PATH ];
  1181. char szCurDir [ _MAX_PATH ];
  1182. char drive [ _MAX_DRIVE ];
  1183. char dir [ _MAX_DIR ];
  1184. char lpszComLine [ 127 ];
  1185. BOOL result = FALSE;
  1186. PROCESS_INFORMATION processinfo;
  1187. STARTUPINFO startupinfo;
  1188. //--------------------------------------------------------------------------
  1189. // Get current drive/directory from _argv[0].
  1190. //--------------------------------------------------------------------------
  1191. _tcscpy( szPath, szArgvPath );
  1192. _tsplitpath( szPath, drive, dir, NULL, NULL );
  1193. _tmakepath ( szPath, drive, dir, NULL, NULL );
  1194. //--------------------------------------------------------------------------
  1195. // Get Windows directory and build path to Explorer. Pas in szPath as
  1196. // the directory for Explorer to open.
  1197. //--------------------------------------------------------------------------
  1198. GetWindowsDirectory( szWindowsPath, _MAX_PATH );
  1199. Path_Add_Back_Slash( szWindowsPath );
  1200. _tcscat( szWindowsPath, EXPLORER_NAME );
  1201. _tcscat( _tcscat( _tcscpy( lpszComLine, szWindowsPath ), _TEXT( " " )), szPath );
  1202. _tcscpy( szCurDir, szPath );
  1203. //==========================================================================
  1204. // Setup the call
  1205. //==========================================================================
  1206. memset( &startupinfo, 0, sizeof( STARTUPINFO ));
  1207. startupinfo.cb = sizeof( STARTUPINFO );
  1208. //--------------------------------------------------------------------------
  1209. // Next, start the process
  1210. //--------------------------------------------------------------------------
  1211. result = CreateProcess(
  1212. szWindowsPath, // address of module name
  1213. lpszComLine, // address of command line
  1214. NULL, // address of process security attributes
  1215. NULL, // address of thread security attributes
  1216. FALSE, // new process inherits handles
  1217. 0, // creation flags
  1218. NULL, // address of new environment block
  1219. szCurDir, // address of current directory name
  1220. &startupinfo, // address of STARTUPINFO
  1221. &processinfo ); // address of PROCESS_INFORMATION
  1222. //--------------------------------------------------------------------------
  1223. // If WinExec returned 0, error occurred.
  1224. //--------------------------------------------------------------------------
  1225. if ( !result ) {
  1226. Cant_Find_MessageBox ( Main::hInstance, szPath );
  1227. #if(BACKGROUND_BITMAP)
  1228. //-----------------------------------------------------------------------
  1229. // Recreate Buttons based on Registry, then repaint window.
  1230. //-----------------------------------------------------------------------
  1231. Create_Buttons( hWnd, rect );
  1232. InvalidateRect( hWnd, rect, FALSE );
  1233. #endif
  1234. }
  1235. return ( result );
  1236. }
  1237. //*****************************************************************************
  1238. // MainWindow::Run_Game -- Launch the game based on registry information.
  1239. //
  1240. // INPUT: none.
  1241. //
  1242. // OUTPUT: none.
  1243. //
  1244. // WARNINGS: none.
  1245. //
  1246. // HISTORY:
  1247. // 06/04/1996 MML : Created.
  1248. //=============================================================================
  1249. unsigned int MainWindow::Run_Game ( HWND hWnd, RECT *rect )
  1250. {
  1251. char dir [_MAX_DIR];
  1252. char ext [_MAX_EXT];
  1253. char drive [_MAX_DRIVE];
  1254. char file [_MAX_FNAME];
  1255. // unsigned abc = 0;
  1256. HANDLE handle;
  1257. WIN32_FIND_DATA FindFileData;
  1258. //--------------------------------------------------------------------------
  1259. // Check if C&C is already running, and is looking for the CDRom.
  1260. // The Autorun keeps asking to "Play" when this happens.
  1261. //--------------------------------------------------------------------------
  1262. HWND game_window = FindWindow ( szGameWindow, NULL );
  1263. if ( game_window ){
  1264. ShowWindow( game_window, SW_RESTORE );
  1265. SetForegroundWindow ( game_window );
  1266. return FALSE;
  1267. }
  1268. //--------------------------------------------------------------------------
  1269. // Split into parts.
  1270. //--------------------------------------------------------------------------
  1271. _tsplitpath( szGamePath, drive, dir, file, ext );
  1272. //--------------------------------------------------------------------------
  1273. // Launch the game.
  1274. //--------------------------------------------------------------------------
  1275. handle = FindFirstFile( szGamePath, &FindFileData );
  1276. if ( handle == INVALID_HANDLE_VALUE ) {
  1277. return FALSE;
  1278. }
  1279. FindClose( handle );
  1280. //-----------------------------------------------------------------------
  1281. // Stop Sound if sound was playing.
  1282. //-----------------------------------------------------------------------
  1283. Stop_Sound_Playing();
  1284. LaunchObject.SetPath( szGamePath );
  1285. LaunchObject.Set_Launch( true );
  1286. return( true );
  1287. }
  1288. //*****************************************************************************
  1289. // MainWindow::Run_WorldBuilder -- Launch the map editor based on registry information.
  1290. //
  1291. // INPUT: none.
  1292. //
  1293. // OUTPUT: none.
  1294. //
  1295. // WARNINGS: none.
  1296. //
  1297. // HISTORY:
  1298. // 12/02/2002 BGC : Created.
  1299. //=============================================================================
  1300. unsigned int MainWindow::Run_WorldBuilder( HWND hWnd, RECT *rect)
  1301. {
  1302. HANDLE handle;
  1303. WIN32_FIND_DATA FindFileData;
  1304. //--------------------------------------------------------------------------
  1305. // Launch the game.
  1306. //--------------------------------------------------------------------------
  1307. handle = FindFirstFile( szWorldbuilderPath, &FindFileData );
  1308. if ( handle == INVALID_HANDLE_VALUE ) {
  1309. return FALSE;
  1310. }
  1311. FindClose( handle );
  1312. //-----------------------------------------------------------------------
  1313. // Stop Sound if sound was playing.
  1314. //-----------------------------------------------------------------------
  1315. Stop_Sound_Playing();
  1316. LaunchObject.SetPath( szWorldbuilderPath );
  1317. LaunchObject.Set_Launch( true );
  1318. return( true );
  1319. }
  1320. //*****************************************************************************
  1321. // MainWindow::Run_PatchGet -- Launch the patch checker based on registry information.
  1322. //
  1323. // INPUT: none.
  1324. //
  1325. // OUTPUT: none.
  1326. //
  1327. // WARNINGS: none.
  1328. //
  1329. // HISTORY:
  1330. // 12/02/2002 BGC : Created.
  1331. //=============================================================================
  1332. unsigned int MainWindow::Run_PatchGet( HWND hWnd, RECT *rect)
  1333. {
  1334. HANDLE handle;
  1335. WIN32_FIND_DATA FindFileData;
  1336. //--------------------------------------------------------------------------
  1337. // Launch the game.
  1338. //--------------------------------------------------------------------------
  1339. handle = FindFirstFile( szPatchgetPath, &FindFileData );
  1340. if ( handle == INVALID_HANDLE_VALUE ) {
  1341. return FALSE;
  1342. }
  1343. FindClose( handle );
  1344. //-----------------------------------------------------------------------
  1345. // Stop Sound if sound was playing.
  1346. //-----------------------------------------------------------------------
  1347. Stop_Sound_Playing();
  1348. LaunchObject.SetPath( szPatchgetPath );
  1349. LaunchObject.Set_Launch( true );
  1350. return( true );
  1351. }
  1352. //*****************************************************************************
  1353. // MainWindow::Run_Demo -- Launch a demo program if desired.
  1354. //
  1355. // INPUT: none.
  1356. //
  1357. // OUTPUT: none.
  1358. //
  1359. // WARNINGS: none.
  1360. //
  1361. // HISTORY:
  1362. // 01/08/2002 MML : Created.
  1363. //=============================================================================
  1364. unsigned int MainWindow::Run_Demo ( HWND hWnd, RECT *rect, int cd_drive )
  1365. {
  1366. // unsigned abc = 0;
  1367. HANDLE handle;
  1368. WIN32_FIND_DATA FindFileData;
  1369. //--------------------------------------------------------------------------
  1370. // Make path to demo program.
  1371. //--------------------------------------------------------------------------
  1372. // Make_Current_Path_To( MOH_DEMO_PROGRAM, szBuffer );
  1373. wsprintf( szBuffer, "%c:\\", 'A' + cd_drive );
  1374. Path_Add_Back_Slash( szBuffer );
  1375. strcat( szBuffer, MOH_DEMO_PROGRAM );
  1376. //--------------------------------------------------------------------------
  1377. // Launch the game.
  1378. //--------------------------------------------------------------------------
  1379. handle = FindFirstFile( szBuffer, &FindFileData );
  1380. if ( handle == INVALID_HANDLE_VALUE ) {
  1381. Cant_Find_MessageBox( Main::hInstance, szBuffer );
  1382. return FALSE;
  1383. }
  1384. FindClose( handle );
  1385. //-----------------------------------------------------------------------
  1386. // Stop Sound if sound was playing.
  1387. //-----------------------------------------------------------------------
  1388. Stop_Sound_Playing();
  1389. LaunchObject.SetPath( szBuffer );
  1390. LaunchObject.Set_Launch( true );
  1391. return( true );
  1392. }
  1393. //*****************************************************************************
  1394. // MainWindow::Run_OpenFile -- Main Window function to perform Setup tasks.
  1395. //
  1396. // INPUT: none.
  1397. //
  1398. // OUTPUT: none.
  1399. //
  1400. // WARNINGS: none.
  1401. //
  1402. // HISTORY:
  1403. // 06/04/1996 MML : Created.
  1404. //=============================================================================
  1405. unsigned int MainWindow::Run_OpenFile(int cd_drive, const char *filename, bool wait /* = false */)
  1406. {
  1407. char filepath[MAX_PATH];
  1408. MSG msg;
  1409. BOOL returnValue;
  1410. SHELLEXECUTEINFO executeInfo;
  1411. memset(&executeInfo, 0, sizeof(executeInfo));
  1412. executeInfo.cbSize = sizeof(executeInfo);
  1413. executeInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
  1414. executeInfo.hwnd = ApplicationHWnd;
  1415. executeInfo.lpVerb = "open";
  1416. executeInfo.lpFile = filename;
  1417. executeInfo.nShow = SW_SHOWNORMAL;
  1418. HANDLE hProcess;
  1419. BOOL ret = ShellExecuteEx(&executeInfo);
  1420. if ((ret == 0) || ((int)(executeInfo.hInstApp) <= 32)) {
  1421. Msg(__LINE__, TEXT(__FILE__), TEXT("Couldn't find executable for %s\n"), filepath);
  1422. return 0;
  1423. }
  1424. hProcess = executeInfo.hProcess;
  1425. if (wait == true) {
  1426. WaitForInputIdle(hProcess, 5000);
  1427. bool waiting = true;
  1428. bool quit = false;
  1429. while ((waiting == true) && (quit != true)) {
  1430. Sleep(0);
  1431. while( PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) )
  1432. {
  1433. // get the message
  1434. returnValue = GetMessage( &msg, NULL, 0, 0 );
  1435. // check for quitting
  1436. if( returnValue == 0 )
  1437. quit = TRUE;
  1438. // translate and dispatch the message
  1439. TranslateMessage( &msg );
  1440. DispatchMessage( &msg );
  1441. } // end while
  1442. DWORD exitCode;
  1443. GetExitCodeProcess(hProcess, &exitCode);
  1444. if (exitCode != STILL_ACTIVE) {
  1445. waiting = false;
  1446. }
  1447. }
  1448. }
  1449. return 1;
  1450. }
  1451. //*****************************************************************************
  1452. // MainWindow::Run_Setup -- Main Window function to perform Setup tasks.
  1453. //
  1454. // INPUT: none.
  1455. //
  1456. // OUTPUT: none.
  1457. //
  1458. // WARNINGS: none.
  1459. //
  1460. // HISTORY:
  1461. // 06/04/1996 MML : Created.
  1462. //=============================================================================
  1463. unsigned int MainWindow::Run_Setup( HWND hWnd, RECT *rect, int cd_drive )
  1464. {
  1465. // UINT result = 0;
  1466. int i = 0;
  1467. char params [ 127 ];
  1468. char filepath[ _MAX_PATH ];
  1469. HANDLE handle;
  1470. WIN32_FIND_DATA FindFileData;
  1471. Msg( __LINE__, TEXT(__FILE__), TEXT("---------------------- Run_Setup --------------------." ));
  1472. //--------------------------------------------------------------------------
  1473. // Clear these buffers for later use.
  1474. //--------------------------------------------------------------------------
  1475. memset( params, '\0', 127 );
  1476. //--------------------------------------------------------------------------
  1477. // Get Drive & Dir from ARGV[0] and create path to SETUP.EXE.
  1478. //--------------------------------------------------------------------------
  1479. // strcpy( filepath, szArgvPath );
  1480. // Path_Add_Back_Slash( filepath );
  1481. wsprintf( filepath, "%c:\\", 'A' + cd_drive );
  1482. Path_Add_Back_Slash( filepath );
  1483. strcat( filepath, SETUP_NAME );
  1484. //--------------------------------------------------------------------------
  1485. // If we could not find SETUP.EXE, then display error msg and exit.
  1486. //--------------------------------------------------------------------------
  1487. handle = FindFirstFile( filepath, &FindFileData );
  1488. if ( handle == INVALID_HANDLE_VALUE ) {
  1489. Cant_Find_MessageBox( Main::hInstance, filepath );
  1490. return FALSE;
  1491. }
  1492. FindClose( handle );
  1493. //--------------------------------------------------------------------------
  1494. // Create parameters to pass in with the program we are calling.
  1495. //--------------------------------------------------------------------------
  1496. memset( params, '\0', sizeof( params ));
  1497. if ( NumberArguments ) {
  1498. _tcscpy( params, Arguments[0] );
  1499. i = 1;
  1500. while (( i < NUM_ARGUMENTS ) && ( i < NumberArguments )) {
  1501. _tcscat( _tcscat( params, _TEXT( " " )), Arguments[i] );
  1502. i++;
  1503. }
  1504. }
  1505. //--------------------------------------------------------------------------
  1506. // Stop Sound if sound was playing.
  1507. //--------------------------------------------------------------------------
  1508. Stop_Sound_Playing();
  1509. LaunchObject.SetPath( filepath );
  1510. LaunchObject.SetArgs( params );
  1511. LaunchObject.Set_Launch( true );
  1512. return( true );
  1513. }
  1514. //*****************************************************************************
  1515. // MainWindow::Run_New_Account -- Create a new online account.
  1516. //
  1517. // INPUT: none.
  1518. //
  1519. // OUTPUT: none.
  1520. //
  1521. // WARNINGS: none.
  1522. //
  1523. // HISTORY:
  1524. // 06/04/1996 MML : Created.
  1525. //=============================================================================
  1526. unsigned int MainWindow::Run_New_Account ( HWND hWnd, RECT *rect )
  1527. {
  1528. // UINT result = 0;
  1529. int i = 0;
  1530. char params [ 127 ];
  1531. char filepath[ _MAX_PATH ];
  1532. HANDLE handle;
  1533. WIN32_FIND_DATA FindFileData;
  1534. //--------------------------------------------------------------------------
  1535. // Clear these buffers for later use.
  1536. //--------------------------------------------------------------------------
  1537. memset( params, '\0', 127 );
  1538. //--------------------------------------------------------------------------
  1539. // Get Drive & Dir from ARGV[0] and create path to SETUP.EXE.
  1540. //--------------------------------------------------------------------------
  1541. _tcscpy( filepath, szArgvPath );
  1542. Path_Add_Back_Slash( filepath );
  1543. _tcscat( filepath, SETUP_NAME );
  1544. //--------------------------------------------------------------------------
  1545. // If we could not find SETUP.EXE, then display error msg and exit.
  1546. //--------------------------------------------------------------------------
  1547. handle = FindFirstFile( filepath, &FindFileData );
  1548. if ( handle == INVALID_HANDLE_VALUE ) {
  1549. Cant_Find_MessageBox( Main::hInstance, SETUP_NAME );
  1550. return FALSE;
  1551. }
  1552. FindClose( handle );
  1553. //--------------------------------------------------------------------------
  1554. // Create parameters to pass in with the program we are calling.
  1555. //--------------------------------------------------------------------------
  1556. memset( params, '\0', sizeof( params ));
  1557. if ( NumberArguments ) {
  1558. _tcscpy( params, Arguments[0] );
  1559. i = 1;
  1560. while (( i < NUM_ARGUMENTS ) && ( i < NumberArguments )) {
  1561. _tcscat( _tcscat( params, _TEXT( " " )), Arguments[i] );
  1562. i++;
  1563. }
  1564. _tcscat( params, _TEXT( " " ));
  1565. }
  1566. _tcscat( params, "-o" );
  1567. //--------------------------------------------------------------------------
  1568. // Stop Sound if sound was playing.
  1569. //--------------------------------------------------------------------------
  1570. Stop_Sound_Playing();
  1571. LaunchObject.SetPath( filepath );
  1572. LaunchObject.SetArgs( params );
  1573. LaunchObject.Set_Launch( true );
  1574. return( true );
  1575. }
  1576. //*****************************************************************************
  1577. // MainWindow::Run_Register_Or_Auto_Update
  1578. //
  1579. // Either run Register.exe or Game Update Program from the user's harddrive.
  1580. //
  1581. // INPUT: none.
  1582. //
  1583. // OUTPUT: none.
  1584. //
  1585. // WARNINGS: none.
  1586. //
  1587. // HISTORY:
  1588. // 02/24/1999 MML : Created.
  1589. //=============================================================================
  1590. unsigned int MainWindow::Run_Register ( HWND hWnd, RECT *rect )
  1591. {
  1592. char szArgs[ MAX_PATH ];
  1593. HANDLE handle;
  1594. WIN32_FIND_DATA FindFileData;
  1595. BOOL result = FALSE;
  1596. //--------------------------------------------------------------------------
  1597. // Register Program is available. Continue...
  1598. //--------------------------------------------------------------------------
  1599. if ( DisplayRegisterButton ) {
  1600. //-----------------------------------------------------------------------
  1601. // Check again. May have been changed ...
  1602. //-----------------------------------------------------------------------
  1603. handle = FindFirstFile( szRegisterPath, &FindFileData );
  1604. if ( handle == INVALID_HANDLE_VALUE ) {
  1605. return( 0 );
  1606. }
  1607. FindClose( handle );
  1608. //-----------------------------------------------------------------------
  1609. // User is already registered, so maybe we should Auto Update!
  1610. //-----------------------------------------------------------------------
  1611. strcpy( szArgs, _TEXT( " " ));
  1612. LaunchObject.SetPath( szRegisterPath );
  1613. LaunchObject.SetArgs( szArgs );
  1614. LaunchObject.Set_Launch( true );
  1615. result = true;
  1616. }
  1617. return( result );
  1618. }
  1619. //*****************************************************************************
  1620. // MainWindow::Run_Auto_Update
  1621. //
  1622. // Either run Register.exe or Game Update Program from the user's harddrive.
  1623. //
  1624. // INPUT: none.
  1625. //
  1626. // OUTPUT: none.
  1627. //
  1628. // WARNINGS: none.
  1629. //
  1630. // HISTORY:
  1631. // 02/24/1999 MML : Created.
  1632. //=============================================================================
  1633. unsigned int MainWindow::Run_Auto_Update ( HWND hWnd, RECT *rect )
  1634. {
  1635. char szArgs [ MAX_PATH ];
  1636. HANDLE handle;
  1637. WIN32_FIND_DATA FindFileData;
  1638. BOOL result = FALSE;
  1639. //--------------------------------------------------------------------------
  1640. // Register Program is available. Continue...
  1641. //--------------------------------------------------------------------------
  1642. if ( !InstallProduct ) {
  1643. //-----------------------------------------------------------------------
  1644. // Check again. May have been changed ...
  1645. //-----------------------------------------------------------------------
  1646. handle = FindFirstFile( szGamePath, &FindFileData );
  1647. if ( handle == INVALID_HANDLE_VALUE ) {
  1648. return( 0 );
  1649. }
  1650. FindClose( handle );
  1651. _tcscpy( szArgs, _TEXT( " GrabPatches" ));
  1652. LaunchObject.SetPath( szGamePath );
  1653. LaunchObject.SetArgs( szArgs );
  1654. LaunchObject.Set_Launch( true );
  1655. result = true;
  1656. }
  1657. return( result );
  1658. }
  1659. //*****************************************************************************
  1660. // MainWindow::Run_Uninstall -- Main Window function to perform Setup tasks.
  1661. //
  1662. // INPUT: none.
  1663. //
  1664. // OUTPUT: none.
  1665. //
  1666. // WARNINGS: none.
  1667. //
  1668. // HISTORY:
  1669. // 06/04/1996 MML : Created.
  1670. //=============================================================================
  1671. unsigned int MainWindow::Run_Uninstall( HWND hWnd, RECT *rect )
  1672. {
  1673. MSG msg;
  1674. UINT result = 0;
  1675. // int done = 0;
  1676. DWORD dwTimeout = 1500;
  1677. DWORD dwRC = WAIT_TIMEOUT;
  1678. DWORD lpExitCode;
  1679. STARTUPINFO startupinfo;
  1680. PROCESS_INFORMATION processinfo;
  1681. HANDLE handle;
  1682. WIN32_FIND_DATA FindFileData;
  1683. char szCurDir [_MAX_PATH];
  1684. char file [_MAX_FNAME];
  1685. char ext [_MAX_EXT];
  1686. char szPath [_MAX_PATH];
  1687. //--------------------------------------------------------------------------
  1688. // Launch the UNINSTALL.
  1689. //--------------------------------------------------------------------------
  1690. handle = FindFirstFile( szUninstallPath, &FindFileData );
  1691. if ( handle == INVALID_HANDLE_VALUE ) {
  1692. return( 0 );
  1693. }
  1694. FindClose( handle );
  1695. _splitpath( szUninstallPath, drive, dir, NULL, NULL );
  1696. _makepath ( szCurDir, drive, dir, NULL, NULL );
  1697. //=======================================================================
  1698. // Setup the call
  1699. //=======================================================================
  1700. memset( &startupinfo, 0, sizeof( STARTUPINFO ));
  1701. startupinfo.cb = sizeof( STARTUPINFO );
  1702. result = CreateProcess(
  1703. szUninstallPath, // address of module name
  1704. szUninstallPath, // address of command line
  1705. NULL, // address of process security attributes
  1706. NULL, // address of thread security attributes
  1707. 0, // new process inherits handles
  1708. 0,
  1709. NULL, // address of new environment block
  1710. // _TEXT("."),
  1711. szCurDir,
  1712. &startupinfo, // address of STARTUPINFO
  1713. &processinfo ); // address of PROCESS_INFORMATION
  1714. //--------------------------------------------------------------------------
  1715. // If WinExec returned 0, error occurred.
  1716. //--------------------------------------------------------------------------
  1717. if ( !result ) {
  1718. _tsplitpath( szUninstallPath, NULL, NULL, file, ext );
  1719. _tmakepath ( szPath, NULL, NULL, file, ext );
  1720. Cant_Find_MessageBox ( Main::hInstance, szPath );
  1721. // #if(BACKGROUND_BITMAP)
  1722. //-----------------------------------------------------------------------
  1723. // Recreate Buttons based on Registry, then repaint window.
  1724. //-----------------------------------------------------------------------
  1725. // Create_Buttons( hWnd, rect );
  1726. // InvalidateRect( hWnd, rect, FALSE );
  1727. // #endif
  1728. return( result );
  1729. }
  1730. //--------------------------------------------------------------------------
  1731. // Wait for App to shutdown
  1732. //--------------------------------------------------------------------------
  1733. while (dwRC == WAIT_TIMEOUT) {
  1734. //-----------------------------------------------------------------------
  1735. // Wait for object
  1736. //-----------------------------------------------------------------------
  1737. dwRC = WaitForSingleObject( processinfo.hProcess, dwTimeout );
  1738. //-----------------------------------------------------------------------
  1739. // Flush the Queue
  1740. //-----------------------------------------------------------------------
  1741. while (PeekMessage( &msg, NULL, 0, 0, PM_REMOVE )) {
  1742. TranslateMessage( &msg );
  1743. DispatchMessage( &msg );
  1744. }
  1745. }
  1746. //--------------------------------------------------------------------------
  1747. // If the specified process has not terminated, the termination status
  1748. // returned is STILL_ACTIVE.
  1749. //--------------------------------------------------------------------------
  1750. GetExitCodeProcess( processinfo.hProcess, &lpExitCode );
  1751. CloseHandle( processinfo.hProcess );
  1752. CloseHandle( processinfo.hThread );
  1753. #if(BACKGROUND_BITMAP)
  1754. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1755. // MML 5/27/99: This function is dropping through because we launch Uninstll.exe
  1756. // which in turn launches Uninst.exe thus ::Run_Install ends before Uninst.exe is done.
  1757. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1758. //--------------------------------------------------------------------------
  1759. // Recreate Buttons based on Registry.
  1760. // Repaint calling Window.
  1761. //--------------------------------------------------------------------------
  1762. Create_Buttons( hWnd, rect );
  1763. InvalidateRect( hWnd, rect, FALSE );
  1764. #endif
  1765. return( result );
  1766. }
  1767. //*****************************************************************************
  1768. // MainWindow::Create_Buttons -- Reset the Buttons.
  1769. //
  1770. // INPUT: none.
  1771. //
  1772. // OUTPUT: none.
  1773. //
  1774. // WARNINGS: none.
  1775. //
  1776. // HISTORY:
  1777. // 06/04/1996 MML : Created.
  1778. //=============================================================================
  1779. void MainWindow::Create_Buttons( HWND hWnd, RECT *dlg_rect )
  1780. {
  1781. int j = 0;
  1782. int i = 0;
  1783. int x_pos = 0;
  1784. int y_pos = 0;
  1785. int width = 0;
  1786. int height = 0;
  1787. // int avg_width = 0;
  1788. // int space_between = 5;
  1789. int button_index = 0;
  1790. HBITMAP hButtonBitmap = 0;
  1791. HPALETTE hpal = 0;
  1792. BITMAP button_bm;
  1793. char next_button_name[_MAX_PATH];
  1794. char focused_button_name[_MAX_PATH];
  1795. RECT * button_size = ButtonSizes;
  1796. //--------------------------------------------------------------------------
  1797. // Reset all the flags.
  1798. //--------------------------------------------------------------------------
  1799. Is_Product_Registered( );
  1800. Msg( __LINE__, TEXT(__FILE__), TEXT("------------------------ Create_Buttons ------------------------" ));
  1801. //--------------------------------------------------------------------------
  1802. // Get width and height of the button.
  1803. //--------------------------------------------------------------------------
  1804. hButtonBitmap = LoadResourceBitmap( Main::hModule, BUTTON_REG, &hpal, TRUE );
  1805. if ( hButtonBitmap ) {
  1806. GetObject( hButtonBitmap, sizeof( BITMAP ), (LPTSTR)&button_bm );
  1807. width = button_bm.bmWidth;
  1808. height = button_bm.bmHeight;
  1809. DeleteObject( hButtonBitmap );
  1810. hButtonBitmap = 0;
  1811. } else {
  1812. button_bm.bmWidth = width = BUTTON_WIDTH;
  1813. button_bm.bmHeight = height = BUTTON_HEIGHT;
  1814. }
  1815. //--------------------------------------------------------------------------
  1816. // Initialize the ButtonList.
  1817. //--------------------------------------------------------------------------
  1818. if( b640X480 || b800X600 ) {
  1819. // x_pos = 0;
  1820. // y_pos = 340;
  1821. x_pos = 410;
  1822. y_pos = 90;
  1823. // width = 123;
  1824. // height = 42;
  1825. } else {
  1826. x_pos = 540;
  1827. y_pos = 117;
  1828. }
  1829. for ( i = 0; i < NUM_BUTTONS; i++ ) {
  1830. if ( ButtonList[i] ) {
  1831. delete( ButtonList[i] );
  1832. }
  1833. ButtonList[i] = NULL;
  1834. ButtonSizes[i].left = x_pos; // X position.
  1835. ButtonSizes[i].top = y_pos; // Y position.
  1836. ButtonSizes[i].right = width; // Button's width.
  1837. ButtonSizes[i].bottom = height; // Button's height.
  1838. // x_pos -= /*height*/ 16;
  1839. y_pos += height + 4;
  1840. Msg( __LINE__, TEXT(__FILE__), TEXT("ButtonSizes[%d] = ( %d, %d, %d, %d )"),
  1841. i, ButtonSizes[i].left, ButtonSizes[i].top, ButtonSizes[i].right, ButtonSizes[i].bottom );
  1842. }
  1843. //==========================================================================
  1844. // Create the "Buttons"
  1845. //==========================================================================
  1846. // i = NUM_BUTTONS-1;
  1847. // j = NUM_BUTTONS-1;
  1848. i = 0;
  1849. j = 0;
  1850. //--------------------------------------------------------------------------
  1851. // Make any other necessary adjustments here.
  1852. //--------------------------------------------------------------------------
  1853. int count = 7;
  1854. if ( !UninstallAvailable ) {
  1855. count--; // No uninstall button.
  1856. }
  1857. if ( InstallProduct ) {
  1858. count--; // No Website button.
  1859. }
  1860. // button_index = NUM_BUTTONS - (( NUM_BUTTONS - count ) / 2 ) - 1;
  1861. button_index = 0;
  1862. strcpy( next_button_name, ButtonImages[button_index] );
  1863. strcpy( focused_button_name, FocusedButtonImages[button_index] );
  1864. button_size = ButtonSizes;
  1865. i = j = button_index;
  1866. // button_index--;
  1867. Msg( __LINE__, TEXT(__FILE__), TEXT("count = %d."), count );
  1868. Msg( __LINE__, TEXT(__FILE__), TEXT("button_index = %d."), button_index );
  1869. Msg( __LINE__, TEXT(__FILE__), TEXT("next_button_name = %s."), next_button_name );
  1870. Msg( __LINE__, TEXT(__FILE__), TEXT("focused_button_name = %s."), focused_button_name );
  1871. //-------------------------------------------------------------------------
  1872. // INSTALL or PLAY?
  1873. //-------------------------------------------------------------------------
  1874. if ( InstallProduct ) {
  1875. //---------------------------------------------------------------------
  1876. // (8) INSTALL button.
  1877. //---------------------------------------------------------------------
  1878. Msg( __LINE__, TEXT(__FILE__), TEXT("ButtonList[%d]: Id=%d, ButtonSizes=%d, String=%s."), i, IDD_OK, j, "Install" );
  1879. ButtonList[i++] = new DrawButton(
  1880. IDD_OK,
  1881. button_size[j++],
  1882. BUTTON_REG,
  1883. BUTTON_SEL,
  1884. BUTTON_SEL,
  1885. #ifdef LEAN_AND_MEAN
  1886. Locale_GetString( "Autorun:Install" ),
  1887. #else
  1888. AsciiString("Autorun:Install"),
  1889. #endif
  1890. TTButtonFontPtr );
  1891. } else {
  1892. //---------------------------------------------------------------------
  1893. // (8) PLAY button.
  1894. //---------------------------------------------------------------------
  1895. Msg( __LINE__, TEXT(__FILE__), TEXT("ButtonList[%d]: Id=%d, ButtonSizes=%d, String=%s."), i, IDD_OK2, j, "Play" );
  1896. ButtonList[i++] = new DrawButton(
  1897. IDD_OK2,
  1898. button_size[j++],
  1899. BUTTON_REG,
  1900. BUTTON_SEL,
  1901. BUTTON_SEL,
  1902. #ifdef LEAN_AND_MEAN
  1903. Locale_GetString( "Autorun:Play" ),
  1904. #else
  1905. AsciiString("Autorun:Play"),
  1906. #endif
  1907. TTButtonFontPtr );
  1908. /*
  1909. //---------------------------------------------------------------------
  1910. // (8) WorldBuilder button.
  1911. //---------------------------------------------------------------------
  1912. Msg( __LINE__, TEXT(__FILE__), TEXT("ButtonList[%d]: Id=%d, ButtonSizes=%d, String=%s."), i, IDD_OK2, j, "WorldBuilder" );
  1913. // ButtonList[i--] = new DrawButton(
  1914. ButtonList[i++] = new DrawButton(
  1915. IDD_OK3,
  1916. // button_size[j--],
  1917. button_size[j++],
  1918. BUTTON_REG,
  1919. BUTTON_SEL,
  1920. BUTTON_SEL,
  1921. #ifdef LEAN_AND_MEAN
  1922. Locale_GetString( "Autorun:Worldbuilder" ),
  1923. #else
  1924. AsciiString("Autorun:Worldbuilder"),
  1925. #endif
  1926. TTButtonFontPtr );
  1927. */
  1928. //---------------------------------------------------------------------
  1929. // (8) Check for updates button.
  1930. //---------------------------------------------------------------------
  1931. Msg( __LINE__, TEXT(__FILE__), TEXT("ButtonList[%d]: Id=%d, ButtonSizes=%d, String=%s."), i, IDD_OK2, j, "Check For Updates" );
  1932. // ButtonList[i--] = new DrawButton(
  1933. ButtonList[i++] = new DrawButton(
  1934. IDD_OK4,
  1935. // button_size[j--],
  1936. button_size[j++],
  1937. BUTTON_REG,
  1938. BUTTON_SEL,
  1939. BUTTON_SEL,
  1940. #ifdef LEAN_AND_MEAN
  1941. Locale_GetString( "Autorun:CheckForUpdates" ),
  1942. #else
  1943. AsciiString("Autorun:CheckForUpdates"),
  1944. #endif
  1945. TTButtonFontPtr );
  1946. }
  1947. //-------------------------------------------------------------------------
  1948. // (7) EXPLORE CD
  1949. //-------------------------------------------------------------------------
  1950. Msg( __LINE__, TEXT(__FILE__), TEXT("ButtonList[%d]: Id=%d, ButtonSizes=%d, String=%s."), i, IDD_EXPLORE, j, "Explore" );
  1951. // ButtonList[i--] = new DrawButton (
  1952. ButtonList[i++] = new DrawButton (
  1953. IDD_EXPLORE,
  1954. // button_size[j--],
  1955. button_size[j++],
  1956. BUTTON_REG,
  1957. BUTTON_SEL,
  1958. BUTTON_SEL,
  1959. #ifdef LEAN_AND_MEAN
  1960. Locale_GetString( "Autorun:ExploreCD" ),
  1961. #else
  1962. AsciiString("Autorun:ExploreCD"),
  1963. #endif
  1964. TTButtonFontPtr );
  1965. // strcpy( next_button_name, ButtonImages[button_index] );
  1966. // strcpy( focused_button_name, FocusedButtonImages[button_index--] );
  1967. // strcpy( focused_button_name, FocusedButtonImages[button_index++] );
  1968. if ( !InstallProduct ) {
  1969. //-----------------------------------------------------------------------
  1970. // (3) WebSite button.
  1971. //-----------------------------------------------------------------------
  1972. Msg( __LINE__, TEXT(__FILE__), TEXT("ButtonList[%d]: Id=%d, ButtonSizes=%d, String=%s."), i, IDD_OK, j, "Install" );
  1973. // ButtonList[i--] = new DrawButton(
  1974. ButtonList[i++] = new DrawButton(
  1975. IDD_INTERNET,
  1976. // button_size[j--],
  1977. button_size[j++],
  1978. BUTTON_REG,
  1979. BUTTON_SEL,
  1980. BUTTON_SEL,
  1981. #ifdef LEAN_AND_MEAN
  1982. Locale_GetString( "Autorun:Website" ),
  1983. #else
  1984. AsciiString("Autorun:Website"),
  1985. #endif
  1986. TTButtonFontPtr );
  1987. // strcpy( next_button_name, ButtonImages[button_index] );
  1988. // strcpy( focused_button_name, FocusedButtonImages[button_index--] );
  1989. // strcpy( focused_button_name, FocusedButtonImages[button_index++] );
  1990. }
  1991. //--------------------------------------------------------------------------
  1992. // (2) UNINSTALL?
  1993. //--------------------------------------------------------------------------
  1994. if ( UninstallAvailable && !InstallProduct ) {
  1995. Msg( __LINE__, TEXT(__FILE__), TEXT("ButtonList[%d]: Id=%d, ButtonSizes=%d, String=%s."), i, IDD_UNINSTALL, j, "Uninstall" );
  1996. // ButtonList[i--] = new DrawButton(
  1997. ButtonList[i++] = new DrawButton(
  1998. IDD_UNINSTALL,
  1999. // button_size[j--],
  2000. button_size[j++],
  2001. BUTTON_REG,
  2002. BUTTON_SEL,
  2003. BUTTON_SEL,
  2004. #ifdef LEAN_AND_MEAN
  2005. Locale_GetString( "Autorun:Uninstall" ),
  2006. #else
  2007. AsciiString("Autorun:Uninstall"),
  2008. #endif
  2009. TTButtonFontPtr );
  2010. // strcpy( next_button_name, ButtonImages[button_index] );
  2011. // strcpy( focused_button_name, FocusedButtonImages[button_index--] );
  2012. // strcpy( focused_button_name, FocusedButtonImages[button_index++] );
  2013. }
  2014. //--------------------------------------------------------------------------
  2015. // (1) MOH movie
  2016. //--------------------------------------------------------------------------
  2017. Msg( __LINE__, TEXT(__FILE__), TEXT("ButtonList[%d]: Id=%d, ButtonSizes=%d, String=%s."), i, IDD_PREVIEWS, j, "Preview Movies");
  2018. ButtonList[i++] = new DrawButton(
  2019. IDD_PREVIEWS,
  2020. button_size[j++],
  2021. BUTTON_REG,
  2022. BUTTON_SEL,
  2023. BUTTON_SEL,
  2024. #ifdef LEAN_AND_MEAN
  2025. Locale_GetString( "Autorun:Previews" ),
  2026. #else
  2027. AsciiString("Autorun:Previews"),
  2028. #endif
  2029. TTButtonFontPtr );
  2030. //--------------------------------------------------------------------------
  2031. // (1) Help file
  2032. //--------------------------------------------------------------------------
  2033. Msg( __LINE__, TEXT(__FILE__), TEXT("ButtonList[%d]: Id=%d, ButtonSizes=%d, String=%s."), i, IDD_HELP, j, "Help file");
  2034. ButtonList[i++] = new DrawButton(
  2035. IDD_HELP,
  2036. button_size[j++],
  2037. BUTTON_REG,
  2038. BUTTON_SEL,
  2039. BUTTON_SEL,
  2040. #ifdef LEAN_AND_MEAN
  2041. Locale_GetString( "Autorun:Help" ),
  2042. #else
  2043. AsciiString("Autorun:Help"),
  2044. #endif
  2045. TTButtonFontPtr );
  2046. //--------------------------------------------------------------------------
  2047. // (1) CANCEL?
  2048. //--------------------------------------------------------------------------
  2049. Msg( __LINE__, TEXT(__FILE__), TEXT("ButtonList[%d]: Id=%d, ButtonSizes=%d, String=%s."), i, IDD_CANCEL, j, "Cancel" );
  2050. // ButtonList[i--] = new DrawButton(
  2051. ButtonList[i++] = new DrawButton(
  2052. IDD_CANCEL,
  2053. // button_size[j--],
  2054. button_size[j++],
  2055. BUTTON_REG,
  2056. BUTTON_SEL,
  2057. BUTTON_SEL,
  2058. #ifdef LEAN_AND_MEAN
  2059. Locale_GetString( "Autorun:Cancel" ),
  2060. #else
  2061. AsciiString("Autorun:Cancel"),
  2062. #endif
  2063. TTButtonFontPtr );
  2064. // strcpy( next_button_name, ButtonImages[button_index] );
  2065. // strcpy( focused_button_name, FocusedButtonImages[button_index--] );
  2066. // strcpy( focused_button_name, FocusedButtonImages[button_index++] );
  2067. //-------------------------------------------------------------------------
  2068. // Set the top button to have the focus.
  2069. //-------------------------------------------------------------------------
  2070. if ( ButtonList[0]) {
  2071. Msg( __LINE__, TEXT(__FILE__), TEXT("Button with starting Focus = %d"), i );
  2072. ButtonList[0]->Set_State( DrawButton::FOCUS_STATE );
  2073. }
  2074. #if( _DEBUG )
  2075. Msg( __LINE__, TEXT(__FILE__), TEXT("----------------------------------------------------------------------------------"));
  2076. for( i=0; i<NUM_BUTTONS; i++ ) {
  2077. if ( ButtonList[i]) {
  2078. Msg( __LINE__, TEXT(__FILE__), TEXT("ButtonList[%d]: Id=%d, ButtonSizes=[%d,%d,%d,%d]."),
  2079. i,
  2080. ButtonList[i]->Return_Id(),
  2081. ButtonList[i]->Return_X_Pos(),
  2082. ButtonList[i]->Return_Y_Pos(),
  2083. ButtonList[i]->Return_Width(),
  2084. ButtonList[i]->Return_Height());
  2085. }
  2086. }
  2087. #endif
  2088. }
  2089. //*****************************************************************************
  2090. // WndProc -- Get Main Window's Stored Word.
  2091. //
  2092. // INPUT: HWND hWnd.
  2093. // Window *pWindow
  2094. //
  2095. // OUTPUT: none.
  2096. //
  2097. // WARNINGS: none.
  2098. //
  2099. // HISTORY:
  2100. // 06/04/1996 MML : Created.
  2101. //=============================================================================
  2102. LRESULT CALLBACK Wnd_Proc ( HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam )
  2103. {
  2104. //--------------------------------------------------------------------------
  2105. // If the GlobalMainWindow Ptr is not initialized, do it when the MW-CREATE
  2106. // msg is called. Then we use the GlobalMainWindow's WindowProc to
  2107. // process all the individual msgs sent.
  2108. //--------------------------------------------------------------------------
  2109. if ( GlobalMainWindow == NULL ) {
  2110. if ( iMessage == WM_CREATE ) {
  2111. LPCREATESTRUCT lpcs;
  2112. lpcs = (LPCREATESTRUCT) lParam;
  2113. GlobalMainWindow = (MainWindow *) lpcs->lpCreateParams;
  2114. //-----------------------------------------------------------------
  2115. // Now let the object perform whatever initialization it needs
  2116. // for WM_CREATE in its own WndProc.
  2117. //-----------------------------------------------------------------
  2118. return GlobalMainWindow->Window_Proc( hWnd, iMessage, wParam, lParam );
  2119. } else {
  2120. return DefWindowProc( hWnd, iMessage, wParam, lParam );
  2121. }
  2122. } else {
  2123. return GlobalMainWindow->Window_Proc( hWnd, iMessage, wParam, lParam );
  2124. }
  2125. }
  2126. //*****************************************************************************
  2127. // DIALOG_BOX_PROC -- Handles dlg messages
  2128. //
  2129. // INPUT: standard windows dialog command parameters
  2130. //
  2131. // OUTPUT: unused
  2132. //
  2133. // WARNINGS: none
  2134. //
  2135. // HISTORY:
  2136. // 06/04/1996 MML : Created.
  2137. //=============================================================================
  2138. BOOL CALLBACK Dialog_Box_Proc( HWND window_handle, UINT message, WPARAM w_param, LPARAM l_param )
  2139. {
  2140. int i = 0, j = 0;
  2141. int nResult = 0;
  2142. // int space_between = 5;
  2143. int prevDCStretchMode;
  2144. int prevMemDCStretchMode;
  2145. int prevButtonDCStretchMode;
  2146. int prevLicenseDCStretchMode;
  2147. int result = 0;
  2148. char buffer1[ 50 ];
  2149. // char buffer2[ 50 ];
  2150. HDC hDC, memDC, buttonDC, licenseDC;
  2151. BITMAP bm, fm, lm;
  2152. // LOGPALETTE * plgpl = NULL;
  2153. PAINTSTRUCT ps;
  2154. static int bits_pixel = 0;
  2155. static int idCtl = 0;
  2156. static int mouse_x, mouse_y;
  2157. static char szBitmap[_MAX_PATH];
  2158. static char szLicense[ _MAX_PATH ];
  2159. static char szButtonBitmap[_MAX_PATH];
  2160. static wchar_t szString1[ 500 ];
  2161. static wchar_t szString2[ 500 ];
  2162. static wchar_t szWholeString[ 1000 ];
  2163. // static wchar_t szWSMsg1[ _MAX_PATH ];
  2164. #ifdef LEAN_AND_MEAN
  2165. #else
  2166. static UnicodeString wsMsg1;
  2167. #endif
  2168. static wchar_t szWSMsg2[ _MAX_PATH ];
  2169. static wchar_t szWholeWSMsg[ 1000 ];
  2170. // static wchar_t szInstallWarningMsg[ _MAX_PATH ];
  2171. static HBITMAP hBitmap = 0;
  2172. static HBITMAP oldBitmap = 0;
  2173. // static HBITMAP oldButtonBitmap = 0;
  2174. static HBITMAP oldLicenseBitmap = 0;
  2175. static HBITMAP hButtonBitmap = 0;
  2176. static HBITMAP hFlicker[NUM_FLICKER_FRAMES];
  2177. static HBITMAP hLicenseBitmap;
  2178. static POINT point;
  2179. static HBRUSH hStaticBrush = 0;
  2180. static HPALETTE hpal = 0;
  2181. static HPALETTE hpalold = 0;
  2182. static BOOL FirstTime = TRUE;
  2183. // static BOOL Flicker = TRUE;
  2184. static BOOL Flicker = FALSE;
  2185. static int FlickerIndex = 0;
  2186. static BOOL PaintOnlyFlicker = TRUE;
  2187. static BOOL PaintBackground = TRUE;
  2188. static UINT timer_id = 0;
  2189. static RECT rect; // Desktop Window ( used once ).
  2190. static RECT tray_rect; // Desktop Window w/o Tray size.
  2191. static RECT paint_rect; // Size that needs to be repainted.
  2192. static RECT dlg_rect; // Dialog client window size.
  2193. static RECT bitmap_rect; // Background bitmap size.
  2194. static RECT flicker_rect; // Flicker bitmap size.
  2195. static RECT buttons_rect; // Area where buttons are.
  2196. static RECT license_rect; // Area where buttons are.
  2197. static RECT BackgroundRect[ ( NUM_BUTTONS * 3 ) + 3 ]; // Background areas outside button area.
  2198. #if(USE_MOUSE_MOVES)
  2199. static int CurrentButton = 0;
  2200. static int LastButton = 0;
  2201. static int PrevButton = 0;
  2202. #endif
  2203. #if(0)
  2204. {
  2205. //-------------------------------------------------------------------------------
  2206. // Used for debugging -- lining up objects using the mouse coordinates.
  2207. //-------------------------------------------------------------------------------
  2208. int i = 0;
  2209. HDC hdc = GetDC( window_handle );
  2210. char string[10];
  2211. POINT pPoint;
  2212. GetCursorPos( &pPoint );
  2213. ScreenToClient( window_handle, &pPoint );
  2214. sprintf( string, "%d, %d", pPoint.x, pPoint.y );
  2215. TextOut( hdc, 10, 50, string, 8 );
  2216. ReleaseDC( window_handle, hdc );
  2217. }
  2218. #endif
  2219. //-----------------------------------------------------------------------------------
  2220. // Process Dialogs messages.
  2221. //-----------------------------------------------------------------------------------
  2222. switch( message ) {
  2223. case WM_INITDIALOG:
  2224. {
  2225. //-----------------------------------------------------------------------
  2226. // Set dialog's caption.
  2227. //-----------------------------------------------------------------------
  2228. #ifdef LEAN_AND_MEAN
  2229. Locale_GetString( "Autorun:Title", szWideBuffer );
  2230. memset( szWideBuffer2, '\0', _MAX_PATH );
  2231. swprintf( szWideBuffer2, szWideBuffer, szProductName );
  2232. swprintf( szWideBuffer2, szWideBuffer, szFullProductName );
  2233. #else
  2234. wideBuffer = TheGameText->fetch("Autorun:Title");
  2235. wideBuffer2.format(wideBuffer, fullProductName.str());
  2236. WideCharToMultiByte( CodePage, 0, wideBuffer2.str(), wideBuffer2.getLength()+1, szBuffer, _MAX_PATH, NULL, NULL );
  2237. #endif
  2238. SetWindowText( window_handle, szBuffer );
  2239. //-----------------------------------------------------------------------
  2240. // Set Icon.
  2241. //-----------------------------------------------------------------------
  2242. SendMessage( window_handle, WM_SETICON, ICON_SMALL, (long)LoadIcon( Main::hInstance, MAKEINTRESOURCE(1)));
  2243. #if(BACKGROUND_BITMAP)
  2244. //-----------------------------------------------------------------------
  2245. // Get the DeskTop's size and this dialogs size (in pixels).
  2246. //-----------------------------------------------------------------------
  2247. GetClientRect( GetDesktopWindow(), &rect );
  2248. SystemParametersInfo( SPI_GETWORKAREA, 0, &tray_rect, 0 );
  2249. /// if( rect.right <= 640 ) {
  2250. // b640X480 = TRUE;
  2251. // } else if( rect.right <= 800 ) {
  2252. b800X600 = TRUE;
  2253. // }
  2254. //=======================================================================
  2255. // Create Fonts.
  2256. //=======================================================================
  2257. HDC hdc = GetDC( window_handle );
  2258. FontManager = new FontManagerClass( hdc );
  2259. assert( FontManager != NULL );
  2260. ReleaseDC( window_handle, hdc );
  2261. //=======================================================================
  2262. // Load messages for bottom of screen.
  2263. //=======================================================================
  2264. // memset( szString1, '\0', MAX_PATH );
  2265. // memset( szString2, '\0', MAX_PATH );
  2266. // memset( szWholeString, '\0', 1000 );
  2267. // Locale_GetString( EA_LICENSE_MSG1, szString1 );
  2268. // Locale_GetString( EA_LICENSE_MSG2, szString2 );
  2269. // swprintf( szWholeString, L"%s %s", szString1, szString2 );
  2270. // memset( szWSMsg1, '\0', _MAX_PATH );
  2271. memset( szWSMsg2, '\0', _MAX_PATH );
  2272. memset( szWholeWSMsg, '\0', 1000 );
  2273. // Locale_GetString( WESTWOOD_COM_MSG, szWSMsg1 );
  2274. // wsMsg1 = TheGameText->fetch("Autorun:WestwoodComMsg");
  2275. // PlugInProductName( szWSMsg1, (wchar_t *)(fullProductName.str()) );
  2276. // PlugInProductName( (wchar_t *)(wsMsg1.str()), (wchar_t *)(fullProductName.str()) );
  2277. // wsMsg1 = Fix_Single_Ampersands ( wsMsg1, false );
  2278. // swprintf( szWholeWSMsg, L"%s", wsMsg1.str() );
  2279. // memset( szInstallWarningMsg, '\0', _MAX_PATH );
  2280. // Locale_GetString( IDS_INSTALL_WARNING_MSG, szWideBuffer );
  2281. // wideBuffer = TheGameText->fetch("Autorun:InstallWarningMsg");
  2282. // swprintf( szInstallWarningMsg, wideBuffer.str(), fullProductName.str() );
  2283. //=======================================================================
  2284. // Load the correct background & animation bitmap.
  2285. //=======================================================================
  2286. memset( buffer1, '\0', sizeof( buffer1 ));
  2287. if( b640X480 ) {
  2288. strcpy( szBitmap, _TEXT( "Background2" ));
  2289. if ( LANG_FRE == LanguageID ) {
  2290. strcpy( szLicense, _TEXT( "License_FRENCH2" ));
  2291. } else if ( LANG_GER == LanguageID ) {
  2292. strcpy( szLicense, _TEXT( "License_GERMAN2" ));
  2293. } else {
  2294. strcpy( szLicense, _TEXT( "License_USA2" ));
  2295. }
  2296. license_rect.left = 186;
  2297. license_rect.top = 414;
  2298. } else if( b800X600 ) {
  2299. strcpy( szBitmap, _TEXT( "Background" ));
  2300. if ( LANG_FRE == LanguageID ) {
  2301. strcpy( szLicense, _TEXT( "License_FRENCH2" ));
  2302. } else if ( LANG_GER == LanguageID ) {
  2303. strcpy( szLicense, _TEXT( "License_GERMAN2" ));
  2304. } else {
  2305. strcpy( szLicense, _TEXT( "License_USA2" ));
  2306. }
  2307. license_rect.left = 186;
  2308. license_rect.top = 414;
  2309. } else {
  2310. strcpy( szBitmap, _TEXT( "Background" ));
  2311. strcpy( buffer1, "FLICKER" );
  2312. if ( LANG_FRE == LanguageID ) {
  2313. strcpy( szLicense, _TEXT( "License_FRENCH" ));
  2314. } else if ( LANG_GER == LanguageID ) {
  2315. strcpy( szLicense, _TEXT( "License_GERMAN" ));
  2316. } else {
  2317. strcpy( szLicense, _TEXT( "License_USA" ));
  2318. }
  2319. license_rect.left = 238;
  2320. license_rect.top = 580;
  2321. }
  2322. //=======================================================================
  2323. // Load flicker bitmap.
  2324. //=======================================================================
  2325. for( i = 0; i < NUM_FLICKER_FRAMES; i++ ) {
  2326. hFlicker[i] = 0;
  2327. // sprintf( buffer2, "%s%02d", buffer1, i );
  2328. // hFlicker[i] = LoadResourceBitmap( Main::hModule, buffer2, &hpal );
  2329. hFlicker[i] = LoadResourceBitmap( Main::hModule, buffer1, &hpal );
  2330. }
  2331. //-----------------------------------------------------------------------
  2332. // Get the flicker bitmap's dimensions.
  2333. //-----------------------------------------------------------------------
  2334. result = 712;
  2335. for( i = 0; i < NUM_FLICKER_POSITIONS; i++ ) {
  2336. if( i == 8 ) {
  2337. FlickerPositions[i][0] = result - 33;
  2338. } else if( i == 9 ) {
  2339. FlickerPositions[i][0] = result - 35;
  2340. } else if ( i > 8 ) {
  2341. FlickerPositions[i][0] = result - 28;
  2342. } else {
  2343. FlickerPositions[i][0] = result - 31;
  2344. }
  2345. FlickerPositions[i][1] = 560;
  2346. result = FlickerPositions[i][0];
  2347. }
  2348. if ( hFlicker[0] ) {
  2349. GetObject( hFlicker[0], sizeof( BITMAP ), (LPTSTR)&fm );
  2350. flicker_rect.left = FlickerPositions[0][0];
  2351. flicker_rect.top = FlickerPositions[0][1];
  2352. flicker_rect.right = flicker_rect.left + fm.bmWidth;
  2353. flicker_rect.bottom = flicker_rect.top + fm.bmHeight;
  2354. }
  2355. //-----------------------------------------------------------------------
  2356. // Get the bitmap's dimensions.
  2357. //-----------------------------------------------------------------------
  2358. hLicenseBitmap = LoadResourceBitmap( Main::hModule, szLicense, &hpal );
  2359. if ( hLicenseBitmap ) {
  2360. GetObject( hLicenseBitmap, sizeof( BITMAP ), (LPTSTR)&lm );
  2361. license_rect.right = license_rect.left + lm.bmWidth;
  2362. license_rect.bottom = license_rect.top + lm.bmHeight;
  2363. }
  2364. //=======================================================================
  2365. // Load background bitmap.
  2366. //=======================================================================
  2367. hBitmap = LoadResourceBitmap( Main::hModule, szBitmap, &hpal );
  2368. if ( hBitmap ) {
  2369. GetObject( hBitmap, sizeof( BITMAP ), (LPTSTR)&bm );
  2370. }
  2371. //-----------------------------------------------------------------------
  2372. // Set the x, y, width, height of the Dialog and bitmaps dimensions.
  2373. //-----------------------------------------------------------------------
  2374. bitmap_rect.left = dlg_rect.left = 0;
  2375. bitmap_rect.top = dlg_rect.top = 0;
  2376. bitmap_rect.right = dlg_rect.right = bm.bmWidth;
  2377. bitmap_rect.bottom = dlg_rect.bottom = bm.bmHeight;
  2378. //-----------------------------------------------------------------------
  2379. // Set the x, y, width, height of the Dialog and bitmaps dimensions.
  2380. //-----------------------------------------------------------------------
  2381. dlg_rect.left = 0;
  2382. dlg_rect.top = 0;
  2383. if( b640X480 ) {
  2384. dlg_rect.right = rect.right;
  2385. dlg_rect.bottom = tray_rect.bottom; // desktop smaller than image
  2386. } else if( b800X600 ) {
  2387. if(true){
  2388. dlg_rect.right = bm.bmWidth + 6;
  2389. dlg_rect.bottom = bm.bmHeight + GetSystemMetrics( SM_CYCAPTION ) + 6; // desktop larger than image
  2390. } else {
  2391. dlg_rect.right = 640;//bm.bmWidth + 6;
  2392. dlg_rect.bottom = 480; //bm.bmHeight + GetSystemMetrics( SM_CYCAPTION ) + 6; // desktop larger than image
  2393. }
  2394. } else {
  2395. dlg_rect.right = bm.bmWidth + 6;
  2396. dlg_rect.bottom = bm.bmHeight + GetSystemMetrics( SM_CYCAPTION ) + 6; // desktop larger than image
  2397. }
  2398. //=======================================================================
  2399. // Recreate Buttons based on Registry.
  2400. //=======================================================================
  2401. GlobalMainWindow->Create_Buttons( window_handle, &dlg_rect );
  2402. //=======================================================================
  2403. // Set Main Rectangle Areas around all the Buttons.
  2404. //=======================================================================
  2405. //-----------------------------------------------------------------------
  2406. // Who is the first button?
  2407. //-----------------------------------------------------------------------
  2408. i = 0;
  2409. while ( i < NUM_BUTTONS ) {
  2410. if ( ButtonList[i] == NULL ) {
  2411. i++;
  2412. } else {
  2413. break;
  2414. }
  2415. }
  2416. if( i >= NUM_BUTTONS || i < 0 ) {
  2417. i = 0;
  2418. }
  2419. Msg( __LINE__, TEXT(__FILE__), TEXT("----------------------------- determining button area ---------------------------" ));
  2420. buttons_rect.left = ButtonSizes[i].left;
  2421. buttons_rect.top = ButtonSizes[i].top;
  2422. buttons_rect.right = ButtonSizes[i].left + ButtonSizes[i].right;
  2423. buttons_rect.bottom = ButtonSizes[i].top + ButtonSizes[i].bottom;
  2424. // Msg( __LINE__, TEXT(__FILE__), TEXT("buttons_rect = [%d,%d,%d,%d]"), buttons_rect.left, buttons_rect.top, buttons_rect.right, buttons_rect.bottom );
  2425. for( j = 0; j < NUM_BUTTONS; j++ ) {
  2426. if ( ButtonList[j] != NULL ) {
  2427. buttons_rect.left = __min( ButtonSizes[j].left , buttons_rect.left );
  2428. buttons_rect.top = __min( ButtonSizes[j].top , buttons_rect.top );
  2429. buttons_rect.right = __max( ButtonSizes[j].left + ButtonSizes[j].right , buttons_rect.right );
  2430. buttons_rect.bottom = __max( ButtonSizes[j].top + ButtonSizes[j].bottom , buttons_rect.bottom );
  2431. }
  2432. }
  2433. Msg( __LINE__, TEXT(__FILE__), TEXT("buttons_rect = [%d,%d,%d,%d]"), buttons_rect.left, buttons_rect.top, buttons_rect.right, buttons_rect.bottom );
  2434. Msg( __LINE__, TEXT(__FILE__), TEXT("----------------------------- determining button area ---------------------------" ));
  2435. //=======================================================================
  2436. // Center the dialog on the desktop.
  2437. //=======================================================================
  2438. if ( !b640X480 ) {
  2439. MoveWindow( window_handle,
  2440. ( rect.right - dlg_rect.right )/2,
  2441. ( rect.bottom - dlg_rect.bottom )/2,
  2442. dlg_rect.right,
  2443. dlg_rect.bottom, TRUE );
  2444. } else {
  2445. MoveWindow( window_handle,
  2446. 0, 0,
  2447. dlg_rect.right,
  2448. dlg_rect.bottom, TRUE );
  2449. }
  2450. //-----------------------------------------------------------------------
  2451. // Get the new Client area.
  2452. //-----------------------------------------------------------------------
  2453. GetClientRect( window_handle, &dlg_rect );
  2454. //=======================================================================
  2455. // These are the areas of the Background to paint minus the Button Area.
  2456. // This will prevent "flickering".
  2457. //=======================================================================
  2458. BackgroundRect[0].left = dlg_rect.left;
  2459. BackgroundRect[0].top = dlg_rect.top;
  2460. BackgroundRect[0].right = dlg_rect.right;
  2461. BackgroundRect[0].bottom = buttons_rect.top;
  2462. BackgroundRect[1].left = dlg_rect.left;
  2463. BackgroundRect[1].top = buttons_rect.top;
  2464. BackgroundRect[1].right = buttons_rect.left;
  2465. BackgroundRect[1].bottom = dlg_rect.bottom;
  2466. BackgroundRect[2].left = buttons_rect.left;
  2467. BackgroundRect[2].top = buttons_rect.bottom;
  2468. BackgroundRect[2].right = buttons_rect.right;
  2469. BackgroundRect[2].bottom = dlg_rect.bottom;
  2470. BackgroundRect[3].left = buttons_rect.right;
  2471. BackgroundRect[3].top = buttons_rect.top;
  2472. BackgroundRect[3].right = dlg_rect.right;
  2473. BackgroundRect[3].bottom = dlg_rect.bottom;
  2474. //=======================================================================
  2475. // Find Areas that are in between, infront of, and behind each Buttons.
  2476. //=======================================================================
  2477. i = 0;
  2478. j = 4;
  2479. //-----------------------------------------------------------------------
  2480. // Who is the first button?
  2481. //-----------------------------------------------------------------------
  2482. while ( i < NUM_BUTTONS ) {
  2483. if ( ButtonList[i] == NULL ) {
  2484. i++;
  2485. } else {
  2486. break;
  2487. }
  2488. }
  2489. if( i >= NUM_BUTTONS || i < 0 ) {
  2490. i = 0;
  2491. }
  2492. //-----------------------------------------------------------------------
  2493. // For each button...
  2494. //-----------------------------------------------------------------------
  2495. for( int index = i; index < NUM_BUTTONS; index++ ) {
  2496. //-------------------------------------------------------------------
  2497. // Make areas between the buttons.
  2498. //-------------------------------------------------------------------
  2499. if ( ButtonList[index] != NULL && ButtonList[index+1] != NULL ) {
  2500. // Area between buttons.
  2501. BackgroundRect[j].top = ButtonList[index]->Return_Y_Pos() + ButtonList[index]->Return_Height();
  2502. BackgroundRect[j].bottom = ButtonList[index+1]->Return_Y_Pos() - BackgroundRect[j].top;
  2503. BackgroundRect[j].left = BackgroundRect[1].right;
  2504. BackgroundRect[j].right = BackgroundRect[3].left - BackgroundRect[1].left - 1;
  2505. j++;
  2506. }
  2507. //-------------------------------------------------------------------
  2508. // Now look for areas in front of and behind each button.
  2509. //-------------------------------------------------------------------
  2510. if ( ButtonList[index] != NULL ) {
  2511. // Area in front of buttons.
  2512. BackgroundRect[j].top = ButtonList[index]->Return_Y_Pos();
  2513. BackgroundRect[j].bottom = ButtonList[index]->Return_Height();
  2514. BackgroundRect[j].left = BackgroundRect[1].right;
  2515. BackgroundRect[j].right = ButtonList[index]->Return_X_Pos() - BackgroundRect[1].right;
  2516. j++;
  2517. // Area behind buttons.
  2518. BackgroundRect[j].top = ButtonList[index]->Return_Y_Pos();
  2519. BackgroundRect[j].bottom = ButtonList[index]->Return_Height();
  2520. BackgroundRect[j].left = ButtonList[index]->Return_X_Pos() + ButtonList[index]->Return_Width();
  2521. BackgroundRect[j].right = BackgroundRect[3].left - ( ButtonList[index]->Return_X_Pos() + ButtonList[index]->Return_Width());
  2522. j++;
  2523. }
  2524. }
  2525. #if(_DEBUG)
  2526. Msg( __LINE__, TEXT(__FILE__), TEXT("----------------------------- WM_INITDIALOG ---------------------------" ));
  2527. Msg( __LINE__, TEXT(__FILE__), TEXT("DeskTopWindowRect(w/o tray) = [%d,%d,%d,%d]"), tray_rect.left, tray_rect.top, tray_rect.right, tray_rect.bottom );
  2528. Msg( __LINE__, TEXT(__FILE__), TEXT("DeskTopWindowRect = [%d,%d,%d,%d]"), rect.left, rect.top, rect.right, rect.bottom );
  2529. Msg( __LINE__, TEXT(__FILE__), TEXT("b640X480 = [%d]"), b640X480 );
  2530. Msg( __LINE__, TEXT(__FILE__), TEXT("b800X600 = [%d]"), b800X600 );
  2531. Msg( __LINE__, TEXT(__FILE__), TEXT("ClientRect = [%d,%d,%d,%d]"), dlg_rect.left, dlg_rect.top, dlg_rect.right, dlg_rect.bottom );
  2532. for( index = 0; index < ( NUM_BUTTONS * 3 ) + 3; index++ ) {
  2533. Msg( __LINE__, TEXT(__FILE__), TEXT("BackgroundRect[%d] = [%d,%d,%d,%d]"), index, BackgroundRect[index].top, BackgroundRect[index].bottom, BackgroundRect[index].left, BackgroundRect[index].right );
  2534. }
  2535. Msg( __LINE__, TEXT(__FILE__), TEXT("BitmapRect = [%d,%d,%d,%d]"), bitmap_rect.left, bitmap_rect.top, bitmap_rect.right, bitmap_rect.bottom );
  2536. Msg( __LINE__, TEXT(__FILE__), TEXT("FlickerRect = [%d,%d,%d,%d]"), flicker_rect.left, flicker_rect.top, flicker_rect.right, flicker_rect.bottom );
  2537. Msg( __LINE__, TEXT(__FILE__), TEXT("ButtonsRect = [%d,%d,%d,%d]"), buttons_rect.left, buttons_rect.top, buttons_rect.right, buttons_rect.bottom );
  2538. Msg( __LINE__, TEXT(__FILE__), TEXT("-----------------------------------------------------------------------" ));
  2539. #endif
  2540. #else
  2541. //-----------------------------------------------------------------------
  2542. // Create Brush.
  2543. //-----------------------------------------------------------------------
  2544. hStaticBrush = CreateSolidBrush( RGB( 192, 192, 192 ));
  2545. #endif
  2546. //=======================================================================
  2547. // Set dialog's timer! 1000 = 1 second.
  2548. //=======================================================================
  2549. // timer_id = SetTimer( window_handle, 1000, 250L, NULL );
  2550. timer_id = SetTimer( window_handle, 1000, 500L, NULL );
  2551. }
  2552. return( TRUE );
  2553. //-------------------------------------------------------------------------------
  2554. // Try and set a custom cursor.
  2555. //-------------------------------------------------------------------------------
  2556. // case WM_SETCURSOR:
  2557. // SetCursor(LoadCursor( Main::hInstance, MAKEINTRESOURCE(2)));
  2558. // break;
  2559. //-------------------------------------------------------------------------------
  2560. // Tell Window to Select Palette if we are not the Focused Window.
  2561. // This is to avoid getting stuck in a loop of receiving this msg
  2562. // when we are focused.
  2563. //-------------------------------------------------------------------------------
  2564. case WM_PALETTECHANGED:
  2565. if (( HWND )w_param != window_handle ) {
  2566. SendMessage( window_handle, WM_QUERYNEWPALETTE, w_param, l_param );
  2567. }
  2568. break;
  2569. //-------------------------------------------------------------------------------
  2570. // Set and Realize our palette, then repaint if necessary.
  2571. // Note that SelectPalette here is passed a FALSE.
  2572. // This means reset palette as if we are in the foreground.
  2573. //-------------------------------------------------------------------------------
  2574. case WM_QUERYNEWPALETTE:
  2575. hDC = GetDC( window_handle );
  2576. hpalold = SelectPalette( hDC, hpal, FALSE );
  2577. i = RealizePalette( hDC );
  2578. if ( i != 0 ) {
  2579. InvalidateRect( window_handle, &dlg_rect, TRUE );
  2580. }
  2581. SelectPalette( hDC, hpalold, TRUE );
  2582. RealizePalette( hDC );
  2583. ReleaseDC( window_handle, hDC );
  2584. return i;
  2585. //-------------------------------------------------------------------------------
  2586. // Process Timer Messages.
  2587. //-------------------------------------------------------------------------------
  2588. case WM_TIMER:
  2589. {
  2590. if ( w_param == 1000 ) {
  2591. // if ( Flicker && hFlicker[FlickerIndex] ) {
  2592. if ( Flicker && hFlicker[0] ) {
  2593. FlickerIndex++;
  2594. // if ( FlickerIndex >= NUM_FLICKER_FRAMES ) {
  2595. if ( FlickerIndex >= NUM_FLICKER_POSITIONS ) {
  2596. FlickerIndex = 0;
  2597. }
  2598. InvalidateRect( window_handle, &flicker_rect, FALSE );
  2599. flicker_rect.left = FlickerPositions[ FlickerIndex ][0];
  2600. InvalidateRect( window_handle, &flicker_rect, FALSE );
  2601. UpdateWindow( window_handle );
  2602. Msg( __LINE__, TEXT(__FILE__), TEXT("WM_TIMER: FlickerRect = [%d,%d,%d,%d]"), flicker_rect.left, flicker_rect.right, flicker_rect.top, flicker_rect.bottom );
  2603. }
  2604. }
  2605. //-----------------------------------------------------------------------
  2606. // If game is running, the mutex will return! Time to exit...
  2607. // Note: This number is unique for Tiberian Sun ONLY!!!
  2608. //-----------------------------------------------------------------------
  2609. if( WinVersion.Is_Win_XP() || WinVersion.Version() > 500 ) {
  2610. strcat( strcpy( szBuffer, "Global\\" ), GAME_MUTEX_OBJECT );
  2611. } else {
  2612. strcpy( szBuffer, GAME_MUTEX_OBJECT );
  2613. }
  2614. GameAppMutex = OpenMutex( MUTEX_ALL_ACCESS, FALSE, szBuffer );
  2615. if ( GameAppMutex != NULL ) {
  2616. //---------------------------------------------------------
  2617. // Handle(s) are closed in the ProgEnd().
  2618. //---------------------------------------------------------
  2619. HWND ccwindow = FindWindow( szGameWindow, NULL );
  2620. if ( ccwindow ) {
  2621. if( IsIconic( ccwindow )){
  2622. ShowWindow( ccwindow, SW_RESTORE );
  2623. }
  2624. SetForegroundWindow( ccwindow );
  2625. } else {
  2626. ccwindow = FindWindow( szSetupWindow, NULL );
  2627. if ( ccwindow ) {
  2628. if( IsIconic( ccwindow )){
  2629. ShowWindow( ccwindow, SW_RESTORE );
  2630. }
  2631. SetForegroundWindow( ccwindow );
  2632. }
  2633. }
  2634. PostMessage( window_handle, WM_COMMAND, (WPARAM)MAKELONG( IDD_CANCEL, BN_CLICKED ), (LPARAM)GetDlgItem( window_handle, IDD_CANCEL ));
  2635. }
  2636. }
  2637. return ( 0 );
  2638. //===============================================================================
  2639. // Dialog's main paint routine.
  2640. //===============================================================================
  2641. case WM_PAINT:
  2642. //---------------------------------------------------------------------------
  2643. // If there is an area to update, repaint it.
  2644. //---------------------------------------------------------------------------
  2645. if ( GetUpdateRect( window_handle, &paint_rect, FALSE )) {
  2646. // Msg( __LINE__, TEXT(__FILE__), TEXT("---------------------- WM_PAINT ---------------------"), i );
  2647. // Msg( __LINE__, TEXT(__FILE__), TEXT("Rectangle to update = [%d,%d,%d,%d]"), paint_rect.left, paint_rect.top, paint_rect.right, paint_rect.bottom );
  2648. //-----------------------------------------------------------------------
  2649. // Get dialog's hDC.
  2650. //-----------------------------------------------------------------------
  2651. hDC = BeginPaint( window_handle, &ps );
  2652. #if( BACKGROUND_BITMAP )
  2653. if ( hBitmap ) {
  2654. //---------------------------------------------------------------
  2655. // Create a compatible DC for the bitmap.
  2656. //---------------------------------------------------------------
  2657. memDC = CreateCompatibleDC( hDC );
  2658. buttonDC = CreateCompatibleDC( hDC );
  2659. licenseDC = CreateCompatibleDC( hDC );
  2660. //---------------------------------------------------------------
  2661. // Set stretching mode for bitmaps.
  2662. //---------------------------------------------------------------
  2663. prevDCStretchMode = SetStretchBltMode( hDC, STRETCH_DELETESCANS );
  2664. prevMemDCStretchMode = SetStretchBltMode( memDC, STRETCH_DELETESCANS );
  2665. prevButtonDCStretchMode = SetStretchBltMode( buttonDC,STRETCH_DELETESCANS );
  2666. prevLicenseDCStretchMode = SetStretchBltMode( licenseDC,STRETCH_DELETESCANS );
  2667. //---------------------------------------------------------------
  2668. // Set the palette in each DC.
  2669. //---------------------------------------------------------------
  2670. hpalold = SelectPalette( hDC, hpal, FALSE );
  2671. RealizePalette( hDC );
  2672. SelectPalette( memDC, hpal, FALSE );
  2673. RealizePalette( memDC );
  2674. SelectPalette( buttonDC, hpal, FALSE );
  2675. RealizePalette( buttonDC );
  2676. SelectPalette( licenseDC, hpal, FALSE );
  2677. RealizePalette( licenseDC );
  2678. //---------------------------------------------------------------
  2679. // If area to update is a button area, this will be drawn farther
  2680. // on. This is to prevent "flickering" by drawing the background
  2681. // then the button image.
  2682. //---------------------------------------------------------------
  2683. for ( i = 0; i < NUM_BUTTONS; i++ ) {
  2684. if ( ButtonList[i] ) {
  2685. ButtonList[i]->Return_Area( &rect );
  2686. if ( paint_rect.left == rect.left &&
  2687. paint_rect.top == rect.top &&
  2688. paint_rect.right == rect.right &&
  2689. paint_rect.bottom == rect.bottom ) {
  2690. PaintBackground = FALSE;
  2691. // Msg( __LINE__, TEXT(__FILE__), TEXT("Rectangle matches a button to update = [%d,%d,%d,%d]"), rect.left, rect.top, rect.right, rect.bottom );
  2692. break;
  2693. }
  2694. }
  2695. }
  2696. //===============================================================
  2697. // Paint the background.
  2698. //===============================================================
  2699. if ( PaintBackground ) {
  2700. //-----------------------------------------------------------
  2701. // Select & Draw the background bitmap.
  2702. //-----------------------------------------------------------
  2703. oldBitmap = ( HBITMAP )SelectObject( memDC, hBitmap );
  2704. //-----------------------------------------------------------
  2705. // Updates area around the button area.
  2706. //-----------------------------------------------------------
  2707. #if(1)
  2708. for( int i=0; i < ( NUM_BUTTONS * 3 ) + 3; i++ ) {
  2709. if( BackgroundRect[i].left != 0 || BackgroundRect[i].top != 0 ||
  2710. BackgroundRect[i].right != 0 || BackgroundRect[i].bottom != 0 ) {
  2711. result = StretchBlt( hDC,
  2712. BackgroundRect[i].left,
  2713. BackgroundRect[i].top,
  2714. BackgroundRect[i].right,
  2715. BackgroundRect[i].bottom,
  2716. memDC,
  2717. BackgroundRect[i].left,
  2718. BackgroundRect[i].top,
  2719. BackgroundRect[i].right,
  2720. BackgroundRect[i].bottom,
  2721. SRCCOPY );
  2722. if( result != 0 ) {
  2723. // Msg( __LINE__, TEXT(__FILE__), TEXT("Paint this rect = [%d,%d,%d,%d]"), BackgroundRect[i].left, BackgroundRect[i].top, BackgroundRect[i].right, BackgroundRect[i].bottom );
  2724. }
  2725. #if(0)
  2726. HPEN pen = CreatePen( /*PS_DOT*/ PS_SOLID, 1, TEXT_COLOR );
  2727. HGDIOBJ oldpen = SelectObject( hDC, pen );
  2728. SetBkMode( hDC, TRANSPARENT );
  2729. MoveToEx( hDC, BackgroundRect[i].left+1, BackgroundRect[i].top+1, NULL );
  2730. LineTo( hDC, BackgroundRect[i].right-1, BackgroundRect[i].top+1 );
  2731. LineTo( hDC, BackgroundRect[i].right-1, BackgroundRect[i].bottom-1 );
  2732. LineTo( hDC, BackgroundRect[i].left+1, BackgroundRect[i].bottom-1 );
  2733. LineTo( hDC, BackgroundRect[i].left+1, BackgroundRect[i].top+1 );
  2734. SelectObject( hDC, oldpen );
  2735. DeleteObject( pen );
  2736. #endif
  2737. }
  2738. }
  2739. /*
  2740. //-----------------------------------------------------------
  2741. // Select & Draw the background bitmap.
  2742. //-----------------------------------------------------------
  2743. oldLicenseBitmap = ( HBITMAP )SelectObject( licenseDC, hLicenseBitmap );
  2744. //-----------------------------------------------------------
  2745. // Updates area around the button area.
  2746. //-----------------------------------------------------------
  2747. result = StretchBlt( hDC,
  2748. license_rect.left,
  2749. license_rect.top,
  2750. license_rect.right,
  2751. license_rect.bottom,
  2752. licenseDC,
  2753. 0,
  2754. 0,
  2755. license_rect.right,
  2756. license_rect.bottom,
  2757. SRCCOPY );
  2758. */
  2759. #else
  2760. //-----------------------------------------------------------
  2761. // Blit whole background, in one shot.
  2762. //-----------------------------------------------------------
  2763. StretchBlt( hDC, dlg_rect.left, dlg_rect.top, dlg_rect.right, dlg_rect.bottom,
  2764. memDC, bitmap_rect.left, bitmap_rect.top, bitmap_rect.right, bitmap_rect.bottom,
  2765. SRCCOPY );
  2766. #endif
  2767. SelectObject( memDC, oldBitmap );
  2768. SelectObject( licenseDC, oldLicenseBitmap );
  2769. } else {
  2770. PaintBackground = TRUE;
  2771. }
  2772. //---------------------------------------------------------------
  2773. // Animation.
  2774. //---------------------------------------------------------------
  2775. // if ( Flicker && hFlicker[FlickerIndex] ) {
  2776. if ( Flicker && hFlicker[0] ) {
  2777. // oldBitmap = ( HBITMAP )SelectObject( memDC, hFlicker[FlickerIndex] );
  2778. oldBitmap = ( HBITMAP )SelectObject( memDC, hFlicker[0] );
  2779. StretchBlt(
  2780. hDC,
  2781. flicker_rect.left,
  2782. flicker_rect.top,
  2783. flicker_rect.right,
  2784. flicker_rect.bottom,
  2785. memDC,
  2786. 0,
  2787. 0,
  2788. flicker_rect.right,
  2789. flicker_rect.bottom,
  2790. SRCCOPY );
  2791. #if(0)
  2792. HPEN pen = CreatePen( /*PS_DOT*/ PS_SOLID, 1, TEXT_COLOR );
  2793. HGDIOBJ oldpen = SelectObject( hDC, pen );
  2794. SetBkMode( hDC, TRANSPARENT );
  2795. MoveToEx( hDC, flicker_rect.left+1, flicker_rect.top+1, NULL );
  2796. LineTo( hDC, flicker_rect.right-1, flicker_rect.top+1 );
  2797. LineTo( hDC, flicker_rect.right-1, flicker_rect.bottom-1 );
  2798. LineTo( hDC, flicker_rect.left+1, flicker_rect.bottom-1 );
  2799. LineTo( hDC, flicker_rect.left+1, flicker_rect.top+1 );
  2800. SelectObject( hDC, oldpen );
  2801. DeleteObject( pen );
  2802. #endif
  2803. SelectObject( memDC, oldBitmap );
  2804. // Msg( __LINE__, TEXT(__FILE__), TEXT(" Drawing Flicker [%d,%d,%d,%d]."), flicker_rect.left, flicker_rect.top, flicker_rect.right, flicker_rect.bottom );
  2805. }
  2806. //---------------------------------------------------------------
  2807. // Draw each button.
  2808. //---------------------------------------------------------------
  2809. for ( i = 0; i < NUM_BUTTONS; i++ ) {
  2810. if ( ButtonList[i] ) {
  2811. Rect rect;
  2812. //-------------------------------------------------------
  2813. // Uses Bitmaps or DrawText???
  2814. //-------------------------------------------------------
  2815. if ( ButtonList[i]->Draw_Bitmaps()) {
  2816. RECT src_rect, dst_rect;
  2817. strcpy( szButtonBitmap, ButtonList[i]->Return_Bitmap( ));
  2818. hButtonBitmap = LoadResourceBitmap( Main::hInstance, szButtonBitmap, &hpal, TRUE );
  2819. if ( hButtonBitmap ) {
  2820. GetObject( hButtonBitmap, sizeof( BITMAP ), (LPTSTR)&bm );
  2821. dst_rect.left = ButtonList[i]->Return_X_Pos();
  2822. dst_rect.top = ButtonList[i]->Return_Y_Pos();
  2823. dst_rect.right = ButtonList[i]->Return_Stretched_Width();
  2824. dst_rect.bottom = ButtonList[i]->Return_Stretched_Height();
  2825. src_rect.left = 0;
  2826. src_rect.top = 0;
  2827. src_rect.right = bm.bmWidth;
  2828. src_rect.bottom = bm.bmHeight;
  2829. //-----------------------------------------------
  2830. // Draw the button's bitmap background.
  2831. //-----------------------------------------------
  2832. oldBitmap = ( HBITMAP ) SelectObject( buttonDC, hButtonBitmap );
  2833. StretchBlt(
  2834. hDC,
  2835. dst_rect.left,
  2836. dst_rect.top,
  2837. dst_rect.right,
  2838. dst_rect.bottom,
  2839. buttonDC,
  2840. src_rect.left,
  2841. src_rect.top,
  2842. src_rect.right,
  2843. src_rect.bottom,
  2844. SRCCOPY );
  2845. SelectObject( buttonDC, oldBitmap );
  2846. DeleteObject( hButtonBitmap );
  2847. hButtonBitmap = 0;
  2848. }
  2849. } // END OF DRAW BITMAPS
  2850. #if(0)
  2851. TTFontClass *fontptr = ButtonList[i]->Return_Font_Ptr();
  2852. if ( fontptr ) {
  2853. RECT outline_rect;
  2854. ButtonList[i]->Return_Area( &outline_rect );
  2855. ButtonList[i]->Return_Text_Area( &rect );
  2856. /*
  2857. ** This function was combining the pixel color with the background,
  2858. ** so it never looked correct.
  2859. */
  2860. // SetTextColor( hDC, RGB( 0, 240, 0 ));
  2861. // DrawFocusRect( hDC, &dst_rect );
  2862. if ( ButtonList[i]->Get_State() == DrawButton::PRESSED_STATE ) {
  2863. fontptr->Print(
  2864. hDC,
  2865. ButtonList[i]->Return_Text(),
  2866. rect,
  2867. TEXT_PRESSED_COLOR,
  2868. TEXT_PRESSED_SHADOW_COLOR,
  2869. TPF_BUTTON,
  2870. TPF_SHADOW );
  2871. } else if ( ButtonList[i]->Get_State() == DrawButton::FOCUS_STATE ) {
  2872. fontptr->Print(
  2873. hDC,
  2874. ButtonList[i]->Return_Text(),
  2875. rect,
  2876. TEXT_FOCUSED_COLOR,
  2877. TEXT_FOCUSED_SHADOW_COLOR,
  2878. TPF_BUTTON,
  2879. TPF_SHADOW );
  2880. } else {
  2881. fontptr->Print(
  2882. hDC,
  2883. ButtonList[i]->Return_Text(),
  2884. rect,
  2885. TEXT_NORMAL_COLOR,
  2886. TEXT_NORMAL_SHADOW_COLOR,
  2887. TPF_BUTTON,
  2888. TPF_SHADOW );
  2889. }
  2890. #if(0)
  2891. HPEN pen = CreatePen( /*PS_DOT*/ PS_SOLID, 2, TEXT_COLOR );
  2892. HGDIOBJ oldpen = SelectObject( hDC, pen );
  2893. SetBkMode( hDC, TRANSPARENT );
  2894. MoveToEx( hDC, // handle to device context
  2895. outline_rect.left, // x-coordinate of new current position
  2896. outline_rect.top, // y-coordinate of new current position
  2897. NULL ); // pointer to old current position
  2898. LineTo( hDC, // device context handle
  2899. outline_rect.right, // x-coordinate of line's ending point
  2900. outline_rect.top ); // y-coordinate of line's ending point
  2901. LineTo( hDC, // device context handle
  2902. outline_rect.right, // x-coordinate of line's ending point
  2903. outline_rect.bottom ); // y-coordinate of line's ending point
  2904. LineTo( hDC, // device context handle
  2905. outline_rect.left, // x-coordinate of line's ending point
  2906. outline_rect.bottom ); // y-coordinate of line's ending point
  2907. LineTo( hDC, // device context handle
  2908. outline_rect.left, // x-coordinate of line's ending point
  2909. outline_rect.top ); // y-coordinate of line's ending point
  2910. SelectObject( hDC, oldpen );
  2911. DeleteObject( pen );
  2912. #endif
  2913. }
  2914. #else
  2915. ButtonList[i]->Draw_Text( hDC );
  2916. #endif
  2917. } // end of if button
  2918. } // For each button...
  2919. //---------------------------------------------------------------
  2920. // Used in debugging -- draw rect around where buttons are.
  2921. //---------------------------------------------------------------
  2922. #if(0)
  2923. {
  2924. HPEN hPen1 = CreatePen( PS_SOLID, 1, RGB( 255, 255, 255 ));
  2925. if (hPen1) {
  2926. for ( int i = 0; i < NUM_BUTTONS; i++ ) {
  2927. if ( ButtonList[i] ) {
  2928. HGDIOBJ oldpen = SelectObject( hDC, hPen1 );
  2929. MoveToEx( hDC,
  2930. ButtonList[i]->Return_X_Pos()-1,
  2931. ButtonList[i]->Return_Y_Pos()-1, NULL );
  2932. LineTo( hDC,
  2933. ButtonList[i]->Return_X_Pos() + ButtonList[i]->Return_Width() + 1,
  2934. ButtonList[i]->Return_Y_Pos()-1 );
  2935. LineTo( hDC,
  2936. ButtonList[i]->Return_X_Pos() + ButtonList[i]->Return_Width() + 1,
  2937. ButtonList[i]->Return_Y_Pos() + ButtonList[i]->Return_Height() + 1);
  2938. LineTo( hDC,
  2939. ButtonList[i]->Return_X_Pos()-1,
  2940. ButtonList[i]->Return_Y_Pos() + ButtonList[i]->Return_Height() + 1);
  2941. LineTo( hDC,
  2942. ButtonList[i]->Return_X_Pos() - 1,
  2943. ButtonList[i]->Return_Y_Pos() - 1);
  2944. SelectObject( hDC, oldpen );
  2945. }
  2946. }
  2947. }
  2948. DeleteObject( hPen1 );
  2949. }
  2950. #endif
  2951. //---------------------------------------------------------------
  2952. // Restore all default objects to DCs and delete.
  2953. //---------------------------------------------------------------
  2954. SetStretchBltMode( hDC, prevDCStretchMode );
  2955. SetStretchBltMode( memDC, prevMemDCStretchMode );
  2956. SetStretchBltMode( buttonDC, prevButtonDCStretchMode );
  2957. SetStretchBltMode( licenseDC, prevLicenseDCStretchMode );
  2958. SelectPalette( hDC, hpalold, FALSE );
  2959. SelectPalette( memDC, hpalold, FALSE );
  2960. SelectPalette( buttonDC, hpalold, FALSE );
  2961. SelectPalette( licenseDC, hpalold, FALSE );
  2962. DeleteDC( memDC );
  2963. DeleteDC( buttonDC );
  2964. DeleteDC( licenseDC );
  2965. } // end of bitmaps
  2966. //===================================================================
  2967. // Draw a solid colored background.
  2968. //===================================================================
  2969. // GetClientRect( window_handle, (LPRECT) &dlg_rect );
  2970. // FillRect( hDC, &dlg_rect, (HBRUSH)( COLOR_WINDOW + 1 ));
  2971. //===================================================================
  2972. // Print text at bottom of screen.
  2973. //===================================================================
  2974. Rect text_rect;
  2975. TTFontClass *fontptr = NULL;
  2976. if ( b640X480 ) {
  2977. fontptr = TTTextFontPtr640;
  2978. } else if ( b800X600 ) {
  2979. fontptr = TTTextFontPtr800;
  2980. } else {
  2981. fontptr = TTTextFontPtr;
  2982. }
  2983. if ( fontptr ) {
  2984. if ( b640X480 || b800X600 ) {
  2985. text_rect.X = 10;
  2986. text_rect.Y = 240;
  2987. text_rect.Width = 140; //498;
  2988. text_rect.Height = 100; //26;
  2989. } else {
  2990. text_rect.X = 20;
  2991. text_rect.Y = 340;
  2992. text_rect.Width = 180; //498;
  2993. text_rect.Height = 120; //26;
  2994. }
  2995. #if(0)
  2996. RECT one;
  2997. one.left = text_rect.X;
  2998. one.top = text_rect.Y;
  2999. one.right = text_rect.X + text_rect.Width;
  3000. one.bottom = text_rect.Y + text_rect.Height;
  3001. FrameRect( hDC, &one, (HBRUSH)( COLOR_WINDOW + 1 ));
  3002. // DrawFocusRect( hDC, &one );
  3003. #endif
  3004. //---------------------------------------------------------------
  3005. // WESTWOOD_COM Message at the top.
  3006. //---------------------------------------------------------------
  3007. /*
  3008. fontptr->Print(
  3009. hDC,
  3010. szWholeWSMsg,
  3011. text_rect,
  3012. TEXT_COLOR,
  3013. SHADOW_COLOR,
  3014. TPF_CENTER_TEXT,
  3015. TPF_SHADOW );
  3016. */
  3017. }
  3018. //---------------------------------------------------------------
  3019. // EA_COM Message at the bottom.
  3020. //---------------------------------------------------------------
  3021. #if(0) // Moved this text to a bitmap.
  3022. fontptr = TTLicenseFontPtr;
  3023. if( fontptr ) {
  3024. if ( b640X480 || b800X600 ) {
  3025. text_rect.X = 220;
  3026. text_rect.Y = 400;
  3027. text_rect.Width = 300; //460;
  3028. text_rect.Height = 48; //26;
  3029. } else {
  3030. text_rect.X = 250;
  3031. text_rect.Y = 574;
  3032. text_rect.Width = 420; //460;
  3033. text_rect.Height = 60; //26;
  3034. }
  3035. #if(0)
  3036. RECT one;
  3037. one.left = text_rect.X;
  3038. one.top = text_rect.Y;
  3039. one.right = text_rect.X + text_rect.Width;
  3040. one.bottom = text_rect.Y + text_rect.Height;
  3041. FrameRect( hDC, &one, (HBRUSH)( COLOR_WINDOW + 1 ));
  3042. // DrawFocusRect( hDC, &one );
  3043. #endif
  3044. fontptr->Print(
  3045. hDC,
  3046. szWholeString,
  3047. text_rect,
  3048. TEXT_COLOR,
  3049. SHADOW_COLOR,
  3050. TPF_CENTER_TEXT,
  3051. TPF_SHADOW );
  3052. }
  3053. #endif
  3054. #else
  3055. //-------------------------------------------------------------------
  3056. // Select the Brush if it was successfully created.
  3057. //-------------------------------------------------------------------
  3058. if ( hStaticBrush ) {
  3059. HBRUSH oldBrush = (HBRUSH) SelectObject( hDC, hStaticBrush );
  3060. GetClientRect( window_handle, (LPRECT) &dlg_rect );
  3061. FillRect( hDC, &dlg_rect, hStaticBrush );
  3062. SelectObject( hDC, oldBrush );
  3063. }
  3064. #endif
  3065. // Msg( __LINE__, TEXT(__FILE__), TEXT("--------------------------------------------------------" ));
  3066. EndPaint( window_handle, &ps );
  3067. //-----------------------------------------------------------------------
  3068. // Play DISK.WAV sound on CD.
  3069. //-----------------------------------------------------------------------
  3070. if ( FirstTime ) {
  3071. if( UseSounds ) {
  3072. PlaySound( szWavs[ SongNumber ], NULL, SND_ASYNC | SND_RESOURCE );
  3073. }
  3074. FirstTime = FALSE;
  3075. }
  3076. } /* end of if */
  3077. break;
  3078. //-------------------------------------------------------------------------------
  3079. // Background needs to be erased. Note we are returning 1 here to "fake"
  3080. // Windows into thinking we have already repainted the background with
  3081. // our window brush. This prevents "flickering" because of background
  3082. // being repainted ( ususally white ) before WM_PAINT is processed.
  3083. //-------------------------------------------------------------------------------
  3084. #if(BACKGROUND_BITMAP)
  3085. case WM_ERASEBKGND:
  3086. InvalidateRect( window_handle, &dlg_rect, FALSE );
  3087. return ( 1 );
  3088. #endif
  3089. //-------------------------------------------------------------------------------
  3090. // Check which button was pressed. If Explorer button was pressed,
  3091. // call it now so we don't have to exit dialog.
  3092. //-------------------------------------------------------------------------------
  3093. case WM_COMMAND:
  3094. {
  3095. idCtl = LOWORD( w_param );
  3096. unsigned int result = TRUE;
  3097. bool end_dialog = false;
  3098. int cd_drive;
  3099. szBuffer[1] = '\0';
  3100. szBuffer[0] = tolower( szArgvPath[0] );
  3101. // cd_drive = (int)( szBuffer[0] - 'a' + 1 );
  3102. cd_drive = (int)( szBuffer[0] - 'a' );
  3103. #if(BACKGROUND_BITMAP)
  3104. switch ( idCtl ) {
  3105. //-------------------------------------------------------------------
  3106. // IDD_MOHAVI
  3107. //-------------------------------------------------------------------
  3108. case IDD_PREVIEWS:
  3109. {
  3110. Msg( __LINE__, TEXT(__FILE__), TEXT("IDD_PREVIEWS Selected." ));
  3111. // show the previews in succession. each will wait for the previous to finish
  3112. // before playing.
  3113. unsigned int success;
  3114. char filepath[MAX_PATH];
  3115. _snprintf(filepath, MAX_PATH, "%s%s", szArgvPath, SC4AVI_FILENAME);
  3116. success = GlobalMainWindow->Run_OpenFile(cd_drive, filepath, true);
  3117. // if (success != 0) {
  3118. // success = GlobalMainWindow->Run_OpenFile(cd_drive, BFAVI_FILENAME, true);
  3119. // }
  3120. /*
  3121. if (success == 0) {
  3122. std::wstring wideBuffer = TheGameText->fetch("Autorun:CantRunAVIs");
  3123. std::wstring wideBuffer2 = TheGameText->fetch("Autorun:Error");
  3124. int length = wideBuffer.length();
  3125. WideCharToMultiByte( CodePage, 0, wideBuffer.c_str(), length+1, szBuffer, _MAX_PATH, NULL, NULL );
  3126. length = wideBuffer2.length();
  3127. WideCharToMultiByte( CodePage, 0, wideBuffer2.c_str(), length+1, szBuffer2, _MAX_PATH, NULL, NULL );
  3128. MessageBox( NULL, szBuffer, szBuffer2, MB_APPLMODAL | MB_OK );
  3129. }
  3130. */
  3131. }
  3132. break;
  3133. case IDD_HELP:
  3134. {
  3135. std::wstring wFileName;
  3136. wFileName = Locale_GetString(HELP_FILENAME);
  3137. std::string fname;
  3138. const wchar_t *tmp = wFileName.c_str();
  3139. char hack[2] = "a";
  3140. while (*tmp)
  3141. {
  3142. hack[0] = (char)( *tmp & 0xFF );
  3143. fname.append( hack );
  3144. tmp++;
  3145. }
  3146. char newdir[MAX_PATH];
  3147. char olddir[MAX_PATH];
  3148. char filepath[MAX_PATH];
  3149. GetCurrentDirectory(MAX_PATH, olddir);
  3150. _snprintf(newdir, MAX_PATH, "%ssupport", szArgvPath);
  3151. SetCurrentDirectory(newdir);
  3152. _snprintf(filepath, MAX_PATH, "%s%s", szArgvPath, fname.c_str());
  3153. unsigned int success;
  3154. success = GlobalMainWindow->Run_OpenFile(cd_drive, filepath, false);
  3155. SetCurrentDirectory(olddir);
  3156. /*
  3157. if (success == 0) {
  3158. std::wstring wideBuffer = TheGameText->fetch("Autorun:CantRunHelp");
  3159. std::wstring wideBuffer2 = TheGameText->fetch("Autorun:Error");
  3160. int length = wideBuffer.length();
  3161. WideCharToMultiByte( CodePage, 0, wideBuffer.c_str(), length+1, szBuffer, _MAX_PATH, NULL, NULL );
  3162. length = wideBuffer2.length();
  3163. WideCharToMultiByte( CodePage, 0, wideBuffer2.c_str(), length+1, szBuffer2, _MAX_PATH, NULL, NULL );
  3164. MessageBox( NULL, szBuffer, szBuffer2, MB_APPLMODAL | MB_OK );
  3165. }
  3166. */
  3167. }
  3168. break;
  3169. //-------------------------------------------------------------------
  3170. // IDD_CANCEL
  3171. //-------------------------------------------------------------------
  3172. case IDD_CANCEL:
  3173. Msg( __LINE__, TEXT(__FILE__), TEXT("IDD_CANCEL Selected." ));
  3174. end_dialog = true;
  3175. break;
  3176. //-------------------------------------------------------------------
  3177. // IDD_OK -- Install
  3178. // IDD_OK2 -- Play
  3179. //-------------------------------------------------------------------
  3180. case IDD_OK:
  3181. case IDD_OK2:
  3182. case IDD_OK3:
  3183. case IDD_OK4:
  3184. // if( !Is_On_CD( PRODUCT_VOLUME_CD1 ) && IsEnglish ) {
  3185. if( !Is_On_CD( PRODUCT_VOLUME_CD1 )) {
  3186. //-----------------------------------------------------------
  3187. // If false is returned, then CANCEL was pressed.
  3188. //-----------------------------------------------------------
  3189. char volume_to_match[ MAX_PATH ];
  3190. Reformat_Volume_Name( PRODUCT_VOLUME_CD1, volume_to_match );
  3191. // result = Prompt_For_CD( window_handle, volume_to_match, IDS_INSERT_CDROM_WITH_VOLUME1, IDS_EXIT_MESSAGE2, &cd_drive );
  3192. result = Prompt_For_CD( window_handle, volume_to_match, "Autorun:InsertCDROMWithVolume1", "Autorun:ExitMessage2", &cd_drive );
  3193. }
  3194. if ( result ) {
  3195. if ( idCtl == IDD_OK ) {
  3196. Msg( __LINE__, TEXT(__FILE__), TEXT("IDD_OK Selected." ));
  3197. result = GlobalMainWindow->Run_Setup( window_handle, &dlg_rect, cd_drive );
  3198. } else if ( idCtl == IDD_OK2 ) {
  3199. Msg( __LINE__, TEXT(__FILE__), TEXT("IDD_OK2 Selected." ));
  3200. result = GlobalMainWindow->Run_Game( window_handle, &dlg_rect );
  3201. } else if (idCtl == IDD_OK3 ) {
  3202. Msg( __LINE__, TEXT(__FILE__), TEXT("IDD_OK3 Selected, running WorldBuilder." ));
  3203. result = GlobalMainWindow->Run_WorldBuilder( window_handle, &dlg_rect );
  3204. } else if (idCtl == IDD_OK4 ) {
  3205. Msg( __LINE__, TEXT(__FILE__), TEXT("IDD_OK4 Selected, running PatchGet." ));
  3206. result = GlobalMainWindow->Run_PatchGet( window_handle, &dlg_rect );
  3207. }
  3208. }
  3209. if ( result ) {
  3210. end_dialog = true;
  3211. }
  3212. break;
  3213. #if(SHOW_MOH_DEMO)
  3214. //-------------------------------------------------------------------
  3215. // Launch demo from CD.
  3216. //-------------------------------------------------------------------
  3217. case IDD_VIEW_DEMO:
  3218. if( !Is_On_CD( PRODUCT_VOLUME_CD2 )) {
  3219. //-----------------------------------------------------------
  3220. // If false is returned, then CANCEL was pressed.
  3221. //-----------------------------------------------------------
  3222. char volume_to_match[ MAX_PATH ];
  3223. Reformat_Volume_Name( PRODUCT_VOLUME_CD2, volume_to_match );
  3224. // result = Prompt_For_CD( window_handle, volume_to_match, IDS_INSERT_CDROM_WITH_VOLUME2, IDS_EXIT_MESSAGE2, &cd_drive );
  3225. result = Prompt_For_CD( window_handle, volume_to_match, AsciiString("Autorun:InsertCDROMWithVolume2"), AsciiString("Autorun:ExitMessage2"), &cd_drive );
  3226. }
  3227. if ( result ) {
  3228. Msg( __LINE__, TEXT(__FILE__), TEXT("IDD_VIEW_DEMO Selected." ));
  3229. result = GlobalMainWindow->Run_Demo( window_handle, &dlg_rect, cd_drive );
  3230. }
  3231. if ( result ) {
  3232. end_dialog = true;
  3233. }
  3234. break;
  3235. #endif
  3236. #if( SHOW_GAMESPY_BUTTON )
  3237. //-------------------------------------------------------------------
  3238. // Launch GameSpy Website.
  3239. //-------------------------------------------------------------------
  3240. case IDD_GAMESPY:
  3241. Msg( __LINE__, TEXT(__FILE__), TEXT("IDD_GAMESPY Selected." ));
  3242. if( ViewHTML( GAMESPY_WEBSITE ))
  3243. {
  3244. end_dialog = true;
  3245. }
  3246. else
  3247. {
  3248. Error_Message( Main::hInstance, AsciiString("Autorun:Generals"), AsciiString("Autorun:CantFindExplorer"), GAME_WEBSITE );
  3249. }
  3250. break;
  3251. #endif
  3252. //-------------------------------------------------------------------
  3253. // Create a new online account.
  3254. //-------------------------------------------------------------------
  3255. case IDD_NEW_ACCOUNT:
  3256. Msg( __LINE__, TEXT(__FILE__), TEXT("IDD_NEW_ACCOUNT Selected." ));
  3257. result = GlobalMainWindow->Run_New_Account( window_handle, &dlg_rect );
  3258. if ( result ) {
  3259. end_dialog = true;
  3260. }
  3261. break;
  3262. //-------------------------------------------------------------------
  3263. // IDD_REGISTER
  3264. //-------------------------------------------------------------------
  3265. case IDD_REGISTER:
  3266. Msg( __LINE__, TEXT(__FILE__), TEXT("IDD_REGISTER Selected." ));
  3267. result = GlobalMainWindow->Run_Register( window_handle, &dlg_rect );
  3268. if ( result ) {
  3269. end_dialog = true;
  3270. }
  3271. break;
  3272. //-------------------------------------------------------------------
  3273. // IDD_INTERNET
  3274. //-------------------------------------------------------------------
  3275. case IDD_INTERNET:
  3276. Msg( __LINE__, TEXT(__FILE__), TEXT("IDD_INTERNET Selected." ));
  3277. if( ViewHTML( GAME_WEBSITE )) {
  3278. end_dialog = true;
  3279. }
  3280. else
  3281. {
  3282. Error_Message( Main::hInstance, "Autorun:Generals", "Autorun:CantFindExplorer", GAME_WEBSITE );
  3283. }
  3284. break;
  3285. //-------------------------------------------------------------------
  3286. // IDD_UPDATE
  3287. //-------------------------------------------------------------------
  3288. case IDD_UPDATE:
  3289. Msg( __LINE__, TEXT(__FILE__), TEXT("IDD_UPDATE Selected." ));
  3290. result = GlobalMainWindow->Run_Auto_Update( window_handle, &dlg_rect );
  3291. if ( result ) {
  3292. end_dialog = true;
  3293. }
  3294. break;
  3295. //-------------------------------------------------------------------
  3296. // IDD_EXPLORE
  3297. //-------------------------------------------------------------------
  3298. case IDD_EXPLORE:
  3299. Msg( __LINE__, TEXT(__FILE__), TEXT("IDD_EXPLORE Selected." ));
  3300. GlobalMainWindow->Run_Explorer( "", window_handle, &dlg_rect );
  3301. end_dialog = true;
  3302. break;
  3303. //-------------------------------------------------------------------
  3304. // IDD_UNINSTALL
  3305. //-------------------------------------------------------------------
  3306. case IDD_UNINSTALL:
  3307. Msg( __LINE__, TEXT(__FILE__), TEXT("IDD_UNINSTALL Selected." ));
  3308. result = GlobalMainWindow->Run_Uninstall( window_handle, &dlg_rect );
  3309. //---------------------------------------------------------------
  3310. // MML 5/27/99: I am exiting here because the we launch
  3311. // Uninstll.exe which in turn launches Uninst.exe thus
  3312. // ::Run_Install ends before Uninst.exe is done.
  3313. //---------------------------------------------------------------
  3314. if ( result ) {
  3315. end_dialog = true;
  3316. }
  3317. break;
  3318. default:
  3319. break;
  3320. }
  3321. //-----------------------------------------------------------------------
  3322. // Exit Autorun.
  3323. //-----------------------------------------------------------------------
  3324. if( end_dialog ) {
  3325. for ( i = 0; i < NUM_BUTTONS; i++ ) {
  3326. if ( ButtonList[i] ) {
  3327. delete( ButtonList[i] );
  3328. ButtonList[i] = NULL;
  3329. }
  3330. }
  3331. if ( hpal ) {
  3332. DeleteObject( hpal );
  3333. }
  3334. if ( hBitmap ) {
  3335. DeleteObject( hBitmap );
  3336. }
  3337. for( i = 0; i < NUM_FLICKER_FRAMES; i++ ) {
  3338. DeleteObject( hFlicker[i] );
  3339. hFlicker[i] = 0;
  3340. }
  3341. Stop_Sound_Playing();
  3342. KillTimer( window_handle, timer_id );
  3343. EndDialog( window_handle, idCtl );
  3344. }
  3345. #else
  3346. if ( hStaticBrush ) {
  3347. DeleteObject( hStaticBrush );
  3348. hStaticBrush = 0;
  3349. }
  3350. EndDialog( window_handle, idCtl );
  3351. KillTimer( window_handle, timer_id );
  3352. KillTimer( window_handle, gem_timer_id );
  3353. #endif
  3354. }
  3355. break;
  3356. //-------------------------------------------------------------------------------
  3357. // This message is the response to the Close Button in upper right corner.
  3358. //-------------------------------------------------------------------------------
  3359. case WM_SYSCOMMAND:
  3360. if ( w_param == SC_CLOSE ) {
  3361. #if(BACKGROUND_BITMAP)
  3362. for ( i = 0; i < NUM_BUTTONS; i++ ) {
  3363. if ( ButtonList[i] ) {
  3364. delete( ButtonList[i] );
  3365. ButtonList[i] = NULL;
  3366. }
  3367. }
  3368. if ( hpal ) {
  3369. DeleteObject( hpal );
  3370. }
  3371. if ( hBitmap ) {
  3372. DeleteObject( hBitmap );
  3373. }
  3374. for( i = 0; i < NUM_FLICKER_FRAMES; i++ ) {
  3375. DeleteObject( hFlicker[i] );
  3376. hFlicker[i] = 0;
  3377. }
  3378. #else
  3379. if ( hStaticBrush ) {
  3380. DeleteObject( hStaticBrush );
  3381. hStaticBrush = 0;
  3382. }
  3383. #endif
  3384. //-----------------------------------------------------------------------
  3385. // Stop the sound if still going.
  3386. //-----------------------------------------------------------------------
  3387. Stop_Sound_Playing();
  3388. //-----------------------------------------------------------------------
  3389. // Delete the arguments.
  3390. //-----------------------------------------------------------------------
  3391. if ( Args ) {
  3392. delete( Args );
  3393. Args = NULL;
  3394. }
  3395. KillTimer( window_handle, timer_id );
  3396. EndDialog( window_handle, w_param );
  3397. }
  3398. break;
  3399. //-------------------------------------------------------------------------------
  3400. // WM_SYSCOLORCHANGE Message.
  3401. // If your applications uses controls in Windows 95/NT, forward the
  3402. // WM_SYSCOLORCHANGE message to the controls.
  3403. //-------------------------------------------------------------------------------
  3404. #if( !BACKGROUND_BITMAP )
  3405. case WM_SYSCOLORCHANGE:
  3406. if ( hStaticBrush ) {
  3407. DeleteObject( hStaticBrush );
  3408. hStaticBrush = CreateSolidBrush( GetSysColor( COLOR_WINDOW ));
  3409. }
  3410. break;
  3411. #endif
  3412. //-------------------------------------------------------------------------------
  3413. // WM_CTLCOLOR Message.
  3414. // wParam Handle to Child Window's device context
  3415. // LOWORD( lParam ) Child Window handle
  3416. // HIWORD( lParam ) Type of Window: CTLCOLOR_MSGBOX, _EDIT, _LISTBOX, _BTN, _DLG, _SCROLLBAR, _STATIC
  3417. //
  3418. // WM_CTLCOLORMSGBOX
  3419. // WM_CTLCOLOREDIT
  3420. // WM_CTLCOLORLISTBOX
  3421. // WM_CTLCOLORBTN
  3422. // WM_CTLCOLORDLG
  3423. // WM_CTLCOLORSCROLLBAR
  3424. // WM_CTLCOLORSTATIC
  3425. // #define WM_CTLCOLOR 0x0019
  3426. // #define GET_WM_CTLCOLOR_HDC (wp, lp, msg) (HDC)(wp)
  3427. // #define GET_WM_CTLCOLOR_HWND(wp, lp, msg) (HWND)(lp)
  3428. // #define GET_WM_CTLCOLOR_TYPE(wp, lp, msg) (WORD)(msg - WM_CTLCOLORMSGBOX)
  3429. // #define GET_WM_CTLCOLOR_MSG (type) (WORD)(WM_CTLCOLORMSGBOX+(type))
  3430. //-------------------------------------------------------------------------------
  3431. #if( !BACKGROUND_BITMAP )
  3432. case WM_CTLCOLOR:
  3433. if ( HIWORD( l_param ) == CTLCOLOR_STATIC ) {
  3434. SetTextColor(( HDC )w_param, GetSysColor( COLOR_WINDOWTEXT ));
  3435. SetBkColor( (HDC)wParam, GetSysColor( COLOR_WINDOW ));
  3436. // SetBkColor(( HDC )w_param, RGB( 192, 192, 192 ));
  3437. UnrealizeObject( hStaticBrush ); // reset the origin of the brush next time used.
  3438. point.x = point.y = 0; // create a point.
  3439. ClientToScreen( window_handle, &point ); // translate into screen coordinates.
  3440. SetBrushOrgEx( (HDC)w_param, point.x, point.y, NULL ); // New Origin to use when next selected.
  3441. return((LRESULT) hStaticBrush );
  3442. }
  3443. #endif
  3444. //===============================================================================
  3445. // Check where Left Mouse button was pressed.
  3446. //===============================================================================
  3447. #if(BACKGROUND_BITMAP)
  3448. case WM_LBUTTONDOWN:
  3449. {
  3450. RECT rect;
  3451. //----------------------------------------------------------------------
  3452. // Get mouse coordinates.
  3453. //----------------------------------------------------------------------
  3454. mouse_x = LOWORD( l_param );
  3455. mouse_y = HIWORD( l_param );
  3456. //----------------------------------------------------------------------
  3457. // For each button in the list...
  3458. //----------------------------------------------------------------------
  3459. for ( i = 0; i < NUM_BUTTONS; i++ ) {
  3460. //-------------------------------------------------------------------
  3461. // If mouse was clicked in one of the "buttons", then change
  3462. // that button's state to "pressed".
  3463. //-------------------------------------------------------------------
  3464. if ( ButtonList[i] && ButtonList[i]->Is_Mouse_In_Region( mouse_x, mouse_y )) {
  3465. if ( ButtonList[i]->Get_State() != DrawButton::PRESSED_STATE ) {
  3466. ButtonList[i]->Return_Area ( &rect );
  3467. ButtonList[i]->Set_State( DrawButton::PRESSED_STATE );
  3468. InvalidateRect( window_handle, &rect, FALSE );
  3469. Msg( __LINE__, TEXT(__FILE__), TEXT("WM_LBUTTONDOWN -- %s. rect = [%d,%d,%d,%d]."),
  3470. ButtonList[i]->Return_Normal_Bitmap(), rect.left, rect.top, rect.right, rect.bottom );
  3471. UpdateWindow( window_handle );
  3472. }
  3473. break;
  3474. }
  3475. }
  3476. }
  3477. break;
  3478. #endif
  3479. //===============================================================================
  3480. // Check where Left Mouse button was released.
  3481. //===============================================================================
  3482. #if(BACKGROUND_BITMAP)
  3483. case WM_LBUTTONUP:
  3484. {
  3485. RECT rect;
  3486. int focus_index = 0;
  3487. int found_focus = -1;
  3488. //-----------------------------------------------------------------------
  3489. // Get mouse coordinates.
  3490. //-----------------------------------------------------------------------
  3491. mouse_x = LOWORD( l_param );
  3492. mouse_y = HIWORD( l_param );
  3493. //=======================================================================
  3494. // focus_index = previous PRESSED/FOCUSED button.
  3495. // found_focus = new PRESSED/FOCUSED button ( if different ).
  3496. //=======================================================================
  3497. //-----------------------------------------------------------------------
  3498. // First find the button that is either focused or pressed.
  3499. //-----------------------------------------------------------------------
  3500. for ( i = 0; i < NUM_BUTTONS; i++ ) {
  3501. if ( ButtonList[i] ) {
  3502. //---------------------------------------------------------------
  3503. // Save index of button with focus.
  3504. //---------------------------------------------------------------
  3505. if( ButtonList[i]->Get_State() == DrawButton::FOCUS_STATE ||
  3506. ButtonList[i]->Get_State() == DrawButton::PRESSED_STATE ) {
  3507. focus_index = i;
  3508. }
  3509. }
  3510. }
  3511. //-----------------------------------------------------------------------
  3512. // Then find the button that is to be focused or pressed.
  3513. //-----------------------------------------------------------------------
  3514. for ( i = 0; i < NUM_BUTTONS; i++ ) {
  3515. if ( ButtonList[i] && ButtonList[i]->Is_Mouse_In_Region( mouse_x, mouse_y )) {
  3516. found_focus = i;
  3517. }
  3518. }
  3519. //-----------------------------------------------------------------------
  3520. // If new button is not found...
  3521. //-----------------------------------------------------------------------
  3522. if ( found_focus == -1 ) {
  3523. //-------------------------------------------------------------------
  3524. // Make sure previously focused/pressed button is now is a
  3525. // focused state and no action is taken. This occurs when
  3526. // mouse is clicked outside of any button areas.
  3527. //-------------------------------------------------------------------
  3528. if ( ButtonList[focus_index] && ( ButtonList[focus_index]->Get_State() != DrawButton::FOCUS_STATE )) {
  3529. ButtonList[focus_index]->Set_State( DrawButton::FOCUS_STATE );
  3530. ButtonList[focus_index]->Return_Area ( &rect );
  3531. InvalidateRect( window_handle, &rect, FALSE );
  3532. Msg( __LINE__, TEXT(__FILE__), TEXT("WM_LBUTTONUP -- %s[FOCUS_STATE] = [x=%d, y=%d, w=%d, h=%d]."),
  3533. ButtonList[ focus_index ]->Return_Normal_Bitmap(), rect.left, rect.top, rect.right, rect.bottom );
  3534. UpdateWindow( window_handle );
  3535. }
  3536. } else {
  3537. //-------------------------------------------------------------------
  3538. // Buttons are one and the same.
  3539. //-------------------------------------------------------------------
  3540. if( focus_index == found_focus ) {
  3541. ButtonList[ found_focus ]->Set_State( DrawButton::FOCUS_STATE );
  3542. ButtonList[ found_focus ]->Return_Area ( &rect );
  3543. InvalidateRect( window_handle, &rect, FALSE );
  3544. Msg( __LINE__, TEXT(__FILE__), TEXT("WM_LBUTTONUP -- %s[FOCUS_STATE] = [x=%d, y=%d, w=%d, h=%d]."),
  3545. ButtonList[ found_focus ]->Return_Normal_Bitmap(), rect.left, rect.top, rect.right, rect.bottom );
  3546. UpdateWindow( window_handle );
  3547. } else {
  3548. //---------------------------------------------------------------
  3549. // Make previously focused button, Normal...
  3550. //---------------------------------------------------------------
  3551. if ( ButtonList[ focus_index ] ) {
  3552. ButtonList[ focus_index ]->Set_State( DrawButton::NORMAL_STATE );
  3553. ButtonList[ focus_index ]->Return_Area ( &rect );
  3554. InvalidateRect( window_handle, &rect, FALSE );
  3555. Msg( __LINE__, TEXT(__FILE__), TEXT("WM_LBUTTONUP -- %s[NORMAL_STATE] = [x=%d, y=%d, w=%d, h=%d]."),
  3556. ButtonList[ focus_index ]->Return_Normal_Bitmap(),
  3557. rect.left, rect.top, rect.right, rect.bottom );
  3558. UpdateWindow( window_handle );
  3559. }
  3560. //---------------------------------------------------------------
  3561. // ...and the new button now has focus.
  3562. //---------------------------------------------------------------
  3563. if ( ButtonList[ found_focus ] ) {
  3564. ButtonList[ found_focus ]->Set_State( DrawButton::FOCUS_STATE );
  3565. ButtonList[ found_focus ]->Return_Area ( &rect );
  3566. InvalidateRect( window_handle, &rect, FALSE );
  3567. Msg( __LINE__, TEXT(__FILE__), TEXT("WM_LBUTTONUP -- %s[FOCUS_STATE] = [x=%d, y=%d, w=%d, h=%d]."),
  3568. ButtonList[ found_focus ]->Return_Normal_Bitmap(), rect.left, rect.top, rect.right, rect.bottom );
  3569. UpdateWindow( window_handle );
  3570. }
  3571. }
  3572. }
  3573. //-----------------------------------------------------------------------
  3574. // Repaint the Window now.
  3575. //-----------------------------------------------------------------------
  3576. nResult = UpdateWindow( window_handle );
  3577. //-----------------------------------------------------------------------
  3578. // Do the focus button's action.
  3579. //-----------------------------------------------------------------------
  3580. if ( found_focus >= 0 ) {
  3581. if (( ButtonList[found_focus] ) &&
  3582. ( ButtonList[found_focus]->Get_State() == DrawButton::FOCUS_STATE ) &&
  3583. ( ButtonList[found_focus]->Is_Mouse_In_Region( mouse_x, mouse_y ))) {
  3584. SendMessage( window_handle, WM_COMMAND, ButtonList[found_focus]->Return_Id(), 0L );
  3585. break;
  3586. }
  3587. }
  3588. }
  3589. break;
  3590. #endif
  3591. //-------------------------------------------------------------------------------
  3592. // Check Mouse moves over buttons.
  3593. //-------------------------------------------------------------------------------
  3594. //#if(DISABLE_KEYBOARD)
  3595. #if(BACKGROUND_BITMAP)
  3596. case WM_MOUSEMOVE:
  3597. {
  3598. RECT rect;
  3599. int j;
  3600. int done = 0;
  3601. //-----------------------------------------------------------------------
  3602. // Get mouse coordinates.
  3603. //-----------------------------------------------------------------------
  3604. mouse_x = LOWORD( l_param );
  3605. mouse_y = HIWORD( l_param );
  3606. #if(USE_MOUSE_MOVES)
  3607. //-----------------------------------------------------------------------
  3608. // Reset most current button.
  3609. //-----------------------------------------------------------------------
  3610. CurrentButton = 0;
  3611. #endif
  3612. //-----------------------------------------------------------------------
  3613. // For each button in the list...
  3614. //-----------------------------------------------------------------------
  3615. i = 0;
  3616. while( i < NUM_BUTTONS && !done ) {
  3617. //-------------------------------------------------------------------
  3618. // For each button, check if mouse is in it's area.
  3619. //-------------------------------------------------------------------
  3620. if ( ButtonList[i] && ButtonList[i]->Is_Mouse_In_Region( mouse_x, mouse_y )) {
  3621. //---------------------------------------------------------------
  3622. // This is now the current button.
  3623. //---------------------------------------------------------------
  3624. CurrentButton = ButtonList[i]->Return_Id();
  3625. if( CurrentButton != LastButton ) {
  3626. //-----------------------------------------------------------
  3627. // Make all other buttons, NORMAL.
  3628. //-----------------------------------------------------------
  3629. for ( j = 0; j < NUM_BUTTONS; j++ ) {
  3630. if ( ButtonList[j] ) {
  3631. ButtonList[j]->Set_State( DrawButton::NORMAL_STATE );
  3632. // Msg( __LINE__, TEXT(__FILE__), TEXT("WM_MOUSEMOVE -- %s[NORMAL_STATE]]."), ButtonList[j]->Return_Normal_Bitmap());
  3633. }
  3634. }
  3635. if ( w_param & MK_LBUTTON ) {
  3636. //--------------------------------------------------------
  3637. // Left Mouse button is pressed! Make it a pressed button!
  3638. //--------------------------------------------------------
  3639. if ( ButtonList[i] && ButtonList[i]->Get_State() != DrawButton::PRESSED_STATE ) {
  3640. ButtonList[i]->Set_State( DrawButton::PRESSED_STATE );
  3641. // Msg( __LINE__, TEXT(__FILE__), TEXT("WM_MOUSEMOVE -- %s[PRESSED_STATE]."), ButtonList[i]->Return_Normal_Bitmap());
  3642. }
  3643. } else {
  3644. //--------------------------------------------------------
  3645. // If this button is not already focused, give it the focus.
  3646. //--------------------------------------------------------
  3647. if ( ButtonList[i] && ButtonList[i]->Get_State() != DrawButton::FOCUS_STATE ) {
  3648. ButtonList[i]->Set_State( DrawButton::FOCUS_STATE );
  3649. // Msg( __LINE__, TEXT(__FILE__), TEXT("WM_MOUSEMOVE -- %s[FOCUS_STATE]."), ButtonList[i]->Return_Normal_Bitmap());
  3650. }
  3651. } // end of if
  3652. //-----------------------------------------------------------
  3653. // Get the area of the button, and post it for updating.
  3654. //-----------------------------------------------------------
  3655. for ( j = 0; j < NUM_BUTTONS; j++ ) {
  3656. if ( ButtonList[j] ) {
  3657. ButtonList[j]->Return_Area ( &rect );
  3658. InvalidateRect( window_handle, &rect, FALSE );
  3659. }
  3660. }
  3661. //-----------------------------------------------------------
  3662. // Repaint now!
  3663. //-----------------------------------------------------------
  3664. UpdateWindow( window_handle );
  3665. done = 1;
  3666. }
  3667. } // end of if
  3668. i++;
  3669. } // end of for
  3670. #if( USE_MOUSE_MOVES )
  3671. //-----------------------------------------------------------------------
  3672. // If a MouseMove was found to be in one of the buttons, then
  3673. // CurrentButton will have a value.
  3674. //-----------------------------------------------------------------------
  3675. if ( CurrentButton != 0 ) {
  3676. LastButton = CurrentButton;
  3677. //-------------------------------------------------------------------
  3678. // If we are still in the same button, don't make a sound!
  3679. //-------------------------------------------------------------------
  3680. if ( LastButton != PrevButton ) {
  3681. PrevButton = LastButton;
  3682. PlaySound( szButtonWav, Main::hModule, SND_ASYNC | SND_RESOURCE );
  3683. }
  3684. }
  3685. #endif
  3686. }
  3687. break;
  3688. #endif // Background_Bitmap flag
  3689. //#endif
  3690. //-------------------------------------------------------------------------------
  3691. // Repaint when focus is restored (does partial repaint), and when
  3692. // mouse is double clicked on dialog ( full repaint ).
  3693. //-------------------------------------------------------------------------------
  3694. case WM_LBUTTONDBLCLK:
  3695. case WM_SETFOCUS:
  3696. InvalidateRect( window_handle, &dlg_rect, TRUE );
  3697. // nResult = UpdateWindow( window_handle );
  3698. // Msg( __LINE__, TEXT(__FILE__), TEXT("WM_LBUTTONDBLCLK -- dlg_rect = [x=%d, y=%d, w=%d, h=%d]."),
  3699. // dlg_rect.left, dlg_rect.top, dlg_rect.right, dlg_rect.bottom );
  3700. break;
  3701. #if(BACKGROUND_BITMAP)
  3702. //-------------------------------------------------------------------------------
  3703. // bit 30 of lParam - Specifies the previous key state.
  3704. // The value is 1 if the key is down before the message is sent,
  3705. // or it is 0 if the key is up.
  3706. //-------------------------------------------------------------------------------
  3707. case WM_KEYUP:
  3708. {
  3709. // int j = 0;
  3710. switch( w_param ) {
  3711. case VK_ESCAPE:
  3712. SendMessage( window_handle, WM_SYSCOMMAND, SC_CLOSE, 0L );
  3713. break;
  3714. //#if(DISABLE_KEYBOARD)
  3715. case VK_RETURN:
  3716. //---------------------------------------------------------------
  3717. // If the Return/Enter key is pressed... find the focused
  3718. // button and call its action.
  3719. //---------------------------------------------------------------
  3720. // result = ( l_param & 0x40000000 );
  3721. for ( i = 0; i < NUM_BUTTONS; i++ ) {
  3722. if ( ButtonList[i] && ButtonList[i]->Get_State() == DrawButton::FOCUS_STATE ) {
  3723. SendMessage( window_handle, WM_COMMAND, ButtonList[i]->Return_Id(), 0L );
  3724. break;
  3725. }
  3726. }
  3727. break;
  3728. //#endif
  3729. //#if(DISABLE_KEYBOARD)
  3730. case VK_TAB:
  3731. case VK_DOWN:
  3732. {
  3733. //-----------------------------------------------------------
  3734. // Find the button with focus and "tab" to the next button by finding
  3735. // the next valid index. If past last button, circle back to the top.
  3736. //-----------------------------------------------------------
  3737. int focused_button = 0;
  3738. int next_button = 0;
  3739. for ( i = 0; i < NUM_BUTTONS; i++ ) {
  3740. if ( ButtonList[i] && ButtonList[i]->Get_State() == DrawButton::FOCUS_STATE ) {
  3741. focused_button = i;
  3742. next_button = i+1;
  3743. if ( next_button >= NUM_BUTTONS ) {
  3744. next_button = 0;
  3745. }
  3746. while (( next_button < NUM_BUTTONS ) && !ButtonList[ next_button ] ) {
  3747. next_button++;
  3748. }
  3749. if ( next_button >= NUM_BUTTONS ) {
  3750. next_button = 0;
  3751. while (( next_button < NUM_BUTTONS ) && !ButtonList[ next_button ] ) {
  3752. next_button++;
  3753. }
  3754. }
  3755. break;
  3756. }
  3757. }
  3758. //-----------------------------------------------------------
  3759. // Set the previous button to Normal status.
  3760. //-----------------------------------------------------------
  3761. if ( ButtonList[focused_button] && ( ButtonList[focused_button]->Get_State() != DrawButton::NORMAL_STATE )) {
  3762. ButtonList[focused_button]->Set_State( DrawButton::NORMAL_STATE );
  3763. ButtonList[focused_button]->Return_Area ( &rect );
  3764. InvalidateRect( window_handle, &rect, FALSE );
  3765. Msg( __LINE__, TEXT(__FILE__), TEXT("VK_DOWN/VK_TAB -- %s = [%s]."), ButtonList[focused_button]->Return_Normal_Bitmap(), "NORMAL_STATE" );
  3766. }
  3767. //-----------------------------------------------------------
  3768. // Set the new button to focus status.
  3769. //-----------------------------------------------------------
  3770. if ( ButtonList[next_button] && ( ButtonList[next_button]->Get_State() != DrawButton::FOCUS_STATE )) {
  3771. ButtonList[next_button]->Set_State( DrawButton::FOCUS_STATE );
  3772. ButtonList[next_button]->Return_Area ( &rect );
  3773. InvalidateRect( window_handle, &rect, FALSE );
  3774. PlaySound( szButtonWav, Main::hModule, SND_ASYNC | SND_RESOURCE );
  3775. Msg( __LINE__, TEXT(__FILE__), TEXT("VK_DOWN/VK_TAB -- %s = [%s]."), ButtonList[next_button]->Return_Normal_Bitmap(), "FOCUS_STATE" );
  3776. }
  3777. }
  3778. break;
  3779. case VK_UP:
  3780. {
  3781. //-----------------------------------------------------------
  3782. // Find the button with focus and "tab" to the next button by finding
  3783. // the next valid index. If past last button, circle back to the top.
  3784. //-----------------------------------------------------------
  3785. int focused_button = 0;
  3786. int next_button = 0;
  3787. for ( i = 0; i < NUM_BUTTONS; i++ ) {
  3788. if ( ButtonList[i] && ButtonList[i]->Get_State() == DrawButton::FOCUS_STATE ) {
  3789. focused_button = i;
  3790. next_button = i-1;
  3791. if ( next_button < 0 ) {
  3792. next_button = NUM_BUTTONS - 1;
  3793. }
  3794. while (( next_button > 0 ) && !ButtonList[ next_button ] ) {
  3795. next_button--;
  3796. }
  3797. if ( !ButtonList[ next_button ]) {
  3798. next_button = NUM_BUTTONS - 1;
  3799. }
  3800. while (( next_button >= 0 ) && !ButtonList[ next_button ] ) {
  3801. next_button--;
  3802. }
  3803. break;
  3804. }
  3805. }
  3806. //-----------------------------------------------------------
  3807. // Set the previous button to Normal status.
  3808. //-----------------------------------------------------------
  3809. if ( ButtonList[focused_button] && ( ButtonList[focused_button]->Get_State() != DrawButton::NORMAL_STATE )) {
  3810. ButtonList[focused_button]->Set_State( DrawButton::NORMAL_STATE );
  3811. ButtonList[focused_button]->Return_Area ( &rect );
  3812. InvalidateRect( window_handle, &rect, FALSE );
  3813. Msg( __LINE__, TEXT(__FILE__), TEXT("VK_DOWN/VK_TAB -- %s = [%s]."), ButtonList[focused_button]->Return_Normal_Bitmap(), "NORMAL_STATE" );
  3814. }
  3815. //-----------------------------------------------------------
  3816. // Set the new button to focus status.
  3817. //-----------------------------------------------------------
  3818. if ( ButtonList[next_button] && ( ButtonList[next_button]->Get_State() != DrawButton::FOCUS_STATE )) {
  3819. ButtonList[next_button]->Set_State( DrawButton::FOCUS_STATE );
  3820. ButtonList[next_button]->Return_Area ( &rect );
  3821. InvalidateRect( window_handle, &rect, FALSE );
  3822. PlaySound( szButtonWav, Main::hModule, SND_ASYNC | SND_RESOURCE );
  3823. Msg( __LINE__, TEXT(__FILE__), TEXT("VK_DOWN/VK_TAB -- %s = [%s]."), ButtonList[next_button]->Return_Normal_Bitmap(), "FOCUS_STATE" );
  3824. }
  3825. }
  3826. break;
  3827. //#endif
  3828. } /* end of switch */
  3829. } /* end of case stmt */
  3830. return ( 0 );
  3831. #endif
  3832. }
  3833. return( FALSE );
  3834. }
  3835. //*****************************************************************************
  3836. // STOP_SOUND_PLAYING -- Stop the background sound.
  3837. //
  3838. // INPUT: none.
  3839. //
  3840. // OUTPUT: none.
  3841. //
  3842. // WARNINGS: Will stop any sound started by PlaySound.
  3843. //
  3844. // HISTORY:
  3845. // 06/04/1999 MML : Created.
  3846. //=============================================================================
  3847. void Stop_Sound_Playing ( void )
  3848. {
  3849. PlaySound( NULL, NULL, SND_ASYNC | SND_FILENAME );
  3850. }
  3851. //*****************************************************************************
  3852. // OPTIONS -- Find any user options and set the correct flags
  3853. //
  3854. // INPUT: int argc = no. of arguments to check
  3855. // BYTE *argv[] = ptr to actual command line parameters
  3856. //
  3857. // OUTPUT:
  3858. //
  3859. // WARNINGS:
  3860. //
  3861. // HISTORY:
  3862. // 06/04/1996 MML : Created.
  3863. //=============================================================================
  3864. BOOL Options( Command_Line_Arguments *Orgs )
  3865. {
  3866. int i;
  3867. BOOL result = TRUE;
  3868. char buffer[ MAX_ARGUMENT_LENGTH ];
  3869. //-------------------------------------------------------------------------
  3870. // Scan arguments for any options ( / or - followed by a letter)
  3871. //-------------------------------------------------------------------------
  3872. for ( i = 0; i < Orgs->Get_argc(); i++ ) {
  3873. //---------------------------------------------------------------------
  3874. // Get the next item in the list.
  3875. //---------------------------------------------------------------------
  3876. memset( buffer, '\0', sizeof( buffer ));
  3877. strcpy( buffer, Orgs->Get_argv(i));
  3878. Msg( __LINE__, TEXT(__FILE__), TEXT("Options -- Argument[%d] = %s."), i, buffer );
  3879. //---------------------------------------------------------------------
  3880. // If starts with / or -
  3881. //---------------------------------------------------------------------
  3882. if (( buffer[0] == '/' ) || ( buffer[0] == '-' )) {
  3883. switch ( tolower( buffer[1] )) {
  3884. //-------------------------------------------------------------
  3885. // Retrieve the game's version info.
  3886. //-------------------------------------------------------------
  3887. case 'v':
  3888. {
  3889. char szPath [ MAX_PATH ];
  3890. char szVersion[ MAX_PATH ];
  3891. Make_Current_Path_To( SETUP_INI_FILE1, szPath );
  3892. GetPrivateProfileString( "Setup", "Version", "1.0", szVersion, sizeof( szVersion ), szPath );
  3893. LoadString( Main::hInstance, IDS_VERSION_STRING, szBuffer, MAX_PATH );
  3894. // sprintf( szBuffer3, "V %s", szVersion );
  3895. sprintf( szBuffer3, szBuffer, szVersion );
  3896. // strcpy( szBuffer, szRegistryKey );
  3897. MessageBox( NULL, szBuffer3, "Autorun", MB_TASKMODAL | MB_OK );
  3898. result = FALSE;
  3899. }
  3900. break;
  3901. //-------------------------------------------------------------
  3902. // Bypass the volume check.
  3903. //-------------------------------------------------------------
  3904. case 'n':
  3905. {
  3906. HANDLE handle;
  3907. WIN32_FIND_DATA FindFileData;
  3908. memset( szVolumeName, '\0', MAX_PATH );
  3909. //-----------------------------------------------------
  3910. // If we think we are on CD2, then use PRODUCT_VOLUME_CD2.
  3911. //-----------------------------------------------------
  3912. Make_Current_Path_To( MOH_DEMO_PROGRAM, szBuffer );
  3913. handle = FindFirstFile( szBuffer, &FindFileData );
  3914. if ( handle == INVALID_HANDLE_VALUE ) {
  3915. strcpy( szVolumeName, PRODUCT_VOLUME_CD1 );
  3916. } else {
  3917. strcpy( szVolumeName, PRODUCT_VOLUME_CD2 );
  3918. FindClose( handle );
  3919. }
  3920. strcpy( Arguments[ NumberArguments++ ], buffer );
  3921. }
  3922. break;
  3923. #if( _DEBUG )
  3924. case 'c':
  3925. if( buffer[2] == 'd' ) {
  3926. szCDDrive[0] = buffer[3];
  3927. szCDDrive[1] = ':';
  3928. szCDDrive[2] = '\\';
  3929. }
  3930. break;
  3931. //-------------------------------------------------------------
  3932. // Change languages?
  3933. //-------------------------------------------------------------
  3934. case 'l':
  3935. {
  3936. //-----------------------------------------------------
  3937. // Identifier Meaning
  3938. // 932 Japan
  3939. // 936 Chinese (PRC, Singapore)
  3940. // 949 Korean
  3941. // 1252 Windows 3.1 Latin 1 (US, Western Europe)
  3942. //-----------------------------------------------------
  3943. char *temp = buffer+2;
  3944. int number = atoi( temp );
  3945. switch( number ) {
  3946. case LANG_GER:
  3947. LanguageToUse = LANG_GER;
  3948. CodePage = 1252;
  3949. break;
  3950. case LANG_FRE:
  3951. LanguageToUse = LANG_FRE;
  3952. CodePage = 1252;
  3953. break;
  3954. case LANG_JAP:
  3955. LanguageToUse = LANG_JAP;
  3956. CodePage = 932;
  3957. break;
  3958. case LANG_KOR:
  3959. LanguageToUse = LANG_KOR;
  3960. CodePage = 949;
  3961. break;
  3962. case LANG_CHI:
  3963. LanguageToUse = LANG_CHI;
  3964. CodePage = 950;
  3965. break;
  3966. case LANG_USA:
  3967. default:
  3968. LanguageToUse = LANG_USA;
  3969. CodePage = 1252;
  3970. break;
  3971. }
  3972. }
  3973. break;
  3974. #endif
  3975. default:
  3976. strcpy( Arguments[ NumberArguments++ ], buffer );
  3977. break;
  3978. }
  3979. }
  3980. }
  3981. Msg( __LINE__, TEXT(__FILE__), TEXT("Options -- Language = %d"), Language );
  3982. Msg( __LINE__, TEXT(__FILE__), TEXT("Options -- CodePage = %d"), CodePage );
  3983. #if(0)
  3984. struct lconv *info = localeconv();
  3985. char szDefaultLangID[ MAX_PATH ];
  3986. GetLocaleInfo(
  3987. LOCALE_USER_DEFAULT, // locale identifier
  3988. LOCALE_ILANGUAGE, // type of information
  3989. szBuffer1, // address of buffer for information
  3990. MAX_PATH ); // size of buffer
  3991. Msg( __LINE__, TEXT(__FILE__), TEXT("Options -- GetLocalInfo = %s"), szBuffer1 );
  3992. sprintf( szDefaultLangID, "%04X", GetUserDefaultLangID());
  3993. Msg( __LINE__, __FILE__, "Options -- GetUserDefaultLangID() = %s", szDefaultLangID );
  3994. sprintf( szDefaultLangID, "%04X", GetSystemDefaultLangID());
  3995. Msg( __LINE__, __FILE__, "Options -- GetSystemDefaultLangID() = %s", szDefaultLangID );
  3996. Msg( __LINE__, __FILE__, "-------------------------------------------------------------" );
  3997. #endif
  3998. return( result );
  3999. }
  4000. //*****************************************************************************
  4001. // Valid_Environment -- Make sure this program is run from CD-ROM disc only
  4002. // AND it is a Win95 system.
  4003. //
  4004. // INPUT: none.
  4005. //
  4006. // OUTPUT: none.
  4007. //
  4008. // WARNINGS: returns 0 if ok to continue.
  4009. //
  4010. // HISTORY:
  4011. // 06/04/1996 MML : Created.
  4012. //=============================================================================
  4013. BOOL Valid_Environment ( void )
  4014. {
  4015. bool result = 0;
  4016. //--------------------------------------------------------------------------
  4017. // Check Windows Version.
  4018. //--------------------------------------------------------------------------
  4019. int length = 0;
  4020. result = WinVersion.Meets_Minimum_Version_Requirements();
  4021. if ( !result )
  4022. {
  4023. std::wstring wideBuffer = TheGameText->fetch("GUI:WindowsVersionText");
  4024. std::wstring wideBuffer2 = TheGameText->fetch("GUI:WindowsVersionTitle");
  4025. length = wideBuffer.length();
  4026. WideCharToMultiByte( CodePage, 0, wideBuffer.c_str(), length+1, szBuffer, _MAX_PATH, NULL, NULL );
  4027. length = wideBuffer2.length();
  4028. WideCharToMultiByte( CodePage, 0, wideBuffer2.c_str(), length+1, szBuffer2, _MAX_PATH, NULL, NULL );
  4029. MessageBox( NULL, szBuffer, szBuffer2, MB_APPLMODAL | MB_OK );
  4030. }
  4031. return( result );
  4032. }
  4033. //****************************************************************************
  4034. // LOADRESOURCEBITMAP -- Find & Load the bitmap from the resource.
  4035. //
  4036. // INPUT: HINSTANCE hInstance -- Program's hInstance.
  4037. // LPTSTR lpString -- name of bitmap to find.
  4038. // HPALETTE FAR *lphPalette -- we will return palette in this.
  4039. //
  4040. // OUTPUT: HBITMAP -- handle to the bitmap if found.
  4041. //
  4042. // WARNINGS:
  4043. //
  4044. // HISTORY: Found this routine on MS Developmemt CD, July 1996.
  4045. // 09/26/1996 MML : Created.
  4046. //=============================================================================
  4047. HBITMAP LoadResourceBitmap( HINSTANCE hInstance, LPTSTR lpString, HPALETTE FAR *lphPalette, bool loading_a_button )
  4048. {
  4049. // HDC hdc;
  4050. int iNumColors;
  4051. HRSRC hRsrc;
  4052. HGLOBAL hGlobal;
  4053. HBITMAP hBitmapFinal = NULL;
  4054. LPBITMAPINFOHEADER lpbi;
  4055. hBitmapFinal = LoadBitmap( hInstance, lpString );
  4056. //--------------------------------------------------------------------------
  4057. // Find the Bitmap in this program's resources.
  4058. //--------------------------------------------------------------------------
  4059. hRsrc = FindResource( hInstance, lpString, RT_BITMAP );
  4060. if ( hRsrc ) {
  4061. //-----------------------------------------------------------------------
  4062. // Load the resource, lock the memory, grab a DC.
  4063. //-----------------------------------------------------------------------
  4064. hGlobal = LoadResource( hInstance, hRsrc );
  4065. lpbi = (LPBITMAPINFOHEADER) LockResource( hGlobal );
  4066. if ( loading_a_button ) {
  4067. //--------------------------------------------------------------------------
  4068. // Set number of colors ( 2 to the nth ).
  4069. //--------------------------------------------------------------------------
  4070. if ( lpbi->biBitCount <= 8 ) {
  4071. iNumColors = ( 1 << lpbi->biBitCount );
  4072. } else {
  4073. iNumColors = 0;
  4074. }
  4075. } else {
  4076. //--------------------------------------------------------------------
  4077. // Get the palette from the resource.
  4078. //--------------------------------------------------------------------
  4079. *lphPalette = CreateDIBPalette((LPBITMAPINFO) lpbi, &iNumColors );
  4080. }
  4081. //-----------------------------------------------------------------------
  4082. // Free DS and memory used.
  4083. //-----------------------------------------------------------------------
  4084. UnlockResource( hGlobal );
  4085. FreeResource( hGlobal );
  4086. }
  4087. return( hBitmapFinal );
  4088. }
  4089. //*****************************************************************************
  4090. // CREATEDIBPALETTE -- Creates the palette from the Bitmap found above.
  4091. //
  4092. // INPUT: LPBITMAPINFO lpbmi -- bitmap info from header.
  4093. // LPINT lpiNumColors -- number of colors.
  4094. //
  4095. // OUTPUT: HPALETTE -- handle to the bitmap if found.
  4096. //
  4097. // WARNINGS:
  4098. //
  4099. // HISTORY: Found this routine on MS Developmemt CD, July 1996.
  4100. // 09/26/1996 MML : Created.
  4101. //=============================================================================
  4102. HPALETTE CreateDIBPalette ( LPBITMAPINFO lpbmi, LPINT lpiNumColors )
  4103. {
  4104. LPBITMAPINFOHEADER lpbi;
  4105. LPLOGPALETTE lpPal;
  4106. HANDLE hLogPal;
  4107. HPALETTE hPal = NULL;
  4108. int i;
  4109. lpbi = (LPBITMAPINFOHEADER) lpbmi;
  4110. //--------------------------------------------------------------------------
  4111. // Set number of colors ( 2 to the nth ).
  4112. //--------------------------------------------------------------------------
  4113. if ( lpbi->biBitCount <= 8 ) {
  4114. *lpiNumColors = ( 1 << lpbi->biBitCount );
  4115. } else {
  4116. *lpiNumColors = 0;
  4117. }
  4118. //--------------------------------------------------------------------------
  4119. // If bitmap has a palette ( bitcount ), lock some memory and create
  4120. // a palette from the bitmapinfoheader passed in.
  4121. //--------------------------------------------------------------------------
  4122. if ( *lpiNumColors ) {
  4123. hLogPal = GlobalAlloc( GHND, sizeof( LOGPALETTE ) + sizeof( PALETTEENTRY ) * ( *lpiNumColors ));
  4124. lpPal = (LPLOGPALETTE) GlobalLock( hLogPal );
  4125. lpPal->palVersion = 0x300;
  4126. lpPal->palNumEntries = (WORD)*lpiNumColors;
  4127. for ( i = 0; i < *lpiNumColors; i++ ) {
  4128. lpPal->palPalEntry[i].peRed = lpbmi->bmiColors[i].rgbRed;
  4129. lpPal->palPalEntry[i].peGreen = lpbmi->bmiColors[i].rgbGreen;
  4130. lpPal->palPalEntry[i].peBlue = lpbmi->bmiColors[i].rgbBlue;
  4131. lpPal->palPalEntry[i].peFlags = 0;
  4132. }
  4133. hPal = CreatePalette( lpPal );
  4134. GlobalUnlock( hLogPal );
  4135. GlobalFree( hLogPal );
  4136. #if(0)
  4137. StandardFileClass fileout;
  4138. char buff[2];
  4139. fileout.Open( "test.pal", MODE_WRITE_TRUNCATE );
  4140. for ( i = 0; i < *lpiNumColors; i++ ) {
  4141. sprintf( buff, "%d", lpPal->palPalEntry[i].peRed >> 2 );
  4142. fileout.Write(( void *)buff, 2 );
  4143. sprintf( buff, "%d", lpPal->palPalEntry[i].peGreen >> 2 );
  4144. fileout.Write(( void *)buff, 2 );
  4145. sprintf( buff, "%d", lpPal->palPalEntry[i].peBlue >> 2 );
  4146. fileout.Write(( void *)buff, 2 );
  4147. }
  4148. fileout.Close();
  4149. #endif
  4150. }
  4151. return( hPal );
  4152. }
  4153. //*****************************************************************************
  4154. // LOADRESOURCEBUTTON -- Find & Load the bitmap from the resource.
  4155. //
  4156. // INPUT: HINSTANCE hInstance -- Program's hInstance.
  4157. // LPTSTR lpString -- name of bitmap to find.
  4158. // HPALETTE FAR *lphPalette -- we will return palette in this.
  4159. //
  4160. // OUTPUT: HBITMAP -- handle to the bitmap if found.
  4161. //
  4162. // WARNINGS:
  4163. //
  4164. // HISTORY: Found this routine on MS Developmemt CD, July 1996.
  4165. // 09/26/1996 MML : Created.
  4166. //=============================================================================
  4167. HBITMAP LoadResourceButton( HINSTANCE hInstance, LPTSTR lpString, HPALETTE FAR lphPalette )
  4168. {
  4169. HDC hdc;
  4170. int iNumColors;
  4171. HRSRC hRsrc;
  4172. HGLOBAL hGlobal;
  4173. HBITMAP hBitmapFinal = NULL;
  4174. LPBITMAPINFOHEADER lpbi;
  4175. //--------------------------------------------------------------------------
  4176. // Find the Bitmap in this program's resources.
  4177. //--------------------------------------------------------------------------
  4178. hRsrc = FindResource( hInstance, lpString, RT_BITMAP );
  4179. if ( hRsrc ) {
  4180. //-----------------------------------------------------------------------
  4181. // Load the resource, lock the memory, grab a DC.
  4182. //-----------------------------------------------------------------------
  4183. hGlobal = LoadResource( hInstance, hRsrc );
  4184. lpbi = (LPBITMAPINFOHEADER) LockResource( hGlobal );
  4185. hdc = GetDC( NULL );
  4186. //--------------------------------------------------------------------------
  4187. // Set number of colors ( 2 to the nth ).
  4188. //--------------------------------------------------------------------------
  4189. if ( lpbi->biBitCount <= 8 ) {
  4190. iNumColors = ( 1 << lpbi->biBitCount );
  4191. } else {
  4192. iNumColors = 0;
  4193. }
  4194. //-----------------------------------------------------------------------
  4195. // Get the palette from the resource.
  4196. // Select to the DC and realize it in the System palette.
  4197. //-----------------------------------------------------------------------
  4198. // *lphPalette = CreateDIBPalette((LPBITMAPINFO) lpbi, &iNumColors );
  4199. if ( lphPalette != NULL ) {
  4200. SelectPalette( hdc, lphPalette, FALSE );
  4201. RealizePalette( hdc );
  4202. }
  4203. //-----------------------------------------------------------------------
  4204. // Now create the bitmap itself.
  4205. //-----------------------------------------------------------------------
  4206. hBitmapFinal = CreateDIBitmap(
  4207. hdc,
  4208. (LPBITMAPINFOHEADER)lpbi,
  4209. (LONG)CBM_INIT,
  4210. (LPTSTR)lpbi + lpbi->biSize + iNumColors * sizeof( RGBQUAD ),
  4211. (LPBITMAPINFO)lpbi,
  4212. DIB_RGB_COLORS );
  4213. //-----------------------------------------------------------------------
  4214. // Free DS and memory used.
  4215. //-----------------------------------------------------------------------
  4216. ReleaseDC( NULL, hdc );
  4217. UnlockResource( hGlobal );
  4218. FreeResource( hGlobal );
  4219. }
  4220. return( hBitmapFinal );
  4221. }
  4222. //*****************************************************************************
  4223. // Cant_Find_MessageBox -- Find & Load the bitmap from the resource.
  4224. //
  4225. // INPUT: HINSTANCE hInstance -- Program's hInstance.
  4226. // LPTSTR lpString -- name of bitmap to find.
  4227. // HPALETTE FAR *lphPalette -- we will return palette in this.
  4228. //
  4229. // OUTPUT: HBITMAP -- handle to the bitmap if found.
  4230. //
  4231. // WARNINGS:
  4232. //
  4233. // HISTORY: Found this routine on MS Developmemt CD, July 1996.
  4234. // 09/26/1996 MML : Created.
  4235. //=============================================================================
  4236. void Cant_Find_MessageBox ( HINSTANCE hInstance, char *szPath )
  4237. {
  4238. #ifdef LEAN_AND_MEAN
  4239. Locale_GetString( "Autorun:AutorunTitle", szWideBuffer );
  4240. swprintf( szWideBuffer2, szWideBuffer, szProductName );
  4241. Locale_GetString( "Autorun:CantFind", szWideBuffer3 );
  4242. #else
  4243. std::wstring wideBuffer = TheGameText->fetch("Autorun:AutorunTitle");
  4244. std::wstring wideBuffer2.format( wideBuffer.str(), productName.str() );
  4245. std::wstring wideBuffer3 = TheGameText->fetch("Autorun:CantFind");
  4246. WideCharToMultiByte( CodePage, 0, wideBuffer3.str(), wideBuffer3.getLength()+1, szBuffer3, _MAX_PATH, NULL, NULL );
  4247. WideCharToMultiByte( CodePage, 0, wideBuffer2.str(), wideBuffer2.getLength()+1, szBuffer2, _MAX_PATH, NULL, NULL );
  4248. #endif
  4249. sprintf( szBuffer1, szBuffer3, szPath );
  4250. if ( strlen( szPath ) < 3 )
  4251. {
  4252. MessageBox( NULL, "The path specified in Cant_Find_MessageBox was blank", "Autorun", MB_APPLMODAL | MB_OK );
  4253. return;
  4254. }
  4255. if ( strlen( szBuffer1 ) < 3 && strlen( szBuffer3 ) < 3 )
  4256. {
  4257. MessageBox( NULL, "***MISSING MESSAGES***... IDS_AUTORUN_TITLE and IDS_CANT_FIND", "Autorun", MB_APPLMODAL | MB_OK );
  4258. return;
  4259. }
  4260. if ( strlen( szBuffer1 ) < 3 )
  4261. {
  4262. MessageBox( NULL, "***MISSING MESSAGE***... IDS_AUTORUN_TITLE", "Autorun", MB_APPLMODAL | MB_OK );
  4263. return;
  4264. }
  4265. if ( strlen( szBuffer3 ) < 3 )
  4266. {
  4267. MessageBox( NULL, "***MISSING MESSAGE***... IDS_CANT_FIND", "Autorun", MB_APPLMODAL | MB_OK );
  4268. return;
  4269. }
  4270. MessageBox( NULL, szBuffer1, szBuffer2, MB_APPLMODAL | MB_OK );
  4271. }
  4272. /******************************************************************************
  4273. * Error_Message --
  4274. *
  4275. * INPUT:
  4276. *
  4277. * OUTPUT:
  4278. *
  4279. * WARNINGS: none
  4280. *
  4281. * HISTORY:
  4282. * 08/14/1998 MML : Created.
  4283. *============================================================================*/
  4284. void Error_Message ( HINSTANCE hInstance, const char * title, const char * string, char *path )
  4285. {
  4286. #ifndef LEAN_AND_MEAN
  4287. wideBuffer2 = TheGameText->fetch(title);
  4288. wideBuffer3 = TheGameText->fetch(string);
  4289. if ( path && ( path[0] != '\0' ))
  4290. {
  4291. wideBuffer3.format( wideBuffer.str(), path );
  4292. }
  4293. else
  4294. {
  4295. wideBuffer3 = wideBuffer; // insert not provided
  4296. }
  4297. WideCharToMultiByte( CodePage, 0, wideBuffer2.str(), wideBuffer2.getLength()+1, szBuffer2, _MAX_PATH, NULL, NULL );
  4298. WideCharToMultiByte( CodePage, 0, wideBuffer3.str(), wideBuffer3.getLength()+1, szBuffer3, _MAX_PATH, NULL, NULL );
  4299. MessageBox( NULL, szBuffer3, szBuffer2, MB_APPLMODAL | MB_OK );
  4300. #endif
  4301. MessageBox( NULL, "ERROR_UNDEFINED", "ERROR_UNDEFINED", MB_APPLMODAL | MB_OK );
  4302. }
  4303. /******************************************************************************
  4304. / Launch Class Object
  4305. /******************************************************************************/
  4306. LaunchObjectClass::LaunchObjectClass ( char *path, char *args )
  4307. {
  4308. memset( szPath, '\0', _MAX_PATH );
  4309. memset( szArgs, '\0', _MAX_PATH );
  4310. if( path != NULL && path[0] != '\0' ) {
  4311. strcpy( szPath, path );
  4312. }
  4313. if( args != NULL && args[0] != '\0' ) {
  4314. strcpy( szArgs, args );
  4315. }
  4316. }
  4317. void LaunchObjectClass::SetPath ( char *path )
  4318. {
  4319. if( path != NULL && path[0] != '\0' ) {
  4320. memset( szPath, '\0', _MAX_PATH );
  4321. strcpy( szPath, path );
  4322. }
  4323. }
  4324. void LaunchObjectClass::SetArgs ( char *args )
  4325. {
  4326. if( args != NULL && args[0] != '\0' ) {
  4327. memset( szArgs, '\0', _MAX_PATH );
  4328. strcpy( szArgs, args );
  4329. }
  4330. }
  4331. unsigned int LaunchObjectClass::Launch ( void )
  4332. {
  4333. char filepath [_MAX_PATH];
  4334. char dir [_MAX_DIR];
  4335. char ext [_MAX_EXT];
  4336. char drive [_MAX_DRIVE];
  4337. char file [_MAX_FNAME];
  4338. char lpszComLine [ 127 ];
  4339. PROCESS_INFORMATION processinfo;
  4340. STARTUPINFO startupinfo;
  4341. unsigned int abc = 0;
  4342. unsigned int result = 0;
  4343. memset( lpszComLine, '\0', 127 );
  4344. //--------------------------------------------------------------------------
  4345. // Split into parts.
  4346. //--------------------------------------------------------------------------
  4347. _splitpath( szPath, drive, dir, file, ext );
  4348. //--------------------------------------------------------------------------
  4349. // Change current path to the correct dir.
  4350. //
  4351. // The _chdrive function changes the current working drive to the drive
  4352. // specified by drive. The drive parameter uses an integer to specify the
  4353. // new working drive (1=A, 2=B, and so forth). This function changes only
  4354. // the working drive; _chdir changes the working directory.
  4355. //--------------------------------------------------------------------------
  4356. _makepath( filepath, drive, dir, NULL, NULL );
  4357. Path_Remove_Back_Slash( filepath );
  4358. abc = (unsigned)( toupper( filepath[0] ) - 'A' + 1 );
  4359. if ( !_chdrive( abc )) {
  4360. //----------------------------------------------------------------------
  4361. // Returns a value of 0 if successful.
  4362. //----------------------------------------------------------------------
  4363. abc = _chdir( filepath );
  4364. }
  4365. #if (_DEBUG)
  4366. int cde = _getdrive();
  4367. _getcwd( szBuffer, _MAX_PATH );
  4368. Msg( __LINE__, TEXT(__FILE__), TEXT("Current Working Dir = %d\\%s." ), cde, szBuffer );
  4369. #endif
  4370. //--------------------------------------------------------------------------
  4371. // Try to launch the EXE...
  4372. //--------------------------------------------------------------------------
  4373. _stprintf( lpszComLine, _TEXT( "%s %s" ), szPath, szArgs );
  4374. //==========================================================================
  4375. // Setup the call
  4376. //==========================================================================
  4377. memset( &startupinfo, 0, sizeof( STARTUPINFO ));
  4378. startupinfo.cb = sizeof( STARTUPINFO );
  4379. Msg( __LINE__, TEXT(__FILE__), TEXT("About to launch %s." ), lpszComLine );
  4380. result = CreateProcess(
  4381. szPath, // address of module name
  4382. lpszComLine, // address of command line
  4383. NULL, // address of process security attributes
  4384. NULL, // address of thread security attributes
  4385. FALSE, // new process inherits handles
  4386. FALSE,
  4387. NULL, // address of new environment block
  4388. NULL, // address of current directory name
  4389. &startupinfo, // address of STARTUPINFO
  4390. &processinfo ); // address of PROCESS_INFORMATION
  4391. //--------------------------------------------------------------------------
  4392. // If WinExec returned 0, error occurred.
  4393. //--------------------------------------------------------------------------
  4394. if ( !result ) {
  4395. Msg( __LINE__, TEXT(__FILE__), TEXT("Launch of %s failed." ), lpszComLine );
  4396. _makepath ( filepath, NULL, NULL, file, ext );
  4397. Cant_Find_MessageBox ( Main::hInstance, filepath );
  4398. }
  4399. Msg( __LINE__, TEXT(__FILE__), TEXT("Launch of %s succeeded." ), lpszComLine );
  4400. return( result );
  4401. }
  4402. void Debug_Date_And_Time_Stamp ( void )
  4403. {
  4404. //-------------------------------------------------------------------------
  4405. // tm_sec - Seconds after minute (0 – 59)
  4406. // tm_min - Minutes after hour (0 – 59)
  4407. // tm_hour - Hours after midnight (0 – 23)
  4408. // tm_mday - Day of month (1 – 31)
  4409. // tm_mon - Month (0 – 11; January = 0)
  4410. // tm_year - Year (current year minus 1900)
  4411. // tm_wday - Day of week (0 – 6; Sunday = 0)
  4412. // tm_yday - Day of year (0 – 365; January 1 = 0)
  4413. //-------------------------------------------------------------------------
  4414. static char *Month_Strings[ 12 ] = {
  4415. "January",
  4416. "February",
  4417. "March",
  4418. "April",
  4419. "May",
  4420. "June",
  4421. "July",
  4422. "August",
  4423. "September",
  4424. "October",
  4425. "November",
  4426. "December"
  4427. };
  4428. static char *Week_Day_Strings[ 7 ] = {
  4429. "Sunday",
  4430. "Monday",
  4431. "Tuesday",
  4432. "Wednesday",
  4433. "Thursday",
  4434. "Friday",
  4435. "Saturday",
  4436. };
  4437. char ampm[] = "AM";
  4438. time_t ltime;
  4439. struct tm * today;
  4440. /*-------------------------------------------------------------------------
  4441. *Convert to time structure and adjust for PM if necessary.
  4442. */
  4443. time( &ltime );
  4444. today = localtime( &ltime );
  4445. if( today->tm_hour > 12 ) {
  4446. strcpy( ampm, "PM" );
  4447. today->tm_hour -= 12;
  4448. }
  4449. if( today->tm_hour == 0 ) { /* Adjust if midnight hour. */
  4450. today->tm_hour = 12;
  4451. }
  4452. Msg( __LINE__, __FILE__, "%s, %s %d, %d %d:%d:%d %s",
  4453. Week_Day_Strings[ today->tm_wday ],
  4454. Month_Strings[ today->tm_mon ],
  4455. today->tm_mday,
  4456. today->tm_year + 1900,
  4457. today->tm_hour,
  4458. today->tm_min,
  4459. today->tm_sec,
  4460. ampm );
  4461. /*-------------------------------------------------------------------------
  4462. * Note how pointer addition is used to skip the first 11
  4463. * characters and printf is used to trim off terminating
  4464. * characters.
  4465. */
  4466. // Msg( __LINE__, __FILE__, "%s %s\n", asctime( today ), ampm );
  4467. }
  4468. bool Is_On_CD ( char *volume_name )
  4469. {
  4470. char volume_to_match[ MAX_PATH ];
  4471. Reformat_Volume_Name( volume_name, volume_to_match );
  4472. if( _stricmp( szVolumeName, volume_to_match ) == 0 ) {
  4473. return true;
  4474. } else {
  4475. return false;
  4476. }
  4477. }
  4478. bool Prompt_For_CD ( HWND window_handle, char *volume_name, const char * message1, const char * message2, int *cd_drive )
  4479. {
  4480. int drive;
  4481. strcpy( szBuffer, Args->Get_argv( 0 ));
  4482. drive = toupper( szBuffer[0] ) - 'A';
  4483. memset( szBuffer, '\0', MAX_PATH );
  4484. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4485. // This is the correct check for a CD Check.
  4486. //
  4487. // MML: Modified on 10/18/2000 so it would check for all available CD drives.
  4488. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4489. int result = IDRETRY;
  4490. while( result == IDRETRY ) {
  4491. if ( CD_Volume_Verification( drive, szBuffer, volume_name )) {
  4492. result = IDOK;
  4493. *cd_drive = drive;
  4494. } else {
  4495. CDList.Reset_Index();
  4496. while(( result == IDRETRY ) && ( CDList.Get_Index() < CDList.Get_Number_Of_Drives())) {
  4497. drive = CDList.Get_Next_CD_Drive();
  4498. if ( CD_Volume_Verification( drive, szBuffer, volume_name )) {
  4499. result = IDOK;
  4500. *cd_drive = drive;
  4501. }
  4502. }
  4503. }
  4504. if ( result == IDRETRY ) {
  4505. result = ( Show_Message( window_handle, message1, message2 ));
  4506. }
  4507. }
  4508. if ( result == IDCANCEL ) {
  4509. return( false );
  4510. // return true;
  4511. }
  4512. return( true );
  4513. }
  4514. int Show_Message ( HWND window_handle, const char * message1, const char * message2 )
  4515. {
  4516. #ifndef LEAN_AND_MEAN
  4517. UnicodeString string1;
  4518. UnicodeString string2;
  4519. WCHAR szString3[ MAX_PATH ];
  4520. int result = false;
  4521. string1 = TheGameText->fetch(message1);
  4522. string2 = TheGameText->fetch(message2);
  4523. wcscpy( szString3, string1.str() );
  4524. wcscat( szString3, L" " );
  4525. wcscat( szString3, string2.str() );
  4526. WideCharToMultiByte( CodePage, 0, szString3, _MAX_PATH, szBuffer, _MAX_PATH, NULL, NULL );
  4527. result = MessageBox( window_handle, szBuffer, "Autorun", MB_RETRYCANCEL|MB_APPLMODAL|MB_SETFOREGROUND );
  4528. return( result );
  4529. #else
  4530. return ( 0 );
  4531. #endif
  4532. }
  4533. void Reformat_Volume_Name ( char *volume_name, char *new_volume_name )
  4534. {
  4535. char temp_volume_name[ MAX_PATH ];
  4536. strcpy( temp_volume_name, volume_name );
  4537. if( WinVersion.Is_Win95()) {
  4538. temp_volume_name[11] = '\0';
  4539. }
  4540. if( new_volume_name != NULL ) {
  4541. strcpy( new_volume_name, temp_volume_name );
  4542. }
  4543. }