| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474 |
- /*
- ** Command & Conquer Generals Zero Hour(tm)
- ** Copyright 2025 Electronic Arts Inc.
- **
- ** This program is free software: you can redistribute it and/or modify
- ** it under the terms of the GNU General Public License as published by
- ** the Free Software Foundation, either version 3 of the License, or
- ** (at your option) any later version.
- **
- ** This program is distributed in the hope that it will be useful,
- ** but WITHOUT ANY WARRANTY; without even the implied warranty of
- ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ** GNU General Public License for more details.
- **
- ** You should have received a copy of the GNU General Public License
- ** along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- /****************************************************************************
- ** 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 ***
- ****************************************************************************
- * *
- * Project Name : Autorun *
- * *
- * File Name : AUTORUN.CPP *
- * *
- * Programmers: Maria del Mar McCready Legg *
- * *
- * Start Date : September 5, 1997 *
- * *
- * Last Update : October 15, 2001 [MML] *
- * *
- *--------------------------------------------------------------------------*
- * Functions: *
- * WinMain *
- * Main::MessageLoop *
- * MainWindow::Register *
- * MainWindow::MainWindow *
- * MainWindow::Window_Proc *
- * MainWindow::Is_Product_Registered *
- * MainWindow::Run_Explorer *
- * MainWindow::Run_Game *
- * MainWindow::Run_Setup *
- * MainWindow::Run_New_Account *
- * MainWindow::Run_Register *
- * MainWindow::Run_Auto_Update *
- * MainWindow::Run_Uninstall *
- * MainWindow::Create_Buttons *
- * Wnd_Proc *
- * Dialog_Box_Proc *
- * Stop_Sound_Playing *
- * Options *
- * Valid_Environment *
- * LoadResourceBitmap *
- * CreateDIBPalette *
- * LoadResourceButton *
- * Cant_Find_MessageBox *
- * Error_Message *
- * Path_Add_Back_Slash *
- * Path_Remove_Back_Slash *
- * PlugInProductName *
- * Fix_Single_Ampersands *
- * Fix_Double_Ampersands *
- * LaunchObjectClass::LaunchObjectClass *
- * LaunchObjectClass::SetPath *
- * LaunchObjectClass::SetArgs *
- * LaunchObjectClass::Launch *
- *--------------------------------------------------------------------------*/
- #define STRICT
- #include <windows.h>
- #include <windowsx.h>
- #include <assert.h>
- #include <ctype.h>
- #include <direct.h>
- #include <dos.h>
- #include <errno.h>
- #include <fcntl.h>
- #include <fstream.h>
- #include <io.h>
- #include <locale.h>
- #include <math.h>
- #include <mbctype.h>
- #include <mmsystem.h>
- #include <process.h>
- #include <stdlib.h>
- #include <string.h>
- #include <stdio.h>
- #include <strstrea.h>
- #include <sys\stat.h>
- #include <time.h>
- #include <winuser.h>
- #include "args.h"
- #include "autorun.h"
- #include "drawbutton.h"
- #include "resource.h"
- #include "wnd_file.h"
- //#include "visualc.h"
- #include "winfix.h"
- #include "cdcntrl.h"
- #include "igr.h"
- #include "viewhtml.h"
- #include "utils.h"
- #include "locale_api.h"
- //#include "resources.h"
- #include "getcd.h"
- #include "WSYS_FileSystem.h"
- #include "WSYS_STDFileSystem.h"
- #include <string>
- #include "GameText.h"
- #include "leanAndMeanAutorun.h"
- #ifndef LEAN_AND_MEAN
- #include "Common/SubsystemInterface.h"
- #include "GameClient/GameText.h"
- #include "Common/UnicodeString.h"
- #include "Win32Device/Common/Win32LocalFileSystem.h"
- #include "Win32Device/Common/Win32BIGFileSystem.h"
- #endif
- //-----------------------------------------------------------------------------
- // DEFINES
- //-----------------------------------------------------------------------------
- #define PRETEND_ON_CD_TEST FALSE // should be FALSE
- //#define PRETEND_ON_CD_TEST TRUE // should be FALSE
- #define WINDOW_BRUSH FALSE
- #define BACKGROUND_BITMAP TRUE
- #define USE_MOUSE_MOVES TRUE
- #define DISABLE_KEYBOARD FALSE
- #define BUTTON_WIDTH 150
- #define BUTTON_HEIGHT 45
- #define NUM_BUTTONS 10
- #define NUM_ARGUMENTS 10
- #define NUM_SONGS 2 //32 //16
- #define NUM_FLICKER_FRAMES 1
- #define NUM_FLICKER_POSITIONS 15
- #define MOUSE_WAV "MouseMove"
- #define SOUND_FILE1 "SPEECH_FILE1"
- #define SOUND_FILE2 "SPEECH_FILE2"
- #define MOH_DEMO_PROGRAM "MOHAADEMO\\SETUP.EXE"
- #define SHOW_MOH_DEMO FALSE
- #define BFAVI_FILENAME "Autorun\\BF1942RTR.avi"
- #define SC4AVI_FILENAME "Autorun\\Preview.avi"
- #define HELP_FILENAME "HELP:FILENAME"//"Support\\eahelp.hlp"
- #define SHOW_GAMESPY_BUTTON FALSE
- #define GAMESPY_WEBSITE "http://www.gamespyarcade.com/features/launch.asp?svcname=ccrenegade&distID=391"
- #define RESOURCE_FILE "Autorun.loc"
- #define SETUP_INI_FILE1 "Setup\\Setup.ini"
- #define SETUP_INI_FILE2 "Setup.ini"
- #define UNINSTALL_EXECUTABLE "IDriver.exe" // JFS
- //-----------------------------------------------------------------------------
- // These defines need the Product name from Setup.ini to complete.
- //-----------------------------------------------------------------------------
- #define SETUP_MAIN_WINDOW_NAME "%s Setup"
- #define CLASS_NAME "%s Autorun"
- #define GAME_MAIN_WINDOW_NAME "%s Game Window"
- //#define GAME_WEBSITE "http://www.westwood.com/"
- #define GAME_WEBSITE "http://generals.ea.com"
- #define AUTORUN_MUTEX_OBJECT "01AF9993-3492-11d3-8F6F-0060089C05B1"
- //#define GAME_MUTEX_OBJECT "C6D925A3-7A9B-4ca3-866D-8B4D506C3665"
- #define GAME_MUTEX_OBJECT "685EAFF2-3216-4265-B047-251C5F4B82F3"
- #define PRODUCT_VOLUME_CD1 "Generals1"
- #define PRODUCT_VOLUME_CD2 "Generals2"
- //-----------------------------------------------------------------------------
- // Global Variables
- //-----------------------------------------------------------------------------
- LaunchObjectClass LaunchObject;
- MainWindow *GlobalMainWindow = NULL;
- int Language = 0;
- int LanguageToUse = 0;
- DrawButton *ButtonList [ NUM_BUTTONS ];
- RECT ButtonSizes [ NUM_BUTTONS ];
- char ButtonImages [ NUM_BUTTONS ][ MAX_PATH ];
- CHAR szSongPath [ MAX_PATH ];
- char FocusedButtonImages [ NUM_BUTTONS ][ MAX_PATH ];
- char Arguments [ NUM_ARGUMENTS ][ 30 ];
- char szWavs [ NUM_SONGS][ _MAX_PATH ];
- char szBuffer [ MAX_PATH ];
- char szBuffer1 [ MAX_PATH ];
- char szBuffer2 [ MAX_PATH ];
- char szBuffer3 [ MAX_PATH * 2];
- char szInternetPath [_MAX_PATH];
- char szGamePath [_MAX_PATH];
- char szWorldbuilderPath [_MAX_PATH];
- char szPatchgetPath [_MAX_PATH];
- char szSetupPath [_MAX_PATH];
- char szUninstallPath [_MAX_PATH];
- char szUninstallCommandLine[_MAX_PATH]; // JFS: Returned value contains parameters needed.
- char szRegisterPath [_MAX_PATH];
- char szButtonWav [_MAX_PATH ];
- char szSpeechWav [_MAX_PATH ];
- char szArgvPath [_MAX_PATH ];
- char drive [_MAX_DRIVE];
- char dir [_MAX_DIR ];
- char szSetupWindow [_MAX_PATH];
- char szGameWindow [_MAX_PATH];
- char szRegistryKey [_MAX_PATH];
- char szClassName [_MAX_PATH];
- char szVolumeName [_MAX_PATH];
- char szProduct_Name [ _MAX_PATH ];
- #ifdef LEAN_AND_MEAN
- wchar_t szWideBuffer [ _MAX_PATH ];
- wchar_t szWideBuffer0 [ _MAX_PATH ];
- wchar_t szWideBuffer2 [ _MAX_PATH ];
- wchar_t szWideBuffer3 [ _MAX_PATH ];
- wchar_t szProductName [ _MAX_PATH ];
- wchar_t szFullProductName [ _MAX_PATH ];
- /*
- enum
- {
- IDS_INSTALL,
- IDS_EXPLORE_CD,
- IDS_PREVIEWS,
- IDS_CANCEL,
- IDS_AUTORUN_TITLE,
- IDS_CANT_FIND_IEXPLORER,
- IDS_WINDOWS_VERSION_TEXT,
- IDS_WINDOWS_VERSION_TITLE,
- IDS_CANT_FIND,
- IDS_UNINSTALL,
- IDS_WEBSITE,
- IDS_CHECKFORUPDATES,
- IDS_WORLDBUILDER,
- IDS_PLAY,
- IDS_GAME_TITLE,
- IDS_FULL_GAME_TITLE,
- IDS_REGISTRY_KEY,
- IDS_MAIN_WINDOW,
- IDS_COUNT // keep this last
- };
- */
- #else
- UnicodeString wideBuffer;
- UnicodeString wideBuffer0;
- UnicodeString wideBuffer2;
- UnicodeString wideBuffer3;
- UnicodeString productName;
- UnicodeString fullProductName;
- #endif
- bool IsEnglish = FALSE;
- bool UseSounds = FALSE;
- bool b640X480 = FALSE;
- bool b800X600 = FALSE;
- BOOL OnCDRom = FALSE;
- BOOL IAmWindows95 = FALSE;
- BOOL InstallProduct = TRUE;
- BOOL UninstallAvailable = FALSE;
- BOOL IsUserRegistered = FALSE;
- BOOL DisplayRegisterButton = FALSE;
- BOOL IsWolapiAvailable = FALSE;
- BOOL CDLocked = FALSE;
- int WindowsVersion = 0;
- int NumberArguments = 0;
- int SongNumber = 0;
- HANDLE AppMutex = NULL;
- HANDLE GameAppMutex = NULL;
- HANDLE SetupAppMutex = NULL;
- #ifdef LEAN_AND_MEAN
- extern FileSystem *TheFileSystem;
- #else
- extern GameTextInterface *TheGameText;
- extern LocalFileSystem *TheLocalFileSystem;
- extern ArchiveFileSystem *TheArchiveFileSystem;
- #endif
- // stuff needed to compile.
- HWND ApplicationHWnd = NULL;
- HINSTANCE ApplicationHInstance; ///< main application instance
- const char *g_strFile = "Autorun.str";
- const char *g_csfFile = "Autorun.csf";
- char *gAppPrefix = "ar_"; // prefix to the debug log.
- int FlickerPositions[ NUM_FLICKER_POSITIONS ][2];
- #if( _DEBUG )
- char szCDDrive[ MAX_PATH ];
- #endif
- //-----------------------------------------------------------------------------
- // Global Function Definitions
- //-----------------------------------------------------------------------------
- void Cant_Find_MessageBox ( HINSTANCE hInstance, char *szPath );
- HPALETTE CreateDIBPalette ( LPBITMAPINFO lpbmi, LPINT lpiNumColors );
- void Debug_Date_And_Time_Stamp ( void );
- void Error_Message ( HINSTANCE hInstance, int title, int string, char *path );
- void Error_Message ( HINSTANCE hInstance, const char * title, const char * string, char *path );
- bool Is_On_CD ( char * );
- HBITMAP LoadResourceBitmap ( HMODULE hInstance, char *lpString, HPALETTE FAR *lphPalette, bool loading_a_button=FALSE );
- HBITMAP LoadResourceButton ( HMODULE hInstance, char *lpString, HPALETTE FAR lphPalette );
- BOOL Options ( Command_Line_Arguments *Orgs );
- void Prog_End ( void );
- bool Prompt_For_CD ( HWND window_handle, char *volume_name, const char * message1, const char * message2, int *cd_drive );
- void Reformat_Volume_Name ( char *volume_name, char *new_volume_name );
- int Show_Message ( HWND window_handle, const char * message_num1, const char * message_num2 );
- int Show_Message ( HWND window_handle, int message_num1 );
- void Stop_Sound_Playing ( void );
- BOOL Valid_Environment ( void );
- BOOL CALLBACK Dialog_Box_Proc ( HWND window_handle, UINT message, WPARAM w_param, LPARAM l_param );
- LRESULT CALLBACK Wnd_Proc ( HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam );
- //-----------------------------------------------------------------------------
- // Main & MainWindow Public Variables
- //-----------------------------------------------------------------------------
- HINSTANCE Main::hInstance = 0;
- HINSTANCE Main::hPrevInstance = 0;
- HMODULE Main::hModule = 0;
- int Main::nCmdShow = 0;
- char MainWindow::szClassName[] = CLASS_NAME;
- //*****************************************************************************
- // WinMain -- Main Program Loop.
- //
- // INPUT: HINSTANCE hInstance
- // HINSTANCE hPrevInstance
- // LPTSTR lpszCmdLine
- // int nCmdShow
- //
- // OUTPUT: int.
- //
- // WARNINGS: none.
- //
- // HISTORY:
- // 06/04/1996 MML : Created.
- //=============================================================================
- int PASCAL WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpszCmdLine, int nCmdShow )
- {
- int i = 0;
- char szPath[ _MAX_PATH ];
- char szIniPath[ _MAX_PATH ];
- HANDLE handle;
- WIN32_FIND_DATA FindFileData;
- Main::hInstance = hInstance;
- ApplicationHInstance = hInstance;
- Main::hPrevInstance = hPrevInstance;
- Main::nCmdShow = nCmdShow;
- Main::hModule = GetModuleHandle( NULL );
- memset( szSetupWindow, '\0', MAX_PATH );
- memset( szGameWindow, '\0', MAX_PATH );
- memset( szProductName, '\0', MAX_PATH );
- memset( szFullProductName, '\0', MAX_PATH );
- memset( szRegistryKey, '\0', MAX_PATH );
- memset( szClassName, '\0', MAX_PATH );
- memset( szVolumeName, '\0', MAX_PATH );
- Msg( __LINE__, __FILE__, "Entering WinMain." );
- //-------------------------------------------------------------------------
- // Set Cleanup function.
- //-------------------------------------------------------------------------
- atexit( Prog_End );
- //-------------------------------------------------------------------------
- // Clear Argument Array.
- //-------------------------------------------------------------------------
- for ( i = 0; i < NUM_ARGUMENTS; i++ ) {
- memset( Arguments[i], '\0', sizeof( Arguments[i] ));
- }
- for ( i = 0; i < NUM_SONGS; i++ ) {
- memset( szWavs[i], '\0', sizeof( szWavs[i] ));
- }
- //-------------------------------------------------------------------------
- // Init Args class.
- //-------------------------------------------------------------------------
- Args = new Command_Line_Arguments( hInstance, GetCommandLine());
- if ( Args == NULL ) {
- // Error_Message( hInstance, IDS_ERROR, IDS_COMMAND_LINE_ERR, NULL );
- Error_Message( hInstance, "Autorun:Error", "Autorun:CommandLineError", NULL );
- return( 0 );
- }
- Msg( __LINE__, __FILE__, "Args Created." );
- #if( PRETEND_ON_CD_TEST )
- strcpy( szCDDrive, "E:\\" );
- Options( Args );
- strcat( szCDDrive, "autorun.exe" );
- Msg( __LINE__, __FILE__, "szCDDrive = %s.", szCDDrive );
- Args->Set_argv( 0, szCDDrive );
- #endif
- //-------------------------------------------------------------------------
- // Get the CD volume to check on which CD in the product we are on.
- //-------------------------------------------------------------------------
- strcpy( szBuffer, Args->Get_argv(0));
- CDList.Get_Volume_For_This_CD_Drive( szBuffer, szVolumeName );
- Msg( __LINE__, __FILE__, "szVolumeName = %s.", szVolumeName );
- #ifdef LEAN_AND_MEAN
- TheFileSystem = new StdFileSystem;
- #else
- // create singletons
- TheFileSystem->init();
- TheLocalFileSystem = new Win32LocalFileSystem;
- TheArchiveFileSystem = new Win32BIGFileSystem;
- TheGameText = CreateGameTextInterface();
- TheGameText->init();
- #endif
- //=========================================================================
- // Make paths to .INI and .LOC files.
- //=========================================================================
- Make_Current_Path_To( RESOURCE_FILE, szPath );
- Make_Current_Path_To( SETUP_INI_FILE1, szIniPath );
- handle = FindFirstFile( szIniPath, &FindFileData );
- if ( handle == INVALID_HANDLE_VALUE ) {
- //---------------------------------------------------------------------
- // This might be a secondary CD.
- //---------------------------------------------------------------------
- Make_Current_Path_To( SETUP_INI_FILE2, szIniPath );
- }
- FindClose( handle );
- Msg( __LINE__, __FILE__, "Resource file = %s.", szPath );
- Msg( __LINE__, __FILE__, "Setup.ini file = %s.", szIniPath );
- //--------------------------------------------------------------------------
- // Get the language we are using from the Setup.ini file.
- //--------------------------------------------------------------------------
- Language = GetPrivateProfileInt( "Setup", "Language", 0, szIniPath );
- if( Language == 0 ) {
- IsEnglish = true;
- }
- Msg( __LINE__, __FILE__, "Language = %d.", Language );
- Msg( __LINE__, __FILE__, "IsEnglish = %d.", IsEnglish );
- //--------------------------------------------------------------------------
- // Set language to use.
- //--------------------------------------------------------------------------
- if( Locale_Use_Multi_Language_Files()) {
- if( IS_LANGUAGE_DBCS( Language ) && !IS_CODEPAGE_DBCS( CodePage )) {
- Language = LANG_USA;
- }
- /*switch( Language ) {
- case LANG_GER:
- LanguageToUse = IDL_GERMAN;
- break;
- case LANG_FRE:
- LanguageToUse = IDL_FRENCH;
- break;
- case LANG_JAP:
- LanguageToUse = IDL_JAPANESE;
- break;
- case LANG_KOR:
- LanguageToUse = IDL_KOREAN;
- break;
- case LANG_CHI:
- LanguageToUse = IDL_CHINESE;
- break;
- case LANG_USA:
- default:
- LanguageToUse = IDL_ENGLISH;
- break;
- }
- */
- LanguageToUse = Language;
- }
- Msg( __LINE__, __FILE__, "LanguageToUse = %d.", LanguageToUse );
- //-------------------------------------------------------------------------
- // Process the Command Line Options. This may change the language id.
- //-------------------------------------------------------------------------
- if ( !Options( Args )) {
- return( 0 );
- }
- //-------------------------------------------------------------------------
- // Save off the Current path for use by other stuff.
- //-------------------------------------------------------------------------
- _tcscpy( szArgvPath, Args->Get_argv(0));
- _tsplitpath( szArgvPath, drive, dir, NULL, NULL );
- _tmakepath ( szArgvPath, drive, dir, NULL, NULL );
- Path_Add_Back_Slash( szArgvPath );
- Msg( __LINE__, TEXT(__FILE__), TEXT("szArgvPath = %s."), szArgvPath );
- Msg( __LINE__, __FILE__, "About to Init text strings." );
- //=========================================================================
- // Init the strings chosen.
- //=========================================================================
- Locale_Init( LanguageToUse, szPath );
- /*
- if( !Locale_Init( LanguageToUse, szPath )) {
- LoadString( Main::hInstance, IDS_CANT_FIND_FILE, szBuffer1, _MAX_PATH );
- MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, szPath, _MAX_PATH, szWideBuffer0, _MAX_PATH );
- sprintf( szBuffer2, szBuffer1, szWideBuffer0 );
- MessageBox( NULL, szBuffer2, "Autorun", MB_APPLMODAL | MB_OK );
- return 0;
- }
- */
- //-------------------------------------------------------------------------
- // Get some pertinent strings.
- //-------------------------------------------------------------------------
- Locale_GetString( "Autorun:Title", szProductName );
- Locale_GetString( "Autorun:Command&ConquerGenerals", szFullProductName );
- //Locale_GetString( IDS_GAME_TITLE, szProductName );
- //Locale_GetString( IDS_FULL_GAME_TITLE, szFullProductName );
- // Locale_GetString( IDS_REGISTRY_KEY, szRegistryKey ); // jfs
- // Locale_GetString( IDS_MAIN_WINDOW, szGameWindow );
- //-------------------------------------------------------------------------
- // Set other variables used through out.
- //-------------------------------------------------------------------------
- #ifdef LEAN_AND_MEAN
- //Fix_Single_Ampersands( &szProductName[0], false );
- //Fix_Single_Ampersands( &szFullProductName[0], false );
- Msg( __LINE__, __FILE__, "szProductName = %s.", szProductName );
- WideCharToMultiByte( CodePage, 0, szProductName, _MAX_PATH, szProduct_Name, _MAX_PATH, NULL, NULL );
- #else
- productName = TheGameText->fetch("Autorun:Generals");
- fullProductName = TheGameText->fetch("Autorun:Command&ConquerGenerals");
- Msg( __LINE__, __FILE__, "Product Name = %ls.", productName.str() );
- Msg( __LINE__, __FILE__, "Full Product Name = %ls.", fullProductName.str() );
- Msg( __LINE__, __FILE__, "szRegistryKey = %s.", szRegistryKey );
- Msg( __LINE__, __FILE__, "szGameWindow = %s.", szGameWindow );
- WideCharToMultiByte( CodePage, 0, productName.str(), productName.getLength()+1, szProduct_Name, _MAX_PATH, NULL, NULL );
- #endif
- sprintf( szClassName, CLASS_NAME, szProduct_Name );
- MainWindow::Reset_Class_Name( szClassName );
- sprintf( szSetupWindow, SETUP_MAIN_WINDOW_NAME, szProduct_Name );
- Msg( __LINE__, __FILE__, "szClassName = %s.", szClassName );
- Msg( __LINE__, __FILE__, "szSetupWindow = %s.", szSetupWindow );
- //=========================================================================
- // Create a mutex with a unique name to Autorun in order to determine if
- // our app is already running.
- //
- // Return Values:
- // If the function succeeds, the return value is a handle to the mutex object.
- // If the named mutex object existed before the function call, the function returns
- // a handle to the existing object and GetLastError returns ERROR_ALREADY_EXISTS.
- // Otherwise, the caller created the mutex.
- // If the function fails, the return value is NULL. To get extended error
- // information, call GetLastError.
- //
- // WARNING: DO NOT use this number for any other application except Autorun
- //=========================================================================
- if( WinVersion.Is_Win_XP() || WinVersion.Version() > 500 ) {
- strcat( strcpy( szBuffer, "Global\\" ), AUTORUN_MUTEX_OBJECT );
- } else {
- strcpy( szBuffer, AUTORUN_MUTEX_OBJECT );
- }
- AppMutex = CreateMutex( NULL, FALSE, szBuffer );
- if ( AppMutex != NULL && ( GetLastError() == ERROR_ALREADY_EXISTS )) {
- Msg( __LINE__, __FILE__, "AppMutex of %s already exists. Exit here.", szBuffer );
- //---------------------------------------------------------------------
- // Handle is closed in the ProgEnd().
- //---------------------------------------------------------------------
- //---------------------------------------------------------------------
- // Check if Game/Setup is already running, and is looking for the CDRom.
- //---------------------------------------------------------------------
- HWND prev = FindWindow( szClassName, NULL );
- if( prev ){
- //if( IsIconic( prev )){
- //ShowWindow( prev, SW_RESTORE );
- //}
- SetForegroundWindow( prev );
- }
- return 0;
- }
- Msg( __LINE__, __FILE__, "AppMutex of %s created.", szBuffer );
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // if AppMutex was NULL, let through. Perhaps in future we want to trap it?
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- if ( AppMutex == NULL ) {
- }
- //=========================================================================
- // Create a mutex with a unique name to Game/Setup in order to
- // determine if our app is already running.
- //
- // Return Values
- // If the function succeeds, the return value is a handle to the mutex object.
- // If the function fails, the return value is NULL. To get extended error
- // information, call GetLastError.
- //
- // WARNING: DO NOT use this number for any other application except Game/Setup.
- //=========================================================================
- if( WinVersion.Is_Win_XP() || WinVersion.Version() > 500 ) {
- strcat( strcpy( szBuffer, "Global\\" ), GAME_MUTEX_OBJECT );
- } else {
- strcpy( szBuffer, GAME_MUTEX_OBJECT );
- }
- GameAppMutex = OpenMutex( MUTEX_ALL_ACCESS, FALSE, szBuffer );
- if ( GameAppMutex != NULL ) {
- Msg( __LINE__, TEXT(__FILE__), TEXT("Mutex Object of game found."));
- Msg( __LINE__, TEXT(__FILE__), TEXT("Looking for Game Window."));
- HWND ccwindow = FindWindow( szGameWindow, NULL );
- if ( ccwindow ) {
-
- Msg( __LINE__, TEXT(__FILE__), TEXT("Found Game Window."));
-
- if( IsIconic( ccwindow )){
- ShowWindow( ccwindow, SW_RESTORE );
- }
- SetForegroundWindow( ccwindow );
- } else {
- Msg( __LINE__, TEXT(__FILE__), TEXT("Looking for Setup Window."));
- ccwindow = FindWindow( szSetupWindow, NULL );
- if ( ccwindow ) {
- Msg( __LINE__, TEXT(__FILE__), TEXT("Found Setup Window."));
- if( IsIconic( ccwindow )){
- ShowWindow( ccwindow, SW_RESTORE );
- }
- BOOL result = SetForegroundWindow( ccwindow );
- Msg( __LINE__, TEXT(__FILE__), TEXT("SetForegroundWindow = %d."), result );
- }
- }
- //---------------------------------------------------------------------
- // Handle(s) are closed in the ProgEnd().
- //---------------------------------------------------------------------
- return 0;
- }
- //---------------------------------------------------------------------
- // Check if Game/Setup is already running, and is looking for the CDRom.
- //---------------------------------------------------------------------
- HWND prev = FindWindow( szClassName, NULL );
- if ( prev == NULL ) {
- prev = FindWindow( szGameWindow, NULL );
- if ( prev == NULL ) {
- prev = FindWindow( szSetupWindow, NULL );
- }
- }
- if( prev ){
- if( IsIconic( prev )){
- ShowWindow( prev, SW_RESTORE );
- }
- SetForegroundWindow( prev );
- Msg( __LINE__, __FILE__, "Either same app, game or setup was found. Exit and set window to foreground." );
- return 0;
- }
- //---------------------------------------------------------------------
- // Check if another installshield session is already running. This happens
- // because we ask the user to insert CD-1 again at the end of the install
- // to prevent a crash on Windows ME where it tries to access CD-1 again.
- //---------------------------------------------------------------------
- prev = FindWindow( NULL,"InstallShield Wizard");
- if( prev ){
- return 0;
- }
- //=========================================================================
- // Select Sounds.
- //=========================================================================
- memset( szButtonWav, '\0', _MAX_PATH );
- _tcscpy( szButtonWav, _TEXT( MOUSE_WAV ));
- // memset( szSpeechWav, '\0', _MAX_PATH );
- // _tcscpy( szSpeechWav, _TEXT( AUTORUN_WAV ));
- if( LanguageID == LANG_USA ) {
- strcpy( szWavs[0], SOUND_FILE1 );
- strcpy( szWavs[1], SOUND_FILE2 );
- // Pick a number between 0 and 1. ( NUM_SONGS - 1 )
- // Seed the random-number generator with current time so that
- // the numbers will be different every time we run.
- Msg( __LINE__, __FILE__, "szWav[0] = %s.", szWavs[0] );
- Msg( __LINE__, __FILE__, "szWav[1] = %s.", szWavs[1] );
- srand(( unsigned )time( NULL ));
- SongNumber = rand() & 1;
- // UseSounds = TRUE;
- Msg( __LINE__, __FILE__, "SongNumber = %d.", SongNumber );
- Msg( __LINE__, __FILE__, "UseSounds = %d.", UseSounds );
- }
- //-------------------------------------------------------------------------
- // Get the CD volume to check on which CD in the product we are on.
- //-------------------------------------------------------------------------
- // strcpy( szBuffer, Args->Get_argv(0));
- // CDList.Get_Volume_For_This_CD_Drive( szBuffer, szVolumeName );
- // Msg( __LINE__, __FILE__, "szVolumeName = %s.", szVolumeName );
- //-------------------------------------------------------------------------
- // Check if we are on the CD-ROM and in Windows 95.
- //-------------------------------------------------------------------------
- if ( !Valid_Environment( )) {
- return( -1 );
- }
- //=========================================================================
- // Lock the CD!
- //=========================================================================
- // memset( szPath, '\0', _MAX_PATH );
- // szPath[0] = (char)( toupper( szArgvPath[0] ));
- // strcat( szPath, ":\\" );
- //-------------------------------------------------------------------------
- // NOTE: Based on A=0, B=1, etc.
- //-------------------------------------------------------------------------
- //#if(!PRETEND_ON_CD_TEST)
- char driveLetter = Args->Get_argv(0)[0];
- Msg( __LINE__, TEXT(__FILE__), TEXT("About to lock on CD: %c:\\ "), toupper( driveLetter ));
- // CDLocked = CDControl.Lock_CD_Tray((unsigned)( toupper( szPath[0] ) - 'A' ));
- CDLocked = CDControl.Lock_CD_Tray((unsigned)( toupper( driveLetter ) - 'A' ));
- Msg( __LINE__, TEXT(__FILE__), TEXT("CDLocked = %d. "), CDLocked );
- //#endif
- //=========================================================================
- // Set the buttons images. Use when images are unique for each button.
- //=========================================================================
- strcpy( ButtonImages[0], BUTTON_REG );
- strcpy( ButtonImages[1], BUTTON_REG );
- strcpy( ButtonImages[2], BUTTON_REG );
- strcpy( ButtonImages[3], BUTTON_REG );
- strcpy( ButtonImages[4], BUTTON_REG );
- strcpy( ButtonImages[5], BUTTON_REG );
- strcpy( ButtonImages[6], BUTTON_REG );
- strcpy( ButtonImages[7], BUTTON_REG );
- strcpy( ButtonImages[8], BUTTON_REG );
- strcpy( ButtonImages[9], BUTTON_REG );
- strcpy( FocusedButtonImages[0], BUTTON_SEL );
- strcpy( FocusedButtonImages[1], BUTTON_SEL );
- strcpy( FocusedButtonImages[2], BUTTON_SEL );
- strcpy( FocusedButtonImages[3], BUTTON_SEL );
- strcpy( FocusedButtonImages[4], BUTTON_SEL );
- strcpy( FocusedButtonImages[5], BUTTON_SEL );
- strcpy( FocusedButtonImages[6], BUTTON_SEL );
- strcpy( FocusedButtonImages[7], BUTTON_SEL );
- strcpy( FocusedButtonImages[8], BUTTON_SEL );
- strcpy( FocusedButtonImages[9], BUTTON_SEL );
- //=========================================================================
- // A Windows class should be registered with Windows before any windows
- // of that type are created. Register here all Windows classes that
- // will be used in the program.
- //-------------------------------------------------------------------------
- // Register the class only AFTER WinMain assigns appropriate values to
- // static members of Main and only if no previous instances of the program
- // exist (a previous instance would have already performed the registration).
- //=========================================================================
- if ( !Main::hPrevInstance ) {
- MainWindow::Register();
- }
- //-------------------------------------------------------------------------
- // Create MainWnd, calls MainWindow Constructor.
- //-------------------------------------------------------------------------
- MainWindow MainWnd;
- //-------------------------------------------------------------------------
- // Begin processing Window Messages.
- //-------------------------------------------------------------------------
- return( Main::MessageLoop( ));
- }
- //*****************************************************************************
- // Prog_End -- Close all objects that were created.
- //
- // INPUT: none.
- //
- // OUTPUT: int.
- //
- // WARNINGS: none.
- //
- // HISTORY:
- // 01/22/2001 MML : Created.
- //=============================================================================
- void Prog_End ( void )
- {
- //==========================================================================
- // UnLock the CD!
- //==========================================================================
- if( CDLocked ) {
- CDControl.Unlock_CD_Tray((unsigned)( toupper( szArgvPath[0] ) - 'A' ));
- CDLocked = false;
- }
- if( Args != NULL ) {
- delete( Args );
- Args = NULL;
- Msg( __LINE__, __FILE__, "Args deleted." );
- }
- if ( AppMutex != NULL ) {
- CloseHandle( AppMutex );
- AppMutex = NULL;
- Msg( __LINE__, __FILE__, "AppMutex deleted." );
- }
- if ( GameAppMutex != NULL) {
- CloseHandle( GameAppMutex );
- GameAppMutex = NULL;
- }
- if ( FontManager != NULL ) {
- delete( FontManager );
- FontManager = NULL;
- Msg( __LINE__, __FILE__, "FontManager deleted." );
- }
- if ( OnlineOptions != NULL ) {
- delete( OnlineOptions );
- OnlineOptions = NULL;
- Msg( __LINE__, __FILE__, "OnlineOptions deleted." );
- }
- //-------------------------------------------------------------------------
- // Delete language resource file.
- //-------------------------------------------------------------------------
- Locale_Restore();
- Debug_Date_And_Time_Stamp();
- }
- //*****************************************************************************
- // Main::MessageLoop -- Dispatch Message Loop.
- //
- // INPUT: none.
- //
- // OUTPUT: int.
- //
- // WARNINGS: none.
- //
- // HISTORY:
- // 06/04/1996 MML : Created.
- //=============================================================================
- int Main::MessageLoop( void )
- {
- MSG msg;
- while( GetMessage( &msg, NULL, 0, 0 )) {
- TranslateMessage( &msg );
- DispatchMessage( &msg );
- }
- //--------------------------------------------------------------------------
- // Stop the sound if still going.
- //--------------------------------------------------------------------------
- Stop_Sound_Playing();
- //==========================================================================
- // UnLock the CD!
- //==========================================================================
- //#if(!PRETEND_ON_CD_TEST)
- if( CDLocked ) {
- CDControl.Unlock_CD_Tray((unsigned)( toupper( szArgvPath[0] ) - 'A' ));
- CDLocked = false;
- }
- //#endif
- //==========================================================================
- // Something to launch?
- //==========================================================================
- if( LaunchObject.Launch_A_Program()) {
- LaunchObject.Launch();
- }
- return( msg.wParam );
- }
- //*****************************************************************************
- // MainWindow::Register -- Register the Main Window.
- //
- // INPUT: none.
- //
- // OUTPUT: none.
- //
- // WARNINGS: none.
- //
- // HISTORY:
- // 06/04/1996 MML : Created.
- //=============================================================================
- void MainWindow::Register( void )
- {
- //--------------------------------------------------------------------------
- // Structure used to register Windows class.
- //--------------------------------------------------------------------------
- WNDCLASSEX wndclass;
- //--------------------------------------------------------------------------
- // set up and register window class
- //--------------------------------------------------------------------------
- wndclass.cbSize = sizeof(WNDCLASSEX);
- wndclass.style = CS_HREDRAW | CS_VREDRAW;
- wndclass.lpfnWndProc = Wnd_Proc;
- wndclass.cbClsExtra = 0;
- //--------------------------------------------------------------------------
- // Reserve extra bytes for each instance of the window. We will use these
- // bytes to store a pointer to the C++ (MainWindow) object corresponding
- // to the window. The size of a 'this' pointer depends on the memory model.
- //--------------------------------------------------------------------------
- wndclass.cbWndExtra = sizeof( MainWindow * );
- wndclass.hInstance = Main::hInstance;
- wndclass.hIcon = LoadIcon( Main::hInstance, MAKEINTRESOURCE(1));
- // strcpy( szBuffer, "C&C2.ICO" );
- // wndclass.hIcon = (HICON)LoadImage( NULL, szBuffer, IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_LOADFROMFILE );
- wndclass.hCursor = LoadCursor( Main::hInstance, MAKEINTRESOURCE(2) );
- wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
- wndclass.lpszMenuName = szClassName;
- wndclass.lpszClassName = szClassName;
- wndclass.hIconSm = LoadIcon( Main::hInstance, MAKEINTRESOURCE(1));
- if ( !RegisterClassEx((const WNDCLASSEX *) &wndclass ) ) {
- #if(_DEBUG)
- LPVOID szMessage;
- FormatMessage(
- FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
- NULL,
- GetLastError(),
- MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ),
- (LPTSTR)&szMessage,
- 0,
- NULL );
- _stprintf( szBuffer, TEXT( "%s(%lx)" ), szMessage, GetLastError());
- Msg( __LINE__, TEXT(__FILE__), TEXT("GetLastError: %s"), szBuffer );
- #endif
- exit( FALSE );
- }
- }
- //*****************************************************************************
- // MainWindow::MainWindow -- Main Window Constructor function.
- //
- // INPUT: none.
- //
- // OUTPUT: none.
- //
- // WARNINGS: none.
- //
- // HISTORY:
- // 06/04/1996 MML : Created.
- //=============================================================================
- MainWindow::MainWindow( void )
- {
- char szTitle[ _MAX_PATH ];
- hWnd = 0;
- #ifdef LEAN_AND_MEAN
- WideCharToMultiByte( CodePage, 0, szFullProductName, _MAX_PATH, szBuffer, _MAX_PATH, NULL, NULL );
- #else
- WideCharToMultiByte( CodePage, 0, fullProductName.str(), fullProductName.getLength()+1, szBuffer, _MAX_PATH, NULL, NULL );
- #endif
- memset( szTitle, '\0', _MAX_PATH );
- sprintf( szTitle, CLASS_NAME, szBuffer );
- //--------------------------------------------------------------------------
- // Create the MainWindow.
- // Pass 'this' pointer in lpParam of CreateWindow().
- //--------------------------------------------------------------------------
- hWnd = CreateWindowEx(
- 0,
- szClassName,
- szClassName,
- WS_POPUPWINDOW | WS_MINIMIZE | !WS_VISIBLE,
- 0,
- 0,
- 640,
- 480,
- NULL,
- NULL,
- Main::hInstance,
- (LPTSTR) this );
- if ( !hWnd ) {
- Stop_Sound_Playing();
- exit( FALSE );
- }
- ApplicationHWnd = hWnd;
- //-------------------------------------------------------------------------
- // Save the pointer so we can access it globally.
- //-------------------------------------------------------------------------
- GlobalMainWindow = this;
- //--------------------------------------------------------------------------
- // If you want to see the Background Window, enable these.
- //--------------------------------------------------------------------------
- // Show( Main::nCmdShow );
- // Update();
- }
- //*****************************************************************************
- // MainWindow::Window_Proc -- Main Window Procedure fnc to process msgs.
- //
- // INPUT: none.
- //
- // OUTPUT: none.
- //
- // WARNINGS: none.
- //
- // HISTORY:
- // 06/04/1996 MML : Created.
- //=============================================================================
- LRESULT MainWindow::Window_Proc( HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam )
- {
- static RECT rect;
- static int cxChar, cyChar;
- static HBRUSH hBrush = 0;
- static POINT point;
- int decision;
- static int bits_pixel = 0;
- switch( iMessage ) {
- //-----------------------------------------------------------------------
- // Create Message.
- //-----------------------------------------------------------------------
- case WM_CREATE:
- #if(0)
- hBrush = CreateSolidBrush( GetSysColor( COLOR_WINDOW ));
- #endif
- GetClientRect( GetDesktopWindow(), &rect );
- SendMessage( hWnd, WM_GO, wParam, lParam );
- break;
- //-----------------------------------------------------------------------
- // Go!
- //-----------------------------------------------------------------------
- case WM_GO:
- decision = DialogBox( Main::hInstance, _TEXT( "BitmapDialog" ), hWnd, Dialog_Box_Proc );
- if ( Args ) {
- delete( Args );
- Args = NULL;
- }
- Stop_Sound_Playing();
- MoveWindow( hWnd, 0, 0, 0, 0, TRUE );
- SendMessage( hWnd, WM_DESTROY, wParam, lParam );
- Msg( __LINE__, TEXT(__FILE__), TEXT("---------------------- end of WM_GO ---------------------" ));
- break;
- //-----------------------------------------------------------------------
- // WM_CTLCOLOR Message.
- // wParam Handle to Child Window's device context
- // LOWORD( lParam ) Child Window handle
- // HIWORD( lParam ) Type of Window: CTLCOLOR_MSGBOX, _EDIT, _LISTBOX, _BTN, _DLG, _SCROLLBAR, _STATIC
- //-----------------------------------------------------------------------
- #if( WINDOW_BRUSH )
- case WM_CTLCOLOR:
- if ( HIWORD( lParam ) == CTLCOLOR_BTN ) {
- SetBkColor( (HDC)wParam, GetSysColor( COLOR_WINDOW ));
- SetTextColor( (HDC)wParam, GetSysColor( COLOR_WINDOWTEXT ));
- UnrealizeObject( hBrush ); // reset the origin of the brush next time used.
- point.x = point.y = 0; // create a point.
- ClientToScreen( hWnd, &point ); // translate into screen coordinates.
- SetBrushOrg( (HDC)wParam, point.x, point.y ); // New Origin to use when next selected.
- return ((DWORD) hBrush);
- }
- break;
- //-----------------------------------------------------------------------
- // WM_SYSCOLORCHANGE Message.
- //-----------------------------------------------------------------------
- case WM_SYSCOLORCHANGE:
- DeleteObject( hBrush );
- hBrush = CreateSolidBrush( GetSysColor( COLOR_WINDOW ));
- break;
- //-----------------------------------------------------------------------
- // WM_SIZE Message.
- //-----------------------------------------------------------------------
- case WM_SIZE:
- rect.left = 24 * cxChar;
- rect.top = 2 * cyChar;
- rect.right = LOWORD( lParam );
- rect.bottom = HIWORD( lParam );
- break;
- #endif
- //-----------------------------------------------------------------------
- // WM_COMMAND Message.
- // wParam Child Window ID
- // LOWORD( lParam ) Child Window handle
- // HIWORD( lParam ) Notification Code: BN_CLICKED, BN_PAINT, etc...
- //-----------------------------------------------------------------------
- case WM_COMMAND:
- break;
- //-----------------------------------------------------------------------
- // WM_DESTROY Message.
- //-----------------------------------------------------------------------
- case WM_DESTROY:
- #if(WINDOW_BRUSH)
- DeleteObject( hBrush );
- #endif
- PostQuitMessage( 0 );
- break;
- default:
- return DefWindowProc( hWnd, iMessage, wParam, lParam );
- }
- return 0;
- }
- //*****************************************************************************
- // MainWindow::Is_Product_Registered -- Check the Registration Table information.
- //
- // INPUT: none.
- //
- // OUTPUT: BOOL - TRUE if product is already installed, FALSE if not.
- //
- // WARNINGS: none.
- //
- // HISTORY:
- // 06/04/1996 MML : Created.
- //=============================================================================
- BOOL MainWindow::Is_Product_Registered( void )
- {
- HKEY phKey;
- BOOL result = FALSE;
- char key [_MAX_PATH];
- wchar_t szPath [_MAX_PATH];
- char aName [_MAX_PATH]; //jfs
- unsigned long Type;
- unsigned long Size = _MAX_PATH;
- HANDLE handle;
- WIN32_FIND_DATA FindFileData;
- memset( szPath, '\0', sizeof( szPath ));
- memset( szGamePath, '\0', sizeof( szGamePath ));
- memset( szSetupPath, '\0', sizeof( szSetupPath ));
- memset( szRegisterPath, '\0', sizeof( szRegisterPath ));
- memset( szInternetPath, '\0', sizeof( szInternetPath ));
- memset( szUninstallPath, '\0', sizeof( szUninstallPath ));
- memset( szUninstallCommandLine, '\0', sizeof( szUninstallCommandLine ));
- memset( FindFileData.cFileName, '\0', sizeof( FindFileData.cFileName ));
- memset( FindFileData.cAlternateFileName, '\0', sizeof( FindFileData.cAlternateFileName ));
- InstallProduct = TRUE;
- UninstallAvailable = FALSE;
- DisplayRegisterButton = FALSE;
- IsWolapiAvailable = FALSE;
- IsUserRegistered = FALSE;
- //==========================================================================
- // Look for keys under the Game's Registry key.
- //==========================================================================
- // _tcscat( _tcscpy( key, SOFTWARE_EAGAMES_KEY ), szRegistryKey );
- _tcscat( _tcscpy( key, EAGAMES_GENERALS_KEY ), szRegistryKey );
- //--------------------------------------------------------------------------
- // Try to open the key.
- //--------------------------------------------------------------------------
- if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE, key, 0, KEY_QUERY_VALUE, &phKey ) == ERROR_SUCCESS ) {
- //-----------------------------------------------------------------------
- // Get Full path\filename of product to execute ("Play").
- //-----------------------------------------------------------------------
- Size = _MAX_PATH;
- if ( RegQueryValueEx( phKey, INSTALL_PATH_KEY, NULL, &Type, (unsigned char *)szGamePath, &Size ) == ERROR_SUCCESS ) {
- _tcscpy(szWorldbuilderPath, szGamePath);
- _tcscpy(szPatchgetPath, szGamePath);
- _tcscat(szGamePath, LAUNCHER_FILENAME);
- _tcscat(szWorldbuilderPath, WORLDBUILDER_FILENAME);
- _tcscat(szPatchgetPath, PATCHGET_FILENAME);
- handle = FindFirstFile( szGamePath, &FindFileData );
- if ( handle != INVALID_HANDLE_VALUE ) {
- InstallProduct = FALSE;
- FindClose( handle );
- }
- }
- Msg( __LINE__, TEXT(__FILE__), TEXT("GamePath = %s."), szGamePath );
- RegCloseKey( phKey );
- }
- //==========================================================================
- // Find Keys under "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall"
- //==========================================================================
- _tcscpy( key, SHELL_UNINSTALL_KEY );
- Path_Add_Back_Slash( key );
- _tcscat( key, szRegistryKey );
- //--------------------------------------------------------------------------
- // Query the Uninstall key "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall"
- //--------------------------------------------------------------------------
- if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE, key, 0, KEY_ALL_ACCESS, &phKey ) == ERROR_SUCCESS ) {
- Size = _MAX_PATH;
- if ( RegQueryValueEx( phKey, UNINSTALL_STRING_SUBKEY, NULL, &Type, (unsigned char *)aName, &Size ) == ERROR_SUCCESS )
- {
- //------------------------------------------------------------------------------------------------------
- // Look for the uninstall program. If found, set flag.
- // JFS... need to extract path and command line... 8/26/03
- // JFS... further verify that we use a very limited uninstall based on the presence of "IDriver.exe"
- //------------------------------------------------------------------------------------------------------
- if(strstr(aName,UNINSTALL_EXECUTABLE) != NULL)
- {
- char *sp;
-
- strcpy( szUninstallPath, aName );
- sp = strchr(szUninstallPath,'/');
- if(*sp != NULL)
- {
- strcpy( szUninstallCommandLine, sp );
- strcpy( szUninstallPath, aName );
- *sp = '\0';
- }
- }
-
- handle = FindFirstFile( szUninstallPath, &FindFileData );
- if ( handle != INVALID_HANDLE_VALUE ) {
- UninstallAvailable = TRUE;
- FindClose( handle );
- }
- }
- RegCloseKey( phKey );
- }
- //==========================================================================
- // Look for keys under Register. If available, we should show the "Register"
- // button. WESTWOOD_REGISTER_KEY "Software\\Westwood\\Register"
- //==========================================================================
- // _tcscpy( key, WESTWOOD_REGISTER_KEY );
- //-------------------------------------------------------------------------
- // Create IGR Options Object.
- //-------------------------------------------------------------------------
- IGROptionsClass *OnlineOptions = new IGROptionsClass();
- if ( OnlineOptions ) {
- OnlineOptions->Init();
- }
- //--------------------------------------------------------------------------
- // If "Options" is set under WOLAPI, then this is a Game Room Edition and
- // registration should NOT be allowed.
- //--------------------------------------------------------------------------
- if ( OnlineOptions ) {
- DisplayRegisterButton = OnlineOptions->Is_Running_Reg_App_Allowed();
- }
- //--------------------------------------------------------------------------
- // If Registration is allowed...
- //--------------------------------------------------------------------------
- /*
- if ( DisplayRegisterButton ) {
- DisplayRegisterButton = false;
- if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE, key, 0, KEY_QUERY_VALUE, &phKey ) == ERROR_SUCCESS ) {
- //-----------------------------------------------------------------------
- // Get Full path\filename of product to execute ("Register.exe").
- //-----------------------------------------------------------------------
- Size = _MAX_PATH;
- if ( RegQueryValueEx( phKey, INSTALLPATH_SUBKEY, NULL, &Type, (unsigned char *)szRegisterPath, &Size ) == ERROR_SUCCESS ) {
- //--------------------------------------------------------------------
- // Check if this executable exists.
- //--------------------------------------------------------------------
- handle = FindFirstFile( szRegisterPath, &FindFileData );
- if ( handle != INVALID_HANDLE_VALUE ) {
- DisplayRegisterButton = TRUE;
- FindClose( handle );
- }
- }
- RegCloseKey( phKey );
- }
- }
- */
- //==========================================================================
- // Is WOLAPI DLL installed?
- //==========================================================================
- /*
- _tcscpy( key, WESTWOOD_WOLAPI_KEY );
- if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE, key, 0, KEY_QUERY_VALUE, &phKey ) == ERROR_SUCCESS ) {
- //-----------------------------------------------------------------------
- // Get Full path\filename of product to execute ("Register.exe").
- //-----------------------------------------------------------------------
- Size = _MAX_PATH;
- if ( RegQueryValueEx( phKey, INSTALLPATH_SUBKEY, NULL, &Type, (unsigned char *)szBuffer, &Size ) == ERROR_SUCCESS ) {
- //--------------------------------------------------------------------
- // Check if this executable exists.
- //--------------------------------------------------------------------
- handle = FindFirstFile( szBuffer, &FindFileData );
- if ( handle != INVALID_HANDLE_VALUE ) {
- IsWolapiAvailable = TRUE;
- FindClose( handle );
- }
- }
- RegCloseKey( phKey );
- }
- */
- Msg( __LINE__, TEXT(__FILE__), TEXT("---------------- Is_Product_Registered---------------" ));
- Msg( __LINE__, TEXT(__FILE__), TEXT(" InstallProduct = %d."), InstallProduct );
- Msg( __LINE__, TEXT(__FILE__), TEXT(" UninstallAvailable = %d."), UninstallAvailable );
- Msg( __LINE__, TEXT(__FILE__), TEXT(" IsUserRegistered = %d."), IsUserRegistered );
- Msg( __LINE__, TEXT(__FILE__), TEXT(" DisplayRegisterButton = %d."), DisplayRegisterButton );
- Msg( __LINE__, TEXT(__FILE__), TEXT(" szGamePath = %s."), szGamePath );
- Msg( __LINE__, TEXT(__FILE__), TEXT(" szSetupPath = %s."), szSetupPath );
- Msg( __LINE__, TEXT(__FILE__), TEXT(" szRegisterPath = %s."), szRegisterPath );
- Msg( __LINE__, TEXT(__FILE__), TEXT(" szInternetPath = %s."), szInternetPath );
- Msg( __LINE__, TEXT(__FILE__), TEXT(" szUninstallPath = %s."), szUninstallPath );
- return( result );
- }
- //*****************************************************************************
- // MainWindow::Run_Explorer
- //
- // Get the Current Dir from argv[0]. Open the Explorer Window with
- // this dir. The Explorer will open and display everything in this dir.
- //
- // INPUT: none.
- //
- // OUTPUT: none.
- //
- // WARNINGS: none.
- //
- // HISTORY:
- // 06/04/1996 MML : Created.
- //=============================================================================
- BOOL MainWindow::Run_Explorer( char *szString, HWND hWnd, RECT *rect )
- {
- char szWindowsPath [ _MAX_PATH ];
- char szPath [ _MAX_PATH ];
- char szCurDir [ _MAX_PATH ];
- char drive [ _MAX_DRIVE ];
- char dir [ _MAX_DIR ];
- char lpszComLine [ 127 ];
- BOOL result = FALSE;
- PROCESS_INFORMATION processinfo;
- STARTUPINFO startupinfo;
- //--------------------------------------------------------------------------
- // Get current drive/directory from _argv[0].
- //--------------------------------------------------------------------------
- _tcscpy( szPath, szArgvPath );
- _tsplitpath( szPath, drive, dir, NULL, NULL );
- _tmakepath ( szPath, drive, dir, NULL, NULL );
- //--------------------------------------------------------------------------
- // Get Windows directory and build path to Explorer. Pas in szPath as
- // the directory for Explorer to open.
- //--------------------------------------------------------------------------
- GetWindowsDirectory( szWindowsPath, _MAX_PATH );
- Path_Add_Back_Slash( szWindowsPath );
- _tcscat( szWindowsPath, EXPLORER_NAME );
- _tcscat( _tcscat( _tcscpy( lpszComLine, szWindowsPath ), _TEXT( " " )), szPath );
- _tcscpy( szCurDir, szPath );
- //==========================================================================
- // Setup the call
- //==========================================================================
- memset( &startupinfo, 0, sizeof( STARTUPINFO ));
- startupinfo.cb = sizeof( STARTUPINFO );
- //--------------------------------------------------------------------------
- // Next, start the process
- //--------------------------------------------------------------------------
- result = CreateProcess(
- szWindowsPath, // address of module name
- lpszComLine, // address of command line
- NULL, // address of process security attributes
- NULL, // address of thread security attributes
- FALSE, // new process inherits handles
- 0, // creation flags
- NULL, // address of new environment block
- szCurDir, // address of current directory name
- &startupinfo, // address of STARTUPINFO
- &processinfo ); // address of PROCESS_INFORMATION
- //--------------------------------------------------------------------------
- // If WinExec returned 0, error occurred.
- //--------------------------------------------------------------------------
- if ( !result ) {
- Cant_Find_MessageBox ( Main::hInstance, szPath );
- #if(BACKGROUND_BITMAP)
- //-----------------------------------------------------------------------
- // Recreate Buttons based on Registry, then repaint window.
- //-----------------------------------------------------------------------
- Create_Buttons( hWnd, rect );
- InvalidateRect( hWnd, rect, FALSE );
- #endif
- }
- return ( result );
- }
- //*****************************************************************************
- // MainWindow::Run_Game -- Launch the game based on registry information.
- //
- // INPUT: none.
- //
- // OUTPUT: none.
- //
- // WARNINGS: none.
- //
- // HISTORY:
- // 06/04/1996 MML : Created.
- //=============================================================================
- unsigned int MainWindow::Run_Game ( HWND hWnd, RECT *rect )
- {
- char dir [_MAX_DIR];
- char ext [_MAX_EXT];
- char drive [_MAX_DRIVE];
- char file [_MAX_FNAME];
- // unsigned abc = 0;
- HANDLE handle;
- WIN32_FIND_DATA FindFileData;
- //--------------------------------------------------------------------------
- // Check if C&C is already running, and is looking for the CDRom.
- // The Autorun keeps asking to "Play" when this happens.
- //--------------------------------------------------------------------------
- HWND game_window = FindWindow ( szGameWindow, NULL );
- if ( game_window ){
- ShowWindow( game_window, SW_RESTORE );
- SetForegroundWindow ( game_window );
- return FALSE;
- }
- //--------------------------------------------------------------------------
- // Split into parts.
- //--------------------------------------------------------------------------
- _tsplitpath( szGamePath, drive, dir, file, ext );
- //--------------------------------------------------------------------------
- // Launch the game.
- //--------------------------------------------------------------------------
- handle = FindFirstFile( szGamePath, &FindFileData );
- if ( handle == INVALID_HANDLE_VALUE ) {
- return FALSE;
- }
- FindClose( handle );
- //-----------------------------------------------------------------------
- // Stop Sound if sound was playing.
- //-----------------------------------------------------------------------
- Stop_Sound_Playing();
- LaunchObject.SetPath( szGamePath );
- LaunchObject.Set_Launch( true );
- return( true );
- }
- //*****************************************************************************
- // MainWindow::Run_WorldBuilder -- Launch the map editor based on registry information.
- //
- // INPUT: none.
- //
- // OUTPUT: none.
- //
- // WARNINGS: none.
- //
- // HISTORY:
- // 12/02/2002 BGC : Created.
- //=============================================================================
- unsigned int MainWindow::Run_WorldBuilder( HWND hWnd, RECT *rect)
- {
- HANDLE handle;
- WIN32_FIND_DATA FindFileData;
- //--------------------------------------------------------------------------
- // Launch the game.
- //--------------------------------------------------------------------------
- handle = FindFirstFile( szWorldbuilderPath, &FindFileData );
- if ( handle == INVALID_HANDLE_VALUE ) {
- return FALSE;
- }
- FindClose( handle );
- //-----------------------------------------------------------------------
- // Stop Sound if sound was playing.
- //-----------------------------------------------------------------------
- Stop_Sound_Playing();
- LaunchObject.SetPath( szWorldbuilderPath );
- LaunchObject.Set_Launch( true );
- return( true );
- }
- //*****************************************************************************
- // MainWindow::Run_PatchGet -- Launch the patch checker based on registry information.
- //
- // INPUT: none.
- //
- // OUTPUT: none.
- //
- // WARNINGS: none.
- //
- // HISTORY:
- // 12/02/2002 BGC : Created.
- //=============================================================================
- unsigned int MainWindow::Run_PatchGet( HWND hWnd, RECT *rect)
- {
- HANDLE handle;
- WIN32_FIND_DATA FindFileData;
- //--------------------------------------------------------------------------
- // Launch the game.
- //--------------------------------------------------------------------------
- handle = FindFirstFile( szPatchgetPath, &FindFileData );
- if ( handle == INVALID_HANDLE_VALUE ) {
- return FALSE;
- }
- FindClose( handle );
- //-----------------------------------------------------------------------
- // Stop Sound if sound was playing.
- //-----------------------------------------------------------------------
- Stop_Sound_Playing();
- LaunchObject.SetPath( szPatchgetPath );
- LaunchObject.Set_Launch( true );
- return( true );
- }
- //*****************************************************************************
- // MainWindow::Run_Demo -- Launch a demo program if desired.
- //
- // INPUT: none.
- //
- // OUTPUT: none.
- //
- // WARNINGS: none.
- //
- // HISTORY:
- // 01/08/2002 MML : Created.
- //=============================================================================
- unsigned int MainWindow::Run_Demo ( HWND hWnd, RECT *rect, int cd_drive )
- {
- // unsigned abc = 0;
- HANDLE handle;
- WIN32_FIND_DATA FindFileData;
- //--------------------------------------------------------------------------
- // Make path to demo program.
- //--------------------------------------------------------------------------
- // Make_Current_Path_To( MOH_DEMO_PROGRAM, szBuffer );
- wsprintf( szBuffer, "%c:\\", 'A' + cd_drive );
- Path_Add_Back_Slash( szBuffer );
- strcat( szBuffer, MOH_DEMO_PROGRAM );
- //--------------------------------------------------------------------------
- // Launch the game.
- //--------------------------------------------------------------------------
- handle = FindFirstFile( szBuffer, &FindFileData );
- if ( handle == INVALID_HANDLE_VALUE ) {
- Cant_Find_MessageBox( Main::hInstance, szBuffer );
- return FALSE;
- }
- FindClose( handle );
- //-----------------------------------------------------------------------
- // Stop Sound if sound was playing.
- //-----------------------------------------------------------------------
- Stop_Sound_Playing();
- LaunchObject.SetPath( szBuffer );
- LaunchObject.Set_Launch( true );
- return( true );
- }
- //*****************************************************************************
- // MainWindow::Run_OpenFile -- Main Window function to perform Setup tasks.
- //
- // INPUT: none.
- //
- // OUTPUT: none.
- //
- // WARNINGS: none.
- //
- // HISTORY:
- // 06/04/1996 MML : Created.
- //=============================================================================
- unsigned int MainWindow::Run_OpenFile(int cd_drive, const char *filename, bool wait /* = false */)
- {
- char filepath[MAX_PATH];
- MSG msg;
- BOOL returnValue;
- SHELLEXECUTEINFO executeInfo;
- memset(&executeInfo, 0, sizeof(executeInfo));
- executeInfo.cbSize = sizeof(executeInfo);
- executeInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
- executeInfo.hwnd = ApplicationHWnd;
- executeInfo.lpVerb = "open";
- executeInfo.lpFile = filename;
- executeInfo.nShow = SW_SHOWNORMAL;
- HANDLE hProcess;
- BOOL ret = ShellExecuteEx(&executeInfo);
- if ((ret == 0) || ((int)(executeInfo.hInstApp) <= 32)) {
- Msg(__LINE__, TEXT(__FILE__), TEXT("Couldn't find executable for %s\n"), filepath);
- return 0;
- }
- hProcess = executeInfo.hProcess;
- if (wait == true) {
- WaitForInputIdle(hProcess, 5000);
- bool waiting = true;
- bool quit = false;
- while ((waiting == true) && (quit != true)) {
- Sleep(0);
- while( PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) )
- {
- // get the message
- returnValue = GetMessage( &msg, NULL, 0, 0 );
- // check for quitting
- if( returnValue == 0 )
- quit = TRUE;
- // translate and dispatch the message
- TranslateMessage( &msg );
- DispatchMessage( &msg );
- } // end while
- DWORD exitCode;
- GetExitCodeProcess(hProcess, &exitCode);
- if (exitCode != STILL_ACTIVE) {
- waiting = false;
- }
- }
- }
- return 1;
- }
- //*****************************************************************************
- // MainWindow::Run_Setup -- Main Window function to perform Setup tasks.
- //
- // INPUT: none.
- //
- // OUTPUT: none.
- //
- // WARNINGS: none.
- //
- // HISTORY:
- // 06/04/1996 MML : Created.
- //=============================================================================
- unsigned int MainWindow::Run_Setup( HWND hWnd, RECT *rect, int cd_drive )
- {
- // UINT result = 0;
- int i = 0;
- char params [ 127 ];
- char filepath[ _MAX_PATH ];
- HANDLE handle;
- WIN32_FIND_DATA FindFileData;
- Msg( __LINE__, TEXT(__FILE__), TEXT("---------------------- Run_Setup --------------------." ));
- //--------------------------------------------------------------------------
- // Clear these buffers for later use.
- //--------------------------------------------------------------------------
- memset( params, '\0', 127 );
- //--------------------------------------------------------------------------
- // Get Drive & Dir from ARGV[0] and create path to SETUP.EXE.
- //--------------------------------------------------------------------------
- // strcpy( filepath, szArgvPath );
- // Path_Add_Back_Slash( filepath );
- wsprintf( filepath, "%c:\\", 'A' + cd_drive );
- Path_Add_Back_Slash( filepath );
- strcat( filepath, SETUP_NAME );
- //--------------------------------------------------------------------------
- // If we could not find SETUP.EXE, then display error msg and exit.
- //--------------------------------------------------------------------------
- handle = FindFirstFile( filepath, &FindFileData );
- if ( handle == INVALID_HANDLE_VALUE ) {
- Cant_Find_MessageBox( Main::hInstance, filepath );
- return FALSE;
- }
- FindClose( handle );
- //--------------------------------------------------------------------------
- // Create parameters to pass in with the program we are calling.
- //--------------------------------------------------------------------------
- memset( params, '\0', sizeof( params ));
- if ( NumberArguments ) {
- _tcscpy( params, Arguments[0] );
- i = 1;
- while (( i < NUM_ARGUMENTS ) && ( i < NumberArguments )) {
- _tcscat( _tcscat( params, _TEXT( " " )), Arguments[i] );
- i++;
- }
- }
- //--------------------------------------------------------------------------
- // Stop Sound if sound was playing.
- //--------------------------------------------------------------------------
- Stop_Sound_Playing();
- LaunchObject.SetPath( filepath );
- LaunchObject.SetArgs( params );
- LaunchObject.Set_Launch( true );
- return( true );
- }
- //*****************************************************************************
- // MainWindow::Run_New_Account -- Create a new online account.
- //
- // INPUT: none.
- //
- // OUTPUT: none.
- //
- // WARNINGS: none.
- //
- // HISTORY:
- // 06/04/1996 MML : Created.
- //=============================================================================
- unsigned int MainWindow::Run_New_Account ( HWND hWnd, RECT *rect )
- {
- // UINT result = 0;
- int i = 0;
- char params [ 127 ];
- char filepath[ _MAX_PATH ];
- HANDLE handle;
- WIN32_FIND_DATA FindFileData;
- //--------------------------------------------------------------------------
- // Clear these buffers for later use.
- //--------------------------------------------------------------------------
- memset( params, '\0', 127 );
- //--------------------------------------------------------------------------
- // Get Drive & Dir from ARGV[0] and create path to SETUP.EXE.
- //--------------------------------------------------------------------------
- _tcscpy( filepath, szArgvPath );
- Path_Add_Back_Slash( filepath );
- _tcscat( filepath, SETUP_NAME );
- //--------------------------------------------------------------------------
- // If we could not find SETUP.EXE, then display error msg and exit.
- //--------------------------------------------------------------------------
- handle = FindFirstFile( filepath, &FindFileData );
- if ( handle == INVALID_HANDLE_VALUE ) {
- Cant_Find_MessageBox( Main::hInstance, SETUP_NAME );
- return FALSE;
- }
- FindClose( handle );
- //--------------------------------------------------------------------------
- // Create parameters to pass in with the program we are calling.
- //--------------------------------------------------------------------------
- memset( params, '\0', sizeof( params ));
- if ( NumberArguments ) {
- _tcscpy( params, Arguments[0] );
- i = 1;
- while (( i < NUM_ARGUMENTS ) && ( i < NumberArguments )) {
- _tcscat( _tcscat( params, _TEXT( " " )), Arguments[i] );
- i++;
- }
- _tcscat( params, _TEXT( " " ));
- }
- _tcscat( params, "-o" );
- //--------------------------------------------------------------------------
- // Stop Sound if sound was playing.
- //--------------------------------------------------------------------------
- Stop_Sound_Playing();
- LaunchObject.SetPath( filepath );
- LaunchObject.SetArgs( params );
- LaunchObject.Set_Launch( true );
- return( true );
- }
- //*****************************************************************************
- // MainWindow::Run_Register_Or_Auto_Update
- //
- // Either run Register.exe or Game Update Program from the user's harddrive.
- //
- // INPUT: none.
- //
- // OUTPUT: none.
- //
- // WARNINGS: none.
- //
- // HISTORY:
- // 02/24/1999 MML : Created.
- //=============================================================================
- unsigned int MainWindow::Run_Register ( HWND hWnd, RECT *rect )
- {
- char szArgs[ MAX_PATH ];
- HANDLE handle;
- WIN32_FIND_DATA FindFileData;
- BOOL result = FALSE;
- //--------------------------------------------------------------------------
- // Register Program is available. Continue...
- //--------------------------------------------------------------------------
- if ( DisplayRegisterButton ) {
- //-----------------------------------------------------------------------
- // Check again. May have been changed ...
- //-----------------------------------------------------------------------
- handle = FindFirstFile( szRegisterPath, &FindFileData );
- if ( handle == INVALID_HANDLE_VALUE ) {
- return( 0 );
- }
- FindClose( handle );
- //-----------------------------------------------------------------------
- // User is already registered, so maybe we should Auto Update!
- //-----------------------------------------------------------------------
- strcpy( szArgs, _TEXT( " " ));
- LaunchObject.SetPath( szRegisterPath );
- LaunchObject.SetArgs( szArgs );
- LaunchObject.Set_Launch( true );
- result = true;
- }
- return( result );
- }
- //*****************************************************************************
- // MainWindow::Run_Auto_Update
- //
- // Either run Register.exe or Game Update Program from the user's harddrive.
- //
- // INPUT: none.
- //
- // OUTPUT: none.
- //
- // WARNINGS: none.
- //
- // HISTORY:
- // 02/24/1999 MML : Created.
- //=============================================================================
- unsigned int MainWindow::Run_Auto_Update ( HWND hWnd, RECT *rect )
- {
- char szArgs [ MAX_PATH ];
- HANDLE handle;
- WIN32_FIND_DATA FindFileData;
- BOOL result = FALSE;
- //--------------------------------------------------------------------------
- // Register Program is available. Continue...
- //--------------------------------------------------------------------------
- if ( !InstallProduct ) {
- //-----------------------------------------------------------------------
- // Check again. May have been changed ...
- //-----------------------------------------------------------------------
- handle = FindFirstFile( szGamePath, &FindFileData );
- if ( handle == INVALID_HANDLE_VALUE ) {
- return( 0 );
- }
- FindClose( handle );
- _tcscpy( szArgs, _TEXT( " GrabPatches" ));
- LaunchObject.SetPath( szGamePath );
- LaunchObject.SetArgs( szArgs );
- LaunchObject.Set_Launch( true );
- result = true;
- }
- return( result );
- }
- //*****************************************************************************
- // MainWindow::Run_Uninstall -- Main Window function to perform Setup tasks.
- //
- // INPUT: none.
- //
- // OUTPUT: none.
- //
- // WARNINGS: none.
- //
- // HISTORY:
- // 06/04/1996 MML : Created.
- //=============================================================================
- unsigned int MainWindow::Run_Uninstall( HWND hWnd, RECT *rect )
- {
- // MSG msg;
- UINT result = 0;
- // int done = 0;
- // DWORD dwTimeout = 1500;
- // DWORD dwRC = WAIT_TIMEOUT;
- DWORD lpExitCode;
- STARTUPINFO startupinfo;
- PROCESS_INFORMATION processinfo;
- HANDLE handle;
- WIN32_FIND_DATA FindFileData;
- char szCurDir [_MAX_PATH];
- char file [_MAX_FNAME];
- char ext [_MAX_EXT];
- char szPath [_MAX_PATH];
- //--------------------------------------------------------------------------
- // Launch the UNINSTALL.
- //--------------------------------------------------------------------------
- handle = FindFirstFile( szUninstallPath, &FindFileData );
- if ( handle == INVALID_HANDLE_VALUE ) {
- return( 0 );
- }
- FindClose( handle );
- _splitpath( szUninstallPath, drive, dir, NULL, NULL );
- _makepath ( szCurDir, drive, dir, NULL, NULL );
- //=======================================================================
- // Setup the call
- //=======================================================================
- memset( &startupinfo, 0, sizeof( STARTUPINFO ));
- startupinfo.cb = sizeof( STARTUPINFO );
- result = CreateProcess(
- szUninstallPath, // address of module name
- szUninstallCommandLine, // address of command line
- NULL, // address of process security attributes
- NULL, // address of thread security attributes
- 0, // new process inherits handles
- 0,
- NULL, // address of new environment block
- szCurDir,
- &startupinfo, // address of STARTUPINFO
- &processinfo ); // address of PROCESS_INFORMATION
- //--------------------------------------------------------------------------
- // If WinExec returned 0, error occurred.
- //--------------------------------------------------------------------------
- if ( !result ) {
- _tsplitpath( szUninstallPath, NULL, NULL, file, ext );
- _tmakepath ( szPath, NULL, NULL, file, ext );
- Cant_Find_MessageBox ( Main::hInstance, szPath );
- // #if(BACKGROUND_BITMAP)
- //-----------------------------------------------------------------------
- // Recreate Buttons based on Registry, then repaint window.
- //-----------------------------------------------------------------------
- // Create_Buttons( hWnd, rect );
- // InvalidateRect( hWnd, rect, FALSE );
- // #endif
- return( result );
- }
- // JFS: 8-26-03... Can't have auto run going during an uninstall!
- #if 0
- //--------------------------------------------------------------------------
- // Wait for App to shutdown
- //--------------------------------------------------------------------------
- while (dwRC == WAIT_TIMEOUT)
- {
- //-----------------------------------------------------------------------
- // Wait for object
- //-----------------------------------------------------------------------
- dwRC = WaitForSingleObject( processinfo.hProcess, dwTimeout );
- //-----------------------------------------------------------------------
- // Flush the Queue
- //-----------------------------------------------------------------------
- while (PeekMessage( &msg, NULL, 0, 0, PM_REMOVE )) {
- TranslateMessage( &msg );
- // DispatchMessage( &msg );
- }
- }
- #endif
- //--------------------------------------------------------------------------
- // If the specified process has not terminated, the termination status
- // returned is STILL_ACTIVE.
- //--------------------------------------------------------------------------
- GetExitCodeProcess( processinfo.hProcess, &lpExitCode );
- CloseHandle( processinfo.hProcess );
- CloseHandle( processinfo.hThread );
- #if(BACKGROUND_BITMAP)
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // MML 5/27/99: This function is dropping through because we launch Uninstll.exe
- // which in turn launches Uninst.exe thus ::Run_Install ends before Uninst.exe is done.
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- //--------------------------------------------------------------------------
- // Recreate Buttons based on Registry.
- // Repaint calling Window.
- //--------------------------------------------------------------------------
- Create_Buttons( hWnd, rect );
- InvalidateRect( hWnd, rect, FALSE );
- #endif
- return( result );
- }
- //*****************************************************************************
- // MainWindow::Create_Buttons -- Reset the Buttons.
- //
- // INPUT: none.
- //
- // OUTPUT: none.
- //
- // WARNINGS: none.
- //
- // HISTORY:
- // 06/04/1996 MML : Created.
- //=============================================================================
- void MainWindow::Create_Buttons( HWND hWnd, RECT *dlg_rect )
- {
- int j = 0;
- int i = 0;
- int x_pos = 0;
- int y_pos = 0;
- int width = 0;
- int height = 0;
- int button_index = 0;
- HBITMAP hButtonBitmap = 0;
- HPALETTE hpal = 0;
- BITMAP button_bm;
- char next_button_name[_MAX_PATH];
- char focused_button_name[_MAX_PATH];
- RECT * button_size = ButtonSizes;
- //--------------------------------------------------------------------------
- // Reset all the flags.
- //--------------------------------------------------------------------------
- Is_Product_Registered( );
- Msg( __LINE__, TEXT(__FILE__), TEXT("------------------------ Create_Buttons ------------------------" ));
- //--------------------------------------------------------------------------
- // Get width and height of the button.
- //--------------------------------------------------------------------------
- hButtonBitmap = LoadResourceBitmap( Main::hModule, BUTTON_REG, &hpal, TRUE );
- if ( hButtonBitmap ) {
- GetObject( hButtonBitmap, sizeof( BITMAP ), (LPTSTR)&button_bm );
- width = button_bm.bmWidth;
- height = button_bm.bmHeight;
- DeleteObject( hButtonBitmap );
- hButtonBitmap = 0;
- } else {
- button_bm.bmWidth = width = BUTTON_WIDTH;
- button_bm.bmHeight = height = BUTTON_HEIGHT;
- }
- //--------------------------------------------------------------------------
- // Initialize the ButtonList.
- //--------------------------------------------------------------------------
- if( b640X480 || b800X600 ) {
- x_pos = 410;
- y_pos = 90;
- } else {
- x_pos = 540;
- y_pos = 117;
- }
- for ( i = 0; i < NUM_BUTTONS; i++ ) {
- if ( ButtonList[i] )
- {
- delete( ButtonList[i] );
- }
- ButtonList[i] = NULL;
- ButtonSizes[i].left = x_pos; // X position.
- ButtonSizes[i].top = y_pos; // Y position.
- ButtonSizes[i].right = width; // Button's width.
- ButtonSizes[i].bottom = height; // Button's height.
- y_pos += height + 4;
- Msg( __LINE__, TEXT(__FILE__), TEXT("ButtonSizes[%d] = ( %d, %d, %d, %d )"),
- i, ButtonSizes[i].left, ButtonSizes[i].top, ButtonSizes[i].right, ButtonSizes[i].bottom );
- }
- //==========================================================================
- // Create the "Buttons"
- //==========================================================================
- i = 0;
- j = 0;
- //--------------------------------------------------------------------------
- // Make any other necessary adjustments here.
- //--------------------------------------------------------------------------
- int count = 7;
- if ( !UninstallAvailable ) {
- count--; // No uninstall button.
- }
- if ( InstallProduct ) {
- count--; // No Website button.
- }
- button_index = 0;
- strcpy( next_button_name, ButtonImages[button_index] );
- strcpy( focused_button_name, FocusedButtonImages[button_index] );
- button_size = ButtonSizes;
- i = j = button_index;
- Msg( __LINE__, TEXT(__FILE__), TEXT("count = %d."), count );
- Msg( __LINE__, TEXT(__FILE__), TEXT("button_index = %d."), button_index );
- Msg( __LINE__, TEXT(__FILE__), TEXT("next_button_name = %s."), next_button_name );
- Msg( __LINE__, TEXT(__FILE__), TEXT("focused_button_name = %s."), focused_button_name );
- //-------------------------------------------------------------------------
- // INSTALL or PLAY?
- //-------------------------------------------------------------------------
- if ( InstallProduct ) {
- //---------------------------------------------------------------------
- // (8) INSTALL button.
- //---------------------------------------------------------------------
- Msg( __LINE__, TEXT(__FILE__), TEXT("ButtonList[%d]: Id=%d, ButtonSizes=%d, String=%s."), i, IDD_OK, j, "Install" );
- ButtonList[i++] = new DrawButton(
- IDD_OK,
- button_size[j++],
- BUTTON_REG,
- BUTTON_SEL,
- BUTTON_SEL,
- #ifdef LEAN_AND_MEAN
- Locale_GetString( "Autorun:Install" ),
- #else
- AsciiString("Autorun:Install"),
- #endif
- TTButtonFontPtr );
- } else {
- //---------------------------------------------------------------------
- // (8) PLAY button.
- //---------------------------------------------------------------------
- Msg( __LINE__, TEXT(__FILE__), TEXT("ButtonList[%d]: Id=%d, ButtonSizes=%d, String=%s."), i, IDD_OK2, j, "Play" );
- ButtonList[i++] = new DrawButton(
- IDD_OK2,
- button_size[j++],
- BUTTON_REG,
- BUTTON_SEL,
- BUTTON_SEL,
- #ifdef LEAN_AND_MEAN
- Locale_GetString( "Autorun:Play" ),
- #else
- AsciiString("Autorun:Play"),
- #endif
- TTButtonFontPtr );
- /*
- //---------------------------------------------------------------------
- // (8) WorldBuilder button.
- //---------------------------------------------------------------------
- Msg( __LINE__, TEXT(__FILE__), TEXT("ButtonList[%d]: Id=%d, ButtonSizes=%d, String=%s."), i, IDD_OK2, j, "WorldBuilder" );
- // ButtonList[i--] = new DrawButton(
- ButtonList[i++] = new DrawButton(
- IDD_OK3,
- // button_size[j--],
- button_size[j++],
- BUTTON_REG,
- BUTTON_SEL,
- BUTTON_SEL,
- #ifdef LEAN_AND_MEAN
- Locale_GetString( "Autorun:Worldbuilder" ),
- #else
- AsciiString("Autorun:Worldbuilder"),
- #endif
- TTButtonFontPtr );
- */
- //---------------------------------------------------------------------
- // (8) Check for updates button.
- //---------------------------------------------------------------------
- Msg( __LINE__, TEXT(__FILE__), TEXT("ButtonList[%d]: Id=%d, ButtonSizes=%d, String=%s."), i, IDD_OK2, j, "Check For Updates" );
- // ButtonList[i--] = new DrawButton(
- ButtonList[i++] = new DrawButton(
- IDD_OK4,
- // button_size[j--],
- button_size[j++],
- BUTTON_REG,
- BUTTON_SEL,
- BUTTON_SEL,
- #ifdef LEAN_AND_MEAN
- Locale_GetString( "Autorun:CheckForUpdates" ),
- #else
- AsciiString("Autorun:CheckForUpdates"),
- #endif
- TTButtonFontPtr );
- }
- //-------------------------------------------------------------------------
- // (7) EXPLORE CD
- //-------------------------------------------------------------------------
- Msg( __LINE__, TEXT(__FILE__), TEXT("ButtonList[%d]: Id=%d, ButtonSizes=%d, String=%s."), i, IDD_EXPLORE, j, "Explore" );
- ButtonList[i++] = new DrawButton (
- IDD_EXPLORE,
- button_size[j++],
- BUTTON_REG,
- BUTTON_SEL,
- BUTTON_SEL,
- #ifdef LEAN_AND_MEAN
- Locale_GetString( "Autorun:ExploreCD" ),
- #else
- AsciiString("Autorun:ExploreCD"),
- #endif
- TTButtonFontPtr );
- // strcpy( next_button_name, ButtonImages[button_index] );
- // strcpy( focused_button_name, FocusedButtonImages[button_index--] );
- // strcpy( focused_button_name, FocusedButtonImages[button_index++] );
- if ( !InstallProduct ) {
- //-----------------------------------------------------------------------
- // (3) WebSite button.
- //-----------------------------------------------------------------------
- Msg( __LINE__, TEXT(__FILE__), TEXT("ButtonList[%d]: Id=%d, ButtonSizes=%d, String=%s."), i, IDD_OK, j, "Install" );
- ButtonList[i++] = new DrawButton(
- IDD_INTERNET,
- button_size[j++],
- BUTTON_REG,
- BUTTON_SEL,
- BUTTON_SEL,
- #ifdef LEAN_AND_MEAN
- Locale_GetString( "Autorun:Website" ),
- #else
- AsciiString("Autorun:Website"),
- #endif
- TTButtonFontPtr );
- // strcpy( next_button_name, ButtonImages[button_index] );
- // strcpy( focused_button_name, FocusedButtonImages[button_index--] );
- // strcpy( focused_button_name, FocusedButtonImages[button_index++] );
- }
- //--------------------------------------------------------------------------
- // (2) UNINSTALL?
- //--------------------------------------------------------------------------
- if ( UninstallAvailable && !InstallProduct ) {
- Msg( __LINE__, TEXT(__FILE__), TEXT("ButtonList[%d]: Id=%d, ButtonSizes=%d, String=%s."), i, IDD_UNINSTALL, j, "Uninstall" );
- ButtonList[i++] = new DrawButton(
- IDD_UNINSTALL,
- button_size[j++],
- BUTTON_REG,
- BUTTON_SEL,
- BUTTON_SEL,
- #ifdef LEAN_AND_MEAN
- Locale_GetString( "Autorun:Uninstall" ),
- #else
- AsciiString("Autorun:Uninstall"),
- #endif
- TTButtonFontPtr );
- // strcpy( next_button_name, ButtonImages[button_index] );
- // strcpy( focused_button_name, FocusedButtonImages[button_index--] );
- // strcpy( focused_button_name, FocusedButtonImages[button_index++] );
- }
- //--------------------------------------------------------------------------
- // (1) MOH movie
- //--------------------------------------------------------------------------
- Msg( __LINE__, TEXT(__FILE__), TEXT("ButtonList[%d]: Id=%d, ButtonSizes=%d, String=%s."), i, IDD_PREVIEWS, j, "Preview Movies");
- ButtonList[i++] = new DrawButton(
- IDD_PREVIEWS,
- button_size[j++],
- BUTTON_REG,
- BUTTON_SEL,
- BUTTON_SEL,
- #ifdef LEAN_AND_MEAN
- Locale_GetString( "Autorun:Previews" ),
- #else
- AsciiString("Autorun:Previews"),
- #endif
- TTButtonFontPtr );
- //--------------------------------------------------------------------------
- // (1) Help file
- //--------------------------------------------------------------------------
- Msg( __LINE__, TEXT(__FILE__), TEXT("ButtonList[%d]: Id=%d, ButtonSizes=%d, String=%s."), i, IDD_HELP, j, "Help file");
- ButtonList[i++] = new DrawButton(
- IDD_HELP,
- button_size[j++],
- BUTTON_REG,
- BUTTON_SEL,
- BUTTON_SEL,
- #ifdef LEAN_AND_MEAN
- Locale_GetString( "Autorun:Help" ),
- #else
- AsciiString("Autorun:Help"),
- #endif
- TTButtonFontPtr );
- //--------------------------------------------------------------------------
- // (1) CANCEL?
- //--------------------------------------------------------------------------
- Msg( __LINE__, TEXT(__FILE__), TEXT("ButtonList[%d]: Id=%d, ButtonSizes=%d, String=%s."), i, IDD_CANCEL, j, "Cancel" );
- ButtonList[i++] = new DrawButton(
- IDD_CANCEL,
- button_size[j++],
- BUTTON_REG,
- BUTTON_SEL,
- BUTTON_SEL,
- #ifdef LEAN_AND_MEAN
- Locale_GetString( "Autorun:Cancel" ),
- #else
- AsciiString("Autorun:Cancel"),
- #endif
- TTButtonFontPtr );
- // strcpy( next_button_name, ButtonImages[button_index] );
- // strcpy( focused_button_name, FocusedButtonImages[button_index--] );
- // strcpy( focused_button_name, FocusedButtonImages[button_index++] );
- //-------------------------------------------------------------------------
- // Set the top button to have the focus.
- //-------------------------------------------------------------------------
- if ( ButtonList[0]) {
- Msg( __LINE__, TEXT(__FILE__), TEXT("Button with starting Focus = %d"), i );
- ButtonList[0]->Set_State( DrawButton::FOCUS_STATE );
- }
- #if( _DEBUG )
- Msg( __LINE__, TEXT(__FILE__), TEXT("----------------------------------------------------------------------------------"));
- for( i=0; i<NUM_BUTTONS; i++ ) {
- if ( ButtonList[i]) {
- Msg( __LINE__, TEXT(__FILE__), TEXT("ButtonList[%d]: Id=%d, ButtonSizes=[%d,%d,%d,%d]."),
- i,
- ButtonList[i]->Return_Id(),
- ButtonList[i]->Return_X_Pos(),
- ButtonList[i]->Return_Y_Pos(),
- ButtonList[i]->Return_Width(),
- ButtonList[i]->Return_Height());
- }
- }
- #endif
- }
- //*****************************************************************************
- // WndProc -- Get Main Window's Stored Word.
- //
- // INPUT: HWND hWnd.
- // Window *pWindow
- //
- // OUTPUT: none.
- //
- // WARNINGS: none.
- //
- // HISTORY:
- // 06/04/1996 MML : Created.
- //=============================================================================
- LRESULT CALLBACK Wnd_Proc ( HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam )
- {
- //--------------------------------------------------------------------------
- // If the GlobalMainWindow Ptr is not initialized, do it when the MW-CREATE
- // msg is called. Then we use the GlobalMainWindow's WindowProc to
- // process all the individual msgs sent.
- //--------------------------------------------------------------------------
- if ( GlobalMainWindow == NULL ) {
- if ( iMessage == WM_CREATE ) {
- LPCREATESTRUCT lpcs;
- lpcs = (LPCREATESTRUCT) lParam;
- GlobalMainWindow = (MainWindow *) lpcs->lpCreateParams;
- //-----------------------------------------------------------------
- // Now let the object perform whatever initialization it needs
- // for WM_CREATE in its own WndProc.
- //-----------------------------------------------------------------
- return GlobalMainWindow->Window_Proc( hWnd, iMessage, wParam, lParam );
- } else {
- return DefWindowProc( hWnd, iMessage, wParam, lParam );
- }
- } else {
- return GlobalMainWindow->Window_Proc( hWnd, iMessage, wParam, lParam );
- }
- }
- //*****************************************************************************
- // DIALOG_BOX_PROC -- Handles dlg messages
- //
- // INPUT: standard windows dialog command parameters
- //
- // OUTPUT: unused
- //
- // WARNINGS: none
- //
- // HISTORY:
- // 06/04/1996 MML : Created.
- //=============================================================================
- BOOL CALLBACK Dialog_Box_Proc( HWND window_handle, UINT message, WPARAM w_param, LPARAM l_param )
- {
- int i = 0, j = 0;
- int nResult = 0;
- // int space_between = 5;
- int prevDCStretchMode;
- int prevMemDCStretchMode;
- int prevButtonDCStretchMode;
- int prevLicenseDCStretchMode;
- int result = 0;
- char buffer1[ 50 ];
- // char buffer2[ 50 ];
- HDC hDC, memDC, buttonDC, licenseDC;
- BITMAP bm, fm, lm;
- // LOGPALETTE * plgpl = NULL;
- PAINTSTRUCT ps;
- static int bits_pixel = 0;
- static int idCtl = 0;
- static int mouse_x, mouse_y;
- static char szBitmap[_MAX_PATH];
- static char szLicense[ _MAX_PATH ];
- static char szButtonBitmap[_MAX_PATH];
- static wchar_t szString1[ 500 ];
- static wchar_t szString2[ 500 ];
- static wchar_t szWholeString[ 1000 ];
- // static wchar_t szWSMsg1[ _MAX_PATH ];
- #ifdef LEAN_AND_MEAN
- #else
- static UnicodeString wsMsg1;
- #endif
- static wchar_t szWSMsg2[ _MAX_PATH ];
- static wchar_t szWholeWSMsg[ 1000 ];
- // static wchar_t szInstallWarningMsg[ _MAX_PATH ];
- static HBITMAP hBitmap = 0;
- static HBITMAP oldBitmap = 0;
- // static HBITMAP oldButtonBitmap = 0;
- static HBITMAP oldLicenseBitmap = 0;
- static HBITMAP hButtonBitmap = 0;
- static HBITMAP hFlicker[NUM_FLICKER_FRAMES];
- static HBITMAP hLicenseBitmap;
- static POINT point;
- static HBRUSH hStaticBrush = 0;
- static HPALETTE hpal = 0;
- static HPALETTE hpalold = 0;
- static BOOL FirstTime = TRUE;
- // static BOOL Flicker = TRUE;
- static BOOL Flicker = FALSE;
- static int FlickerIndex = 0;
- static BOOL PaintOnlyFlicker = TRUE;
- static BOOL PaintBackground = TRUE;
- static UINT timer_id = 0;
- static RECT rect; // Desktop Window ( used once ).
- static RECT tray_rect; // Desktop Window w/o Tray size.
- static RECT paint_rect; // Size that needs to be repainted.
- static RECT dlg_rect; // Dialog client window size.
- static RECT bitmap_rect; // Background bitmap size.
- static RECT flicker_rect; // Flicker bitmap size.
- static RECT buttons_rect; // Area where buttons are.
- static RECT license_rect; // Area where buttons are.
- static RECT BackgroundRect[ ( NUM_BUTTONS * 3 ) + 3 ]; // Background areas outside button area.
- #if(USE_MOUSE_MOVES)
- static int CurrentButton = 0;
- static int LastButton = 0;
- static int PrevButton = 0;
- #endif
- #if(0)
- {
- //-------------------------------------------------------------------------------
- // Used for debugging -- lining up objects using the mouse coordinates.
- //-------------------------------------------------------------------------------
- int i = 0;
- HDC hdc = GetDC( window_handle );
- char string[10];
- POINT pPoint;
- GetCursorPos( &pPoint );
- ScreenToClient( window_handle, &pPoint );
- sprintf( string, "%d, %d", pPoint.x, pPoint.y );
- TextOut( hdc, 10, 50, string, 8 );
- ReleaseDC( window_handle, hdc );
- }
- #endif
- //-----------------------------------------------------------------------------------
- // Process Dialogs messages.
- //-----------------------------------------------------------------------------------
- switch( message ) {
- case WM_INITDIALOG:
- {
- //-----------------------------------------------------------------------
- // Set dialog's caption.
- //-----------------------------------------------------------------------
- #ifdef LEAN_AND_MEAN
- Locale_GetString( "Autorun:Title", szWideBuffer );
- memset( szWideBuffer2, '\0', _MAX_PATH );
- swprintf( szWideBuffer2, szWideBuffer, szProductName );
- swprintf( szWideBuffer2, szWideBuffer, szFullProductName );
- #else
- wideBuffer = TheGameText->fetch("Autorun:Title");
- wideBuffer2.format(wideBuffer, fullProductName.str());
- WideCharToMultiByte( CodePage, 0, wideBuffer2.str(), wideBuffer2.getLength()+1, szBuffer, _MAX_PATH, NULL, NULL );
- #endif
- SetWindowText( window_handle, szBuffer );
- //-----------------------------------------------------------------------
- // Set Icon.
- //-----------------------------------------------------------------------
- SendMessage( window_handle, WM_SETICON, ICON_SMALL, (long)LoadIcon( Main::hInstance, MAKEINTRESOURCE(1)));
- #if(BACKGROUND_BITMAP)
- //-----------------------------------------------------------------------
- // Get the DeskTop's size and this dialogs size (in pixels).
- //-----------------------------------------------------------------------
- GetClientRect( GetDesktopWindow(), &rect );
- SystemParametersInfo( SPI_GETWORKAREA, 0, &tray_rect, 0 );
- /// if( rect.right <= 640 ) {
- // b640X480 = TRUE;
- // } else if( rect.right <= 800 ) {
- b800X600 = TRUE;
- // }
- //=======================================================================
- // Create Fonts.
- //=======================================================================
- HDC hdc = GetDC( window_handle );
- FontManager = new FontManagerClass( hdc );
- assert( FontManager != NULL );
- ReleaseDC( window_handle, hdc );
- //=======================================================================
- // Load messages for bottom of screen.
- //=======================================================================
- // memset( szString1, '\0', MAX_PATH );
- // memset( szString2, '\0', MAX_PATH );
- // memset( szWholeString, '\0', 1000 );
- // Locale_GetString( EA_LICENSE_MSG1, szString1 );
- // Locale_GetString( EA_LICENSE_MSG2, szString2 );
- // swprintf( szWholeString, L"%s %s", szString1, szString2 );
- // memset( szWSMsg1, '\0', _MAX_PATH );
- memset( szWSMsg2, '\0', _MAX_PATH );
- memset( szWholeWSMsg, '\0', 1000 );
- // Locale_GetString( WESTWOOD_COM_MSG, szWSMsg1 );
- // wsMsg1 = TheGameText->fetch("Autorun:WestwoodComMsg");
- // PlugInProductName( szWSMsg1, (wchar_t *)(fullProductName.str()) );
- // PlugInProductName( (wchar_t *)(wsMsg1.str()), (wchar_t *)(fullProductName.str()) );
- // wsMsg1 = Fix_Single_Ampersands ( wsMsg1, false );
- // swprintf( szWholeWSMsg, L"%s", wsMsg1.str() );
- // memset( szInstallWarningMsg, '\0', _MAX_PATH );
-
- // Locale_GetString( IDS_INSTALL_WARNING_MSG, szWideBuffer );
- // wideBuffer = TheGameText->fetch("Autorun:InstallWarningMsg");
- // swprintf( szInstallWarningMsg, wideBuffer.str(), fullProductName.str() );
- //=======================================================================
- // Load the correct background & animation bitmap.
- //=======================================================================
- memset( buffer1, '\0', sizeof( buffer1 ));
- if( b640X480 ) {
- strcpy( szBitmap, _TEXT( "Background2" ));
- if ( LANG_FRE == LanguageID ) {
- strcpy( szLicense, _TEXT( "License_FRENCH2" ));
- } else if ( LANG_GER == LanguageID ) {
- strcpy( szLicense, _TEXT( "License_GERMAN2" ));
- } else {
- strcpy( szLicense, _TEXT( "License_USA2" ));
- }
- license_rect.left = 186;
- license_rect.top = 414;
- } else if( b800X600 ) {
- strcpy( szBitmap, _TEXT( "BacKground" ));
- if ( LANG_FRE == LanguageID ) {
- strcpy( szLicense, _TEXT( "License_FRENCH2" ));
- } else if ( LANG_GER == LanguageID ) {
- strcpy( szLicense, _TEXT( "License_GERMAN2" ));
- } else {
- strcpy( szLicense, _TEXT( "License_USA2" ));
- }
- license_rect.left = 186;
- license_rect.top = 414;
- } else {
- strcpy( szBitmap, _TEXT( "Background" ));
- strcpy( buffer1, "FLICKER" );
- if ( LANG_FRE == LanguageID ) {
- strcpy( szLicense, _TEXT( "License_FRENCH" ));
- } else if ( LANG_GER == LanguageID ) {
- strcpy( szLicense, _TEXT( "License_GERMAN" ));
- } else {
- strcpy( szLicense, _TEXT( "License_USA" ));
- }
- license_rect.left = 238;
- license_rect.top = 580;
- }
- //=======================================================================
- // Load flicker bitmap.
- //=======================================================================
- for( i = 0; i < NUM_FLICKER_FRAMES; i++ ) {
- hFlicker[i] = 0;
- // sprintf( buffer2, "%s%02d", buffer1, i );
- // hFlicker[i] = LoadResourceBitmap( Main::hModule, buffer2, &hpal );
- hFlicker[i] = LoadResourceBitmap( Main::hModule, buffer1, &hpal );
- }
- //-----------------------------------------------------------------------
- // Get the flicker bitmap's dimensions.
- //-----------------------------------------------------------------------
- result = 712;
- for( i = 0; i < NUM_FLICKER_POSITIONS; i++ ) {
- if( i == 8 ) {
- FlickerPositions[i][0] = result - 33;
- } else if( i == 9 ) {
- FlickerPositions[i][0] = result - 35;
- } else if ( i > 8 ) {
- FlickerPositions[i][0] = result - 28;
- } else {
- FlickerPositions[i][0] = result - 31;
- }
- FlickerPositions[i][1] = 560;
- result = FlickerPositions[i][0];
- }
- if ( hFlicker[0] ) {
- GetObject( hFlicker[0], sizeof( BITMAP ), (LPTSTR)&fm );
- flicker_rect.left = FlickerPositions[0][0];
- flicker_rect.top = FlickerPositions[0][1];
- flicker_rect.right = flicker_rect.left + fm.bmWidth;
- flicker_rect.bottom = flicker_rect.top + fm.bmHeight;
- }
- //-----------------------------------------------------------------------
- // Get the bitmap's dimensions.
- //-----------------------------------------------------------------------
- hLicenseBitmap = LoadResourceBitmap( Main::hModule, szLicense, &hpal );
- if ( hLicenseBitmap ) {
- GetObject( hLicenseBitmap, sizeof( BITMAP ), (LPTSTR)&lm );
- license_rect.right = license_rect.left + lm.bmWidth;
- license_rect.bottom = license_rect.top + lm.bmHeight;
- }
- //=======================================================================
- // Load background bitmap.
- //=======================================================================
- hBitmap = LoadResourceBitmap( Main::hModule, szBitmap, &hpal );
- if ( hBitmap ) {
- GetObject( hBitmap, sizeof( BITMAP ), (LPTSTR)&bm );
- }
- //-----------------------------------------------------------------------
- // Set the x, y, width, height of the Dialog and bitmaps dimensions.
- //-----------------------------------------------------------------------
- bitmap_rect.left = dlg_rect.left = 0;
- bitmap_rect.top = dlg_rect.top = 0;
- bitmap_rect.right = dlg_rect.right = bm.bmWidth;
- bitmap_rect.bottom = dlg_rect.bottom = bm.bmHeight;
-
- //-----------------------------------------------------------------------
- // Set the x, y, width, height of the Dialog and bitmaps dimensions.
- //-----------------------------------------------------------------------
- dlg_rect.left = 0;
- dlg_rect.top = 0;
- if( b640X480 ) {
- dlg_rect.right = rect.right;
- dlg_rect.bottom = tray_rect.bottom; // desktop smaller than image
- } else if( b800X600 ) {
- if(true){
- dlg_rect.right = bm.bmWidth + 6;
- dlg_rect.bottom = bm.bmHeight + GetSystemMetrics( SM_CYCAPTION ) + 6; // desktop larger than image
- } else {
- dlg_rect.right = 640;//bm.bmWidth + 6;
- dlg_rect.bottom = 480; //bm.bmHeight + GetSystemMetrics( SM_CYCAPTION ) + 6; // desktop larger than image
- }
- } else {
- dlg_rect.right = bm.bmWidth + 6;
- dlg_rect.bottom = bm.bmHeight + GetSystemMetrics( SM_CYCAPTION ) + 6; // desktop larger than image
- }
- //=======================================================================
- // Recreate Buttons based on Registry.
- //=======================================================================
- GlobalMainWindow->Create_Buttons( window_handle, &dlg_rect );
- //=======================================================================
- // Set Main Rectangle Areas around all the Buttons.
- //=======================================================================
- //-----------------------------------------------------------------------
- // Who is the first button?
- //-----------------------------------------------------------------------
- i = 0;
- while ( i < NUM_BUTTONS ) {
- if ( ButtonList[i] == NULL ) {
- i++;
- } else {
- break;
- }
- }
- if( i >= NUM_BUTTONS || i < 0 ) {
- i = 0;
- }
- Msg( __LINE__, TEXT(__FILE__), TEXT("----------------------------- determining button area ---------------------------" ));
- buttons_rect.left = ButtonSizes[i].left;
- buttons_rect.top = ButtonSizes[i].top;
- buttons_rect.right = ButtonSizes[i].left + ButtonSizes[i].right;
- buttons_rect.bottom = ButtonSizes[i].top + ButtonSizes[i].bottom;
- // Msg( __LINE__, TEXT(__FILE__), TEXT("buttons_rect = [%d,%d,%d,%d]"), buttons_rect.left, buttons_rect.top, buttons_rect.right, buttons_rect.bottom );
- for( j = 0; j < NUM_BUTTONS; j++ ) {
- if ( ButtonList[j] != NULL ) {
- buttons_rect.left = __min( ButtonSizes[j].left , buttons_rect.left );
- buttons_rect.top = __min( ButtonSizes[j].top , buttons_rect.top );
- buttons_rect.right = __max( ButtonSizes[j].left + ButtonSizes[j].right , buttons_rect.right );
- buttons_rect.bottom = __max( ButtonSizes[j].top + ButtonSizes[j].bottom , buttons_rect.bottom );
- }
- }
- Msg( __LINE__, TEXT(__FILE__), TEXT("buttons_rect = [%d,%d,%d,%d]"), buttons_rect.left, buttons_rect.top, buttons_rect.right, buttons_rect.bottom );
- Msg( __LINE__, TEXT(__FILE__), TEXT("----------------------------- determining button area ---------------------------" ));
- //=======================================================================
- // Center the dialog on the desktop.
- //=======================================================================
- if ( !b640X480 ) {
- MoveWindow( window_handle,
- ( rect.right - dlg_rect.right )/2,
- ( rect.bottom - dlg_rect.bottom )/2,
- dlg_rect.right,
- dlg_rect.bottom, TRUE );
- } else {
- MoveWindow( window_handle,
- 0, 0,
- dlg_rect.right,
- dlg_rect.bottom, TRUE );
- }
- //-----------------------------------------------------------------------
- // Get the new Client area.
- //-----------------------------------------------------------------------
- GetClientRect( window_handle, &dlg_rect );
-
- //=======================================================================================
- // JFS: 8/26/03 -- This was not getting cleared so if the button cnt were reduced...
- //=======================================================================================
- memset( BackgroundRect, 0, sizeof ( BackgroundRect ) );
- //=======================================================================
- // These are the areas of the Background to paint minus the Button Area.
- // This will prevent "flickering".
- //=======================================================================
- BackgroundRect[0].left = dlg_rect.left;
- BackgroundRect[0].top = dlg_rect.top;
- BackgroundRect[0].right = dlg_rect.right;
- BackgroundRect[0].bottom = buttons_rect.top;
- BackgroundRect[1].left = dlg_rect.left;
- BackgroundRect[1].top = buttons_rect.top;
- BackgroundRect[1].right = buttons_rect.left;
- BackgroundRect[1].bottom = dlg_rect.bottom;
- BackgroundRect[2].left = buttons_rect.left;
- BackgroundRect[2].top = buttons_rect.bottom;
- BackgroundRect[2].right = buttons_rect.right;
- BackgroundRect[2].bottom = dlg_rect.bottom;
- BackgroundRect[3].left = buttons_rect.right;
- BackgroundRect[3].top = buttons_rect.top;
- BackgroundRect[3].right = dlg_rect.right;
- BackgroundRect[3].bottom = dlg_rect.bottom;
- //=======================================================================
- // Find Areas that are in between, infront of, and behind each Buttons.
- //=======================================================================
- i = 0;
- j = 4;
- //-----------------------------------------------------------------------
- // Who is the first button?
- //-----------------------------------------------------------------------
- while ( i < NUM_BUTTONS ) {
- if ( ButtonList[i] == NULL ) {
- i++;
- } else {
- break;
- }
- }
- if( i >= NUM_BUTTONS || i < 0 ) {
- i = 0;
- }
- //-----------------------------------------------------------------------
- // For each button...
- //-----------------------------------------------------------------------
- for( int index = i; index < NUM_BUTTONS; index++ ) {
- //-------------------------------------------------------------------
- // Make areas between the buttons.
- //-------------------------------------------------------------------
- if ( ButtonList[index] != NULL && ButtonList[index+1] != NULL ) {
- // Area between buttons.
- BackgroundRect[j].top = ButtonList[index]->Return_Y_Pos() + ButtonList[index]->Return_Height();
- BackgroundRect[j].bottom = ButtonList[index+1]->Return_Y_Pos() - BackgroundRect[j].top;
- BackgroundRect[j].left = BackgroundRect[1].right;
- BackgroundRect[j].right = BackgroundRect[3].left - BackgroundRect[1].left - 1;
- j++;
- }
- //-------------------------------------------------------------------
- // Now look for areas in front of and behind each button.
- //-------------------------------------------------------------------
- if ( ButtonList[index] != NULL ) {
- // Area in front of buttons.
- BackgroundRect[j].top = ButtonList[index]->Return_Y_Pos();
- BackgroundRect[j].bottom = ButtonList[index]->Return_Height();
- BackgroundRect[j].left = BackgroundRect[1].right;
- BackgroundRect[j].right = ButtonList[index]->Return_X_Pos() - BackgroundRect[1].right;
- j++;
- // Area behind buttons.
- BackgroundRect[j].top = ButtonList[index]->Return_Y_Pos();
- BackgroundRect[j].bottom = ButtonList[index]->Return_Height();
- BackgroundRect[j].left = ButtonList[index]->Return_X_Pos() + ButtonList[index]->Return_Width();
- BackgroundRect[j].right = BackgroundRect[3].left - ( ButtonList[index]->Return_X_Pos() + ButtonList[index]->Return_Width());
- j++;
- }
- }
- #if(_DEBUG)
- Msg( __LINE__, TEXT(__FILE__), TEXT("----------------------------- WM_INITDIALOG ---------------------------" ));
- 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 );
- Msg( __LINE__, TEXT(__FILE__), TEXT("DeskTopWindowRect = [%d,%d,%d,%d]"), rect.left, rect.top, rect.right, rect.bottom );
- Msg( __LINE__, TEXT(__FILE__), TEXT("b640X480 = [%d]"), b640X480 );
- Msg( __LINE__, TEXT(__FILE__), TEXT("b800X600 = [%d]"), b800X600 );
- Msg( __LINE__, TEXT(__FILE__), TEXT("ClientRect = [%d,%d,%d,%d]"), dlg_rect.left, dlg_rect.top, dlg_rect.right, dlg_rect.bottom );
-
- for( index = 0; index < ( NUM_BUTTONS * 3 ) + 3; index++ ) {
- Msg( __LINE__, TEXT(__FILE__), TEXT("BackgroundRect[%d] = [%d,%d,%d,%d]"), index, BackgroundRect[index].top, BackgroundRect[index].bottom, BackgroundRect[index].left, BackgroundRect[index].right );
- }
-
- Msg( __LINE__, TEXT(__FILE__), TEXT("BitmapRect = [%d,%d,%d,%d]"), bitmap_rect.left, bitmap_rect.top, bitmap_rect.right, bitmap_rect.bottom );
- Msg( __LINE__, TEXT(__FILE__), TEXT("FlickerRect = [%d,%d,%d,%d]"), flicker_rect.left, flicker_rect.top, flicker_rect.right, flicker_rect.bottom );
- Msg( __LINE__, TEXT(__FILE__), TEXT("ButtonsRect = [%d,%d,%d,%d]"), buttons_rect.left, buttons_rect.top, buttons_rect.right, buttons_rect.bottom );
- Msg( __LINE__, TEXT(__FILE__), TEXT("-----------------------------------------------------------------------" ));
- #endif
- #else
- //-----------------------------------------------------------------------
- // Create Brush.
- //-----------------------------------------------------------------------
- hStaticBrush = CreateSolidBrush( RGB( 192, 192, 192 ));
- #endif
- //=======================================================================
- // Set dialog's timer! 1000 = 1 second.
- //=======================================================================
- // timer_id = SetTimer( window_handle, 1000, 250L, NULL );
- timer_id = SetTimer( window_handle, 1000, 500L, NULL );
- }
- return( TRUE );
- //-------------------------------------------------------------------------------
- // Try and set a custom cursor.
- //-------------------------------------------------------------------------------
- // case WM_SETCURSOR:
- // SetCursor(LoadCursor( Main::hInstance, MAKEINTRESOURCE(2)));
- // break;
- //-------------------------------------------------------------------------------
- // Tell Window to Select Palette if we are not the Focused Window.
- // This is to avoid getting stuck in a loop of receiving this msg
- // when we are focused.
- //-------------------------------------------------------------------------------
- case WM_PALETTECHANGED:
- if (( HWND )w_param != window_handle ) {
- SendMessage( window_handle, WM_QUERYNEWPALETTE, w_param, l_param );
- }
- break;
- //-------------------------------------------------------------------------------
- // Set and Realize our palette, then repaint if necessary.
- // Note that SelectPalette here is passed a FALSE.
- // This means reset palette as if we are in the foreground.
- //-------------------------------------------------------------------------------
- case WM_QUERYNEWPALETTE:
- hDC = GetDC( window_handle );
- hpalold = SelectPalette( hDC, hpal, FALSE );
- i = RealizePalette( hDC );
- if ( i != 0 ) {
- InvalidateRect( window_handle, &dlg_rect, TRUE );
- }
- SelectPalette( hDC, hpalold, TRUE );
- RealizePalette( hDC );
- ReleaseDC( window_handle, hDC );
- return i;
- //-------------------------------------------------------------------------------
- // Process Timer Messages.
- //-------------------------------------------------------------------------------
- case WM_TIMER:
- {
- if ( w_param == 1000 ) {
- // if ( Flicker && hFlicker[FlickerIndex] ) {
- if ( Flicker && hFlicker[0] ) {
- FlickerIndex++;
- // if ( FlickerIndex >= NUM_FLICKER_FRAMES ) {
- if ( FlickerIndex >= NUM_FLICKER_POSITIONS ) {
- FlickerIndex = 0;
- }
- InvalidateRect( window_handle, &flicker_rect, FALSE );
- flicker_rect.left = FlickerPositions[ FlickerIndex ][0];
- InvalidateRect( window_handle, &flicker_rect, FALSE );
- UpdateWindow( window_handle );
- Msg( __LINE__, TEXT(__FILE__), TEXT("WM_TIMER: FlickerRect = [%d,%d,%d,%d]"), flicker_rect.left, flicker_rect.right, flicker_rect.top, flicker_rect.bottom );
- }
- }
- //-----------------------------------------------------------------------
- // If game is running, the mutex will return! Time to exit...
- // Note: This number is unique for Tiberian Sun ONLY!!!
- //-----------------------------------------------------------------------
- if( WinVersion.Is_Win_XP() || WinVersion.Version() > 500 ) {
- strcat( strcpy( szBuffer, "Global\\" ), GAME_MUTEX_OBJECT );
- } else {
- strcpy( szBuffer, GAME_MUTEX_OBJECT );
- }
- GameAppMutex = OpenMutex( MUTEX_ALL_ACCESS, FALSE, szBuffer );
- if ( GameAppMutex != NULL ) {
- //---------------------------------------------------------
- // Handle(s) are closed in the ProgEnd().
- //---------------------------------------------------------
- HWND ccwindow = FindWindow( szGameWindow, NULL );
- if ( ccwindow ) {
- if( IsIconic( ccwindow )){
- ShowWindow( ccwindow, SW_RESTORE );
- }
- SetForegroundWindow( ccwindow );
- } else {
- ccwindow = FindWindow( szSetupWindow, NULL );
- if ( ccwindow ) {
- if( IsIconic( ccwindow )){
- ShowWindow( ccwindow, SW_RESTORE );
- }
- SetForegroundWindow( ccwindow );
- }
- }
- PostMessage( window_handle, WM_COMMAND, (WPARAM)MAKELONG( IDD_CANCEL, BN_CLICKED ), (LPARAM)GetDlgItem( window_handle, IDD_CANCEL ));
- }
- }
- return ( 0 );
- //===============================================================================
- // Dialog's main paint routine.
- //===============================================================================
- case WM_PAINT:
- //---------------------------------------------------------------------------
- // If there is an area to update, repaint it.
- //---------------------------------------------------------------------------
- if ( GetUpdateRect( window_handle, &paint_rect, FALSE )) {
- // Msg( __LINE__, TEXT(__FILE__), TEXT("---------------------- WM_PAINT ---------------------"), i );
- // Msg( __LINE__, TEXT(__FILE__), TEXT("Rectangle to update = [%d,%d,%d,%d]"), paint_rect.left, paint_rect.top, paint_rect.right, paint_rect.bottom );
-
- //-----------------------------------------------------------------------
- // Get dialog's hDC.
- //-----------------------------------------------------------------------
- hDC = BeginPaint( window_handle, &ps );
- #if( BACKGROUND_BITMAP )
- if ( hBitmap ) {
- //---------------------------------------------------------------
- // Create a compatible DC for the bitmap.
- //---------------------------------------------------------------
- memDC = CreateCompatibleDC( hDC );
- buttonDC = CreateCompatibleDC( hDC );
- licenseDC = CreateCompatibleDC( hDC );
- //---------------------------------------------------------------
- // Set stretching mode for bitmaps.
- //---------------------------------------------------------------
- prevDCStretchMode = SetStretchBltMode( hDC, STRETCH_DELETESCANS );
- prevMemDCStretchMode = SetStretchBltMode( memDC, STRETCH_DELETESCANS );
- prevButtonDCStretchMode = SetStretchBltMode( buttonDC,STRETCH_DELETESCANS );
- prevLicenseDCStretchMode = SetStretchBltMode( licenseDC,STRETCH_DELETESCANS );
- //---------------------------------------------------------------
- // Set the palette in each DC.
- //---------------------------------------------------------------
- hpalold = SelectPalette( hDC, hpal, FALSE );
- RealizePalette( hDC );
- SelectPalette( memDC, hpal, FALSE );
- RealizePalette( memDC );
- SelectPalette( buttonDC, hpal, FALSE );
- RealizePalette( buttonDC );
- SelectPalette( licenseDC, hpal, FALSE );
- RealizePalette( licenseDC );
-
- //---------------------------------------------------------------
- // If area to update is a button area, this will be drawn farther
- // on. This is to prevent "flickering" by drawing the background
- // then the button image.
- //---------------------------------------------------------------
- for ( i = 0; i < NUM_BUTTONS; i++ ) {
- if ( ButtonList[i] ) {
- ButtonList[i]->Return_Area( &rect );
- if ( paint_rect.left == rect.left &&
- paint_rect.top == rect.top &&
- paint_rect.right == rect.right &&
- paint_rect.bottom == rect.bottom ) {
-
- PaintBackground = FALSE;
- // Msg( __LINE__, TEXT(__FILE__), TEXT("Rectangle matches a button to update = [%d,%d,%d,%d]"), rect.left, rect.top, rect.right, rect.bottom );
- break;
- }
- }
- }
- //===============================================================
- // Paint the background.
- //===============================================================
- if ( PaintBackground ) {
- //-----------------------------------------------------------
- // Select & Draw the background bitmap.
- //-----------------------------------------------------------
- oldBitmap = ( HBITMAP )SelectObject( memDC, hBitmap );
- //-----------------------------------------------------------
- // Updates area around the button area.
- //-----------------------------------------------------------
- #if(1)
- for( int i=0; i < ( NUM_BUTTONS * 3 ) + 3; i++ ) {
- if( BackgroundRect[i].left != 0 || BackgroundRect[i].top != 0 ||
- BackgroundRect[i].right != 0 || BackgroundRect[i].bottom != 0 ) {
- result = StretchBlt( hDC,
- BackgroundRect[i].left,
- BackgroundRect[i].top,
- BackgroundRect[i].right,
- BackgroundRect[i].bottom,
- memDC,
- BackgroundRect[i].left,
- BackgroundRect[i].top,
- BackgroundRect[i].right,
- BackgroundRect[i].bottom,
- SRCCOPY );
- if( result != 0 ) {
- // Msg( __LINE__, TEXT(__FILE__), TEXT("Paint this rect = [%d,%d,%d,%d]"), BackgroundRect[i].left, BackgroundRect[i].top, BackgroundRect[i].right, BackgroundRect[i].bottom );
- }
- #if(0)
- HPEN pen = CreatePen( /*PS_DOT*/ PS_SOLID, 1, TEXT_COLOR );
- HGDIOBJ oldpen = SelectObject( hDC, pen );
- SetBkMode( hDC, TRANSPARENT );
-
- MoveToEx( hDC, BackgroundRect[i].left+1, BackgroundRect[i].top+1, NULL );
- LineTo( hDC, BackgroundRect[i].right-1, BackgroundRect[i].top+1 );
- LineTo( hDC, BackgroundRect[i].right-1, BackgroundRect[i].bottom-1 );
- LineTo( hDC, BackgroundRect[i].left+1, BackgroundRect[i].bottom-1 );
- LineTo( hDC, BackgroundRect[i].left+1, BackgroundRect[i].top+1 );
- SelectObject( hDC, oldpen );
- DeleteObject( pen );
- #endif
- }
- }
- /*
- //-----------------------------------------------------------
- // Select & Draw the background bitmap.
- //-----------------------------------------------------------
- oldLicenseBitmap = ( HBITMAP )SelectObject( licenseDC, hLicenseBitmap );
- //-----------------------------------------------------------
- // Updates area around the button area.
- //-----------------------------------------------------------
- result = StretchBlt( hDC,
- license_rect.left,
- license_rect.top,
- license_rect.right,
- license_rect.bottom,
- licenseDC,
- 0,
- 0,
- license_rect.right,
- license_rect.bottom,
- SRCCOPY );
- */
- #else
- //-----------------------------------------------------------
- // Blit whole background, in one shot.
- //-----------------------------------------------------------
- StretchBlt( hDC, dlg_rect.left, dlg_rect.top, dlg_rect.right, dlg_rect.bottom,
- memDC, bitmap_rect.left, bitmap_rect.top, bitmap_rect.right, bitmap_rect.bottom,
- SRCCOPY );
- #endif
- SelectObject( memDC, oldBitmap );
- SelectObject( licenseDC, oldLicenseBitmap );
- } else {
- PaintBackground = TRUE;
- }
- //---------------------------------------------------------------
- // Animation.
- //---------------------------------------------------------------
- // if ( Flicker && hFlicker[FlickerIndex] ) {
- if ( Flicker && hFlicker[0] ) {
- // oldBitmap = ( HBITMAP )SelectObject( memDC, hFlicker[FlickerIndex] );
- oldBitmap = ( HBITMAP )SelectObject( memDC, hFlicker[0] );
- StretchBlt(
- hDC,
- flicker_rect.left,
- flicker_rect.top,
- flicker_rect.right,
- flicker_rect.bottom,
- memDC,
- 0,
- 0,
- flicker_rect.right,
- flicker_rect.bottom,
- SRCCOPY );
- #if(0)
- HPEN pen = CreatePen( /*PS_DOT*/ PS_SOLID, 1, TEXT_COLOR );
- HGDIOBJ oldpen = SelectObject( hDC, pen );
- SetBkMode( hDC, TRANSPARENT );
-
- MoveToEx( hDC, flicker_rect.left+1, flicker_rect.top+1, NULL );
- LineTo( hDC, flicker_rect.right-1, flicker_rect.top+1 );
- LineTo( hDC, flicker_rect.right-1, flicker_rect.bottom-1 );
- LineTo( hDC, flicker_rect.left+1, flicker_rect.bottom-1 );
- LineTo( hDC, flicker_rect.left+1, flicker_rect.top+1 );
- SelectObject( hDC, oldpen );
- DeleteObject( pen );
- #endif
- SelectObject( memDC, oldBitmap );
- // Msg( __LINE__, TEXT(__FILE__), TEXT(" Drawing Flicker [%d,%d,%d,%d]."), flicker_rect.left, flicker_rect.top, flicker_rect.right, flicker_rect.bottom );
- }
- //---------------------------------------------------------------
- // Draw each button.
- //---------------------------------------------------------------
- for ( i = 0; i < NUM_BUTTONS; i++ ) {
- if ( ButtonList[i] ) {
- Rect rect;
- //-------------------------------------------------------
- // Uses Bitmaps or DrawText???
- //-------------------------------------------------------
- if ( ButtonList[i]->Draw_Bitmaps()) {
- RECT src_rect, dst_rect;
- strcpy( szButtonBitmap, ButtonList[i]->Return_Bitmap( ));
- hButtonBitmap = LoadResourceBitmap( Main::hInstance, szButtonBitmap, &hpal, TRUE );
- if ( hButtonBitmap ) {
- GetObject( hButtonBitmap, sizeof( BITMAP ), (LPTSTR)&bm );
- dst_rect.left = ButtonList[i]->Return_X_Pos();
- dst_rect.top = ButtonList[i]->Return_Y_Pos();
- dst_rect.right = ButtonList[i]->Return_Stretched_Width();
- dst_rect.bottom = ButtonList[i]->Return_Stretched_Height();
- src_rect.left = 0;
- src_rect.top = 0;
- src_rect.right = bm.bmWidth;
- src_rect.bottom = bm.bmHeight;
- //-----------------------------------------------
- // Draw the button's bitmap background.
- //-----------------------------------------------
- oldBitmap = ( HBITMAP ) SelectObject( buttonDC, hButtonBitmap );
- StretchBlt(
- hDC,
- dst_rect.left,
- dst_rect.top,
- dst_rect.right,
- dst_rect.bottom,
- buttonDC,
- src_rect.left,
- src_rect.top,
- src_rect.right,
- src_rect.bottom,
- SRCCOPY );
- SelectObject( buttonDC, oldBitmap );
- DeleteObject( hButtonBitmap );
- hButtonBitmap = 0;
- }
- } // END OF DRAW BITMAPS
- #if(0)
- TTFontClass *fontptr = ButtonList[i]->Return_Font_Ptr();
- if ( fontptr ) {
- RECT outline_rect;
- ButtonList[i]->Return_Area( &outline_rect );
- ButtonList[i]->Return_Text_Area( &rect );
- /*
- ** This function was combining the pixel color with the background,
- ** so it never looked correct.
- */
- // SetTextColor( hDC, RGB( 0, 240, 0 ));
- // DrawFocusRect( hDC, &dst_rect );
-
- if ( ButtonList[i]->Get_State() == DrawButton::PRESSED_STATE ) {
- fontptr->Print(
- hDC,
- ButtonList[i]->Return_Text(),
- rect,
- TEXT_PRESSED_COLOR,
- TEXT_PRESSED_SHADOW_COLOR,
- TPF_BUTTON,
- TPF_SHADOW );
- } else if ( ButtonList[i]->Get_State() == DrawButton::FOCUS_STATE ) {
- fontptr->Print(
- hDC,
- ButtonList[i]->Return_Text(),
- rect,
- TEXT_FOCUSED_COLOR,
- TEXT_FOCUSED_SHADOW_COLOR,
- TPF_BUTTON,
- TPF_SHADOW );
- } else {
- fontptr->Print(
- hDC,
- ButtonList[i]->Return_Text(),
- rect,
- TEXT_NORMAL_COLOR,
- TEXT_NORMAL_SHADOW_COLOR,
- TPF_BUTTON,
- TPF_SHADOW );
- }
-
- #if(0)
- HPEN pen = CreatePen( /*PS_DOT*/ PS_SOLID, 2, TEXT_COLOR );
- HGDIOBJ oldpen = SelectObject( hDC, pen );
- SetBkMode( hDC, TRANSPARENT );
-
- MoveToEx( hDC, // handle to device context
- outline_rect.left, // x-coordinate of new current position
- outline_rect.top, // y-coordinate of new current position
- NULL ); // pointer to old current position
-
- LineTo( hDC, // device context handle
- outline_rect.right, // x-coordinate of line's ending point
- outline_rect.top ); // y-coordinate of line's ending point
-
- LineTo( hDC, // device context handle
- outline_rect.right, // x-coordinate of line's ending point
- outline_rect.bottom ); // y-coordinate of line's ending point
-
- LineTo( hDC, // device context handle
- outline_rect.left, // x-coordinate of line's ending point
- outline_rect.bottom ); // y-coordinate of line's ending point
-
- LineTo( hDC, // device context handle
- outline_rect.left, // x-coordinate of line's ending point
- outline_rect.top ); // y-coordinate of line's ending point
-
- SelectObject( hDC, oldpen );
- DeleteObject( pen );
- #endif
- }
- #else
- ButtonList[i]->Draw_Text( hDC );
- #endif
- } // end of if button
- } // For each button...
- //---------------------------------------------------------------
- // Used in debugging -- draw rect around where buttons are.
- //---------------------------------------------------------------
- #if(0)
- {
- HPEN hPen1 = CreatePen( PS_SOLID, 1, RGB( 255, 255, 255 ));
- if (hPen1) {
- for ( int i = 0; i < NUM_BUTTONS; i++ ) {
- if ( ButtonList[i] ) {
- HGDIOBJ oldpen = SelectObject( hDC, hPen1 );
- MoveToEx( hDC,
- ButtonList[i]->Return_X_Pos()-1,
- ButtonList[i]->Return_Y_Pos()-1, NULL );
- LineTo( hDC,
- ButtonList[i]->Return_X_Pos() + ButtonList[i]->Return_Width() + 1,
- ButtonList[i]->Return_Y_Pos()-1 );
- LineTo( hDC,
- ButtonList[i]->Return_X_Pos() + ButtonList[i]->Return_Width() + 1,
- ButtonList[i]->Return_Y_Pos() + ButtonList[i]->Return_Height() + 1);
- LineTo( hDC,
- ButtonList[i]->Return_X_Pos()-1,
- ButtonList[i]->Return_Y_Pos() + ButtonList[i]->Return_Height() + 1);
- LineTo( hDC,
- ButtonList[i]->Return_X_Pos() - 1,
- ButtonList[i]->Return_Y_Pos() - 1);
- SelectObject( hDC, oldpen );
- }
- }
- }
- DeleteObject( hPen1 );
- }
- #endif
- //---------------------------------------------------------------
- // Restore all default objects to DCs and delete.
- //---------------------------------------------------------------
- SetStretchBltMode( hDC, prevDCStretchMode );
- SetStretchBltMode( memDC, prevMemDCStretchMode );
- SetStretchBltMode( buttonDC, prevButtonDCStretchMode );
- SetStretchBltMode( licenseDC, prevLicenseDCStretchMode );
-
- SelectPalette( hDC, hpalold, FALSE );
- SelectPalette( memDC, hpalold, FALSE );
- SelectPalette( buttonDC, hpalold, FALSE );
- SelectPalette( licenseDC, hpalold, FALSE );
- DeleteDC( memDC );
- DeleteDC( buttonDC );
- DeleteDC( licenseDC );
- } // end of bitmaps
- //===================================================================
- // Draw a solid colored background.
- //===================================================================
- // GetClientRect( window_handle, (LPRECT) &dlg_rect );
- // FillRect( hDC, &dlg_rect, (HBRUSH)( COLOR_WINDOW + 1 ));
- //===================================================================
- // Print text at bottom of screen.
- //===================================================================
- Rect text_rect;
- TTFontClass *fontptr = NULL;
- if ( b640X480 ) {
- fontptr = TTTextFontPtr640;
- } else if ( b800X600 ) {
- fontptr = TTTextFontPtr800;
- } else {
- fontptr = TTTextFontPtr;
- }
- if ( fontptr ) {
- if ( b640X480 || b800X600 ) {
- text_rect.X = 10;
- text_rect.Y = 240;
- text_rect.Width = 140; //498;
- text_rect.Height = 100; //26;
- } else {
- text_rect.X = 20;
- text_rect.Y = 340;
- text_rect.Width = 180; //498;
- text_rect.Height = 120; //26;
- }
- #if(0)
- RECT one;
- one.left = text_rect.X;
- one.top = text_rect.Y;
- one.right = text_rect.X + text_rect.Width;
- one.bottom = text_rect.Y + text_rect.Height;
- FrameRect( hDC, &one, (HBRUSH)( COLOR_WINDOW + 1 ));
- // DrawFocusRect( hDC, &one );
- #endif
- //---------------------------------------------------------------
- // WESTWOOD_COM Message at the top.
- //---------------------------------------------------------------
- /*
- fontptr->Print(
- hDC,
- szWholeWSMsg,
- text_rect,
- TEXT_COLOR,
- SHADOW_COLOR,
- TPF_CENTER_TEXT,
- TPF_SHADOW );
- */
- }
- //---------------------------------------------------------------
- // EA_COM Message at the bottom.
- //---------------------------------------------------------------
- #if(0) // Moved this text to a bitmap.
- fontptr = TTLicenseFontPtr;
- if( fontptr ) {
- if ( b640X480 || b800X600 ) {
- text_rect.X = 220;
- text_rect.Y = 400;
- text_rect.Width = 300; //460;
- text_rect.Height = 48; //26;
- } else {
- text_rect.X = 250;
- text_rect.Y = 574;
- text_rect.Width = 420; //460;
- text_rect.Height = 60; //26;
- }
- #if(0)
- RECT one;
- one.left = text_rect.X;
- one.top = text_rect.Y;
- one.right = text_rect.X + text_rect.Width;
- one.bottom = text_rect.Y + text_rect.Height;
- FrameRect( hDC, &one, (HBRUSH)( COLOR_WINDOW + 1 ));
- // DrawFocusRect( hDC, &one );
- #endif
- fontptr->Print(
- hDC,
- szWholeString,
- text_rect,
- TEXT_COLOR,
- SHADOW_COLOR,
- TPF_CENTER_TEXT,
- TPF_SHADOW );
- }
- #endif
- #else
- //-------------------------------------------------------------------
- // Select the Brush if it was successfully created.
- //-------------------------------------------------------------------
- if ( hStaticBrush ) {
- HBRUSH oldBrush = (HBRUSH) SelectObject( hDC, hStaticBrush );
- GetClientRect( window_handle, (LPRECT) &dlg_rect );
- FillRect( hDC, &dlg_rect, hStaticBrush );
- SelectObject( hDC, oldBrush );
- }
- #endif
- // Msg( __LINE__, TEXT(__FILE__), TEXT("--------------------------------------------------------" ));
- EndPaint( window_handle, &ps );
- //-----------------------------------------------------------------------
- // Play DISK.WAV sound on CD.
- //-----------------------------------------------------------------------
- if ( FirstTime ) {
- if( UseSounds ) {
- PlaySound( szWavs[ SongNumber ], NULL, SND_ASYNC | SND_RESOURCE );
- }
- FirstTime = FALSE;
- }
- } /* end of if */
- break;
- //-------------------------------------------------------------------------------
- // Background needs to be erased. Note we are returning 1 here to "fake"
- // Windows into thinking we have already repainted the background with
- // our window brush. This prevents "flickering" because of background
- // being repainted ( ususally white ) before WM_PAINT is processed.
- //-------------------------------------------------------------------------------
- #if(BACKGROUND_BITMAP)
- case WM_ERASEBKGND:
- InvalidateRect( window_handle, &dlg_rect, FALSE );
- return ( 1 );
- #endif
- //-------------------------------------------------------------------------------
- // Check which button was pressed. If Explorer button was pressed,
- // call it now so we don't have to exit dialog.
- //-------------------------------------------------------------------------------
- case WM_COMMAND:
- {
- idCtl = LOWORD( w_param );
- unsigned int result = TRUE;
- bool end_dialog = false;
- int cd_drive;
- szBuffer[1] = '\0';
- szBuffer[0] = tolower( szArgvPath[0] );
- // cd_drive = (int)( szBuffer[0] - 'a' + 1 );
- cd_drive = (int)( szBuffer[0] - 'a' );
- #if(BACKGROUND_BITMAP)
- switch ( idCtl ) {
- //-------------------------------------------------------------------
- // IDD_MOHAVI
- //-------------------------------------------------------------------
- case IDD_PREVIEWS:
- {
- Msg( __LINE__, TEXT(__FILE__), TEXT("IDD_PREVIEWS Selected." ));
- // show the previews in succession. each will wait for the previous to finish
- // before playing.
- unsigned int success;
- char filepath[MAX_PATH];
- _snprintf(filepath, MAX_PATH, "%s%s", szArgvPath, SC4AVI_FILENAME);
- success = GlobalMainWindow->Run_OpenFile(cd_drive, filepath, true);
- // if (success != 0) {
- // success = GlobalMainWindow->Run_OpenFile(cd_drive, BFAVI_FILENAME, true);
- // }
- /*
- if (success == 0) {
- std::wstring wideBuffer = TheGameText->fetch("Autorun:CantRunAVIs");
- std::wstring wideBuffer2 = TheGameText->fetch("Autorun:Error");
- int length = wideBuffer.length();
- WideCharToMultiByte( CodePage, 0, wideBuffer.c_str(), length+1, szBuffer, _MAX_PATH, NULL, NULL );
- length = wideBuffer2.length();
- WideCharToMultiByte( CodePage, 0, wideBuffer2.c_str(), length+1, szBuffer2, _MAX_PATH, NULL, NULL );
- MessageBox( NULL, szBuffer, szBuffer2, MB_APPLMODAL | MB_OK );
- }
- */
- }
- break;
- case IDD_HELP:
- {
- std::wstring wFileName;
- wFileName = Locale_GetString(HELP_FILENAME);
-
- std::string fname;
- const wchar_t *tmp = wFileName.c_str();
- char hack[2] = "a";
- while (*tmp)
- {
- hack[0] = (char)( *tmp & 0xFF );
- fname.append( hack );
- tmp++;
- }
- char newdir[MAX_PATH];
- char olddir[MAX_PATH];
- char filepath[MAX_PATH];
- GetCurrentDirectory(MAX_PATH, olddir);
- _snprintf(newdir, MAX_PATH, "%ssupport", szArgvPath);
- SetCurrentDirectory(newdir);
- _snprintf(filepath, MAX_PATH, "%s%s", szArgvPath, fname.c_str());
- unsigned int success;
- success = GlobalMainWindow->Run_OpenFile(cd_drive, filepath, false);
- SetCurrentDirectory(olddir);
- /*
- if (success == 0) {
- std::wstring wideBuffer = TheGameText->fetch("Autorun:CantRunHelp");
- std::wstring wideBuffer2 = TheGameText->fetch("Autorun:Error");
- int length = wideBuffer.length();
- WideCharToMultiByte( CodePage, 0, wideBuffer.c_str(), length+1, szBuffer, _MAX_PATH, NULL, NULL );
- length = wideBuffer2.length();
- WideCharToMultiByte( CodePage, 0, wideBuffer2.c_str(), length+1, szBuffer2, _MAX_PATH, NULL, NULL );
- MessageBox( NULL, szBuffer, szBuffer2, MB_APPLMODAL | MB_OK );
- }
- */
- }
- break;
- //-------------------------------------------------------------------
- // IDD_CANCEL
- //-------------------------------------------------------------------
- case IDD_CANCEL:
- Msg( __LINE__, TEXT(__FILE__), TEXT("IDD_CANCEL Selected." ));
- end_dialog = true;
- break;
- //-------------------------------------------------------------------
- // IDD_OK -- Install
- // IDD_OK2 -- Play
- //-------------------------------------------------------------------
- case IDD_OK:
- case IDD_OK2:
- case IDD_OK3:
- case IDD_OK4:
- // if( !Is_On_CD( PRODUCT_VOLUME_CD1 ) && IsEnglish ) {
- if( !Is_On_CD( PRODUCT_VOLUME_CD1 )) {
- //-----------------------------------------------------------
- // If false is returned, then CANCEL was pressed.
- //-----------------------------------------------------------
- char volume_to_match[ MAX_PATH ];
- Reformat_Volume_Name( PRODUCT_VOLUME_CD1, volume_to_match );
- // result = Prompt_For_CD( window_handle, volume_to_match, IDS_INSERT_CDROM_WITH_VOLUME1, IDS_EXIT_MESSAGE2, &cd_drive );
- result = Prompt_For_CD( window_handle, volume_to_match, "Autorun:InsertCDROMWithVolume1", "Autorun:ExitMessage2", &cd_drive );
- }
- if ( result ) {
- if ( idCtl == IDD_OK ) {
- Msg( __LINE__, TEXT(__FILE__), TEXT("IDD_OK Selected." ));
- result = GlobalMainWindow->Run_Setup( window_handle, &dlg_rect, cd_drive );
- } else if ( idCtl == IDD_OK2 ) {
- Msg( __LINE__, TEXT(__FILE__), TEXT("IDD_OK2 Selected." ));
- result = GlobalMainWindow->Run_Game( window_handle, &dlg_rect );
- } else if (idCtl == IDD_OK3 ) {
- Msg( __LINE__, TEXT(__FILE__), TEXT("IDD_OK3 Selected, running WorldBuilder." ));
- result = GlobalMainWindow->Run_WorldBuilder( window_handle, &dlg_rect );
- } else if (idCtl == IDD_OK4 ) {
- Msg( __LINE__, TEXT(__FILE__), TEXT("IDD_OK4 Selected, running PatchGet." ));
- result = GlobalMainWindow->Run_PatchGet( window_handle, &dlg_rect );
- }
- }
- if ( result ) {
- end_dialog = true;
- }
- break;
- #if(SHOW_MOH_DEMO)
- //-------------------------------------------------------------------
- // Launch demo from CD.
- //-------------------------------------------------------------------
- case IDD_VIEW_DEMO:
- if( !Is_On_CD( PRODUCT_VOLUME_CD2 )) {
- //-----------------------------------------------------------
- // If false is returned, then CANCEL was pressed.
- //-----------------------------------------------------------
- char volume_to_match[ MAX_PATH ];
- Reformat_Volume_Name( PRODUCT_VOLUME_CD2, volume_to_match );
- // result = Prompt_For_CD( window_handle, volume_to_match, IDS_INSERT_CDROM_WITH_VOLUME2, IDS_EXIT_MESSAGE2, &cd_drive );
- result = Prompt_For_CD( window_handle, volume_to_match, AsciiString("Autorun:InsertCDROMWithVolume2"), AsciiString("Autorun:ExitMessage2"), &cd_drive );
- }
- if ( result ) {
- Msg( __LINE__, TEXT(__FILE__), TEXT("IDD_VIEW_DEMO Selected." ));
- result = GlobalMainWindow->Run_Demo( window_handle, &dlg_rect, cd_drive );
- }
- if ( result ) {
- end_dialog = true;
- }
- break;
- #endif
- #if( SHOW_GAMESPY_BUTTON )
- //-------------------------------------------------------------------
- // Launch GameSpy Website.
- //-------------------------------------------------------------------
- case IDD_GAMESPY:
- Msg( __LINE__, TEXT(__FILE__), TEXT("IDD_GAMESPY Selected." ));
- if( ViewHTML( GAMESPY_WEBSITE ))
- {
- end_dialog = true;
- }
- else
- {
- Error_Message( Main::hInstance, AsciiString("Autorun:Generals"), AsciiString("Autorun:CantFindExplorer"), GAME_WEBSITE );
- }
- break;
- #endif
- //-------------------------------------------------------------------
- // Create a new online account.
- //-------------------------------------------------------------------
- case IDD_NEW_ACCOUNT:
- Msg( __LINE__, TEXT(__FILE__), TEXT("IDD_NEW_ACCOUNT Selected." ));
- result = GlobalMainWindow->Run_New_Account( window_handle, &dlg_rect );
- if ( result ) {
- end_dialog = true;
- }
- break;
- //-------------------------------------------------------------------
- // IDD_REGISTER
- //-------------------------------------------------------------------
- case IDD_REGISTER:
- Msg( __LINE__, TEXT(__FILE__), TEXT("IDD_REGISTER Selected." ));
- result = GlobalMainWindow->Run_Register( window_handle, &dlg_rect );
- if ( result ) {
- end_dialog = true;
- }
- break;
- //-------------------------------------------------------------------
- // IDD_INTERNET
- //-------------------------------------------------------------------
- case IDD_INTERNET:
- Msg( __LINE__, TEXT(__FILE__), TEXT("IDD_INTERNET Selected." ));
- if( ViewHTML( GAME_WEBSITE )) {
- end_dialog = true;
- }
- else
- {
- Error_Message( Main::hInstance, "Autorun:Generals", "Autorun:CantFindExplorer", GAME_WEBSITE );
- }
- break;
- //-------------------------------------------------------------------
- // IDD_UPDATE
- //-------------------------------------------------------------------
- case IDD_UPDATE:
- Msg( __LINE__, TEXT(__FILE__), TEXT("IDD_UPDATE Selected." ));
- result = GlobalMainWindow->Run_Auto_Update( window_handle, &dlg_rect );
- if ( result ) {
- end_dialog = true;
- }
- break;
- //-------------------------------------------------------------------
- // IDD_EXPLORE
- //-------------------------------------------------------------------
- case IDD_EXPLORE:
- Msg( __LINE__, TEXT(__FILE__), TEXT("IDD_EXPLORE Selected." ));
- GlobalMainWindow->Run_Explorer( "", window_handle, &dlg_rect );
- end_dialog = true;
- break;
- //-------------------------------------------------------------------
- // IDD_UNINSTALL
- //-------------------------------------------------------------------
- case IDD_UNINSTALL:
- Msg( __LINE__, TEXT(__FILE__), TEXT("IDD_UNINSTALL Selected." ));
- result = GlobalMainWindow->Run_Uninstall( window_handle, &dlg_rect );
- //---------------------------------------------------------------
- // MML 5/27/99: I am exiting here because the we launch
- // Uninstll.exe which in turn launches Uninst.exe thus
- // ::Run_Install ends before Uninst.exe is done.
- //---------------------------------------------------------------
- #if 1
- if ( result ) {
- end_dialog = true;
- }
- #endif
- break;
- default:
- break;
- }
- //-----------------------------------------------------------------------
- // Exit Autorun.
- //-----------------------------------------------------------------------
- if( end_dialog ) {
- for ( i = 0; i < NUM_BUTTONS; i++ ) {
- if ( ButtonList[i] ) {
- delete( ButtonList[i] );
- ButtonList[i] = NULL;
- }
- }
- if ( hpal ) {
- DeleteObject( hpal );
- }
- if ( hBitmap ) {
- DeleteObject( hBitmap );
- }
- for( i = 0; i < NUM_FLICKER_FRAMES; i++ ) {
- DeleteObject( hFlicker[i] );
- hFlicker[i] = 0;
- }
- Stop_Sound_Playing();
- KillTimer( window_handle, timer_id );
- EndDialog( window_handle, idCtl );
- }
- #else
- if ( hStaticBrush ) {
- DeleteObject( hStaticBrush );
- hStaticBrush = 0;
- }
- EndDialog( window_handle, idCtl );
- KillTimer( window_handle, timer_id );
- KillTimer( window_handle, gem_timer_id );
- #endif
- }
- break;
- //-------------------------------------------------------------------------------
- // This message is the response to the Close Button in upper right corner.
- //-------------------------------------------------------------------------------
- case WM_SYSCOMMAND:
- if ( w_param == SC_CLOSE ) {
- #if(BACKGROUND_BITMAP)
- for ( i = 0; i < NUM_BUTTONS; i++ ) {
- if ( ButtonList[i] ) {
- delete( ButtonList[i] );
- ButtonList[i] = NULL;
- }
- }
- if ( hpal ) {
- DeleteObject( hpal );
- }
- if ( hBitmap ) {
- DeleteObject( hBitmap );
- }
- for( i = 0; i < NUM_FLICKER_FRAMES; i++ ) {
- DeleteObject( hFlicker[i] );
- hFlicker[i] = 0;
- }
- #else
- if ( hStaticBrush ) {
- DeleteObject( hStaticBrush );
- hStaticBrush = 0;
- }
- #endif
- //-----------------------------------------------------------------------
- // Stop the sound if still going.
- //-----------------------------------------------------------------------
- Stop_Sound_Playing();
- //-----------------------------------------------------------------------
- // Delete the arguments.
- //-----------------------------------------------------------------------
- if ( Args ) {
- delete( Args );
- Args = NULL;
- }
- KillTimer( window_handle, timer_id );
- EndDialog( window_handle, w_param );
- }
- break;
- //-------------------------------------------------------------------------------
- // WM_SYSCOLORCHANGE Message.
- // If your applications uses controls in Windows 95/NT, forward the
- // WM_SYSCOLORCHANGE message to the controls.
- //-------------------------------------------------------------------------------
- #if( !BACKGROUND_BITMAP )
- case WM_SYSCOLORCHANGE:
- if ( hStaticBrush ) {
- DeleteObject( hStaticBrush );
- hStaticBrush = CreateSolidBrush( GetSysColor( COLOR_WINDOW ));
- }
- break;
- #endif
- //-------------------------------------------------------------------------------
- // WM_CTLCOLOR Message.
- // wParam Handle to Child Window's device context
- // LOWORD( lParam ) Child Window handle
- // HIWORD( lParam ) Type of Window: CTLCOLOR_MSGBOX, _EDIT, _LISTBOX, _BTN, _DLG, _SCROLLBAR, _STATIC
- //
- // WM_CTLCOLORMSGBOX
- // WM_CTLCOLOREDIT
- // WM_CTLCOLORLISTBOX
- // WM_CTLCOLORBTN
- // WM_CTLCOLORDLG
- // WM_CTLCOLORSCROLLBAR
- // WM_CTLCOLORSTATIC
- // #define WM_CTLCOLOR 0x0019
- // #define GET_WM_CTLCOLOR_HDC (wp, lp, msg) (HDC)(wp)
- // #define GET_WM_CTLCOLOR_HWND(wp, lp, msg) (HWND)(lp)
- // #define GET_WM_CTLCOLOR_TYPE(wp, lp, msg) (WORD)(msg - WM_CTLCOLORMSGBOX)
- // #define GET_WM_CTLCOLOR_MSG (type) (WORD)(WM_CTLCOLORMSGBOX+(type))
- //-------------------------------------------------------------------------------
- #if( !BACKGROUND_BITMAP )
- case WM_CTLCOLOR:
- if ( HIWORD( l_param ) == CTLCOLOR_STATIC ) {
- SetTextColor(( HDC )w_param, GetSysColor( COLOR_WINDOWTEXT ));
- SetBkColor( (HDC)wParam, GetSysColor( COLOR_WINDOW ));
- // SetBkColor(( HDC )w_param, RGB( 192, 192, 192 ));
- UnrealizeObject( hStaticBrush ); // reset the origin of the brush next time used.
- point.x = point.y = 0; // create a point.
- ClientToScreen( window_handle, &point ); // translate into screen coordinates.
- SetBrushOrgEx( (HDC)w_param, point.x, point.y, NULL ); // New Origin to use when next selected.
- return((LRESULT) hStaticBrush );
- }
- #endif
- //===============================================================================
- // Check where Left Mouse button was pressed.
- //===============================================================================
- #if(BACKGROUND_BITMAP)
- case WM_LBUTTONDOWN:
- {
- RECT rect;
- //----------------------------------------------------------------------
- // Get mouse coordinates.
- //----------------------------------------------------------------------
- mouse_x = LOWORD( l_param );
- mouse_y = HIWORD( l_param );
- //----------------------------------------------------------------------
- // For each button in the list...
- //----------------------------------------------------------------------
- for ( i = 0; i < NUM_BUTTONS; i++ ) {
- //-------------------------------------------------------------------
- // If mouse was clicked in one of the "buttons", then change
- // that button's state to "pressed".
- //-------------------------------------------------------------------
- if ( ButtonList[i] && ButtonList[i]->Is_Mouse_In_Region( mouse_x, mouse_y )) {
- if ( ButtonList[i]->Get_State() != DrawButton::PRESSED_STATE ) {
- ButtonList[i]->Return_Area ( &rect );
- ButtonList[i]->Set_State( DrawButton::PRESSED_STATE );
- InvalidateRect( window_handle, &rect, FALSE );
- Msg( __LINE__, TEXT(__FILE__), TEXT("WM_LBUTTONDOWN -- %s. rect = [%d,%d,%d,%d]."),
- ButtonList[i]->Return_Normal_Bitmap(), rect.left, rect.top, rect.right, rect.bottom );
- UpdateWindow( window_handle );
- }
- break;
- }
- }
- }
- break;
- #endif
- //===============================================================================
- // Check where Left Mouse button was released.
- //===============================================================================
- #if(BACKGROUND_BITMAP)
- case WM_LBUTTONUP:
- {
- RECT rect;
- int focus_index = 0;
- int found_focus = -1;
- //-----------------------------------------------------------------------
- // Get mouse coordinates.
- //-----------------------------------------------------------------------
- mouse_x = LOWORD( l_param );
- mouse_y = HIWORD( l_param );
- //=======================================================================
- // focus_index = previous PRESSED/FOCUSED button.
- // found_focus = new PRESSED/FOCUSED button ( if different ).
- //=======================================================================
- //-----------------------------------------------------------------------
- // First find the button that is either focused or pressed.
- //-----------------------------------------------------------------------
- for ( i = 0; i < NUM_BUTTONS; i++ ) {
- if ( ButtonList[i] ) {
- //---------------------------------------------------------------
- // Save index of button with focus.
- //---------------------------------------------------------------
- if( ButtonList[i]->Get_State() == DrawButton::FOCUS_STATE ||
- ButtonList[i]->Get_State() == DrawButton::PRESSED_STATE ) {
- focus_index = i;
- }
- }
- }
- //-----------------------------------------------------------------------
- // Then find the button that is to be focused or pressed.
- //-----------------------------------------------------------------------
- for ( i = 0; i < NUM_BUTTONS; i++ ) {
- if ( ButtonList[i] && ButtonList[i]->Is_Mouse_In_Region( mouse_x, mouse_y )) {
- found_focus = i;
- }
- }
- //-----------------------------------------------------------------------
- // If new button is not found...
- //-----------------------------------------------------------------------
- if ( found_focus == -1 ) {
- //-------------------------------------------------------------------
- // Make sure previously focused/pressed button is now is a
- // focused state and no action is taken. This occurs when
- // mouse is clicked outside of any button areas.
- //-------------------------------------------------------------------
- if ( ButtonList[focus_index] && ( ButtonList[focus_index]->Get_State() != DrawButton::FOCUS_STATE )) {
- ButtonList[focus_index]->Set_State( DrawButton::FOCUS_STATE );
- ButtonList[focus_index]->Return_Area ( &rect );
- InvalidateRect( window_handle, &rect, FALSE );
- Msg( __LINE__, TEXT(__FILE__), TEXT("WM_LBUTTONUP -- %s[FOCUS_STATE] = [x=%d, y=%d, w=%d, h=%d]."),
- ButtonList[ focus_index ]->Return_Normal_Bitmap(), rect.left, rect.top, rect.right, rect.bottom );
- UpdateWindow( window_handle );
- }
- } else {
- //-------------------------------------------------------------------
- // Buttons are one and the same.
- //-------------------------------------------------------------------
- if( focus_index == found_focus ) {
- ButtonList[ found_focus ]->Set_State( DrawButton::FOCUS_STATE );
- ButtonList[ found_focus ]->Return_Area ( &rect );
- InvalidateRect( window_handle, &rect, FALSE );
- Msg( __LINE__, TEXT(__FILE__), TEXT("WM_LBUTTONUP -- %s[FOCUS_STATE] = [x=%d, y=%d, w=%d, h=%d]."),
- ButtonList[ found_focus ]->Return_Normal_Bitmap(), rect.left, rect.top, rect.right, rect.bottom );
- UpdateWindow( window_handle );
- } else {
- //---------------------------------------------------------------
- // Make previously focused button, Normal...
- //---------------------------------------------------------------
- if ( ButtonList[ focus_index ] ) {
-
- ButtonList[ focus_index ]->Set_State( DrawButton::NORMAL_STATE );
- ButtonList[ focus_index ]->Return_Area ( &rect );
- InvalidateRect( window_handle, &rect, FALSE );
-
- Msg( __LINE__, TEXT(__FILE__), TEXT("WM_LBUTTONUP -- %s[NORMAL_STATE] = [x=%d, y=%d, w=%d, h=%d]."),
- ButtonList[ focus_index ]->Return_Normal_Bitmap(),
- rect.left, rect.top, rect.right, rect.bottom );
-
- UpdateWindow( window_handle );
- }
- //---------------------------------------------------------------
- // ...and the new button now has focus.
- //---------------------------------------------------------------
- if ( ButtonList[ found_focus ] ) {
-
- ButtonList[ found_focus ]->Set_State( DrawButton::FOCUS_STATE );
- ButtonList[ found_focus ]->Return_Area ( &rect );
- InvalidateRect( window_handle, &rect, FALSE );
- Msg( __LINE__, TEXT(__FILE__), TEXT("WM_LBUTTONUP -- %s[FOCUS_STATE] = [x=%d, y=%d, w=%d, h=%d]."),
- ButtonList[ found_focus ]->Return_Normal_Bitmap(), rect.left, rect.top, rect.right, rect.bottom );
- UpdateWindow( window_handle );
- }
- }
- }
- //-----------------------------------------------------------------------
- // Repaint the Window now.
- //-----------------------------------------------------------------------
- nResult = UpdateWindow( window_handle );
- //-----------------------------------------------------------------------
- // Do the focus button's action.
- //-----------------------------------------------------------------------
- if ( found_focus >= 0 ) {
- if (( ButtonList[found_focus] ) &&
- ( ButtonList[found_focus]->Get_State() == DrawButton::FOCUS_STATE ) &&
- ( ButtonList[found_focus]->Is_Mouse_In_Region( mouse_x, mouse_y ))) {
- SendMessage( window_handle, WM_COMMAND, ButtonList[found_focus]->Return_Id(), 0L );
- break;
- }
- }
- }
- break;
- #endif
- //-------------------------------------------------------------------------------
- // Check Mouse moves over buttons.
- //-------------------------------------------------------------------------------
- //#if(DISABLE_KEYBOARD)
- #if(BACKGROUND_BITMAP)
- case WM_MOUSEMOVE:
- {
- RECT rect;
- int j;
- int done = 0;
- //-----------------------------------------------------------------------
- // Get mouse coordinates.
- //-----------------------------------------------------------------------
- mouse_x = LOWORD( l_param );
- mouse_y = HIWORD( l_param );
- #if(USE_MOUSE_MOVES)
- //-----------------------------------------------------------------------
- // Reset most current button.
- //-----------------------------------------------------------------------
- CurrentButton = 0;
- #endif
- //-----------------------------------------------------------------------
- // For each button in the list...
- //-----------------------------------------------------------------------
- i = 0;
- while( i < NUM_BUTTONS && !done ) {
- //-------------------------------------------------------------------
- // For each button, check if mouse is in it's area.
- //-------------------------------------------------------------------
- if ( ButtonList[i] && ButtonList[i]->Is_Mouse_In_Region( mouse_x, mouse_y )) {
- //---------------------------------------------------------------
- // This is now the current button.
- //---------------------------------------------------------------
- CurrentButton = ButtonList[i]->Return_Id();
- if( CurrentButton != LastButton ) {
- //-----------------------------------------------------------
- // Make all other buttons, NORMAL.
- //-----------------------------------------------------------
- for ( j = 0; j < NUM_BUTTONS; j++ ) {
- if ( ButtonList[j] ) {
- ButtonList[j]->Set_State( DrawButton::NORMAL_STATE );
- // Msg( __LINE__, TEXT(__FILE__), TEXT("WM_MOUSEMOVE -- %s[NORMAL_STATE]]."), ButtonList[j]->Return_Normal_Bitmap());
- }
- }
- if ( w_param & MK_LBUTTON ) {
- //--------------------------------------------------------
- // Left Mouse button is pressed! Make it a pressed button!
- //--------------------------------------------------------
- if ( ButtonList[i] && ButtonList[i]->Get_State() != DrawButton::PRESSED_STATE ) {
- ButtonList[i]->Set_State( DrawButton::PRESSED_STATE );
- // Msg( __LINE__, TEXT(__FILE__), TEXT("WM_MOUSEMOVE -- %s[PRESSED_STATE]."), ButtonList[i]->Return_Normal_Bitmap());
- }
- } else {
-
- //--------------------------------------------------------
- // If this button is not already focused, give it the focus.
- //--------------------------------------------------------
- if ( ButtonList[i] && ButtonList[i]->Get_State() != DrawButton::FOCUS_STATE ) {
- ButtonList[i]->Set_State( DrawButton::FOCUS_STATE );
- // Msg( __LINE__, TEXT(__FILE__), TEXT("WM_MOUSEMOVE -- %s[FOCUS_STATE]."), ButtonList[i]->Return_Normal_Bitmap());
- }
- } // end of if
- //-----------------------------------------------------------
- // Get the area of the button, and post it for updating.
- //-----------------------------------------------------------
- for ( j = 0; j < NUM_BUTTONS; j++ ) {
- if ( ButtonList[j] ) {
- ButtonList[j]->Return_Area ( &rect );
- InvalidateRect( window_handle, &rect, FALSE );
- }
- }
- //-----------------------------------------------------------
- // Repaint now!
- //-----------------------------------------------------------
- UpdateWindow( window_handle );
- done = 1;
- }
- } // end of if
- i++;
- } // end of for
- #if( USE_MOUSE_MOVES )
- //-----------------------------------------------------------------------
- // If a MouseMove was found to be in one of the buttons, then
- // CurrentButton will have a value.
- //-----------------------------------------------------------------------
- if ( CurrentButton != 0 ) {
- LastButton = CurrentButton;
- //-------------------------------------------------------------------
- // If we are still in the same button, don't make a sound!
- //-------------------------------------------------------------------
- if ( LastButton != PrevButton ) {
- PrevButton = LastButton;
- PlaySound( szButtonWav, Main::hModule, SND_ASYNC | SND_RESOURCE );
- }
- }
- #endif
- }
- break;
- #endif // Background_Bitmap flag
- //#endif
- //-------------------------------------------------------------------------------
- // Repaint when focus is restored (does partial repaint), and when
- // mouse is double clicked on dialog ( full repaint ).
- //-------------------------------------------------------------------------------
- case WM_LBUTTONDBLCLK:
- case WM_SETFOCUS:
- InvalidateRect( window_handle, &dlg_rect, TRUE );
- // nResult = UpdateWindow( window_handle );
- // Msg( __LINE__, TEXT(__FILE__), TEXT("WM_LBUTTONDBLCLK -- dlg_rect = [x=%d, y=%d, w=%d, h=%d]."),
- // dlg_rect.left, dlg_rect.top, dlg_rect.right, dlg_rect.bottom );
- break;
- #if(BACKGROUND_BITMAP)
- //-------------------------------------------------------------------------------
- // bit 30 of lParam - Specifies the previous key state.
- // The value is 1 if the key is down before the message is sent,
- // or it is 0 if the key is up.
- //-------------------------------------------------------------------------------
- case WM_KEYUP:
- {
- // int j = 0;
- switch( w_param ) {
- case VK_ESCAPE:
- SendMessage( window_handle, WM_SYSCOMMAND, SC_CLOSE, 0L );
- break;
- //#if(DISABLE_KEYBOARD)
- case VK_RETURN:
- //---------------------------------------------------------------
- // If the Return/Enter key is pressed... find the focused
- // button and call its action.
- //---------------------------------------------------------------
- // result = ( l_param & 0x40000000 );
- for ( i = 0; i < NUM_BUTTONS; i++ ) {
- if ( ButtonList[i] && ButtonList[i]->Get_State() == DrawButton::FOCUS_STATE ) {
- SendMessage( window_handle, WM_COMMAND, ButtonList[i]->Return_Id(), 0L );
- break;
- }
- }
- break;
- //#endif
- //#if(DISABLE_KEYBOARD)
- case VK_TAB:
- case VK_DOWN:
- {
- //-----------------------------------------------------------
- // Find the button with focus and "tab" to the next button by finding
- // the next valid index. If past last button, circle back to the top.
- //-----------------------------------------------------------
- int focused_button = 0;
- int next_button = 0;
- for ( i = 0; i < NUM_BUTTONS; i++ ) {
- if ( ButtonList[i] && ButtonList[i]->Get_State() == DrawButton::FOCUS_STATE ) {
- focused_button = i;
- next_button = i+1;
- if ( next_button >= NUM_BUTTONS ) {
- next_button = 0;
- }
- while (( next_button < NUM_BUTTONS ) && !ButtonList[ next_button ] ) {
- next_button++;
- }
- if ( next_button >= NUM_BUTTONS ) {
- next_button = 0;
- while (( next_button < NUM_BUTTONS ) && !ButtonList[ next_button ] ) {
- next_button++;
- }
- }
- break;
- }
- }
- //-----------------------------------------------------------
- // Set the previous button to Normal status.
- //-----------------------------------------------------------
- if ( ButtonList[focused_button] && ( ButtonList[focused_button]->Get_State() != DrawButton::NORMAL_STATE )) {
- ButtonList[focused_button]->Set_State( DrawButton::NORMAL_STATE );
- ButtonList[focused_button]->Return_Area ( &rect );
- InvalidateRect( window_handle, &rect, FALSE );
- Msg( __LINE__, TEXT(__FILE__), TEXT("VK_DOWN/VK_TAB -- %s = [%s]."), ButtonList[focused_button]->Return_Normal_Bitmap(), "NORMAL_STATE" );
- }
- //-----------------------------------------------------------
- // Set the new button to focus status.
- //-----------------------------------------------------------
- if ( ButtonList[next_button] && ( ButtonList[next_button]->Get_State() != DrawButton::FOCUS_STATE )) {
- ButtonList[next_button]->Set_State( DrawButton::FOCUS_STATE );
- ButtonList[next_button]->Return_Area ( &rect );
- InvalidateRect( window_handle, &rect, FALSE );
- PlaySound( szButtonWav, Main::hModule, SND_ASYNC | SND_RESOURCE );
- Msg( __LINE__, TEXT(__FILE__), TEXT("VK_DOWN/VK_TAB -- %s = [%s]."), ButtonList[next_button]->Return_Normal_Bitmap(), "FOCUS_STATE" );
- }
- }
- break;
- case VK_UP:
- {
- //-----------------------------------------------------------
- // Find the button with focus and "tab" to the next button by finding
- // the next valid index. If past last button, circle back to the top.
- //-----------------------------------------------------------
- int focused_button = 0;
- int next_button = 0;
- for ( i = 0; i < NUM_BUTTONS; i++ ) {
- if ( ButtonList[i] && ButtonList[i]->Get_State() == DrawButton::FOCUS_STATE ) {
- focused_button = i;
- next_button = i-1;
- if ( next_button < 0 ) {
- next_button = NUM_BUTTONS - 1;
- }
- while (( next_button > 0 ) && !ButtonList[ next_button ] ) {
- next_button--;
- }
- if ( !ButtonList[ next_button ]) {
- next_button = NUM_BUTTONS - 1;
- }
- while (( next_button >= 0 ) && !ButtonList[ next_button ] ) {
- next_button--;
- }
- break;
- }
- }
- //-----------------------------------------------------------
- // Set the previous button to Normal status.
- //-----------------------------------------------------------
- if ( ButtonList[focused_button] && ( ButtonList[focused_button]->Get_State() != DrawButton::NORMAL_STATE )) {
- ButtonList[focused_button]->Set_State( DrawButton::NORMAL_STATE );
- ButtonList[focused_button]->Return_Area ( &rect );
- InvalidateRect( window_handle, &rect, FALSE );
- Msg( __LINE__, TEXT(__FILE__), TEXT("VK_DOWN/VK_TAB -- %s = [%s]."), ButtonList[focused_button]->Return_Normal_Bitmap(), "NORMAL_STATE" );
- }
- //-----------------------------------------------------------
- // Set the new button to focus status.
- //-----------------------------------------------------------
- if ( ButtonList[next_button] && ( ButtonList[next_button]->Get_State() != DrawButton::FOCUS_STATE )) {
- ButtonList[next_button]->Set_State( DrawButton::FOCUS_STATE );
- ButtonList[next_button]->Return_Area ( &rect );
- InvalidateRect( window_handle, &rect, FALSE );
- PlaySound( szButtonWav, Main::hModule, SND_ASYNC | SND_RESOURCE );
- Msg( __LINE__, TEXT(__FILE__), TEXT("VK_DOWN/VK_TAB -- %s = [%s]."), ButtonList[next_button]->Return_Normal_Bitmap(), "FOCUS_STATE" );
- }
- }
- break;
- //#endif
- } /* end of switch */
- } /* end of case stmt */
- return ( 0 );
- #endif
- }
- return( FALSE );
- }
- //*****************************************************************************
- // STOP_SOUND_PLAYING -- Stop the background sound.
- //
- // INPUT: none.
- //
- // OUTPUT: none.
- //
- // WARNINGS: Will stop any sound started by PlaySound.
- //
- // HISTORY:
- // 06/04/1999 MML : Created.
- //=============================================================================
- void Stop_Sound_Playing ( void )
- {
- PlaySound( NULL, NULL, SND_ASYNC | SND_FILENAME );
- }
- //*****************************************************************************
- // OPTIONS -- Find any user options and set the correct flags
- //
- // INPUT: int argc = no. of arguments to check
- // BYTE *argv[] = ptr to actual command line parameters
- //
- // OUTPUT:
- //
- // WARNINGS:
- //
- // HISTORY:
- // 06/04/1996 MML : Created.
- //=============================================================================
- BOOL Options( Command_Line_Arguments *Orgs )
- {
- int i;
- BOOL result = TRUE;
- char buffer[ MAX_ARGUMENT_LENGTH ];
- //-------------------------------------------------------------------------
- // Scan arguments for any options ( / or - followed by a letter)
- //-------------------------------------------------------------------------
- for ( i = 0; i < Orgs->Get_argc(); i++ ) {
- //---------------------------------------------------------------------
- // Get the next item in the list.
- //---------------------------------------------------------------------
- memset( buffer, '\0', sizeof( buffer ));
- strcpy( buffer, Orgs->Get_argv(i));
- Msg( __LINE__, TEXT(__FILE__), TEXT("Options -- Argument[%d] = %s."), i, buffer );
- //---------------------------------------------------------------------
- // If starts with / or -
- //---------------------------------------------------------------------
- if (( buffer[0] == '/' ) || ( buffer[0] == '-' )) {
- switch ( tolower( buffer[1] )) {
- //-------------------------------------------------------------
- // Retrieve the game's version info.
- //-------------------------------------------------------------
- case 'v':
- {
- char szPath [ MAX_PATH ];
- char szVersion[ MAX_PATH ];
- Make_Current_Path_To( SETUP_INI_FILE1, szPath );
- GetPrivateProfileString( "Setup", "Version", "1.0", szVersion, sizeof( szVersion ), szPath );
- LoadString( Main::hInstance, IDS_VERSION_STRING, szBuffer, MAX_PATH );
- // sprintf( szBuffer3, "V %s", szVersion );
- sprintf( szBuffer3, szBuffer, szVersion );
- // strcpy( szBuffer, szRegistryKey );
- MessageBox( NULL, szBuffer3, "Autorun", MB_TASKMODAL | MB_OK );
- result = FALSE;
- }
- break;
- //-------------------------------------------------------------
- // Bypass the volume check.
- //-------------------------------------------------------------
- case 'n':
- {
- HANDLE handle;
- WIN32_FIND_DATA FindFileData;
- memset( szVolumeName, '\0', MAX_PATH );
- //-----------------------------------------------------
- // If we think we are on CD2, then use PRODUCT_VOLUME_CD2.
- //-----------------------------------------------------
- Make_Current_Path_To( MOH_DEMO_PROGRAM, szBuffer );
- handle = FindFirstFile( szBuffer, &FindFileData );
- if ( handle == INVALID_HANDLE_VALUE ) {
- strcpy( szVolumeName, PRODUCT_VOLUME_CD1 );
- } else {
- strcpy( szVolumeName, PRODUCT_VOLUME_CD2 );
- FindClose( handle );
- }
- strcpy( Arguments[ NumberArguments++ ], buffer );
- }
- break;
- #if( _DEBUG )
- case 'c':
- if( buffer[2] == 'd' ) {
- szCDDrive[0] = buffer[3];
- szCDDrive[1] = ':';
- szCDDrive[2] = '\\';
- }
- break;
- //-------------------------------------------------------------
- // Change languages?
- //-------------------------------------------------------------
- case 'l':
- {
- //-----------------------------------------------------
- // Identifier Meaning
- // 932 Japan
- // 936 Chinese (PRC, Singapore)
- // 949 Korean
- // 1252 Windows 3.1 Latin 1 (US, Western Europe)
- //-----------------------------------------------------
- char *temp = buffer+2;
- int number = atoi( temp );
- switch( number ) {
- case LANG_GER:
- LanguageToUse = LANG_GER;
- CodePage = 1252;
- break;
- case LANG_FRE:
- LanguageToUse = LANG_FRE;
- CodePage = 1252;
- break;
- case LANG_JAP:
- LanguageToUse = LANG_JAP;
- CodePage = 932;
- break;
- case LANG_KOR:
- LanguageToUse = LANG_KOR;
- CodePage = 949;
- break;
- case LANG_CHI:
- LanguageToUse = LANG_CHI;
- CodePage = 950;
- break;
- case LANG_USA:
- default:
- LanguageToUse = LANG_USA;
- CodePage = 1252;
- break;
- }
- }
- break;
- #endif
- default:
- strcpy( Arguments[ NumberArguments++ ], buffer );
- break;
- }
- }
- }
- Msg( __LINE__, TEXT(__FILE__), TEXT("Options -- Language = %d"), Language );
- Msg( __LINE__, TEXT(__FILE__), TEXT("Options -- CodePage = %d"), CodePage );
- #if(0)
- struct lconv *info = localeconv();
- char szDefaultLangID[ MAX_PATH ];
- GetLocaleInfo(
- LOCALE_USER_DEFAULT, // locale identifier
- LOCALE_ILANGUAGE, // type of information
- szBuffer1, // address of buffer for information
- MAX_PATH ); // size of buffer
- Msg( __LINE__, TEXT(__FILE__), TEXT("Options -- GetLocalInfo = %s"), szBuffer1 );
- sprintf( szDefaultLangID, "%04X", GetUserDefaultLangID());
- Msg( __LINE__, __FILE__, "Options -- GetUserDefaultLangID() = %s", szDefaultLangID );
- sprintf( szDefaultLangID, "%04X", GetSystemDefaultLangID());
- Msg( __LINE__, __FILE__, "Options -- GetSystemDefaultLangID() = %s", szDefaultLangID );
- Msg( __LINE__, __FILE__, "-------------------------------------------------------------" );
- #endif
- return( result );
- }
- //*****************************************************************************
- // Valid_Environment -- Make sure this program is run from CD-ROM disc only
- // AND it is a Win95 system.
- //
- // INPUT: none.
- //
- // OUTPUT: none.
- //
- // WARNINGS: returns 0 if ok to continue.
- //
- // HISTORY:
- // 06/04/1996 MML : Created.
- //=============================================================================
- BOOL Valid_Environment ( void )
- {
- bool result = 0;
- //--------------------------------------------------------------------------
- // Check Windows Version.
- //--------------------------------------------------------------------------
- int length = 0;
- result = WinVersion.Meets_Minimum_Version_Requirements();
- if ( !result )
- {
- std::wstring wideBuffer = TheGameText->fetch("GUI:WindowsVersionText");
- std::wstring wideBuffer2 = TheGameText->fetch("GUI:WindowsVersionTitle");
- length = wideBuffer.length();
- WideCharToMultiByte( CodePage, 0, wideBuffer.c_str(), length+1, szBuffer, _MAX_PATH, NULL, NULL );
- length = wideBuffer2.length();
- WideCharToMultiByte( CodePage, 0, wideBuffer2.c_str(), length+1, szBuffer2, _MAX_PATH, NULL, NULL );
- MessageBox( NULL, szBuffer, szBuffer2, MB_APPLMODAL | MB_OK );
- }
- return( result );
- }
- //****************************************************************************
- // LOADRESOURCEBITMAP -- Find & Load the bitmap from the resource.
- //
- // INPUT: HINSTANCE hInstance -- Program's hInstance.
- // LPTSTR lpString -- name of bitmap to find.
- // HPALETTE FAR *lphPalette -- we will return palette in this.
- //
- // OUTPUT: HBITMAP -- handle to the bitmap if found.
- //
- // WARNINGS:
- //
- // HISTORY: Found this routine on MS Developmemt CD, July 1996.
- // 09/26/1996 MML : Created.
- //=============================================================================
- HBITMAP LoadResourceBitmap( HINSTANCE hInstance, LPTSTR lpString, HPALETTE FAR *lphPalette, bool loading_a_button )
- {
- // HDC hdc;
- int iNumColors;
- HRSRC hRsrc;
- HGLOBAL hGlobal;
- HBITMAP hBitmapFinal = NULL;
- LPBITMAPINFOHEADER lpbi;
- hBitmapFinal = LoadBitmap( hInstance, lpString );
- //--------------------------------------------------------------------------
- // Find the Bitmap in this program's resources.
- //--------------------------------------------------------------------------
- hRsrc = FindResource( hInstance, lpString, RT_BITMAP );
- if ( hRsrc ) {
- //-----------------------------------------------------------------------
- // Load the resource, lock the memory, grab a DC.
- //-----------------------------------------------------------------------
- hGlobal = LoadResource( hInstance, hRsrc );
- lpbi = (LPBITMAPINFOHEADER) LockResource( hGlobal );
- if ( loading_a_button ) {
- //--------------------------------------------------------------------------
- // Set number of colors ( 2 to the nth ).
- //--------------------------------------------------------------------------
- if ( lpbi->biBitCount <= 8 ) {
- iNumColors = ( 1 << lpbi->biBitCount );
- } else {
- iNumColors = 0;
- }
- } else {
- //--------------------------------------------------------------------
- // Get the palette from the resource.
- //--------------------------------------------------------------------
- *lphPalette = CreateDIBPalette((LPBITMAPINFO) lpbi, &iNumColors );
- }
- //-----------------------------------------------------------------------
- // Free DS and memory used.
- //-----------------------------------------------------------------------
- UnlockResource( hGlobal );
- FreeResource( hGlobal );
- }
- return( hBitmapFinal );
- }
-
- //*****************************************************************************
- // CREATEDIBPALETTE -- Creates the palette from the Bitmap found above.
- //
- // INPUT: LPBITMAPINFO lpbmi -- bitmap info from header.
- // LPINT lpiNumColors -- number of colors.
- //
- // OUTPUT: HPALETTE -- handle to the bitmap if found.
- //
- // WARNINGS:
- //
- // HISTORY: Found this routine on MS Developmemt CD, July 1996.
- // 09/26/1996 MML : Created.
- //=============================================================================
- HPALETTE CreateDIBPalette ( LPBITMAPINFO lpbmi, LPINT lpiNumColors )
- {
- LPBITMAPINFOHEADER lpbi;
- LPLOGPALETTE lpPal;
- HANDLE hLogPal;
- HPALETTE hPal = NULL;
- int i;
- lpbi = (LPBITMAPINFOHEADER) lpbmi;
- //--------------------------------------------------------------------------
- // Set number of colors ( 2 to the nth ).
- //--------------------------------------------------------------------------
- if ( lpbi->biBitCount <= 8 ) {
- *lpiNumColors = ( 1 << lpbi->biBitCount );
- } else {
- *lpiNumColors = 0;
- }
- //--------------------------------------------------------------------------
- // If bitmap has a palette ( bitcount ), lock some memory and create
- // a palette from the bitmapinfoheader passed in.
- //--------------------------------------------------------------------------
- if ( *lpiNumColors ) {
- hLogPal = GlobalAlloc( GHND, sizeof( LOGPALETTE ) + sizeof( PALETTEENTRY ) * ( *lpiNumColors ));
- lpPal = (LPLOGPALETTE) GlobalLock( hLogPal );
- lpPal->palVersion = 0x300;
- lpPal->palNumEntries = (WORD)*lpiNumColors;
- for ( i = 0; i < *lpiNumColors; i++ ) {
- lpPal->palPalEntry[i].peRed = lpbmi->bmiColors[i].rgbRed;
- lpPal->palPalEntry[i].peGreen = lpbmi->bmiColors[i].rgbGreen;
- lpPal->palPalEntry[i].peBlue = lpbmi->bmiColors[i].rgbBlue;
- lpPal->palPalEntry[i].peFlags = 0;
- }
- hPal = CreatePalette( lpPal );
- GlobalUnlock( hLogPal );
- GlobalFree( hLogPal );
- #if(0)
- StandardFileClass fileout;
- char buff[2];
- fileout.Open( "test.pal", MODE_WRITE_TRUNCATE );
- for ( i = 0; i < *lpiNumColors; i++ ) {
- sprintf( buff, "%d", lpPal->palPalEntry[i].peRed >> 2 );
- fileout.Write(( void *)buff, 2 );
- sprintf( buff, "%d", lpPal->palPalEntry[i].peGreen >> 2 );
- fileout.Write(( void *)buff, 2 );
- sprintf( buff, "%d", lpPal->palPalEntry[i].peBlue >> 2 );
- fileout.Write(( void *)buff, 2 );
- }
- fileout.Close();
- #endif
- }
- return( hPal );
- }
- //*****************************************************************************
- // LOADRESOURCEBUTTON -- Find & Load the bitmap from the resource.
- //
- // INPUT: HINSTANCE hInstance -- Program's hInstance.
- // LPTSTR lpString -- name of bitmap to find.
- // HPALETTE FAR *lphPalette -- we will return palette in this.
- //
- // OUTPUT: HBITMAP -- handle to the bitmap if found.
- //
- // WARNINGS:
- //
- // HISTORY: Found this routine on MS Developmemt CD, July 1996.
- // 09/26/1996 MML : Created.
- //=============================================================================
- HBITMAP LoadResourceButton( HINSTANCE hInstance, LPTSTR lpString, HPALETTE FAR lphPalette )
- {
- HDC hdc;
- int iNumColors;
- HRSRC hRsrc;
- HGLOBAL hGlobal;
- HBITMAP hBitmapFinal = NULL;
- LPBITMAPINFOHEADER lpbi;
- //--------------------------------------------------------------------------
- // Find the Bitmap in this program's resources.
- //--------------------------------------------------------------------------
- hRsrc = FindResource( hInstance, lpString, RT_BITMAP );
- if ( hRsrc ) {
- //-----------------------------------------------------------------------
- // Load the resource, lock the memory, grab a DC.
- //-----------------------------------------------------------------------
- hGlobal = LoadResource( hInstance, hRsrc );
- lpbi = (LPBITMAPINFOHEADER) LockResource( hGlobal );
- hdc = GetDC( NULL );
- //--------------------------------------------------------------------------
- // Set number of colors ( 2 to the nth ).
- //--------------------------------------------------------------------------
- if ( lpbi->biBitCount <= 8 ) {
- iNumColors = ( 1 << lpbi->biBitCount );
- } else {
- iNumColors = 0;
- }
- //-----------------------------------------------------------------------
- // Get the palette from the resource.
- // Select to the DC and realize it in the System palette.
- //-----------------------------------------------------------------------
- // *lphPalette = CreateDIBPalette((LPBITMAPINFO) lpbi, &iNumColors );
- if ( lphPalette != NULL ) {
- SelectPalette( hdc, lphPalette, FALSE );
- RealizePalette( hdc );
- }
- //-----------------------------------------------------------------------
- // Now create the bitmap itself.
- //-----------------------------------------------------------------------
- hBitmapFinal = CreateDIBitmap(
- hdc,
- (LPBITMAPINFOHEADER)lpbi,
- (LONG)CBM_INIT,
- (LPTSTR)lpbi + lpbi->biSize + iNumColors * sizeof( RGBQUAD ),
- (LPBITMAPINFO)lpbi,
- DIB_RGB_COLORS );
- //-----------------------------------------------------------------------
- // Free DS and memory used.
- //-----------------------------------------------------------------------
- ReleaseDC( NULL, hdc );
- UnlockResource( hGlobal );
- FreeResource( hGlobal );
- }
- return( hBitmapFinal );
- }
- //*****************************************************************************
- // Cant_Find_MessageBox -- Find & Load the bitmap from the resource.
- //
- // INPUT: HINSTANCE hInstance -- Program's hInstance.
- // LPTSTR lpString -- name of bitmap to find.
- // HPALETTE FAR *lphPalette -- we will return palette in this.
- //
- // OUTPUT: HBITMAP -- handle to the bitmap if found.
- //
- // WARNINGS:
- //
- // HISTORY: Found this routine on MS Developmemt CD, July 1996.
- // 09/26/1996 MML : Created.
- // 08/27/2003 JFS : Repaired!
- //=============================================================================
- void Cant_Find_MessageBox ( HINSTANCE hInstance, char *szPath )
- {
- //
- // JFS... Added functionality to make this work in wide characters.
- //
- #ifdef LEAN_AND_MEAN
- {
- Locale_GetString( "Autorun:AutorunTitle", szWideBuffer );
- swprintf( szWideBuffer3, szWideBuffer, szProductName );
- Locale_GetString( "Autorun:CantFind", szWideBuffer );
- MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, szPath, _MAX_PATH, szWideBuffer0, _MAX_PATH );
- swprintf( szWideBuffer2, szWideBuffer, szWideBuffer0 );
- MessageBoxW( NULL, szWideBuffer2, szWideBuffer3, MB_APPLMODAL | MB_OK );
- }
- #else
- std::wstring wideBuffer = TheGameText->fetch("Autorun:AutorunTitle");
- std::wstring wideBuffer2.format( wideBuffer.str(), productName.str() );
- std::wstring wideBuffer3 = TheGameText->fetch("Autorun:CantFind");
- WideCharToMultiByte( CodePage, 0, wideBuffer3.str(), wideBuffer3.getLength()+1, szBuffer3, _MAX_PATH, NULL, NULL );
- WideCharToMultiByte( CodePage, 0, wideBuffer2.str(), wideBuffer2.getLength()+1, szBuffer2, _MAX_PATH, NULL, NULL );
- sprintf( szBuffer1, szBuffer3, szPath );
- if ( strlen( szPath ) < 3 )
- {
- MessageBox( NULL, "The path specified in Cant_Find_MessageBox was blank", "Autorun", MB_APPLMODAL | MB_OK );
- return;
- }
- if ( strlen( szBuffer1 ) < 3 && strlen( szBuffer3 ) < 3 )
- {
- MessageBox( NULL, "***MISSING MESSAGES***... IDS_AUTORUN_TITLE and IDS_CANT_FIND", "Autorun", MB_APPLMODAL | MB_OK );
- return;
- }
- if ( strlen( szBuffer1 ) < 3 )
- {
- MessageBox( NULL, "***MISSING MESSAGE***... IDS_AUTORUN_TITLE", "Autorun", MB_APPLMODAL | MB_OK );
- return;
- }
- if ( strlen( szBuffer3 ) < 3 )
- {
- MessageBox( NULL, "***MISSING MESSAGE***... IDS_CANT_FIND", "Autorun", MB_APPLMODAL | MB_OK );
- return;
- }
- MessageBox( NULL, szBuffer1, szBuffer2, MB_APPLMODAL | MB_OK );
- #endif
- }
- /******************************************************************************
- * Error_Message --
- *
- * INPUT:
- *
- * OUTPUT:
- *
- * WARNINGS: none
- *
- * HISTORY:
- * 08/14/1998 MML : Created.
- *============================================================================*/
- void Error_Message ( HINSTANCE hInstance, const char * title, const char * string, char *path )
- {
- #ifndef LEAN_AND_MEAN
- wideBuffer2 = TheGameText->fetch(title);
- wideBuffer3 = TheGameText->fetch(string);
- if ( path && ( path[0] != '\0' ))
- {
- wideBuffer3.format( wideBuffer.str(), path );
- }
- else
- {
- wideBuffer3 = wideBuffer; // insert not provided
- }
- WideCharToMultiByte( CodePage, 0, wideBuffer2.str(), wideBuffer2.getLength()+1, szBuffer2, _MAX_PATH, NULL, NULL );
- WideCharToMultiByte( CodePage, 0, wideBuffer3.str(), wideBuffer3.getLength()+1, szBuffer3, _MAX_PATH, NULL, NULL );
- MessageBox( NULL, szBuffer3, szBuffer2, MB_APPLMODAL | MB_OK );
- #endif
- MessageBox( NULL, "ERROR_UNDEFINED", "ERROR_UNDEFINED", MB_APPLMODAL | MB_OK );
- }
- /******************************************************************************
- / Launch Class Object
- /******************************************************************************/
- LaunchObjectClass::LaunchObjectClass ( char *path, char *args )
- {
- memset( szPath, '\0', _MAX_PATH );
- memset( szArgs, '\0', _MAX_PATH );
- if( path != NULL && path[0] != '\0' ) {
- strcpy( szPath, path );
- }
- if( args != NULL && args[0] != '\0' ) {
- strcpy( szArgs, args );
- }
- }
- void LaunchObjectClass::SetPath ( char *path )
- {
- if( path != NULL && path[0] != '\0' ) {
- memset( szPath, '\0', _MAX_PATH );
- strcpy( szPath, path );
- }
- }
- void LaunchObjectClass::SetArgs ( char *args )
- {
- if( args != NULL && args[0] != '\0' ) {
- memset( szArgs, '\0', _MAX_PATH );
- strcpy( szArgs, args );
- }
- }
- unsigned int LaunchObjectClass::Launch ( void )
- {
- char filepath [_MAX_PATH];
- char dir [_MAX_DIR];
- char ext [_MAX_EXT];
- char drive [_MAX_DRIVE];
- char file [_MAX_FNAME];
- char lpszComLine [ 127 ];
- PROCESS_INFORMATION processinfo;
- STARTUPINFO startupinfo;
- unsigned int abc = 0;
- unsigned int result = 0;
- memset( lpszComLine, '\0', 127 );
- //--------------------------------------------------------------------------
- // Split into parts.
- //--------------------------------------------------------------------------
- _splitpath( szPath, drive, dir, file, ext );
- //--------------------------------------------------------------------------
- // Change current path to the correct dir.
- //
- // The _chdrive function changes the current working drive to the drive
- // specified by drive. The drive parameter uses an integer to specify the
- // new working drive (1=A, 2=B, and so forth). This function changes only
- // the working drive; _chdir changes the working directory.
- //--------------------------------------------------------------------------
- _makepath( filepath, drive, dir, NULL, NULL );
- Path_Remove_Back_Slash( filepath );
- abc = (unsigned)( toupper( filepath[0] ) - 'A' + 1 );
- if ( !_chdrive( abc )) {
- //----------------------------------------------------------------------
- // Returns a value of 0 if successful.
- //----------------------------------------------------------------------
- abc = _chdir( filepath );
- }
- #if (_DEBUG)
- int cde = _getdrive();
- _getcwd( szBuffer, _MAX_PATH );
- Msg( __LINE__, TEXT(__FILE__), TEXT("Current Working Dir = %d\\%s." ), cde, szBuffer );
- #endif
- //--------------------------------------------------------------------------
- // Try to launch the EXE...
- //--------------------------------------------------------------------------
- _stprintf( lpszComLine, _TEXT( "%s %s" ), szPath, szArgs );
- //==========================================================================
- // Setup the call
- //==========================================================================
- memset( &startupinfo, 0, sizeof( STARTUPINFO ));
- startupinfo.cb = sizeof( STARTUPINFO );
- Msg( __LINE__, TEXT(__FILE__), TEXT("About to launch %s." ), lpszComLine );
- result = CreateProcess(
- szPath, // address of module name
- lpszComLine, // address of command line
- NULL, // address of process security attributes
- NULL, // address of thread security attributes
- FALSE, // new process inherits handles
- FALSE,
- NULL, // address of new environment block
- NULL, // address of current directory name
- &startupinfo, // address of STARTUPINFO
- &processinfo ); // address of PROCESS_INFORMATION
- //--------------------------------------------------------------------------
- // If WinExec returned 0, error occurred.
- //--------------------------------------------------------------------------
- if ( !result ) {
- Msg( __LINE__, TEXT(__FILE__), TEXT("Launch of %s failed." ), lpszComLine );
- _makepath ( filepath, NULL, NULL, file, ext );
- Cant_Find_MessageBox ( Main::hInstance, filepath );
- }
- Msg( __LINE__, TEXT(__FILE__), TEXT("Launch of %s succeeded." ), lpszComLine );
- return( result );
- }
- void Debug_Date_And_Time_Stamp ( void )
- {
- //-------------------------------------------------------------------------
- // tm_sec - Seconds after minute (0 – 59)
- // tm_min - Minutes after hour (0 – 59)
- // tm_hour - Hours after midnight (0 – 23)
- // tm_mday - Day of month (1 – 31)
- // tm_mon - Month (0 – 11; January = 0)
- // tm_year - Year (current year minus 1900)
- // tm_wday - Day of week (0 – 6; Sunday = 0)
- // tm_yday - Day of year (0 – 365; January 1 = 0)
- //-------------------------------------------------------------------------
- static char *Month_Strings[ 12 ] = {
- "January",
- "February",
- "March",
- "April",
- "May",
- "June",
- "July",
- "August",
- "September",
- "October",
- "November",
- "December"
- };
- static char *Week_Day_Strings[ 7 ] = {
- "Sunday",
- "Monday",
- "Tuesday",
- "Wednesday",
- "Thursday",
- "Friday",
- "Saturday",
- };
- char ampm[] = "AM";
- time_t ltime;
- struct tm * today;
- /*-------------------------------------------------------------------------
- *Convert to time structure and adjust for PM if necessary.
- */
- time( <ime );
- today = localtime( <ime );
- if( today->tm_hour > 12 ) {
- strcpy( ampm, "PM" );
- today->tm_hour -= 12;
- }
- if( today->tm_hour == 0 ) { /* Adjust if midnight hour. */
- today->tm_hour = 12;
- }
- Msg( __LINE__, __FILE__, "%s, %s %d, %d %d:%d:%d %s",
- Week_Day_Strings[ today->tm_wday ],
- Month_Strings[ today->tm_mon ],
- today->tm_mday,
- today->tm_year + 1900,
- today->tm_hour,
- today->tm_min,
- today->tm_sec,
- ampm );
- /*-------------------------------------------------------------------------
- * Note how pointer addition is used to skip the first 11
- * characters and printf is used to trim off terminating
- * characters.
- */
- // Msg( __LINE__, __FILE__, "%s %s\n", asctime( today ), ampm );
- }
- bool Is_On_CD ( char *volume_name )
- {
- char volume_to_match[ MAX_PATH ];
- Reformat_Volume_Name( volume_name, volume_to_match );
- if( _stricmp( szVolumeName, volume_to_match ) == 0 ) {
- return true;
- } else {
- return false;
- }
- }
- bool Prompt_For_CD ( HWND window_handle, char *volume_name, const char * message1, const char * message2, int *cd_drive )
- {
- int drive;
- strcpy( szBuffer, Args->Get_argv( 0 ));
- drive = toupper( szBuffer[0] ) - 'A';
- memset( szBuffer, '\0', MAX_PATH );
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // This is the correct check for a CD Check.
- //
- // MML: Modified on 10/18/2000 so it would check for all available CD drives.
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- int result = IDRETRY;
- while( result == IDRETRY ) {
- if ( CD_Volume_Verification( drive, szBuffer, volume_name )) {
- result = IDOK;
- *cd_drive = drive;
- } else {
- CDList.Reset_Index();
- while(( result == IDRETRY ) && ( CDList.Get_Index() < CDList.Get_Number_Of_Drives())) {
- drive = CDList.Get_Next_CD_Drive();
- if ( CD_Volume_Verification( drive, szBuffer, volume_name )) {
- result = IDOK;
- *cd_drive = drive;
- }
- }
- }
- if ( result == IDRETRY ) {
- result = ( Show_Message( window_handle, message1, message2 ));
- }
- }
- if ( result == IDCANCEL ) {
- return( false );
- // return true;
- }
- return( true );
- }
- int Show_Message ( HWND window_handle, const char * message1, const char * message2 )
- {
- #ifndef LEAN_AND_MEAN
- UnicodeString string1;
- UnicodeString string2;
- WCHAR szString3[ MAX_PATH ];
- int result = false;
- string1 = TheGameText->fetch(message1);
- string2 = TheGameText->fetch(message2);
- wcscpy( szString3, string1.str() );
- wcscat( szString3, L" " );
- wcscat( szString3, string2.str() );
- WideCharToMultiByte( CodePage, 0, szString3, _MAX_PATH, szBuffer, _MAX_PATH, NULL, NULL );
- result = MessageBox( window_handle, szBuffer, "Autorun", MB_RETRYCANCEL|MB_APPLMODAL|MB_SETFOREGROUND );
- return( result );
- #else
- return ( 0 );
- #endif
- }
- void Reformat_Volume_Name ( char *volume_name, char *new_volume_name )
- {
- char temp_volume_name[ MAX_PATH ];
- strcpy( temp_volume_name, volume_name );
- if( WinVersion.Is_Win95()) {
- temp_volume_name[11] = '\0';
- }
- if( new_volume_name != NULL ) {
- strcpy( new_volume_name, temp_volume_name );
- }
- }
|