autorun.cpp 193 KB

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