atlctrls.h 258 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725
  1. // Windows Template Library - WTL version 10.0
  2. // Copyright (C) Microsoft Corporation, WTL Team. All rights reserved.
  3. //
  4. // This file is a part of the Windows Template Library.
  5. // The use and distribution terms for this software are covered by the
  6. // Microsoft Public License (http://opensource.org/licenses/MS-PL)
  7. // which can be found in the file MS-PL.txt at the root folder.
  8. #ifndef __ATLCTRLS_H__
  9. #define __ATLCTRLS_H__
  10. #pragma once
  11. #ifndef __ATLAPP_H__
  12. #error atlctrls.h requires atlapp.h to be included first
  13. #endif
  14. #ifndef __ATLWIN_H__
  15. #error atlctrls.h requires atlwin.h to be included first
  16. #endif
  17. #include <richedit.h>
  18. #include <richole.h>
  19. #if (_RICHEDIT_VER < 0x0300)
  20. #error WTL10 requires RichEdit version 3 or higher
  21. #endif
  22. // protect template members from windowsx.h macros
  23. #ifdef _INC_WINDOWSX
  24. #undef GetNextSibling
  25. #undef GetPrevSibling
  26. #endif // _INC_WINDOWSX
  27. ///////////////////////////////////////////////////////////////////////////////
  28. // Classes in this file:
  29. //
  30. // CStaticT<TBase> - CStatic
  31. // CButtonT<TBase> - CButton
  32. // CListBoxT<TBase> - CListBox
  33. // CComboBoxT<TBase> - CComboBox
  34. // CEditT<TBase> - CEdit
  35. // CEditCommands<T>
  36. // CScrollBarT<TBase> - CScrollBar
  37. //
  38. // CImageListT<t_bManaged> - CImageList, CImageListManaged
  39. // CListViewCtrlT<TBase> - CListViewCtrl
  40. // CTreeViewCtrlT<TBase> - CTreeViewCtrl
  41. // CTreeItemT<TBase> - CTreeItem
  42. // CTreeViewCtrlExT<TBase> - CTreeViewCtrlEx
  43. // CHeaderCtrlT<TBase> - CHeaderCtrl
  44. // CToolBarCtrlT<TBase> - CToolBarCtrl
  45. // CStatusBarCtrlT<TBase> - CStatusBarCtrl
  46. // CTabCtrlT<TBase> - CTabCtrl
  47. // CToolInfo
  48. // CToolTipCtrlT<TBase> - CToolTipCtrl
  49. // CTrackBarCtrlT<TBase> - CTrackBarCtrl
  50. // CUpDownCtrlT<TBase> - CUpDownCtrl
  51. // CProgressBarCtrlT<TBase> - CProgressBarCtrl
  52. // CHotKeyCtrlT<TBase> - CHotKeyCtrl
  53. // CAnimateCtrlT<TBase> - CAnimateCtrl
  54. // CRichEditCtrlT<TBase> - CRichEditCtrl
  55. // CRichEditCommands<T>
  56. // CDragListBoxT<TBase> - CDragListBox
  57. // CDragListNotifyImpl<T>
  58. // CReBarCtrlT<TBase> - CReBarCtrl
  59. // CComboBoxExT<TBase> - CComboBoxEx
  60. // CDateTimePickerCtrlT<TBase> - CDateTimePickerCtrl
  61. // CMonthCalendarCtrlT<TBase> - CMonthCalendarCtrl
  62. // CFlatScrollBarImpl<T>
  63. // CFlatScrollBarT<TBase> - CFlatScrollBar
  64. // CIPAddressCtrlT<TBase> - CIPAddressCtrl
  65. // CPagerCtrlT<TBase> - CPagerCtrl
  66. // CLinkCtrlT<TBase> - CLinkCtrl
  67. //
  68. // CCustomDraw<T>
  69. namespace WTL
  70. {
  71. // These are wrapper classes for Windows standard and common controls.
  72. // To implement a window based on a control, use following:
  73. // Example: Implementing a window based on a list box
  74. //
  75. // class CMyListBox : CWindowImpl<CMyListBox, CListBox>
  76. // {
  77. // public:
  78. // BEGIN_MSG_MAP(CMyListBox)
  79. // // put your message handler entries here
  80. // END_MSG_MAP()
  81. // };
  82. // --- Standard Windows controls ---
  83. ///////////////////////////////////////////////////////////////////////////////
  84. // CStatic - client side for a Windows STATIC control
  85. template <class TBase>
  86. class CStaticT : public TBase
  87. {
  88. public:
  89. // Constructors
  90. CStaticT(HWND hWnd = NULL) : TBase(hWnd)
  91. { }
  92. CStaticT< TBase >& operator =(HWND hWnd)
  93. {
  94. this->m_hWnd = hWnd;
  95. return *this;
  96. }
  97. HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  98. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  99. ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  100. {
  101. return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  102. }
  103. // Attributes
  104. static LPCTSTR GetWndClassName()
  105. {
  106. return _T("STATIC");
  107. }
  108. HICON GetIcon() const
  109. {
  110. ATLASSERT(::IsWindow(this->m_hWnd));
  111. return (HICON)::SendMessage(this->m_hWnd, STM_GETICON, 0, 0L);
  112. }
  113. HICON SetIcon(HICON hIcon)
  114. {
  115. ATLASSERT(::IsWindow(this->m_hWnd));
  116. return (HICON)::SendMessage(this->m_hWnd, STM_SETICON, (WPARAM)hIcon, 0L);
  117. }
  118. HENHMETAFILE GetEnhMetaFile() const
  119. {
  120. ATLASSERT(::IsWindow(this->m_hWnd));
  121. return (HENHMETAFILE)::SendMessage(this->m_hWnd, STM_GETIMAGE, IMAGE_ENHMETAFILE, 0L);
  122. }
  123. HENHMETAFILE SetEnhMetaFile(HENHMETAFILE hMetaFile)
  124. {
  125. ATLASSERT(::IsWindow(this->m_hWnd));
  126. return (HENHMETAFILE)::SendMessage(this->m_hWnd, STM_SETIMAGE, IMAGE_ENHMETAFILE, (LPARAM)hMetaFile);
  127. }
  128. CBitmapHandle GetBitmap() const
  129. {
  130. ATLASSERT(::IsWindow(this->m_hWnd));
  131. return CBitmapHandle((HBITMAP)::SendMessage(this->m_hWnd, STM_GETIMAGE, IMAGE_BITMAP, 0L));
  132. }
  133. CBitmapHandle SetBitmap(HBITMAP hBitmap)
  134. {
  135. ATLASSERT(::IsWindow(this->m_hWnd));
  136. return CBitmapHandle((HBITMAP)::SendMessage(this->m_hWnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmap));
  137. }
  138. HCURSOR GetCursor() const
  139. {
  140. ATLASSERT(::IsWindow(this->m_hWnd));
  141. return (HCURSOR)::SendMessage(this->m_hWnd, STM_GETIMAGE, IMAGE_CURSOR, 0L);
  142. }
  143. HCURSOR SetCursor(HCURSOR hCursor)
  144. {
  145. ATLASSERT(::IsWindow(this->m_hWnd));
  146. return (HCURSOR)::SendMessage(this->m_hWnd, STM_SETIMAGE, IMAGE_CURSOR, (LPARAM)hCursor);
  147. }
  148. };
  149. typedef CStaticT<ATL::CWindow> CStatic;
  150. ///////////////////////////////////////////////////////////////////////////////
  151. // CButton - client side for a Windows BUTTON control
  152. template <class TBase>
  153. class CButtonT : public TBase
  154. {
  155. public:
  156. // Constructors
  157. CButtonT(HWND hWnd = NULL) : TBase(hWnd)
  158. { }
  159. CButtonT< TBase >& operator =(HWND hWnd)
  160. {
  161. this->m_hWnd = hWnd;
  162. return *this;
  163. }
  164. HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  165. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  166. ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  167. {
  168. return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  169. }
  170. // Attributes
  171. static LPCTSTR GetWndClassName()
  172. {
  173. return _T("BUTTON");
  174. }
  175. UINT GetState() const
  176. {
  177. ATLASSERT(::IsWindow(this->m_hWnd));
  178. return (UINT)::SendMessage(this->m_hWnd, BM_GETSTATE, 0, 0L);
  179. }
  180. void SetState(BOOL bHighlight)
  181. {
  182. ATLASSERT(::IsWindow(this->m_hWnd));
  183. ::SendMessage(this->m_hWnd, BM_SETSTATE, bHighlight, 0L);
  184. }
  185. int GetCheck() const
  186. {
  187. ATLASSERT(::IsWindow(this->m_hWnd));
  188. return (int)::SendMessage(this->m_hWnd, BM_GETCHECK, 0, 0L);
  189. }
  190. void SetCheck(int nCheck)
  191. {
  192. ATLASSERT(::IsWindow(this->m_hWnd));
  193. ::SendMessage(this->m_hWnd, BM_SETCHECK, nCheck, 0L);
  194. }
  195. UINT GetButtonStyle() const
  196. {
  197. ATLASSERT(::IsWindow(this->m_hWnd));
  198. return (UINT)::GetWindowLong(this->m_hWnd, GWL_STYLE) & 0xFFFF;
  199. }
  200. void SetButtonStyle(UINT nStyle, BOOL bRedraw = TRUE)
  201. {
  202. ATLASSERT(::IsWindow(this->m_hWnd));
  203. ::SendMessage(this->m_hWnd, BM_SETSTYLE, nStyle, (LPARAM)bRedraw);
  204. }
  205. HICON GetIcon() const
  206. {
  207. ATLASSERT(::IsWindow(this->m_hWnd));
  208. return (HICON)::SendMessage(this->m_hWnd, BM_GETIMAGE, IMAGE_ICON, 0L);
  209. }
  210. HICON SetIcon(HICON hIcon)
  211. {
  212. ATLASSERT(::IsWindow(this->m_hWnd));
  213. return (HICON)::SendMessage(this->m_hWnd, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon);
  214. }
  215. CBitmapHandle GetBitmap() const
  216. {
  217. ATLASSERT(::IsWindow(this->m_hWnd));
  218. return CBitmapHandle((HBITMAP)::SendMessage(this->m_hWnd, BM_GETIMAGE, IMAGE_BITMAP, 0L));
  219. }
  220. CBitmapHandle SetBitmap(HBITMAP hBitmap)
  221. {
  222. ATLASSERT(::IsWindow(this->m_hWnd));
  223. return CBitmapHandle((HBITMAP)::SendMessage(this->m_hWnd, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmap));
  224. }
  225. BOOL GetIdealSize(LPSIZE lpSize) const
  226. {
  227. ATLASSERT(::IsWindow(this->m_hWnd));
  228. return (BOOL)::SendMessage(this->m_hWnd, BCM_GETIDEALSIZE, 0, (LPARAM)lpSize);
  229. }
  230. BOOL GetImageList(PBUTTON_IMAGELIST pButtonImagelist) const
  231. {
  232. ATLASSERT(::IsWindow(this->m_hWnd));
  233. return (BOOL)::SendMessage(this->m_hWnd, BCM_GETIMAGELIST, 0, (LPARAM)pButtonImagelist);
  234. }
  235. BOOL SetImageList(PBUTTON_IMAGELIST pButtonImagelist)
  236. {
  237. ATLASSERT(::IsWindow(this->m_hWnd));
  238. return (BOOL)::SendMessage(this->m_hWnd, BCM_SETIMAGELIST, 0, (LPARAM)pButtonImagelist);
  239. }
  240. BOOL GetTextMargin(LPRECT lpRect) const
  241. {
  242. ATLASSERT(::IsWindow(this->m_hWnd));
  243. return (BOOL)::SendMessage(this->m_hWnd, BCM_GETTEXTMARGIN, 0, (LPARAM)lpRect);
  244. }
  245. BOOL SetTextMargin(LPRECT lpRect)
  246. {
  247. ATLASSERT(::IsWindow(this->m_hWnd));
  248. return (BOOL)::SendMessage(this->m_hWnd, BCM_SETTEXTMARGIN, 0, (LPARAM)lpRect);
  249. }
  250. #if (WINVER >= 0x0600)
  251. void SetDontClick(BOOL bDontClick)
  252. {
  253. ATLASSERT(::IsWindow(this->m_hWnd));
  254. ::SendMessage(this->m_hWnd, BM_SETDONTCLICK, (WPARAM)bDontClick, 0L);
  255. }
  256. #endif // (WINVER >= 0x0600)
  257. #if (_WIN32_WINNT >= 0x0600)
  258. BOOL SetDropDownState(BOOL bDropDown)
  259. {
  260. ATLASSERT(::IsWindow(this->m_hWnd));
  261. ATLASSERT((this->GetStyle() & (BS_SPLITBUTTON | BS_DEFSPLITBUTTON)) != 0);
  262. return (BOOL)::SendMessage(this->m_hWnd, BCM_SETDROPDOWNSTATE, (WPARAM)bDropDown, 0L);
  263. }
  264. BOOL GetSplitInfo(PBUTTON_SPLITINFO pSplitInfo) const
  265. {
  266. ATLASSERT(::IsWindow(this->m_hWnd));
  267. ATLASSERT((this->GetStyle() & (BS_SPLITBUTTON | BS_DEFSPLITBUTTON)) != 0);
  268. return (BOOL)::SendMessage(this->m_hWnd, BCM_GETSPLITINFO, 0, (LPARAM)pSplitInfo);
  269. }
  270. BOOL SetSplitInfo(PBUTTON_SPLITINFO pSplitInfo)
  271. {
  272. ATLASSERT(::IsWindow(this->m_hWnd));
  273. ATLASSERT((this->GetStyle() & (BS_SPLITBUTTON | BS_DEFSPLITBUTTON)) != 0);
  274. return (BOOL)::SendMessage(this->m_hWnd, BCM_SETSPLITINFO, 0, (LPARAM)pSplitInfo);
  275. }
  276. int GetNoteLength() const
  277. {
  278. ATLASSERT(::IsWindow(this->m_hWnd));
  279. ATLASSERT((this->GetStyle() & (BS_COMMANDLINK | BS_DEFCOMMANDLINK)) != 0);
  280. return (int)::SendMessage(this->m_hWnd, BCM_GETNOTELENGTH, 0, 0L);
  281. }
  282. BOOL GetNote(LPWSTR lpstrNoteText, int cchNoteText) const
  283. {
  284. ATLASSERT(::IsWindow(this->m_hWnd));
  285. ATLASSERT((this->GetStyle() & (BS_COMMANDLINK | BS_DEFCOMMANDLINK)) != 0);
  286. return (BOOL)::SendMessage(this->m_hWnd, BCM_GETNOTE, cchNoteText, (LPARAM)lpstrNoteText);
  287. }
  288. BOOL SetNote(LPCWSTR lpstrNoteText)
  289. {
  290. ATLASSERT(::IsWindow(this->m_hWnd));
  291. ATLASSERT((this->GetStyle() & (BS_COMMANDLINK | BS_DEFCOMMANDLINK)) != 0);
  292. return (BOOL)::SendMessage(this->m_hWnd, BCM_SETNOTE, 0, (LPARAM)lpstrNoteText);
  293. }
  294. LRESULT SetElevationRequiredState(BOOL bSet)
  295. {
  296. ATLASSERT(::IsWindow(this->m_hWnd));
  297. return ::SendMessage(this->m_hWnd, BCM_SETSHIELD, 0, (LPARAM)bSet);
  298. }
  299. #endif // (_WIN32_WINNT >= 0x0600)
  300. // Operations
  301. void Click()
  302. {
  303. ATLASSERT(::IsWindow(this->m_hWnd));
  304. ::SendMessage(this->m_hWnd, BM_CLICK, 0, 0L);
  305. }
  306. };
  307. typedef CButtonT<ATL::CWindow> CButton;
  308. ///////////////////////////////////////////////////////////////////////////////
  309. // CListBox - client side for a Windows LISTBOX control
  310. template <class TBase>
  311. class CListBoxT : public TBase
  312. {
  313. public:
  314. // Constructors
  315. CListBoxT(HWND hWnd = NULL) : TBase(hWnd)
  316. { }
  317. CListBoxT< TBase >& operator =(HWND hWnd)
  318. {
  319. this->m_hWnd = hWnd;
  320. return *this;
  321. }
  322. HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  323. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  324. ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  325. {
  326. return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  327. }
  328. // Attributes
  329. static LPCTSTR GetWndClassName()
  330. {
  331. return _T("LISTBOX");
  332. }
  333. // for entire listbox
  334. int GetCount() const
  335. {
  336. ATLASSERT(::IsWindow(this->m_hWnd));
  337. return (int)::SendMessage(this->m_hWnd, LB_GETCOUNT, 0, 0L);
  338. }
  339. int SetCount(int cItems)
  340. {
  341. ATLASSERT(::IsWindow(this->m_hWnd));
  342. ATLASSERT(((this->GetStyle() & LBS_NODATA) != 0) && ((this->GetStyle() & LBS_HASSTRINGS) == 0));
  343. return (int)::SendMessage(this->m_hWnd, LB_SETCOUNT, cItems, 0L);
  344. }
  345. int GetHorizontalExtent() const
  346. {
  347. ATLASSERT(::IsWindow(this->m_hWnd));
  348. return (int)::SendMessage(this->m_hWnd, LB_GETHORIZONTALEXTENT, 0, 0L);
  349. }
  350. void SetHorizontalExtent(int cxExtent)
  351. {
  352. ATLASSERT(::IsWindow(this->m_hWnd));
  353. ::SendMessage(this->m_hWnd, LB_SETHORIZONTALEXTENT, cxExtent, 0L);
  354. }
  355. int GetTopIndex() const
  356. {
  357. ATLASSERT(::IsWindow(this->m_hWnd));
  358. return (int)::SendMessage(this->m_hWnd, LB_GETTOPINDEX, 0, 0L);
  359. }
  360. int SetTopIndex(int nIndex)
  361. {
  362. ATLASSERT(::IsWindow(this->m_hWnd));
  363. return (int)::SendMessage(this->m_hWnd, LB_SETTOPINDEX, nIndex, 0L);
  364. }
  365. LCID GetLocale() const
  366. {
  367. ATLASSERT(::IsWindow(this->m_hWnd));
  368. return (LCID)::SendMessage(this->m_hWnd, LB_GETLOCALE, 0, 0L);
  369. }
  370. LCID SetLocale(LCID nNewLocale)
  371. {
  372. ATLASSERT(::IsWindow(this->m_hWnd));
  373. return (LCID)::SendMessage(this->m_hWnd, LB_SETLOCALE, (WPARAM)nNewLocale, 0L);
  374. }
  375. DWORD GetListBoxInfo() const
  376. {
  377. ATLASSERT(::IsWindow(this->m_hWnd));
  378. return (DWORD)::SendMessage(this->m_hWnd, LB_GETLISTBOXINFO, 0, 0L);
  379. }
  380. // for single-selection listboxes
  381. int GetCurSel() const
  382. {
  383. ATLASSERT(::IsWindow(this->m_hWnd));
  384. ATLASSERT((this->GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) == 0);
  385. return (int)::SendMessage(this->m_hWnd, LB_GETCURSEL, 0, 0L);
  386. }
  387. int SetCurSel(int nSelect)
  388. {
  389. ATLASSERT(::IsWindow(this->m_hWnd));
  390. ATLASSERT((this->GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) == 0);
  391. return (int)::SendMessage(this->m_hWnd, LB_SETCURSEL, nSelect, 0L);
  392. }
  393. // for multiple-selection listboxes
  394. int GetSel(int nIndex) const // also works for single-selection
  395. {
  396. ATLASSERT(::IsWindow(this->m_hWnd));
  397. return (int)::SendMessage(this->m_hWnd, LB_GETSEL, nIndex, 0L);
  398. }
  399. int SetSel(int nIndex, BOOL bSelect = TRUE)
  400. {
  401. ATLASSERT(::IsWindow(this->m_hWnd));
  402. ATLASSERT((this->GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) != 0);
  403. return (int)::SendMessage(this->m_hWnd, LB_SETSEL, bSelect, nIndex);
  404. }
  405. int GetSelCount() const
  406. {
  407. ATLASSERT(::IsWindow(this->m_hWnd));
  408. ATLASSERT((this->GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) != 0);
  409. return (int)::SendMessage(this->m_hWnd, LB_GETSELCOUNT, 0, 0L);
  410. }
  411. int GetSelItems(int nMaxItems, LPINT rgIndex) const
  412. {
  413. ATLASSERT(::IsWindow(this->m_hWnd));
  414. ATLASSERT((this->GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) != 0);
  415. return (int)::SendMessage(this->m_hWnd, LB_GETSELITEMS, nMaxItems, (LPARAM)rgIndex);
  416. }
  417. int GetAnchorIndex() const
  418. {
  419. ATLASSERT(::IsWindow(this->m_hWnd));
  420. ATLASSERT((this->GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) != 0);
  421. return (int)::SendMessage(this->m_hWnd, LB_GETANCHORINDEX, 0, 0L);
  422. }
  423. void SetAnchorIndex(int nIndex)
  424. {
  425. ATLASSERT(::IsWindow(this->m_hWnd));
  426. ATLASSERT((this->GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) != 0);
  427. ::SendMessage(this->m_hWnd, LB_SETANCHORINDEX, nIndex, 0L);
  428. }
  429. int GetCaretIndex() const
  430. {
  431. ATLASSERT(::IsWindow(this->m_hWnd));
  432. return (int)::SendMessage(this->m_hWnd, LB_GETCARETINDEX, 0, 0);
  433. }
  434. int SetCaretIndex(int nIndex, BOOL bScroll = TRUE)
  435. {
  436. ATLASSERT(::IsWindow(this->m_hWnd));
  437. return (int)::SendMessage(this->m_hWnd, LB_SETCARETINDEX, nIndex, MAKELONG(bScroll, 0));
  438. }
  439. // for listbox items
  440. DWORD_PTR GetItemData(int nIndex) const
  441. {
  442. ATLASSERT(::IsWindow(this->m_hWnd));
  443. return (DWORD_PTR)::SendMessage(this->m_hWnd, LB_GETITEMDATA, nIndex, 0L);
  444. }
  445. int SetItemData(int nIndex, DWORD_PTR dwItemData)
  446. {
  447. ATLASSERT(::IsWindow(this->m_hWnd));
  448. return (int)::SendMessage(this->m_hWnd, LB_SETITEMDATA, nIndex, (LPARAM)dwItemData);
  449. }
  450. void* GetItemDataPtr(int nIndex) const
  451. {
  452. ATLASSERT(::IsWindow(this->m_hWnd));
  453. return (void*)::SendMessage(this->m_hWnd, LB_GETITEMDATA, nIndex, 0L);
  454. }
  455. int SetItemDataPtr(int nIndex, void* pData)
  456. {
  457. ATLASSERT(::IsWindow(this->m_hWnd));
  458. return SetItemData(nIndex, (DWORD_PTR)pData);
  459. }
  460. int GetItemRect(int nIndex, LPRECT lpRect) const
  461. {
  462. ATLASSERT(::IsWindow(this->m_hWnd));
  463. return (int)::SendMessage(this->m_hWnd, LB_GETITEMRECT, nIndex, (LPARAM)lpRect);
  464. }
  465. int GetText(int nIndex, LPTSTR lpszBuffer) const
  466. {
  467. ATLASSERT(::IsWindow(this->m_hWnd));
  468. return (int)::SendMessage(this->m_hWnd, LB_GETTEXT, nIndex, (LPARAM)lpszBuffer);
  469. }
  470. #ifdef _OLEAUTO_H_
  471. BOOL GetTextBSTR(int nIndex, BSTR& bstrText) const
  472. {
  473. USES_CONVERSION;
  474. ATLASSERT(::IsWindow(this->m_hWnd));
  475. ATLASSERT(bstrText == NULL);
  476. int nLen = GetTextLen(nIndex);
  477. if(nLen == LB_ERR)
  478. return FALSE;
  479. ATL::CTempBuffer<TCHAR, _WTL_STACK_ALLOC_THRESHOLD> buff;
  480. LPTSTR lpstrText = buff.Allocate(nLen + 1);
  481. if(lpstrText == NULL)
  482. return FALSE;
  483. if(GetText(nIndex, lpstrText) == LB_ERR)
  484. return FALSE;
  485. bstrText = ::SysAllocString(T2OLE(lpstrText));
  486. return (bstrText != NULL) ? TRUE : FALSE;
  487. }
  488. #endif // _OLEAUTO_H_
  489. #ifdef __ATLSTR_H__
  490. int GetText(int nIndex, ATL::CString& strText) const
  491. {
  492. ATLASSERT(::IsWindow(this->m_hWnd));
  493. int cchLen = GetTextLen(nIndex);
  494. if(cchLen == LB_ERR)
  495. return LB_ERR;
  496. int nRet = LB_ERR;
  497. LPTSTR lpstr = strText.GetBufferSetLength(cchLen);
  498. if(lpstr != NULL)
  499. {
  500. nRet = GetText(nIndex, lpstr);
  501. strText.ReleaseBuffer();
  502. }
  503. return nRet;
  504. }
  505. #endif // __ATLSTR_H__
  506. int GetTextLen(int nIndex) const
  507. {
  508. ATLASSERT(::IsWindow(this->m_hWnd));
  509. return (int)::SendMessage(this->m_hWnd, LB_GETTEXTLEN, nIndex, 0L);
  510. }
  511. int GetItemHeight(int nIndex) const
  512. {
  513. ATLASSERT(::IsWindow(this->m_hWnd));
  514. return (int)::SendMessage(this->m_hWnd, LB_GETITEMHEIGHT, nIndex, 0L);
  515. }
  516. int SetItemHeight(int nIndex, UINT cyItemHeight)
  517. {
  518. ATLASSERT(::IsWindow(this->m_hWnd));
  519. return (int)::SendMessage(this->m_hWnd, LB_SETITEMHEIGHT, nIndex, MAKELONG(cyItemHeight, 0));
  520. }
  521. // Settable only attributes
  522. void SetColumnWidth(int cxWidth)
  523. {
  524. ATLASSERT(::IsWindow(this->m_hWnd));
  525. ::SendMessage(this->m_hWnd, LB_SETCOLUMNWIDTH, cxWidth, 0L);
  526. }
  527. BOOL SetTabStops(int nTabStops, LPINT rgTabStops)
  528. {
  529. ATLASSERT(::IsWindow(this->m_hWnd));
  530. ATLASSERT((this->GetStyle() & LBS_USETABSTOPS) != 0);
  531. return (BOOL)::SendMessage(this->m_hWnd, LB_SETTABSTOPS, nTabStops, (LPARAM)rgTabStops);
  532. }
  533. BOOL SetTabStops()
  534. {
  535. ATLASSERT(::IsWindow(this->m_hWnd));
  536. ATLASSERT((this->GetStyle() & LBS_USETABSTOPS) != 0);
  537. return (BOOL)::SendMessage(this->m_hWnd, LB_SETTABSTOPS, 0, 0L);
  538. }
  539. BOOL SetTabStops(const int& cxEachStop) // takes an 'int'
  540. {
  541. ATLASSERT(::IsWindow(this->m_hWnd));
  542. ATLASSERT((this->GetStyle() & LBS_USETABSTOPS) != 0);
  543. return (BOOL)::SendMessage(this->m_hWnd, LB_SETTABSTOPS, 1, (LPARAM)(LPINT)&cxEachStop);
  544. }
  545. // Operations
  546. int InitStorage(int nItems, UINT nBytes)
  547. {
  548. ATLASSERT(::IsWindow(this->m_hWnd));
  549. return (int)::SendMessage(this->m_hWnd, LB_INITSTORAGE, (WPARAM)nItems, nBytes);
  550. }
  551. void ResetContent()
  552. {
  553. ATLASSERT(::IsWindow(this->m_hWnd));
  554. ::SendMessage(this->m_hWnd, LB_RESETCONTENT, 0, 0L);
  555. }
  556. UINT ItemFromPoint(POINT pt, BOOL& bOutside) const
  557. {
  558. ATLASSERT(::IsWindow(this->m_hWnd));
  559. DWORD dw = (DWORD)::SendMessage(this->m_hWnd, LB_ITEMFROMPOINT, 0, MAKELPARAM(pt.x, pt.y));
  560. bOutside = (BOOL)HIWORD(dw);
  561. return (UINT)LOWORD(dw);
  562. }
  563. // manipulating listbox items
  564. int AddString(LPCTSTR lpszItem)
  565. {
  566. ATLASSERT(::IsWindow(this->m_hWnd));
  567. return (int)::SendMessage(this->m_hWnd, LB_ADDSTRING, 0, (LPARAM)lpszItem);
  568. }
  569. int DeleteString(UINT nIndex)
  570. {
  571. ATLASSERT(::IsWindow(this->m_hWnd));
  572. return (int)::SendMessage(this->m_hWnd, LB_DELETESTRING, nIndex, 0L);
  573. }
  574. int InsertString(int nIndex, LPCTSTR lpszItem)
  575. {
  576. ATLASSERT(::IsWindow(this->m_hWnd));
  577. return (int)::SendMessage(this->m_hWnd, LB_INSERTSTRING, nIndex, (LPARAM)lpszItem);
  578. }
  579. int Dir(UINT attr, LPCTSTR lpszWildCard)
  580. {
  581. ATLASSERT(::IsWindow(this->m_hWnd));
  582. return (int)::SendMessage(this->m_hWnd, LB_DIR, attr, (LPARAM)lpszWildCard);
  583. }
  584. int AddFile(LPCTSTR lpstrFileName)
  585. {
  586. ATLASSERT(::IsWindow(this->m_hWnd));
  587. return (int)::SendMessage(this->m_hWnd, LB_ADDFILE, 0, (LPARAM)lpstrFileName);
  588. }
  589. // selection helpers
  590. int FindString(int nStartAfter, LPCTSTR lpszItem) const
  591. {
  592. ATLASSERT(::IsWindow(this->m_hWnd));
  593. return (int)::SendMessage(this->m_hWnd, LB_FINDSTRING, nStartAfter, (LPARAM)lpszItem);
  594. }
  595. int FindStringExact(int nIndexStart, LPCTSTR lpszFind) const
  596. {
  597. ATLASSERT(::IsWindow(this->m_hWnd));
  598. return (int)::SendMessage(this->m_hWnd, LB_FINDSTRINGEXACT, nIndexStart, (LPARAM)lpszFind);
  599. }
  600. int SelectString(int nStartAfter, LPCTSTR lpszItem)
  601. {
  602. ATLASSERT(::IsWindow(this->m_hWnd));
  603. return (int)::SendMessage(this->m_hWnd, LB_SELECTSTRING, nStartAfter, (LPARAM)lpszItem);
  604. }
  605. int SelItemRange(BOOL bSelect, int nFirstItem, int nLastItem)
  606. {
  607. ATLASSERT(::IsWindow(this->m_hWnd));
  608. ATLASSERT((this->GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) != 0);
  609. ATLASSERT(nFirstItem <= nLastItem);
  610. return bSelect ? (int)::SendMessage(this->m_hWnd, LB_SELITEMRANGEEX, nFirstItem, nLastItem) : (int)::SendMessage(this->m_hWnd, LB_SELITEMRANGEEX, nLastItem, nFirstItem);
  611. }
  612. };
  613. typedef CListBoxT<ATL::CWindow> CListBox;
  614. ///////////////////////////////////////////////////////////////////////////////
  615. // CComboBox - client side for a Windows COMBOBOX control
  616. template <class TBase>
  617. class CComboBoxT : public TBase
  618. {
  619. public:
  620. // Constructors
  621. CComboBoxT(HWND hWnd = NULL) : TBase(hWnd)
  622. { }
  623. CComboBoxT< TBase >& operator =(HWND hWnd)
  624. {
  625. this->m_hWnd = hWnd;
  626. return *this;
  627. }
  628. HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  629. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  630. ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  631. {
  632. return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  633. }
  634. // Attributes
  635. static LPCTSTR GetWndClassName()
  636. {
  637. return _T("COMBOBOX");
  638. }
  639. // for entire combo box
  640. int GetCount() const
  641. {
  642. ATLASSERT(::IsWindow(this->m_hWnd));
  643. return (int)::SendMessage(this->m_hWnd, CB_GETCOUNT, 0, 0L);
  644. }
  645. int GetCurSel() const
  646. {
  647. ATLASSERT(::IsWindow(this->m_hWnd));
  648. return (int)::SendMessage(this->m_hWnd, CB_GETCURSEL, 0, 0L);
  649. }
  650. int SetCurSel(int nSelect)
  651. {
  652. ATLASSERT(::IsWindow(this->m_hWnd));
  653. return (int)::SendMessage(this->m_hWnd, CB_SETCURSEL, nSelect, 0L);
  654. }
  655. LCID GetLocale() const
  656. {
  657. ATLASSERT(::IsWindow(this->m_hWnd));
  658. return (LCID)::SendMessage(this->m_hWnd, CB_GETLOCALE, 0, 0L);
  659. }
  660. LCID SetLocale(LCID nNewLocale)
  661. {
  662. ATLASSERT(::IsWindow(this->m_hWnd));
  663. return (LCID)::SendMessage(this->m_hWnd, CB_SETLOCALE, (WPARAM)nNewLocale, 0L);
  664. }
  665. int GetTopIndex() const
  666. {
  667. ATLASSERT(::IsWindow(this->m_hWnd));
  668. return (int)::SendMessage(this->m_hWnd, CB_GETTOPINDEX, 0, 0L);
  669. }
  670. int SetTopIndex(int nIndex)
  671. {
  672. ATLASSERT(::IsWindow(this->m_hWnd));
  673. return (int)::SendMessage(this->m_hWnd, CB_SETTOPINDEX, nIndex, 0L);
  674. }
  675. UINT GetHorizontalExtent() const
  676. {
  677. ATLASSERT(::IsWindow(this->m_hWnd));
  678. return (UINT)::SendMessage(this->m_hWnd, CB_GETHORIZONTALEXTENT, 0, 0L);
  679. }
  680. void SetHorizontalExtent(UINT nExtent)
  681. {
  682. ATLASSERT(::IsWindow(this->m_hWnd));
  683. ::SendMessage(this->m_hWnd, CB_SETHORIZONTALEXTENT, nExtent, 0L);
  684. }
  685. int GetDroppedWidth() const
  686. {
  687. ATLASSERT(::IsWindow(this->m_hWnd));
  688. return (int)::SendMessage(this->m_hWnd, CB_GETDROPPEDWIDTH, 0, 0L);
  689. }
  690. int SetDroppedWidth(UINT nWidth)
  691. {
  692. ATLASSERT(::IsWindow(this->m_hWnd));
  693. return (int)::SendMessage(this->m_hWnd, CB_SETDROPPEDWIDTH, nWidth, 0L);
  694. }
  695. BOOL GetComboBoxInfo(PCOMBOBOXINFO pComboBoxInfo) const
  696. {
  697. ATLASSERT(::IsWindow(this->m_hWnd));
  698. return (BOOL)::SendMessage(this->m_hWnd, CB_GETCOMBOBOXINFO, 0, (LPARAM)pComboBoxInfo);
  699. }
  700. // for edit control
  701. DWORD GetEditSel() const
  702. {
  703. ATLASSERT(::IsWindow(this->m_hWnd));
  704. return (DWORD)::SendMessage(this->m_hWnd, CB_GETEDITSEL, 0, 0L);
  705. }
  706. BOOL SetEditSel(int nStartChar, int nEndChar)
  707. {
  708. ATLASSERT(::IsWindow(this->m_hWnd));
  709. return (BOOL)::SendMessage(this->m_hWnd, CB_SETEDITSEL, 0, MAKELONG(nStartChar, nEndChar));
  710. }
  711. // for combobox item
  712. DWORD_PTR GetItemData(int nIndex) const
  713. {
  714. ATLASSERT(::IsWindow(this->m_hWnd));
  715. return (DWORD_PTR)::SendMessage(this->m_hWnd, CB_GETITEMDATA, nIndex, 0L);
  716. }
  717. int SetItemData(int nIndex, DWORD_PTR dwItemData)
  718. {
  719. ATLASSERT(::IsWindow(this->m_hWnd));
  720. return (int)::SendMessage(this->m_hWnd, CB_SETITEMDATA, nIndex, (LPARAM)dwItemData);
  721. }
  722. void* GetItemDataPtr(int nIndex) const
  723. {
  724. ATLASSERT(::IsWindow(this->m_hWnd));
  725. return (void*)GetItemData(nIndex);
  726. }
  727. int SetItemDataPtr(int nIndex, void* pData)
  728. {
  729. ATLASSERT(::IsWindow(this->m_hWnd));
  730. return SetItemData(nIndex, (DWORD_PTR)pData);
  731. }
  732. int GetLBText(int nIndex, LPTSTR lpszText) const
  733. {
  734. ATLASSERT(::IsWindow(this->m_hWnd));
  735. return (int)::SendMessage(this->m_hWnd, CB_GETLBTEXT, nIndex, (LPARAM)lpszText);
  736. }
  737. BOOL GetLBTextBSTR(int nIndex, BSTR& bstrText) const
  738. {
  739. USES_CONVERSION;
  740. ATLASSERT(::IsWindow(this->m_hWnd));
  741. ATLASSERT(bstrText == NULL);
  742. int nLen = GetLBTextLen(nIndex);
  743. if(nLen == CB_ERR)
  744. return FALSE;
  745. ATL::CTempBuffer<TCHAR, _WTL_STACK_ALLOC_THRESHOLD> buff;
  746. LPTSTR lpstrText = buff.Allocate(nLen + 1);
  747. if(lpstrText == NULL)
  748. return FALSE;
  749. if(GetLBText(nIndex, lpstrText) == CB_ERR)
  750. return FALSE;
  751. bstrText = ::SysAllocString(T2OLE(lpstrText));
  752. return (bstrText != NULL) ? TRUE : FALSE;
  753. }
  754. #ifdef __ATLSTR_H__
  755. int GetLBText(int nIndex, ATL::CString& strText) const
  756. {
  757. ATLASSERT(::IsWindow(this->m_hWnd));
  758. int cchLen = GetLBTextLen(nIndex);
  759. if(cchLen == CB_ERR)
  760. return CB_ERR;
  761. int nRet = CB_ERR;
  762. LPTSTR lpstr = strText.GetBufferSetLength(cchLen);
  763. if(lpstr != NULL)
  764. {
  765. nRet = GetLBText(nIndex, lpstr);
  766. strText.ReleaseBuffer();
  767. }
  768. return nRet;
  769. }
  770. #endif // __ATLSTR_H__
  771. int GetLBTextLen(int nIndex) const
  772. {
  773. ATLASSERT(::IsWindow(this->m_hWnd));
  774. return (int)::SendMessage(this->m_hWnd, CB_GETLBTEXTLEN, nIndex, 0L);
  775. }
  776. int GetItemHeight(int nIndex) const
  777. {
  778. ATLASSERT(::IsWindow(this->m_hWnd));
  779. return (int)::SendMessage(this->m_hWnd, CB_GETITEMHEIGHT, nIndex, 0L);
  780. }
  781. int SetItemHeight(int nIndex, UINT cyItemHeight)
  782. {
  783. ATLASSERT(::IsWindow(this->m_hWnd));
  784. return (int)::SendMessage(this->m_hWnd, CB_SETITEMHEIGHT, nIndex, MAKELONG(cyItemHeight, 0));
  785. }
  786. BOOL GetExtendedUI() const
  787. {
  788. ATLASSERT(::IsWindow(this->m_hWnd));
  789. return (BOOL)::SendMessage(this->m_hWnd, CB_GETEXTENDEDUI, 0, 0L);
  790. }
  791. int SetExtendedUI(BOOL bExtended = TRUE)
  792. {
  793. ATLASSERT(::IsWindow(this->m_hWnd));
  794. return (int)::SendMessage(this->m_hWnd, CB_SETEXTENDEDUI, bExtended, 0L);
  795. }
  796. void GetDroppedControlRect(LPRECT lprect) const
  797. {
  798. ATLASSERT(::IsWindow(this->m_hWnd));
  799. ::SendMessage(this->m_hWnd, CB_GETDROPPEDCONTROLRECT, 0, (LPARAM)lprect);
  800. }
  801. BOOL GetDroppedState() const
  802. {
  803. ATLASSERT(::IsWindow(this->m_hWnd));
  804. return (BOOL)::SendMessage(this->m_hWnd, CB_GETDROPPEDSTATE, 0, 0L);
  805. }
  806. int GetMinVisible() const
  807. {
  808. ATLASSERT(::IsWindow(this->m_hWnd));
  809. return (int)::SendMessage(this->m_hWnd, CB_GETMINVISIBLE, 0, 0L);
  810. }
  811. BOOL SetMinVisible(int nMinVisible)
  812. {
  813. ATLASSERT(::IsWindow(this->m_hWnd));
  814. return (BOOL)::SendMessage(this->m_hWnd, CB_SETMINVISIBLE, nMinVisible, 0L);
  815. }
  816. // Vista only
  817. BOOL GetCueBannerText(LPWSTR lpwText, int cchText) const
  818. {
  819. ATLASSERT(::IsWindow(this->m_hWnd));
  820. return (BOOL)::SendMessage(this->m_hWnd, CB_GETCUEBANNER, (WPARAM)lpwText, cchText);
  821. }
  822. // Vista only
  823. BOOL SetCueBannerText(LPCWSTR lpcwText)
  824. {
  825. ATLASSERT(::IsWindow(this->m_hWnd));
  826. return (BOOL)::SendMessage(this->m_hWnd, CB_SETCUEBANNER, 0, (LPARAM)lpcwText);
  827. }
  828. // Operations
  829. int InitStorage(int nItems, UINT nBytes)
  830. {
  831. ATLASSERT(::IsWindow(this->m_hWnd));
  832. return (int)::SendMessage(this->m_hWnd, CB_INITSTORAGE, (WPARAM)nItems, nBytes);
  833. }
  834. void ResetContent()
  835. {
  836. ATLASSERT(::IsWindow(this->m_hWnd));
  837. ::SendMessage(this->m_hWnd, CB_RESETCONTENT, 0, 0L);
  838. }
  839. // for edit control
  840. BOOL LimitText(int nMaxChars)
  841. {
  842. ATLASSERT(::IsWindow(this->m_hWnd));
  843. return (BOOL)::SendMessage(this->m_hWnd, CB_LIMITTEXT, nMaxChars, 0L);
  844. }
  845. // for drop-down combo boxes
  846. void ShowDropDown(BOOL bShowIt = TRUE)
  847. {
  848. ATLASSERT(::IsWindow(this->m_hWnd));
  849. ::SendMessage(this->m_hWnd, CB_SHOWDROPDOWN, bShowIt, 0L);
  850. }
  851. // manipulating listbox items
  852. int AddString(LPCTSTR lpszString)
  853. {
  854. ATLASSERT(::IsWindow(this->m_hWnd));
  855. return (int)::SendMessage(this->m_hWnd, CB_ADDSTRING, 0, (LPARAM)lpszString);
  856. }
  857. int DeleteString(UINT nIndex)
  858. {
  859. ATLASSERT(::IsWindow(this->m_hWnd));
  860. return (int)::SendMessage(this->m_hWnd, CB_DELETESTRING, nIndex, 0L);
  861. }
  862. int InsertString(int nIndex, LPCTSTR lpszString)
  863. {
  864. ATLASSERT(::IsWindow(this->m_hWnd));
  865. return (int)::SendMessage(this->m_hWnd, CB_INSERTSTRING, nIndex, (LPARAM)lpszString);
  866. }
  867. int Dir(UINT attr, LPCTSTR lpszWildCard)
  868. {
  869. ATLASSERT(::IsWindow(this->m_hWnd));
  870. return (int)::SendMessage(this->m_hWnd, CB_DIR, attr, (LPARAM)lpszWildCard);
  871. }
  872. // selection helpers
  873. int FindString(int nStartAfter, LPCTSTR lpszString) const
  874. {
  875. ATLASSERT(::IsWindow(this->m_hWnd));
  876. return (int)::SendMessage(this->m_hWnd, CB_FINDSTRING, nStartAfter, (LPARAM)lpszString);
  877. }
  878. int FindStringExact(int nIndexStart, LPCTSTR lpszFind) const
  879. {
  880. ATLASSERT(::IsWindow(this->m_hWnd));
  881. return (int)::SendMessage(this->m_hWnd, CB_FINDSTRINGEXACT, nIndexStart, (LPARAM)lpszFind);
  882. }
  883. int SelectString(int nStartAfter, LPCTSTR lpszString)
  884. {
  885. ATLASSERT(::IsWindow(this->m_hWnd));
  886. return (int)::SendMessage(this->m_hWnd, CB_SELECTSTRING, nStartAfter, (LPARAM)lpszString);
  887. }
  888. // Clipboard operations
  889. void Clear()
  890. {
  891. ATLASSERT(::IsWindow(this->m_hWnd));
  892. ::SendMessage(this->m_hWnd, WM_CLEAR, 0, 0L);
  893. }
  894. void Copy()
  895. {
  896. ATLASSERT(::IsWindow(this->m_hWnd));
  897. ::SendMessage(this->m_hWnd, WM_COPY, 0, 0L);
  898. }
  899. void Cut()
  900. {
  901. ATLASSERT(::IsWindow(this->m_hWnd));
  902. ::SendMessage(this->m_hWnd, WM_CUT, 0, 0L);
  903. }
  904. void Paste()
  905. {
  906. ATLASSERT(::IsWindow(this->m_hWnd));
  907. ::SendMessage(this->m_hWnd, WM_PASTE, 0, 0L);
  908. }
  909. };
  910. typedef CComboBoxT<ATL::CWindow> CComboBox;
  911. ///////////////////////////////////////////////////////////////////////////////
  912. // CEdit - client side for a Windows EDIT control
  913. template <class TBase>
  914. class CEditT : public TBase
  915. {
  916. public:
  917. // Constructors
  918. CEditT(HWND hWnd = NULL) : TBase(hWnd)
  919. { }
  920. CEditT< TBase >& operator =(HWND hWnd)
  921. {
  922. this->m_hWnd = hWnd;
  923. return *this;
  924. }
  925. HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  926. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  927. ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  928. {
  929. return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  930. }
  931. // Attributes
  932. static LPCTSTR GetWndClassName()
  933. {
  934. return _T("EDIT");
  935. }
  936. BOOL CanUndo() const
  937. {
  938. ATLASSERT(::IsWindow(this->m_hWnd));
  939. return (BOOL)::SendMessage(this->m_hWnd, EM_CANUNDO, 0, 0L);
  940. }
  941. int GetLineCount() const
  942. {
  943. ATLASSERT(::IsWindow(this->m_hWnd));
  944. return (int)::SendMessage(this->m_hWnd, EM_GETLINECOUNT, 0, 0L);
  945. }
  946. BOOL GetModify() const
  947. {
  948. ATLASSERT(::IsWindow(this->m_hWnd));
  949. return (BOOL)::SendMessage(this->m_hWnd, EM_GETMODIFY, 0, 0L);
  950. }
  951. void SetModify(BOOL bModified = TRUE)
  952. {
  953. ATLASSERT(::IsWindow(this->m_hWnd));
  954. ::SendMessage(this->m_hWnd, EM_SETMODIFY, bModified, 0L);
  955. }
  956. void GetRect(LPRECT lpRect) const
  957. {
  958. ATLASSERT(::IsWindow(this->m_hWnd));
  959. ::SendMessage(this->m_hWnd, EM_GETRECT, 0, (LPARAM)lpRect);
  960. }
  961. DWORD GetSel() const
  962. {
  963. ATLASSERT(::IsWindow(this->m_hWnd));
  964. return (DWORD)::SendMessage(this->m_hWnd, EM_GETSEL, 0, 0L);
  965. }
  966. void GetSel(int& nStartChar, int& nEndChar) const
  967. {
  968. ATLASSERT(::IsWindow(this->m_hWnd));
  969. ::SendMessage(this->m_hWnd, EM_GETSEL, (WPARAM)&nStartChar, (LPARAM)&nEndChar);
  970. }
  971. HLOCAL GetHandle() const
  972. {
  973. ATLASSERT(::IsWindow(this->m_hWnd));
  974. return (HLOCAL)::SendMessage(this->m_hWnd, EM_GETHANDLE, 0, 0L);
  975. }
  976. void SetHandle(HLOCAL hBuffer)
  977. {
  978. ATLASSERT(::IsWindow(this->m_hWnd));
  979. ::SendMessage(this->m_hWnd, EM_SETHANDLE, (WPARAM)hBuffer, 0L);
  980. }
  981. DWORD GetMargins() const
  982. {
  983. ATLASSERT(::IsWindow(this->m_hWnd));
  984. return (DWORD)::SendMessage(this->m_hWnd, EM_GETMARGINS, 0, 0L);
  985. }
  986. void GetMargins(UINT& nLeft, UINT& nRight) const
  987. {
  988. ATLASSERT(::IsWindow(this->m_hWnd));
  989. DWORD dwRet = (DWORD)::SendMessage(this->m_hWnd, EM_GETMARGINS, 0, 0L);
  990. nLeft = LOWORD(dwRet);
  991. nRight = HIWORD(dwRet);
  992. }
  993. void SetMargins(UINT nLeft, UINT nRight, WORD wFlags = EC_LEFTMARGIN | EC_RIGHTMARGIN)
  994. {
  995. ATLASSERT(::IsWindow(this->m_hWnd));
  996. ::SendMessage(this->m_hWnd, EM_SETMARGINS, wFlags, MAKELONG(nLeft, nRight));
  997. }
  998. UINT GetLimitText() const
  999. {
  1000. ATLASSERT(::IsWindow(this->m_hWnd));
  1001. return (UINT)::SendMessage(this->m_hWnd, EM_GETLIMITTEXT, 0, 0L);
  1002. }
  1003. void SetLimitText(UINT nMax)
  1004. {
  1005. ATLASSERT(::IsWindow(this->m_hWnd));
  1006. ::SendMessage(this->m_hWnd, EM_SETLIMITTEXT, nMax, 0L);
  1007. }
  1008. POINT PosFromChar(UINT nChar) const
  1009. {
  1010. ATLASSERT(::IsWindow(this->m_hWnd));
  1011. DWORD dwRet = (DWORD)::SendMessage(this->m_hWnd, EM_POSFROMCHAR, nChar, 0);
  1012. POINT point = { GET_X_LPARAM(dwRet), GET_Y_LPARAM(dwRet) };
  1013. return point;
  1014. }
  1015. int CharFromPos(POINT pt, int* pLine = NULL) const
  1016. {
  1017. ATLASSERT(::IsWindow(this->m_hWnd));
  1018. DWORD dwRet = (DWORD)::SendMessage(this->m_hWnd, EM_CHARFROMPOS, 0, MAKELPARAM(pt.x, pt.y));
  1019. if(pLine != NULL)
  1020. *pLine = (int)(short)HIWORD(dwRet);
  1021. return (int)(short)LOWORD(dwRet);
  1022. }
  1023. // NOTE: first word in lpszBuffer must contain the size of the buffer!
  1024. int GetLine(int nIndex, LPTSTR lpszBuffer) const
  1025. {
  1026. ATLASSERT(::IsWindow(this->m_hWnd));
  1027. return (int)::SendMessage(this->m_hWnd, EM_GETLINE, nIndex, (LPARAM)lpszBuffer);
  1028. }
  1029. int GetLine(int nIndex, LPTSTR lpszBuffer, int nMaxLength) const
  1030. {
  1031. ATLASSERT(::IsWindow(this->m_hWnd));
  1032. *(LPWORD)lpszBuffer = (WORD)nMaxLength;
  1033. return (int)::SendMessage(this->m_hWnd, EM_GETLINE, nIndex, (LPARAM)lpszBuffer);
  1034. }
  1035. TCHAR GetPasswordChar() const
  1036. {
  1037. ATLASSERT(::IsWindow(this->m_hWnd));
  1038. return (TCHAR)::SendMessage(this->m_hWnd, EM_GETPASSWORDCHAR, 0, 0L);
  1039. }
  1040. void SetPasswordChar(TCHAR ch)
  1041. {
  1042. ATLASSERT(::IsWindow(this->m_hWnd));
  1043. ::SendMessage(this->m_hWnd, EM_SETPASSWORDCHAR, ch, 0L);
  1044. }
  1045. EDITWORDBREAKPROC GetWordBreakProc() const
  1046. {
  1047. ATLASSERT(::IsWindow(this->m_hWnd));
  1048. return (EDITWORDBREAKPROC)::SendMessage(this->m_hWnd, EM_GETWORDBREAKPROC, 0, 0L);
  1049. }
  1050. void SetWordBreakProc(EDITWORDBREAKPROC ewbprc)
  1051. {
  1052. ATLASSERT(::IsWindow(this->m_hWnd));
  1053. ::SendMessage(this->m_hWnd, EM_SETWORDBREAKPROC, 0, (LPARAM)ewbprc);
  1054. }
  1055. int GetFirstVisibleLine() const
  1056. {
  1057. ATLASSERT(::IsWindow(this->m_hWnd));
  1058. return (int)::SendMessage(this->m_hWnd, EM_GETFIRSTVISIBLELINE, 0, 0L);
  1059. }
  1060. int GetThumb() const
  1061. {
  1062. ATLASSERT(::IsWindow(this->m_hWnd));
  1063. ATLASSERT((this->GetStyle() & ES_MULTILINE) != 0);
  1064. return (int)::SendMessage(this->m_hWnd, EM_GETTHUMB, 0, 0L);
  1065. }
  1066. BOOL SetReadOnly(BOOL bReadOnly = TRUE)
  1067. {
  1068. ATLASSERT(::IsWindow(this->m_hWnd));
  1069. return (BOOL)::SendMessage(this->m_hWnd, EM_SETREADONLY, bReadOnly, 0L);
  1070. }
  1071. UINT GetImeStatus(UINT uStatus) const
  1072. {
  1073. ATLASSERT(::IsWindow(this->m_hWnd));
  1074. return (UINT)::SendMessage(this->m_hWnd, EM_GETIMESTATUS, uStatus, 0L);
  1075. }
  1076. UINT SetImeStatus(UINT uStatus, UINT uData)
  1077. {
  1078. ATLASSERT(::IsWindow(this->m_hWnd));
  1079. return (UINT)::SendMessage(this->m_hWnd, EM_SETIMESTATUS, uStatus, uData);
  1080. }
  1081. BOOL GetCueBannerText(LPCWSTR lpstrText, int cchText) const
  1082. {
  1083. ATLASSERT(::IsWindow(this->m_hWnd));
  1084. return (BOOL)::SendMessage(this->m_hWnd, EM_GETCUEBANNER, (WPARAM)lpstrText, cchText);
  1085. }
  1086. // bKeepWithFocus - Vista only
  1087. BOOL SetCueBannerText(LPCWSTR lpstrText, BOOL bKeepWithFocus = FALSE)
  1088. {
  1089. ATLASSERT(::IsWindow(this->m_hWnd));
  1090. return (BOOL)::SendMessage(this->m_hWnd, EM_SETCUEBANNER, (WPARAM)bKeepWithFocus, (LPARAM)(lpstrText));
  1091. }
  1092. // Operations
  1093. void EmptyUndoBuffer()
  1094. {
  1095. ATLASSERT(::IsWindow(this->m_hWnd));
  1096. ::SendMessage(this->m_hWnd, EM_EMPTYUNDOBUFFER, 0, 0L);
  1097. }
  1098. BOOL FmtLines(BOOL bAddEOL)
  1099. {
  1100. ATLASSERT(::IsWindow(this->m_hWnd));
  1101. return (BOOL)::SendMessage(this->m_hWnd, EM_FMTLINES, bAddEOL, 0L);
  1102. }
  1103. void LimitText(int nChars = 0)
  1104. {
  1105. ATLASSERT(::IsWindow(this->m_hWnd));
  1106. ::SendMessage(this->m_hWnd, EM_LIMITTEXT, nChars, 0L);
  1107. }
  1108. int LineFromChar(int nIndex = -1) const
  1109. {
  1110. ATLASSERT(::IsWindow(this->m_hWnd));
  1111. return (int)::SendMessage(this->m_hWnd, EM_LINEFROMCHAR, nIndex, 0L);
  1112. }
  1113. int LineIndex(int nLine = -1) const
  1114. {
  1115. ATLASSERT(::IsWindow(this->m_hWnd));
  1116. return (int)::SendMessage(this->m_hWnd, EM_LINEINDEX, nLine, 0L);
  1117. }
  1118. int LineLength(int nLine = -1) const
  1119. {
  1120. ATLASSERT(::IsWindow(this->m_hWnd));
  1121. return (int)::SendMessage(this->m_hWnd, EM_LINELENGTH, nLine, 0L);
  1122. }
  1123. void LineScroll(int nLines, int nChars = 0)
  1124. {
  1125. ATLASSERT(::IsWindow(this->m_hWnd));
  1126. ::SendMessage(this->m_hWnd, EM_LINESCROLL, nChars, nLines);
  1127. }
  1128. void ReplaceSel(LPCTSTR lpszNewText, BOOL bCanUndo = FALSE)
  1129. {
  1130. ATLASSERT(::IsWindow(this->m_hWnd));
  1131. ::SendMessage(this->m_hWnd, EM_REPLACESEL, (WPARAM) bCanUndo, (LPARAM)lpszNewText);
  1132. }
  1133. void SetRect(LPCRECT lpRect)
  1134. {
  1135. ATLASSERT(::IsWindow(this->m_hWnd));
  1136. ::SendMessage(this->m_hWnd, EM_SETRECT, 0, (LPARAM)lpRect);
  1137. }
  1138. void SetRectNP(LPCRECT lpRect)
  1139. {
  1140. ATLASSERT(::IsWindow(this->m_hWnd));
  1141. ::SendMessage(this->m_hWnd, EM_SETRECTNP, 0, (LPARAM)lpRect);
  1142. }
  1143. void SetSel(DWORD dwSelection, BOOL bNoScroll = FALSE)
  1144. {
  1145. ATLASSERT(::IsWindow(this->m_hWnd));
  1146. ::SendMessage(this->m_hWnd, EM_SETSEL, LOWORD(dwSelection), HIWORD(dwSelection));
  1147. if(!bNoScroll)
  1148. ::SendMessage(this->m_hWnd, EM_SCROLLCARET, 0, 0L);
  1149. }
  1150. void SetSel(int nStartChar, int nEndChar, BOOL bNoScroll = FALSE)
  1151. {
  1152. ATLASSERT(::IsWindow(this->m_hWnd));
  1153. ::SendMessage(this->m_hWnd, EM_SETSEL, nStartChar, nEndChar);
  1154. if(!bNoScroll)
  1155. ::SendMessage(this->m_hWnd, EM_SCROLLCARET, 0, 0L);
  1156. }
  1157. void SetSelAll(BOOL bNoScroll = FALSE)
  1158. {
  1159. SetSel(0, -1, bNoScroll);
  1160. }
  1161. void SetSelNone(BOOL bNoScroll = FALSE)
  1162. {
  1163. SetSel(-1, 0, bNoScroll);
  1164. }
  1165. BOOL SetTabStops(int nTabStops, LPINT rgTabStops)
  1166. {
  1167. ATLASSERT(::IsWindow(this->m_hWnd));
  1168. return (BOOL)::SendMessage(this->m_hWnd, EM_SETTABSTOPS, nTabStops, (LPARAM)rgTabStops);
  1169. }
  1170. BOOL SetTabStops()
  1171. {
  1172. ATLASSERT(::IsWindow(this->m_hWnd));
  1173. return (BOOL)::SendMessage(this->m_hWnd, EM_SETTABSTOPS, 0, 0L);
  1174. }
  1175. BOOL SetTabStops(const int& cxEachStop) // takes an 'int'
  1176. {
  1177. ATLASSERT(::IsWindow(this->m_hWnd));
  1178. return (BOOL)::SendMessage(this->m_hWnd, EM_SETTABSTOPS, 1, (LPARAM)(LPINT)&cxEachStop);
  1179. }
  1180. void ScrollCaret()
  1181. {
  1182. ATLASSERT(::IsWindow(this->m_hWnd));
  1183. ::SendMessage(this->m_hWnd, EM_SCROLLCARET, 0, 0L);
  1184. }
  1185. int Scroll(int nScrollAction)
  1186. {
  1187. ATLASSERT(::IsWindow(this->m_hWnd));
  1188. ATLASSERT((this->GetStyle() & ES_MULTILINE) != 0);
  1189. LRESULT lRet = ::SendMessage(this->m_hWnd, EM_SCROLL, nScrollAction, 0L);
  1190. if(!(BOOL)HIWORD(lRet))
  1191. return -1; // failed
  1192. return (int)(short)LOWORD(lRet);
  1193. }
  1194. void InsertText(int nInsertAfterChar, LPCTSTR lpstrText, BOOL bNoScroll = FALSE, BOOL bCanUndo = FALSE)
  1195. {
  1196. SetSel(nInsertAfterChar, nInsertAfterChar, bNoScroll);
  1197. ReplaceSel(lpstrText, bCanUndo);
  1198. }
  1199. void AppendText(LPCTSTR lpstrText, BOOL bNoScroll = FALSE, BOOL bCanUndo = FALSE)
  1200. {
  1201. InsertText(this->GetWindowTextLength(), lpstrText, bNoScroll, bCanUndo);
  1202. }
  1203. BOOL ShowBalloonTip(PEDITBALLOONTIP pEditBaloonTip)
  1204. {
  1205. ATLASSERT(::IsWindow(this->m_hWnd));
  1206. return (BOOL)::SendMessage(this->m_hWnd, EM_SHOWBALLOONTIP, 0, (LPARAM)pEditBaloonTip);
  1207. }
  1208. BOOL HideBalloonTip()
  1209. {
  1210. ATLASSERT(::IsWindow(this->m_hWnd));
  1211. return (BOOL)::SendMessage(this->m_hWnd, EM_HIDEBALLOONTIP, 0, 0L);
  1212. }
  1213. #if (_WIN32_WINNT >= 0x0600)
  1214. DWORD GetHilite() const
  1215. {
  1216. ATLASSERT(::IsWindow(this->m_hWnd));
  1217. return (DWORD)::SendMessage(this->m_hWnd, EM_GETHILITE, 0, 0L);
  1218. }
  1219. void GetHilite(int& nStartChar, int& nEndChar) const
  1220. {
  1221. ATLASSERT(::IsWindow(this->m_hWnd));
  1222. DWORD dwRet = (DWORD)::SendMessage(this->m_hWnd, EM_GETHILITE, 0, 0L);
  1223. nStartChar = (int)(short)LOWORD(dwRet);
  1224. nEndChar = (int)(short)HIWORD(dwRet);
  1225. }
  1226. void SetHilite(int nStartChar, int nEndChar)
  1227. {
  1228. ATLASSERT(::IsWindow(this->m_hWnd));
  1229. ::SendMessage(this->m_hWnd, EM_SETHILITE, nStartChar, nEndChar);
  1230. }
  1231. #endif // (_WIN32_WINNT >= 0x0600)
  1232. // Clipboard operations
  1233. BOOL Undo()
  1234. {
  1235. ATLASSERT(::IsWindow(this->m_hWnd));
  1236. return (BOOL)::SendMessage(this->m_hWnd, EM_UNDO, 0, 0L);
  1237. }
  1238. void Clear()
  1239. {
  1240. ATLASSERT(::IsWindow(this->m_hWnd));
  1241. ::SendMessage(this->m_hWnd, WM_CLEAR, 0, 0L);
  1242. }
  1243. void Copy()
  1244. {
  1245. ATLASSERT(::IsWindow(this->m_hWnd));
  1246. ::SendMessage(this->m_hWnd, WM_COPY, 0, 0L);
  1247. }
  1248. void Cut()
  1249. {
  1250. ATLASSERT(::IsWindow(this->m_hWnd));
  1251. ::SendMessage(this->m_hWnd, WM_CUT, 0, 0L);
  1252. }
  1253. void Paste()
  1254. {
  1255. ATLASSERT(::IsWindow(this->m_hWnd));
  1256. ::SendMessage(this->m_hWnd, WM_PASTE, 0, 0L);
  1257. }
  1258. // New messages added in Windows 10.0.17763
  1259. #if defined(NTDDI_VERSION) && defined(NTDDI_WIN10_RS5) && (NTDDI_VERSION >= NTDDI_WIN10_RS5)
  1260. DWORD SetExtendedStyle(DWORD dwStyle, DWORD dwMask)
  1261. {
  1262. ATLASSERT(::IsWindow(this->m_hWnd));
  1263. return ::SendMessage(this->m_hWnd, EM_SETEXTENDEDSTYLE, dwMask, dwStyle);
  1264. }
  1265. DWORD GetExtendedStyle() const
  1266. {
  1267. ATLASSERT(::IsWindow(this->m_hWnd));
  1268. return ::SendMessage(this->m_hWnd, EM_GETEXTENDEDSTYLE, 0, 0L);
  1269. }
  1270. BOOL SetEndOfLine(EC_ENDOFLINE eolType)
  1271. {
  1272. ATLASSERT(::IsWindow(this->m_hWnd));
  1273. return (BOOL)::SendMessage(this->m_hWnd, EM_SETENDOFLINE, eolType, 0L);
  1274. }
  1275. EC_ENDOFLINE GetEndOfLine() const
  1276. {
  1277. ATLASSERT(::IsWindow(this->m_hWnd));
  1278. return (EC_ENDOFLINE)::SendMessage(this->m_hWnd, EM_GETENDOFLINE, 0, 0L);
  1279. }
  1280. BOOL EnableSearchWeb(BOOL bEnable)
  1281. {
  1282. ATLASSERT(::IsWindow(this->m_hWnd));
  1283. return (BOOL)::SendMessage(this->m_hWnd, EM_ENABLESEARCHWEB, (WPARAM)bEnable, 0L);
  1284. }
  1285. void SearchWeb()
  1286. {
  1287. ATLASSERT(::IsWindow(this->m_hWnd));
  1288. ::SendMessage(this->m_hWnd, EM_SEARCHWEB, 0, 0L);
  1289. }
  1290. BOOL SetCaretIndex(DWORD dwCaretIndex)
  1291. {
  1292. ATLASSERT(::IsWindow(this->m_hWnd));
  1293. return (BOOL)::SendMessage(this->m_hWnd, EM_SETCARETINDEX, dwCaretIndex, 0L);
  1294. }
  1295. DWORD GetCaretIndex() const
  1296. {
  1297. ATLASSERT(::IsWindow(this->m_hWnd));
  1298. return ::SendMessage(this->m_hWnd, EM_GETCARETINDEX, 0, 0L);
  1299. }
  1300. BOOL GetZoom(int& nNum, int& nDen) const
  1301. {
  1302. ATLASSERT(::IsWindow(this->m_hWnd));
  1303. return (BOOL)::SendMessage(this->m_hWnd, EM_GETZOOM, (WPARAM)&nNum, (LPARAM)&nDen);
  1304. }
  1305. BOOL SetZoom(int nNum, int nDen)
  1306. {
  1307. ATLASSERT(::IsWindow(this->m_hWnd));
  1308. ATLASSERT((nNum >= 0) && (nNum <= 64));
  1309. ATLASSERT((nDen >= 0) && (nDen <= 64));
  1310. return (BOOL)::SendMessage(this->m_hWnd, EM_SETZOOM, nNum, nDen);
  1311. }
  1312. DWORD GetFileLineFromChar(DWORD dwCharIndex) const
  1313. {
  1314. ATLASSERT(::IsWindow(this->m_hWnd));
  1315. return ::SendMessage(this->m_hWnd, EM_FILELINEFROMCHAR, dwCharIndex, 0L);
  1316. }
  1317. DWORD GetFileLineIndex(DWORD dwLineNum) const
  1318. {
  1319. ATLASSERT(::IsWindow(this->m_hWnd));
  1320. return ::SendMessage(this->m_hWnd, EM_FILELINEINDEX, dwLineNum, 0L);
  1321. }
  1322. DWORD GetFileLineLength(DWORD dwCharIndex) const
  1323. {
  1324. ATLASSERT(::IsWindow(this->m_hWnd));
  1325. return ::SendMessage(this->m_hWnd, EM_FILELINELENGTH, dwCharIndex, 0L);
  1326. }
  1327. DWORD GetFileLine(DWORD dwLineNum, LPTSTR lpstrLine, WORD wLen) const
  1328. {
  1329. ATLASSERT(::IsWindow(this->m_hWnd));
  1330. WORD* pw = (WORD*)lpstrLine;
  1331. *pw = wLen;
  1332. return ::SendMessage(this->m_hWnd, EM_GETFILELINE, dwLineNum, (LPARAM)lpstrLine);
  1333. }
  1334. #ifdef __ATLSTR_H__
  1335. ATL::CString GetFileLine(DWORD dwLineNum) const
  1336. {
  1337. ATL::CString strLine;
  1338. DWORD dwCharIndex = GetFileLineIndex(dwLineNum);
  1339. if(dwCharIndex != (DWORD)-1)
  1340. {
  1341. DWORD dwLen = GetFileLineLength(dwCharIndex);
  1342. if(dwLen > 0)
  1343. {
  1344. LPTSTR lpstrLine = strLine.GetBufferSetLength(dwLen);
  1345. ATLVERIFY(GetFileLine(dwLineNum, lpstrLine, (WORD)dwLen) == dwLen);
  1346. strLine.ReleaseBuffer();
  1347. }
  1348. }
  1349. return strLine;
  1350. }
  1351. #endif // __ATLSTR_H__
  1352. DWORD GetFileLineCount() const
  1353. {
  1354. ATLASSERT(::IsWindow(this->m_hWnd));
  1355. return ::SendMessage(this->m_hWnd, EM_GETFILELINECOUNT, 0, 0L);
  1356. }
  1357. #endif // defined(NTDDI_VERSION) && defined(NTDDI_WIN10_RS5) && (NTDDI_VERSION >= NTDDI_WIN10_RS5)
  1358. };
  1359. typedef CEditT<ATL::CWindow> CEdit;
  1360. ///////////////////////////////////////////////////////////////////////////////
  1361. // CEditCommands - message handlers for standard EDIT commands
  1362. // Chain to CEditCommands message map. Your class must also derive from CEdit.
  1363. // Example:
  1364. // class CMyEdit : public CWindowImpl<CMyEdit, CEdit>,
  1365. // public CEditCommands<CMyEdit>
  1366. // {
  1367. // public:
  1368. // BEGIN_MSG_MAP(CMyEdit)
  1369. // // your handlers...
  1370. // CHAIN_MSG_MAP_ALT(CEditCommands<CMyEdit>, 1)
  1371. // END_MSG_MAP()
  1372. // // other stuff...
  1373. // };
  1374. template <class T>
  1375. class CEditCommands
  1376. {
  1377. public:
  1378. BEGIN_MSG_MAP(CEditCommands< T >)
  1379. ALT_MSG_MAP(1)
  1380. COMMAND_ID_HANDLER(ID_EDIT_CLEAR, OnEditClear)
  1381. COMMAND_ID_HANDLER(ID_EDIT_CLEAR_ALL, OnEditClearAll)
  1382. COMMAND_ID_HANDLER(ID_EDIT_COPY, OnEditCopy)
  1383. COMMAND_ID_HANDLER(ID_EDIT_CUT, OnEditCut)
  1384. COMMAND_ID_HANDLER(ID_EDIT_PASTE, OnEditPaste)
  1385. COMMAND_ID_HANDLER(ID_EDIT_SELECT_ALL, OnEditSelectAll)
  1386. COMMAND_ID_HANDLER(ID_EDIT_UNDO, OnEditUndo)
  1387. END_MSG_MAP()
  1388. LRESULT OnEditClear(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  1389. {
  1390. T* pT = static_cast<T*>(this);
  1391. pT->Clear();
  1392. return 0;
  1393. }
  1394. LRESULT OnEditClearAll(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  1395. {
  1396. T* pT = static_cast<T*>(this);
  1397. pT->SetSel(0, -1);
  1398. pT->Clear();
  1399. return 0;
  1400. }
  1401. LRESULT OnEditCopy(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  1402. {
  1403. T* pT = static_cast<T*>(this);
  1404. pT->Copy();
  1405. return 0;
  1406. }
  1407. LRESULT OnEditCut(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  1408. {
  1409. T* pT = static_cast<T*>(this);
  1410. pT->Cut();
  1411. return 0;
  1412. }
  1413. LRESULT OnEditPaste(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  1414. {
  1415. T* pT = static_cast<T*>(this);
  1416. pT->Paste();
  1417. return 0;
  1418. }
  1419. LRESULT OnEditSelectAll(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  1420. {
  1421. T* pT = static_cast<T*>(this);
  1422. pT->SetSel(0, -1);
  1423. return 0;
  1424. }
  1425. LRESULT OnEditUndo(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  1426. {
  1427. T* pT = static_cast<T*>(this);
  1428. pT->Undo();
  1429. return 0;
  1430. }
  1431. // State (update UI) helpers
  1432. BOOL CanCut() const
  1433. { return HasSelection(); }
  1434. BOOL CanCopy() const
  1435. { return HasSelection(); }
  1436. BOOL CanClear() const
  1437. { return HasSelection(); }
  1438. BOOL CanSelectAll() const
  1439. { return HasText(); }
  1440. BOOL CanFind() const
  1441. { return HasText(); }
  1442. BOOL CanRepeat() const
  1443. { return HasText(); }
  1444. BOOL CanReplace() const
  1445. { return HasText(); }
  1446. BOOL CanClearAll() const
  1447. { return HasText(); }
  1448. // Implementation
  1449. BOOL HasSelection() const
  1450. {
  1451. const T* pT = static_cast<const T*>(this);
  1452. int nMin = 0, nMax = 0;
  1453. ::SendMessage(pT->m_hWnd, EM_GETSEL, (WPARAM)&nMin, (LPARAM)&nMax);
  1454. return (nMin != nMax);
  1455. }
  1456. BOOL HasText() const
  1457. {
  1458. const T* pT = static_cast<const T*>(this);
  1459. return (pT->GetWindowTextLength() > 0);
  1460. }
  1461. };
  1462. ///////////////////////////////////////////////////////////////////////////////
  1463. // CScrollBar - client side for a Windows SCROLLBAR control
  1464. template <class TBase>
  1465. class CScrollBarT : public TBase
  1466. {
  1467. public:
  1468. // Constructors
  1469. CScrollBarT(HWND hWnd = NULL) : TBase(hWnd)
  1470. { }
  1471. CScrollBarT< TBase >& operator =(HWND hWnd)
  1472. {
  1473. this->m_hWnd = hWnd;
  1474. return *this;
  1475. }
  1476. HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  1477. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  1478. ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  1479. {
  1480. return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  1481. }
  1482. // Attributes
  1483. static LPCTSTR GetWndClassName()
  1484. {
  1485. return _T("SCROLLBAR");
  1486. }
  1487. int GetScrollPos() const
  1488. {
  1489. ATLASSERT(::IsWindow(this->m_hWnd));
  1490. return ::GetScrollPos(this->m_hWnd, SB_CTL);
  1491. }
  1492. int SetScrollPos(int nPos, BOOL bRedraw = TRUE)
  1493. {
  1494. ATLASSERT(::IsWindow(this->m_hWnd));
  1495. return ::SetScrollPos(this->m_hWnd, SB_CTL, nPos, bRedraw);
  1496. }
  1497. void GetScrollRange(LPINT lpMinPos, LPINT lpMaxPos) const
  1498. {
  1499. ATLASSERT(::IsWindow(this->m_hWnd));
  1500. ::GetScrollRange(this->m_hWnd, SB_CTL, lpMinPos, lpMaxPos);
  1501. }
  1502. void SetScrollRange(int nMinPos, int nMaxPos, BOOL bRedraw = TRUE)
  1503. {
  1504. ATLASSERT(::IsWindow(this->m_hWnd));
  1505. ::SetScrollRange(this->m_hWnd, SB_CTL, nMinPos, nMaxPos, bRedraw);
  1506. }
  1507. BOOL GetScrollInfo(LPSCROLLINFO lpScrollInfo) const
  1508. {
  1509. ATLASSERT(::IsWindow(this->m_hWnd));
  1510. return ::GetScrollInfo(this->m_hWnd, SB_CTL, lpScrollInfo);
  1511. }
  1512. int SetScrollInfo(LPSCROLLINFO lpScrollInfo, BOOL bRedraw = TRUE)
  1513. {
  1514. ATLASSERT(::IsWindow(this->m_hWnd));
  1515. return ::SetScrollInfo(this->m_hWnd, SB_CTL, lpScrollInfo, bRedraw);
  1516. }
  1517. int GetScrollLimit() const
  1518. {
  1519. SCROLLINFO info = { sizeof(SCROLLINFO), SIF_RANGE | SIF_PAGE };
  1520. ::GetScrollInfo(this->m_hWnd, SB_CTL, &info);
  1521. if(info.nPage > 1)
  1522. info.nMax -= info.nPage - 1;
  1523. return info.nMax;
  1524. }
  1525. BOOL GetScrollBarInfo(PSCROLLBARINFO pScrollBarInfo) const
  1526. {
  1527. ATLASSERT(::IsWindow(this->m_hWnd));
  1528. return (BOOL)::SendMessage(this->m_hWnd, SBM_GETSCROLLBARINFO, 0, (LPARAM)pScrollBarInfo);
  1529. }
  1530. // Operations
  1531. void ShowScrollBar(BOOL bShow = TRUE)
  1532. {
  1533. ATLASSERT(::IsWindow(this->m_hWnd));
  1534. ::ShowScrollBar(this->m_hWnd, SB_CTL, bShow);
  1535. }
  1536. BOOL EnableScrollBar(UINT nArrowFlags = ESB_ENABLE_BOTH)
  1537. {
  1538. ATLASSERT(::IsWindow(this->m_hWnd));
  1539. return ::EnableScrollBar(this->m_hWnd, SB_CTL, nArrowFlags);
  1540. }
  1541. };
  1542. typedef CScrollBarT<ATL::CWindow> CScrollBar;
  1543. // --- Windows Common Controls ---
  1544. ///////////////////////////////////////////////////////////////////////////////
  1545. // CImageList
  1546. // forward declarations
  1547. template <bool t_bManaged> class CImageListT;
  1548. typedef CImageListT<false> CImageList;
  1549. typedef CImageListT<true> CImageListManaged;
  1550. template <bool t_bManaged>
  1551. class CImageListT
  1552. {
  1553. public:
  1554. // Data members
  1555. HIMAGELIST m_hImageList;
  1556. // Constructor/destructor/operators
  1557. CImageListT(HIMAGELIST hImageList = NULL) : m_hImageList(hImageList)
  1558. { }
  1559. ~CImageListT()
  1560. {
  1561. if(t_bManaged && (m_hImageList != NULL))
  1562. Destroy();
  1563. }
  1564. CImageListT<t_bManaged>& operator =(HIMAGELIST hImageList)
  1565. {
  1566. Attach(hImageList);
  1567. return *this;
  1568. }
  1569. void Attach(HIMAGELIST hImageList)
  1570. {
  1571. if(t_bManaged && (m_hImageList != NULL) && (m_hImageList != hImageList))
  1572. ImageList_Destroy(m_hImageList);
  1573. m_hImageList = hImageList;
  1574. }
  1575. HIMAGELIST Detach()
  1576. {
  1577. HIMAGELIST hImageList = m_hImageList;
  1578. m_hImageList = NULL;
  1579. return hImageList;
  1580. }
  1581. operator HIMAGELIST() const { return m_hImageList; }
  1582. bool IsNull() const { return (m_hImageList == NULL); }
  1583. // Attributes
  1584. int GetImageCount() const
  1585. {
  1586. ATLASSERT(m_hImageList != NULL);
  1587. return ImageList_GetImageCount(m_hImageList);
  1588. }
  1589. COLORREF GetBkColor() const
  1590. {
  1591. ATLASSERT(m_hImageList != NULL);
  1592. return ImageList_GetBkColor(m_hImageList);
  1593. }
  1594. COLORREF SetBkColor(COLORREF cr)
  1595. {
  1596. ATLASSERT(m_hImageList != NULL);
  1597. return ImageList_SetBkColor(m_hImageList, cr);
  1598. }
  1599. BOOL GetImageInfo(int nImage, IMAGEINFO* pImageInfo) const
  1600. {
  1601. ATLASSERT(m_hImageList != NULL);
  1602. return ImageList_GetImageInfo(m_hImageList, nImage, pImageInfo);
  1603. }
  1604. HICON GetIcon(int nIndex, UINT uFlags = ILD_NORMAL) const
  1605. {
  1606. ATLASSERT(m_hImageList != NULL);
  1607. return ImageList_GetIcon(m_hImageList, nIndex, uFlags);
  1608. }
  1609. BOOL GetIconSize(int& cx, int& cy) const
  1610. {
  1611. ATLASSERT(m_hImageList != NULL);
  1612. return ImageList_GetIconSize(m_hImageList, &cx, &cy);
  1613. }
  1614. BOOL GetIconSize(SIZE& size) const
  1615. {
  1616. ATLASSERT(m_hImageList != NULL);
  1617. return ImageList_GetIconSize(m_hImageList, (int*)&size.cx, (int*)&size.cy);
  1618. }
  1619. BOOL SetIconSize(int cx, int cy)
  1620. {
  1621. ATLASSERT(m_hImageList != NULL);
  1622. return ImageList_SetIconSize(m_hImageList, cx, cy);
  1623. }
  1624. BOOL SetIconSize(SIZE size)
  1625. {
  1626. ATLASSERT(m_hImageList != NULL);
  1627. return ImageList_SetIconSize(m_hImageList, size.cx, size.cy);
  1628. }
  1629. BOOL SetImageCount(UINT uNewCount)
  1630. {
  1631. ATLASSERT(m_hImageList != NULL);
  1632. return ImageList_SetImageCount(m_hImageList, uNewCount);
  1633. }
  1634. BOOL SetOverlayImage(int nImage, int nOverlay)
  1635. {
  1636. ATLASSERT(m_hImageList != NULL);
  1637. return ImageList_SetOverlayImage(m_hImageList, nImage, nOverlay);
  1638. }
  1639. // Operations
  1640. BOOL Create(int cx, int cy, UINT nFlags, int nInitial, int nGrow)
  1641. {
  1642. ATLASSERT(m_hImageList == NULL);
  1643. m_hImageList = ImageList_Create(cx, cy, nFlags, nInitial, nGrow);
  1644. return (m_hImageList != NULL) ? TRUE : FALSE;
  1645. }
  1646. BOOL Create(ATL::_U_STRINGorID bitmap, int cx, int nGrow, COLORREF crMask)
  1647. {
  1648. ATLASSERT(m_hImageList == NULL);
  1649. m_hImageList = ImageList_LoadBitmap(ModuleHelper::GetResourceInstance(), bitmap.m_lpstr, cx, nGrow, crMask);
  1650. return (m_hImageList != NULL) ? TRUE : FALSE;
  1651. }
  1652. BOOL CreateFromImage(ATL::_U_STRINGorID image, int cx, int nGrow, COLORREF crMask, UINT uType, UINT uFlags = LR_DEFAULTCOLOR | LR_DEFAULTSIZE)
  1653. {
  1654. ATLASSERT(m_hImageList == NULL);
  1655. m_hImageList = ImageList_LoadImage(ModuleHelper::GetResourceInstance(), image.m_lpstr, cx, nGrow, crMask, uType, uFlags);
  1656. return (m_hImageList != NULL) ? TRUE : FALSE;
  1657. }
  1658. BOOL Merge(HIMAGELIST hImageList1, int nImage1, HIMAGELIST hImageList2, int nImage2, int dx, int dy)
  1659. {
  1660. ATLASSERT(m_hImageList == NULL);
  1661. m_hImageList = ImageList_Merge(hImageList1, nImage1, hImageList2, nImage2, dx, dy);
  1662. return (m_hImageList != NULL) ? TRUE : FALSE;
  1663. }
  1664. #ifdef __IStream_INTERFACE_DEFINED__
  1665. BOOL CreateFromStream(LPSTREAM lpStream)
  1666. {
  1667. ATLASSERT(m_hImageList == NULL);
  1668. m_hImageList = ImageList_Read(lpStream);
  1669. return (m_hImageList != NULL) ? TRUE : FALSE;
  1670. }
  1671. #endif // __IStream_INTERFACE_DEFINED__
  1672. BOOL Destroy()
  1673. {
  1674. if (m_hImageList == NULL)
  1675. return FALSE;
  1676. BOOL bRet = ImageList_Destroy(m_hImageList);
  1677. if(bRet)
  1678. m_hImageList = NULL;
  1679. return bRet;
  1680. }
  1681. int Add(HBITMAP hBitmap, HBITMAP hBitmapMask = NULL)
  1682. {
  1683. ATLASSERT(m_hImageList != NULL);
  1684. return ImageList_Add(m_hImageList, hBitmap, hBitmapMask);
  1685. }
  1686. int Add(HBITMAP hBitmap, COLORREF crMask)
  1687. {
  1688. ATLASSERT(m_hImageList != NULL);
  1689. return ImageList_AddMasked(m_hImageList, hBitmap, crMask);
  1690. }
  1691. BOOL Remove(int nImage)
  1692. {
  1693. ATLASSERT(m_hImageList != NULL);
  1694. return ImageList_Remove(m_hImageList, nImage);
  1695. }
  1696. BOOL RemoveAll()
  1697. {
  1698. ATLASSERT(m_hImageList != NULL);
  1699. return ImageList_RemoveAll(m_hImageList);
  1700. }
  1701. BOOL Replace(int nImage, HBITMAP hBitmap, HBITMAP hBitmapMask)
  1702. {
  1703. ATLASSERT(m_hImageList != NULL);
  1704. return ImageList_Replace(m_hImageList, nImage, hBitmap, hBitmapMask);
  1705. }
  1706. int AddIcon(HICON hIcon)
  1707. {
  1708. ATLASSERT(m_hImageList != NULL);
  1709. return ImageList_AddIcon(m_hImageList, hIcon);
  1710. }
  1711. int ReplaceIcon(int nImage, HICON hIcon)
  1712. {
  1713. ATLASSERT(m_hImageList != NULL);
  1714. return ImageList_ReplaceIcon(m_hImageList, nImage, hIcon);
  1715. }
  1716. HICON ExtractIcon(int nImage)
  1717. {
  1718. ATLASSERT(m_hImageList != NULL);
  1719. return ImageList_ExtractIcon(NULL, m_hImageList, nImage);
  1720. }
  1721. BOOL Draw(HDC hDC, int nImage, int x, int y, UINT nStyle)
  1722. {
  1723. ATLASSERT(m_hImageList != NULL);
  1724. ATLASSERT(hDC != NULL);
  1725. return ImageList_Draw(m_hImageList, nImage, hDC, x, y, nStyle);
  1726. }
  1727. BOOL Draw(HDC hDC, int nImage, POINT pt, UINT nStyle)
  1728. {
  1729. ATLASSERT(m_hImageList != NULL);
  1730. ATLASSERT(hDC != NULL);
  1731. return ImageList_Draw(m_hImageList, nImage, hDC, pt.x, pt.y, nStyle);
  1732. }
  1733. BOOL DrawEx(int nImage, HDC hDC, int x, int y, int dx, int dy, COLORREF rgbBk, COLORREF rgbFg, UINT fStyle)
  1734. {
  1735. ATLASSERT(m_hImageList != NULL);
  1736. ATLASSERT(hDC != NULL);
  1737. return ImageList_DrawEx(m_hImageList, nImage, hDC, x, y, dx, dy, rgbBk, rgbFg, fStyle);
  1738. }
  1739. BOOL DrawEx(int nImage, HDC hDC, RECT& rect, COLORREF rgbBk, COLORREF rgbFg, UINT fStyle)
  1740. {
  1741. ATLASSERT(m_hImageList != NULL);
  1742. ATLASSERT(hDC != NULL);
  1743. return ImageList_DrawEx(m_hImageList, nImage, hDC, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, rgbBk, rgbFg, fStyle);
  1744. }
  1745. static BOOL DrawIndirect(IMAGELISTDRAWPARAMS* pimldp)
  1746. {
  1747. return ImageList_DrawIndirect(pimldp);
  1748. }
  1749. BOOL Copy(int nSrc, int nDst, UINT uFlags = ILCF_MOVE)
  1750. {
  1751. ATLASSERT(m_hImageList != NULL);
  1752. return ImageList_Copy(m_hImageList, nDst, m_hImageList, nSrc, uFlags);
  1753. }
  1754. #ifdef __IStream_INTERFACE_DEFINED__
  1755. static HIMAGELIST Read(LPSTREAM lpStream)
  1756. {
  1757. return ImageList_Read(lpStream);
  1758. }
  1759. BOOL Write(LPSTREAM lpStream)
  1760. {
  1761. ATLASSERT(m_hImageList != NULL);
  1762. return ImageList_Write(m_hImageList, lpStream);
  1763. }
  1764. static HRESULT ReadEx(DWORD dwFlags, LPSTREAM lpStream, REFIID riid, PVOID* ppv)
  1765. {
  1766. return ImageList_ReadEx(dwFlags, lpStream, riid, ppv);
  1767. }
  1768. HRESULT WriteEx(DWORD dwFlags, LPSTREAM lpStream)
  1769. {
  1770. ATLASSERT(m_hImageList != NULL);
  1771. return ImageList_WriteEx(m_hImageList, dwFlags, lpStream);
  1772. }
  1773. #endif // __IStream_INTERFACE_DEFINED__
  1774. // Drag operations
  1775. BOOL BeginDrag(int nImage, POINT ptHotSpot)
  1776. {
  1777. ATLASSERT(m_hImageList != NULL);
  1778. return ImageList_BeginDrag(m_hImageList, nImage, ptHotSpot.x, ptHotSpot.y);
  1779. }
  1780. BOOL BeginDrag(int nImage, int xHotSpot, int yHotSpot)
  1781. {
  1782. ATLASSERT(m_hImageList != NULL);
  1783. return ImageList_BeginDrag(m_hImageList, nImage, xHotSpot, yHotSpot);
  1784. }
  1785. static void EndDrag()
  1786. {
  1787. ImageList_EndDrag();
  1788. }
  1789. static BOOL DragMove(POINT pt)
  1790. {
  1791. return ImageList_DragMove(pt.x, pt.y);
  1792. }
  1793. static BOOL DragMove(int x, int y)
  1794. {
  1795. return ImageList_DragMove(x, y);
  1796. }
  1797. BOOL SetDragCursorImage(int nDrag, POINT ptHotSpot)
  1798. {
  1799. ATLASSERT(m_hImageList != NULL);
  1800. return ImageList_SetDragCursorImage(m_hImageList, nDrag, ptHotSpot.x, ptHotSpot.y);
  1801. }
  1802. BOOL SetDragCursorImage(int nDrag, int xHotSpot, int yHotSpot)
  1803. {
  1804. ATLASSERT(m_hImageList != NULL);
  1805. return ImageList_SetDragCursorImage(m_hImageList, nDrag, xHotSpot, yHotSpot);
  1806. }
  1807. static BOOL DragShowNolock(BOOL bShow = TRUE)
  1808. {
  1809. return ImageList_DragShowNolock(bShow);
  1810. }
  1811. static CImageList GetDragImage(LPPOINT lpPoint, LPPOINT lpPointHotSpot)
  1812. {
  1813. return CImageList(ImageList_GetDragImage(lpPoint, lpPointHotSpot));
  1814. }
  1815. static BOOL DragEnter(HWND hWnd, POINT point)
  1816. {
  1817. return ImageList_DragEnter(hWnd, point.x, point.y);
  1818. }
  1819. static BOOL DragEnter(HWND hWnd, int x, int y)
  1820. {
  1821. return ImageList_DragEnter(hWnd, x, y);
  1822. }
  1823. static BOOL DragLeave(HWND hWnd)
  1824. {
  1825. return ImageList_DragLeave(hWnd);
  1826. }
  1827. CImageList Duplicate() const
  1828. {
  1829. ATLASSERT(m_hImageList != NULL);
  1830. return CImageList(ImageList_Duplicate(m_hImageList));
  1831. }
  1832. static CImageList Duplicate(HIMAGELIST hImageList)
  1833. {
  1834. ATLASSERT(hImageList != NULL);
  1835. return CImageList(ImageList_Duplicate(hImageList));
  1836. }
  1837. };
  1838. ///////////////////////////////////////////////////////////////////////////////
  1839. // CToolTipCtrl
  1840. class CToolInfo : public TOOLINFO
  1841. {
  1842. public:
  1843. CToolInfo(UINT nFlags, HWND hWnd, UINT_PTR nIDTool = 0, LPRECT lpRect = NULL, LPTSTR lpstrText = LPSTR_TEXTCALLBACK, LPARAM lUserParam = NULL)
  1844. {
  1845. Init(nFlags, hWnd, nIDTool, lpRect, lpstrText, lUserParam);
  1846. }
  1847. operator LPTOOLINFO() { return this; }
  1848. operator LPARAM() { return (LPARAM)this; }
  1849. void Init(UINT nFlags, HWND hWnd, UINT_PTR nIDTool = 0, LPRECT lpRect = NULL, LPTSTR lpstrText = LPSTR_TEXTCALLBACK, LPARAM lUserParam = NULL)
  1850. {
  1851. ATLASSERT(::IsWindow(hWnd));
  1852. memset(this, 0, sizeof(TOOLINFO));
  1853. cbSize = RunTimeHelper::SizeOf_TOOLINFO();
  1854. uFlags = nFlags;
  1855. if(nIDTool == 0)
  1856. {
  1857. hwnd = ::GetParent(hWnd);
  1858. uFlags |= TTF_IDISHWND;
  1859. uId = (UINT_PTR)hWnd;
  1860. }
  1861. else
  1862. {
  1863. hwnd = hWnd;
  1864. uId = nIDTool;
  1865. }
  1866. if(lpRect != NULL)
  1867. rect = *lpRect;
  1868. hinst = ModuleHelper::GetResourceInstance();
  1869. lpszText = lpstrText;
  1870. lParam = lUserParam;
  1871. }
  1872. };
  1873. template <class TBase>
  1874. class CToolTipCtrlT : public TBase
  1875. {
  1876. public:
  1877. // Constructors
  1878. CToolTipCtrlT(HWND hWnd = NULL) : TBase(hWnd)
  1879. { }
  1880. CToolTipCtrlT< TBase >& operator =(HWND hWnd)
  1881. {
  1882. this->m_hWnd = hWnd;
  1883. return *this;
  1884. }
  1885. HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  1886. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  1887. ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  1888. {
  1889. return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  1890. }
  1891. // Attributes
  1892. static LPCTSTR GetWndClassName()
  1893. {
  1894. return TOOLTIPS_CLASS;
  1895. }
  1896. void GetText(LPTOOLINFO lpToolInfo) const
  1897. {
  1898. ATLASSERT(::IsWindow(this->m_hWnd));
  1899. ::SendMessage(this->m_hWnd, TTM_GETTEXT, 0, (LPARAM)&lpToolInfo);
  1900. }
  1901. void GetText(LPTSTR lpstrText, HWND hWnd, UINT_PTR nIDTool = 0) const
  1902. {
  1903. ATLASSERT(::IsWindow(this->m_hWnd));
  1904. ATLASSERT(hWnd != NULL);
  1905. CToolInfo ti(0, hWnd, nIDTool, NULL, lpstrText);
  1906. ::SendMessage(this->m_hWnd, TTM_GETTEXT, 0, ti);
  1907. }
  1908. BOOL GetToolInfo(LPTOOLINFO lpToolInfo) const
  1909. {
  1910. ATLASSERT(::IsWindow(this->m_hWnd));
  1911. return (BOOL)::SendMessage(this->m_hWnd, TTM_GETTOOLINFO, 0, (LPARAM)lpToolInfo);
  1912. }
  1913. BOOL GetToolInfo(HWND hWnd, UINT_PTR nIDTool, UINT* puFlags, LPRECT lpRect, LPTSTR lpstrText) const
  1914. {
  1915. ATLASSERT(::IsWindow(this->m_hWnd));
  1916. ATLASSERT(hWnd != NULL);
  1917. ATLASSERT(puFlags != NULL);
  1918. ATLASSERT(lpRect != NULL);
  1919. CToolInfo ti(0, hWnd, nIDTool, NULL, lpstrText);
  1920. BOOL bRet = (BOOL)::SendMessage(this->m_hWnd, TTM_GETTOOLINFO, 0, ti);
  1921. if(bRet != FALSE)
  1922. {
  1923. *puFlags = ti.uFlags;
  1924. *lpRect = ti.rect;
  1925. }
  1926. return bRet;
  1927. }
  1928. void SetToolInfo(LPTOOLINFO lpToolInfo)
  1929. {
  1930. ATLASSERT(::IsWindow(this->m_hWnd));
  1931. ::SendMessage(this->m_hWnd, TTM_SETTOOLINFO, 0, (LPARAM)lpToolInfo);
  1932. }
  1933. void SetToolRect(LPTOOLINFO lpToolInfo)
  1934. {
  1935. ATLASSERT(::IsWindow(this->m_hWnd));
  1936. ::SendMessage(this->m_hWnd, TTM_NEWTOOLRECT, 0, (LPARAM)lpToolInfo);
  1937. }
  1938. void SetToolRect(HWND hWnd, UINT_PTR nIDTool, LPCRECT lpRect)
  1939. {
  1940. ATLASSERT(::IsWindow(this->m_hWnd));
  1941. ATLASSERT(hWnd != NULL);
  1942. ATLASSERT(nIDTool != 0);
  1943. CToolInfo ti(0, hWnd, nIDTool, (LPRECT)lpRect, NULL);
  1944. ::SendMessage(this->m_hWnd, TTM_NEWTOOLRECT, 0, ti);
  1945. }
  1946. int GetToolCount() const
  1947. {
  1948. ATLASSERT(::IsWindow(this->m_hWnd));
  1949. return (int)::SendMessage(this->m_hWnd, TTM_GETTOOLCOUNT, 0, 0L);
  1950. }
  1951. int GetDelayTime(DWORD dwType) const
  1952. {
  1953. ATLASSERT(::IsWindow(this->m_hWnd));
  1954. return (int)::SendMessage(this->m_hWnd, TTM_GETDELAYTIME, dwType, 0L);
  1955. }
  1956. void SetDelayTime(DWORD dwType, int nTime)
  1957. {
  1958. ATLASSERT(::IsWindow(this->m_hWnd));
  1959. ::SendMessage(this->m_hWnd, TTM_SETDELAYTIME, dwType, MAKELPARAM(nTime, 0));
  1960. }
  1961. void GetMargin(LPRECT lpRect) const
  1962. {
  1963. ATLASSERT(::IsWindow(this->m_hWnd));
  1964. ::SendMessage(this->m_hWnd, TTM_GETMARGIN, 0, (LPARAM)lpRect);
  1965. }
  1966. void SetMargin(LPRECT lpRect)
  1967. {
  1968. ATLASSERT(::IsWindow(this->m_hWnd));
  1969. ::SendMessage(this->m_hWnd, TTM_SETMARGIN, 0, (LPARAM)lpRect);
  1970. }
  1971. int GetMaxTipWidth() const
  1972. {
  1973. ATLASSERT(::IsWindow(this->m_hWnd));
  1974. return (int)::SendMessage(this->m_hWnd, TTM_GETMAXTIPWIDTH, 0, 0L);
  1975. }
  1976. int SetMaxTipWidth(int nWidth)
  1977. {
  1978. ATLASSERT(::IsWindow(this->m_hWnd));
  1979. return (int)::SendMessage(this->m_hWnd, TTM_SETMAXTIPWIDTH, 0, nWidth);
  1980. }
  1981. COLORREF GetTipBkColor() const
  1982. {
  1983. ATLASSERT(::IsWindow(this->m_hWnd));
  1984. return (COLORREF)::SendMessage(this->m_hWnd, TTM_GETTIPBKCOLOR, 0, 0L);
  1985. }
  1986. void SetTipBkColor(COLORREF clr)
  1987. {
  1988. ATLASSERT(::IsWindow(this->m_hWnd));
  1989. ::SendMessage(this->m_hWnd, TTM_SETTIPBKCOLOR, (WPARAM)clr, 0L);
  1990. }
  1991. COLORREF GetTipTextColor() const
  1992. {
  1993. ATLASSERT(::IsWindow(this->m_hWnd));
  1994. return (COLORREF)::SendMessage(this->m_hWnd, TTM_GETTIPTEXTCOLOR, 0, 0L);
  1995. }
  1996. void SetTipTextColor(COLORREF clr)
  1997. {
  1998. ATLASSERT(::IsWindow(this->m_hWnd));
  1999. ::SendMessage(this->m_hWnd, TTM_SETTIPTEXTCOLOR, (WPARAM)clr, 0L);
  2000. }
  2001. BOOL GetCurrentTool(LPTOOLINFO lpToolInfo) const
  2002. {
  2003. ATLASSERT(::IsWindow(this->m_hWnd));
  2004. return (BOOL)::SendMessage(this->m_hWnd, TTM_GETCURRENTTOOL, 0, (LPARAM)lpToolInfo);
  2005. }
  2006. SIZE GetBubbleSize(LPTOOLINFO lpToolInfo) const
  2007. {
  2008. ATLASSERT(::IsWindow(this->m_hWnd));
  2009. DWORD dwRet = (DWORD)::SendMessage(this->m_hWnd, TTM_GETBUBBLESIZE, 0, (LPARAM)lpToolInfo);
  2010. SIZE size = { GET_X_LPARAM(dwRet), GET_Y_LPARAM(dwRet) };
  2011. return size;
  2012. }
  2013. BOOL SetTitle(UINT_PTR uIcon, LPCTSTR lpstrTitle)
  2014. {
  2015. ATLASSERT(::IsWindow(this->m_hWnd));
  2016. return (BOOL)::SendMessage(this->m_hWnd, TTM_SETTITLE, uIcon, (LPARAM)lpstrTitle);
  2017. }
  2018. BOOL SetTitle(HICON hIcon, LPCTSTR lpstrTitle)
  2019. {
  2020. ATLASSERT(::IsWindow(this->m_hWnd));
  2021. return (BOOL)::SendMessage(this->m_hWnd, TTM_SETTITLE, (WPARAM)hIcon, (LPARAM)lpstrTitle);
  2022. }
  2023. void GetTitle(PTTGETTITLE pTTGetTitle) const
  2024. {
  2025. ATLASSERT(::IsWindow(this->m_hWnd));
  2026. ::SendMessage(this->m_hWnd, TTM_GETTITLE, 0, (LPARAM)pTTGetTitle);
  2027. }
  2028. void SetWindowTheme(LPCWSTR lpstrTheme)
  2029. {
  2030. ATLASSERT(::IsWindow(this->m_hWnd));
  2031. ::SendMessage(this->m_hWnd, TTM_SETWINDOWTHEME, 0, (LPARAM)lpstrTheme);
  2032. }
  2033. // Operations
  2034. void Activate(BOOL bActivate)
  2035. {
  2036. ATLASSERT(::IsWindow(this->m_hWnd));
  2037. ::SendMessage(this->m_hWnd, TTM_ACTIVATE, bActivate, 0L);
  2038. }
  2039. BOOL AddTool(LPTOOLINFO lpToolInfo)
  2040. {
  2041. ATLASSERT(::IsWindow(this->m_hWnd));
  2042. return (BOOL)::SendMessage(this->m_hWnd, TTM_ADDTOOL, 0, (LPARAM)lpToolInfo);
  2043. }
  2044. BOOL AddTool(HWND hWnd, ATL::_U_STRINGorID text = LPSTR_TEXTCALLBACK, LPCRECT lpRectTool = NULL, UINT_PTR nIDTool = 0)
  2045. {
  2046. ATLASSERT(::IsWindow(this->m_hWnd));
  2047. ATLASSERT(hWnd != NULL);
  2048. // the toolrect and toolid must both be zero or both valid
  2049. ATLASSERT(((lpRectTool != NULL) && (nIDTool != 0)) || ((lpRectTool == NULL) && (nIDTool == 0)));
  2050. CToolInfo ti(0, hWnd, nIDTool, (LPRECT)lpRectTool, (LPTSTR)text.m_lpstr);
  2051. return (BOOL)::SendMessage(this->m_hWnd, TTM_ADDTOOL, 0, ti);
  2052. }
  2053. void DelTool(LPTOOLINFO lpToolInfo)
  2054. {
  2055. ATLASSERT(::IsWindow(this->m_hWnd));
  2056. ::SendMessage(this->m_hWnd, TTM_DELTOOL, 0, (LPARAM)lpToolInfo);
  2057. }
  2058. void DelTool(HWND hWnd, UINT_PTR nIDTool = 0)
  2059. {
  2060. ATLASSERT(::IsWindow(this->m_hWnd));
  2061. ATLASSERT(hWnd != NULL);
  2062. CToolInfo ti(0, hWnd, nIDTool, NULL, NULL);
  2063. ::SendMessage(this->m_hWnd, TTM_DELTOOL, 0, ti);
  2064. }
  2065. BOOL HitTest(LPTTHITTESTINFO lpHitTestInfo) const
  2066. {
  2067. ATLASSERT(::IsWindow(this->m_hWnd));
  2068. return (BOOL)::SendMessage(this->m_hWnd, TTM_HITTEST, 0, (LPARAM)lpHitTestInfo);
  2069. }
  2070. BOOL HitTest(HWND hWnd, POINT pt, LPTOOLINFO lpToolInfo) const
  2071. {
  2072. ATLASSERT(::IsWindow(this->m_hWnd));
  2073. ATLASSERT(hWnd != NULL);
  2074. ATLASSERT(lpToolInfo != NULL);
  2075. TTHITTESTINFO hti = {};
  2076. hti.ti.cbSize = RunTimeHelper::SizeOf_TOOLINFO();
  2077. hti.hwnd = hWnd;
  2078. hti.pt.x = pt.x;
  2079. hti.pt.y = pt.y;
  2080. if((BOOL)::SendMessage(this->m_hWnd, TTM_HITTEST, 0, (LPARAM)&hti) != FALSE)
  2081. {
  2082. *lpToolInfo = hti.ti;
  2083. return TRUE;
  2084. }
  2085. return FALSE;
  2086. }
  2087. void RelayEvent(LPMSG lpMsg)
  2088. {
  2089. ATLASSERT(::IsWindow(this->m_hWnd));
  2090. ::SendMessage(this->m_hWnd, TTM_RELAYEVENT, 0, (LPARAM)lpMsg);
  2091. }
  2092. void UpdateTipText(LPTOOLINFO lpToolInfo)
  2093. {
  2094. ATLASSERT(::IsWindow(this->m_hWnd));
  2095. ::SendMessage(this->m_hWnd, TTM_UPDATETIPTEXT, 0, (LPARAM)lpToolInfo);
  2096. }
  2097. void UpdateTipText(ATL::_U_STRINGorID text, HWND hWnd, UINT_PTR nIDTool = 0)
  2098. {
  2099. ATLASSERT(::IsWindow(this->m_hWnd));
  2100. ATLASSERT(hWnd != NULL);
  2101. CToolInfo ti(0, hWnd, nIDTool, NULL, (LPTSTR)text.m_lpstr);
  2102. ::SendMessage(this->m_hWnd, TTM_UPDATETIPTEXT, 0, ti);
  2103. }
  2104. BOOL EnumTools(UINT_PTR nTool, LPTOOLINFO lpToolInfo) const
  2105. {
  2106. ATLASSERT(::IsWindow(this->m_hWnd));
  2107. return (BOOL)::SendMessage(this->m_hWnd, TTM_ENUMTOOLS, nTool, (LPARAM)lpToolInfo);
  2108. }
  2109. void Pop()
  2110. {
  2111. ATLASSERT(::IsWindow(this->m_hWnd));
  2112. ::SendMessage(this->m_hWnd, TTM_POP, 0, 0L);
  2113. }
  2114. void TrackActivate(LPTOOLINFO lpToolInfo, BOOL bActivate)
  2115. {
  2116. ATLASSERT(::IsWindow(this->m_hWnd));
  2117. ::SendMessage(this->m_hWnd, TTM_TRACKACTIVATE, bActivate, (LPARAM)lpToolInfo);
  2118. }
  2119. void TrackActivate(HWND hWnd, UINT_PTR nIDTool, BOOL bActivate)
  2120. {
  2121. ATLASSERT(::IsWindow(this->m_hWnd));
  2122. ATLASSERT(hWnd != NULL);
  2123. CToolInfo ti(0, hWnd, nIDTool);
  2124. ::SendMessage(this->m_hWnd, TTM_TRACKACTIVATE, bActivate, ti);
  2125. }
  2126. void TrackPosition(int xPos, int yPos)
  2127. {
  2128. ATLASSERT(::IsWindow(this->m_hWnd));
  2129. ::SendMessage(this->m_hWnd, TTM_TRACKPOSITION, 0, MAKELPARAM(xPos, yPos));
  2130. }
  2131. void Update()
  2132. {
  2133. ATLASSERT(::IsWindow(this->m_hWnd));
  2134. ::SendMessage(this->m_hWnd, TTM_UPDATE, 0, 0L);
  2135. }
  2136. BOOL AdjustRect(LPRECT lpRect, BOOL bLarger /*= TRUE*/)
  2137. {
  2138. ATLASSERT(::IsWindow(this->m_hWnd));
  2139. return (BOOL)::SendMessage(this->m_hWnd, TTM_ADJUSTRECT, bLarger, (LPARAM)lpRect);
  2140. }
  2141. void Popup()
  2142. {
  2143. ATLASSERT(::IsWindow(this->m_hWnd));
  2144. ::SendMessage(this->m_hWnd, TTM_POPUP, 0, 0L);
  2145. }
  2146. };
  2147. typedef CToolTipCtrlT<ATL::CWindow> CToolTipCtrl;
  2148. ///////////////////////////////////////////////////////////////////////////////
  2149. // CHeaderCtrl
  2150. template <class TBase>
  2151. class CHeaderCtrlT : public TBase
  2152. {
  2153. public:
  2154. // Constructors
  2155. CHeaderCtrlT(HWND hWnd = NULL) : TBase(hWnd)
  2156. { }
  2157. CHeaderCtrlT< TBase >& operator =(HWND hWnd)
  2158. {
  2159. this->m_hWnd = hWnd;
  2160. return *this;
  2161. }
  2162. HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  2163. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  2164. ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  2165. {
  2166. return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  2167. }
  2168. // Attributes
  2169. static LPCTSTR GetWndClassName()
  2170. {
  2171. return WC_HEADER;
  2172. }
  2173. int GetItemCount() const
  2174. {
  2175. ATLASSERT(::IsWindow(this->m_hWnd));
  2176. return (int)::SendMessage(this->m_hWnd, HDM_GETITEMCOUNT, 0, 0L);
  2177. }
  2178. BOOL GetItem(int nIndex, LPHDITEM pHeaderItem) const
  2179. {
  2180. ATLASSERT(::IsWindow(this->m_hWnd));
  2181. return (BOOL)::SendMessage(this->m_hWnd, HDM_GETITEM, nIndex, (LPARAM)pHeaderItem);
  2182. }
  2183. BOOL SetItem(int nIndex, LPHDITEM pHeaderItem)
  2184. {
  2185. ATLASSERT(::IsWindow(this->m_hWnd));
  2186. return (BOOL)::SendMessage(this->m_hWnd, HDM_SETITEM, nIndex, (LPARAM)pHeaderItem);
  2187. }
  2188. CImageList GetImageList() const
  2189. {
  2190. ATLASSERT(::IsWindow(this->m_hWnd));
  2191. return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, HDM_GETIMAGELIST, 0, 0L));
  2192. }
  2193. CImageList SetImageList(HIMAGELIST hImageList)
  2194. {
  2195. ATLASSERT(::IsWindow(this->m_hWnd));
  2196. return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, HDM_SETIMAGELIST, 0, (LPARAM)hImageList));
  2197. }
  2198. BOOL GetOrderArray(int nSize, int* lpnArray) const
  2199. {
  2200. ATLASSERT(::IsWindow(this->m_hWnd));
  2201. return (BOOL)::SendMessage(this->m_hWnd, HDM_GETORDERARRAY, nSize, (LPARAM)lpnArray);
  2202. }
  2203. BOOL SetOrderArray(int nSize, int* lpnArray)
  2204. {
  2205. ATLASSERT(::IsWindow(this->m_hWnd));
  2206. return (BOOL)::SendMessage(this->m_hWnd, HDM_SETORDERARRAY, nSize, (LPARAM)lpnArray);
  2207. }
  2208. BOOL GetItemRect(int nIndex, LPRECT lpItemRect) const
  2209. {
  2210. ATLASSERT(::IsWindow(this->m_hWnd));
  2211. return (BOOL)::SendMessage(this->m_hWnd, HDM_GETITEMRECT, nIndex, (LPARAM)lpItemRect);
  2212. }
  2213. int SetHotDivider(BOOL bPos, DWORD dwInputValue)
  2214. {
  2215. ATLASSERT(::IsWindow(this->m_hWnd));
  2216. return (int)::SendMessage(this->m_hWnd, HDM_SETHOTDIVIDER, bPos, dwInputValue);
  2217. }
  2218. BOOL GetUnicodeFormat() const
  2219. {
  2220. ATLASSERT(::IsWindow(this->m_hWnd));
  2221. return (BOOL)::SendMessage(this->m_hWnd, HDM_GETUNICODEFORMAT, 0, 0L);
  2222. }
  2223. BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
  2224. {
  2225. ATLASSERT(::IsWindow(this->m_hWnd));
  2226. return (BOOL)::SendMessage(this->m_hWnd, HDM_SETUNICODEFORMAT, bUnicode, 0L);
  2227. }
  2228. int GetBitmapMargin() const
  2229. {
  2230. ATLASSERT(::IsWindow(this->m_hWnd));
  2231. return (int)::SendMessage(this->m_hWnd, HDM_GETBITMAPMARGIN, 0, 0L);
  2232. }
  2233. int SetBitmapMargin(int nWidth)
  2234. {
  2235. ATLASSERT(::IsWindow(this->m_hWnd));
  2236. return (int)::SendMessage(this->m_hWnd, HDM_SETBITMAPMARGIN, nWidth, 0L);
  2237. }
  2238. int SetFilterChangeTimeout(DWORD dwTimeOut)
  2239. {
  2240. ATLASSERT(::IsWindow(this->m_hWnd));
  2241. return (int)::SendMessage(this->m_hWnd, HDM_SETFILTERCHANGETIMEOUT, 0, dwTimeOut);
  2242. }
  2243. #if (_WIN32_WINNT >= 0x0600)
  2244. BOOL GetItemDropDownRect(int nIndex, LPRECT lpRect) const
  2245. {
  2246. ATLASSERT(::IsWindow(this->m_hWnd));
  2247. return (BOOL)::SendMessage(this->m_hWnd, HDM_GETITEMDROPDOWNRECT, nIndex, (LPARAM)lpRect);
  2248. }
  2249. BOOL GetOverflowRect(LPRECT lpRect) const
  2250. {
  2251. ATLASSERT(::IsWindow(this->m_hWnd));
  2252. return (BOOL)::SendMessage(this->m_hWnd, HDM_GETOVERFLOWRECT, 0, (LPARAM)lpRect);
  2253. }
  2254. int GetFocusedItem() const
  2255. {
  2256. ATLASSERT(::IsWindow(this->m_hWnd));
  2257. return (int)::SendMessage(this->m_hWnd, HDM_GETFOCUSEDITEM, 0, 0L);
  2258. }
  2259. BOOL SetFocusedItem(int nIndex)
  2260. {
  2261. ATLASSERT(::IsWindow(this->m_hWnd));
  2262. return (BOOL)::SendMessage(this->m_hWnd, HDM_SETFOCUSEDITEM, 0, nIndex);
  2263. }
  2264. #endif // (_WIN32_WINNT >= 0x0600)
  2265. // Operations
  2266. int InsertItem(int nIndex, LPHDITEM phdi)
  2267. {
  2268. ATLASSERT(::IsWindow(this->m_hWnd));
  2269. return (int)::SendMessage(this->m_hWnd, HDM_INSERTITEM, nIndex, (LPARAM)phdi);
  2270. }
  2271. int AddItem(LPHDITEM phdi)
  2272. {
  2273. return InsertItem(GetItemCount(), phdi);
  2274. }
  2275. BOOL DeleteItem(int nIndex)
  2276. {
  2277. ATLASSERT(::IsWindow(this->m_hWnd));
  2278. return (BOOL)::SendMessage(this->m_hWnd, HDM_DELETEITEM, nIndex, 0L);
  2279. }
  2280. BOOL Layout(HD_LAYOUT* pHeaderLayout)
  2281. {
  2282. ATLASSERT(::IsWindow(this->m_hWnd));
  2283. return (BOOL)::SendMessage(this->m_hWnd, HDM_LAYOUT, 0, (LPARAM)pHeaderLayout);
  2284. }
  2285. int HitTest(LPHDHITTESTINFO lpHitTestInfo) const
  2286. {
  2287. ATLASSERT(::IsWindow(this->m_hWnd));
  2288. return (int)::SendMessage(this->m_hWnd, HDM_HITTEST, 0, (LPARAM)lpHitTestInfo);
  2289. }
  2290. int OrderToIndex(int nOrder)
  2291. {
  2292. ATLASSERT(::IsWindow(this->m_hWnd));
  2293. return (int)::SendMessage(this->m_hWnd, HDM_ORDERTOINDEX, nOrder, 0L);
  2294. }
  2295. CImageList CreateDragImage(int nIndex)
  2296. {
  2297. ATLASSERT(::IsWindow(this->m_hWnd));
  2298. return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, HDM_CREATEDRAGIMAGE, nIndex, 0L));
  2299. }
  2300. int EditFilter(int nColumn, BOOL bDiscardChanges)
  2301. {
  2302. ATLASSERT(::IsWindow(this->m_hWnd));
  2303. return (int)::SendMessage(this->m_hWnd, HDM_EDITFILTER, nColumn, MAKELPARAM(bDiscardChanges, 0));
  2304. }
  2305. int ClearFilter(int nColumn)
  2306. {
  2307. ATLASSERT(::IsWindow(this->m_hWnd));
  2308. return (int)::SendMessage(this->m_hWnd, HDM_CLEARFILTER, nColumn, 0L);
  2309. }
  2310. int ClearAllFilters()
  2311. {
  2312. ATLASSERT(::IsWindow(this->m_hWnd));
  2313. return (int)::SendMessage(this->m_hWnd, HDM_CLEARFILTER, (WPARAM)-1, 0L);
  2314. }
  2315. };
  2316. typedef CHeaderCtrlT<ATL::CWindow> CHeaderCtrl;
  2317. ///////////////////////////////////////////////////////////////////////////////
  2318. // CListViewCtrl
  2319. template <class TBase>
  2320. class CListViewCtrlT : public TBase
  2321. {
  2322. public:
  2323. // Constructors
  2324. CListViewCtrlT(HWND hWnd = NULL) : TBase(hWnd)
  2325. { }
  2326. CListViewCtrlT< TBase >& operator =(HWND hWnd)
  2327. {
  2328. this->m_hWnd = hWnd;
  2329. return *this;
  2330. }
  2331. HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  2332. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  2333. ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  2334. {
  2335. return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  2336. }
  2337. // Attributes
  2338. static LPCTSTR GetWndClassName()
  2339. {
  2340. return WC_LISTVIEW;
  2341. }
  2342. COLORREF GetBkColor() const
  2343. {
  2344. ATLASSERT(::IsWindow(this->m_hWnd));
  2345. return (COLORREF)::SendMessage(this->m_hWnd, LVM_GETBKCOLOR, 0, 0L);
  2346. }
  2347. BOOL SetBkColor(COLORREF cr)
  2348. {
  2349. ATLASSERT(::IsWindow(this->m_hWnd));
  2350. return (BOOL)::SendMessage(this->m_hWnd, LVM_SETBKCOLOR, 0, cr);
  2351. }
  2352. CImageList GetImageList(int nImageListType) const
  2353. {
  2354. ATLASSERT(::IsWindow(this->m_hWnd));
  2355. return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, LVM_GETIMAGELIST, nImageListType, 0L));
  2356. }
  2357. CImageList SetImageList(HIMAGELIST hImageList, int nImageList)
  2358. {
  2359. ATLASSERT(::IsWindow(this->m_hWnd));
  2360. return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, LVM_SETIMAGELIST, nImageList, (LPARAM)hImageList));
  2361. }
  2362. int GetItemCount() const
  2363. {
  2364. ATLASSERT(::IsWindow(this->m_hWnd));
  2365. return (int)::SendMessage(this->m_hWnd, LVM_GETITEMCOUNT, 0, 0L);
  2366. }
  2367. BOOL SetItemCount(int nItems)
  2368. {
  2369. ATLASSERT(::IsWindow(this->m_hWnd));
  2370. return (BOOL)::SendMessage(this->m_hWnd, LVM_SETITEMCOUNT, nItems, 0L);
  2371. }
  2372. BOOL GetItem(LPLVITEM pItem) const
  2373. {
  2374. ATLASSERT(::IsWindow(this->m_hWnd));
  2375. return (BOOL)::SendMessage(this->m_hWnd, LVM_GETITEM, 0, (LPARAM)pItem);
  2376. }
  2377. BOOL SetItem(const LVITEM* pItem)
  2378. {
  2379. ATLASSERT(::IsWindow(this->m_hWnd));
  2380. return (BOOL)::SendMessage(this->m_hWnd, LVM_SETITEM, 0, (LPARAM)pItem);
  2381. }
  2382. BOOL SetItem(int nItem, int nSubItem, UINT nMask, LPCTSTR lpszItem,
  2383. int nImage, UINT nState, UINT nStateMask, LPARAM lParam)
  2384. {
  2385. ATLASSERT(::IsWindow(this->m_hWnd));
  2386. LVITEM lvi = {};
  2387. lvi.mask = nMask;
  2388. lvi.iItem = nItem;
  2389. lvi.iSubItem = nSubItem;
  2390. lvi.stateMask = nStateMask;
  2391. lvi.state = nState;
  2392. lvi.pszText = (LPTSTR) lpszItem;
  2393. lvi.iImage = nImage;
  2394. lvi.lParam = lParam;
  2395. return (BOOL)::SendMessage(this->m_hWnd, LVM_SETITEM, 0, (LPARAM)&lvi);
  2396. }
  2397. UINT GetItemState(int nItem, UINT nMask) const
  2398. {
  2399. ATLASSERT(::IsWindow(this->m_hWnd));
  2400. return (UINT)::SendMessage(this->m_hWnd, LVM_GETITEMSTATE, nItem, nMask);
  2401. }
  2402. BOOL SetItemState(int nItem, UINT nState, UINT nStateMask)
  2403. {
  2404. ATLASSERT(::IsWindow(this->m_hWnd));
  2405. LVITEM lvi = {};
  2406. lvi.state = nState;
  2407. lvi.stateMask = nStateMask;
  2408. return (BOOL)::SendMessage(this->m_hWnd, LVM_SETITEMSTATE, nItem, (LPARAM)&lvi);
  2409. }
  2410. BOOL SetItemState(int nItem, LPLVITEM pItem)
  2411. {
  2412. ATLASSERT(::IsWindow(this->m_hWnd));
  2413. return (BOOL)::SendMessage(this->m_hWnd, LVM_SETITEMSTATE, nItem, (LPARAM)pItem);
  2414. }
  2415. BOOL GetItemText(int nItem, int nSubItem, BSTR& bstrText) const
  2416. {
  2417. USES_CONVERSION;
  2418. ATLASSERT(::IsWindow(this->m_hWnd));
  2419. ATLASSERT(bstrText == NULL);
  2420. LVITEM lvi = {};
  2421. lvi.iSubItem = nSubItem;
  2422. LPTSTR lpstrText = NULL;
  2423. int nRes = 0;
  2424. for(int nLen = 256; ; nLen *= 2)
  2425. {
  2426. ATLTRY(lpstrText = new TCHAR[nLen]);
  2427. if(lpstrText == NULL)
  2428. break;
  2429. lpstrText[0] = NULL;
  2430. lvi.cchTextMax = nLen;
  2431. lvi.pszText = lpstrText;
  2432. nRes = (int)::SendMessage(this->m_hWnd, LVM_GETITEMTEXT, (WPARAM)nItem, (LPARAM)&lvi);
  2433. if(nRes < nLen - 1)
  2434. break;
  2435. delete [] lpstrText;
  2436. lpstrText = NULL;
  2437. }
  2438. if(lpstrText != NULL)
  2439. {
  2440. if(nRes != 0)
  2441. bstrText = ::SysAllocString(T2OLE(lpstrText));
  2442. delete [] lpstrText;
  2443. }
  2444. return (bstrText != NULL) ? TRUE : FALSE;
  2445. }
  2446. #ifdef __ATLSTR_H__
  2447. int GetItemText(int nItem, int nSubItem, ATL::CString& strText) const
  2448. {
  2449. ATLASSERT(::IsWindow(this->m_hWnd));
  2450. LVITEM lvi = {};
  2451. lvi.iSubItem = nSubItem;
  2452. strText.Empty();
  2453. int nRes = 0;
  2454. for(int nLen = 256; ; nLen *= 2)
  2455. {
  2456. lvi.cchTextMax = nLen;
  2457. lvi.pszText = strText.GetBufferSetLength(nLen);
  2458. if(lvi.pszText == NULL)
  2459. {
  2460. nRes = 0;
  2461. break;
  2462. }
  2463. nRes = (int)::SendMessage(this->m_hWnd, LVM_GETITEMTEXT, (WPARAM)nItem, (LPARAM)&lvi);
  2464. if(nRes < nLen - 1)
  2465. break;
  2466. }
  2467. strText.ReleaseBuffer();
  2468. return nRes;
  2469. }
  2470. #endif // __ATLSTR_H__
  2471. int GetItemText(int nItem, int nSubItem, LPTSTR lpszText, int nLen) const
  2472. {
  2473. ATLASSERT(::IsWindow(this->m_hWnd));
  2474. LVITEM lvi = {};
  2475. lvi.iSubItem = nSubItem;
  2476. lvi.cchTextMax = nLen;
  2477. lvi.pszText = lpszText;
  2478. return (int)::SendMessage(this->m_hWnd, LVM_GETITEMTEXT, (WPARAM)nItem, (LPARAM)&lvi);
  2479. }
  2480. BOOL SetItemText(int nItem, int nSubItem, LPCTSTR lpszText)
  2481. {
  2482. ATLASSERT(::IsWindow(this->m_hWnd));
  2483. return SetItem(nItem, nSubItem, LVIF_TEXT, lpszText, 0, 0, 0, 0);
  2484. }
  2485. DWORD_PTR GetItemData(int nItem) const
  2486. {
  2487. ATLASSERT(::IsWindow(this->m_hWnd));
  2488. LVITEM lvi = {};
  2489. lvi.iItem = nItem;
  2490. lvi.mask = LVIF_PARAM;
  2491. BOOL bRet = (BOOL)::SendMessage(this->m_hWnd, LVM_GETITEM, 0, (LPARAM)&lvi);
  2492. return (DWORD_PTR)(bRet ? lvi.lParam : NULL);
  2493. }
  2494. BOOL SetItemData(int nItem, DWORD_PTR dwData)
  2495. {
  2496. ATLASSERT(::IsWindow(this->m_hWnd));
  2497. return SetItem(nItem, 0, LVIF_PARAM, NULL, 0, 0, 0, (LPARAM)dwData);
  2498. }
  2499. UINT GetCallbackMask() const
  2500. {
  2501. ATLASSERT(::IsWindow(this->m_hWnd));
  2502. return (UINT)::SendMessage(this->m_hWnd, LVM_GETCALLBACKMASK, 0, 0L);
  2503. }
  2504. BOOL SetCallbackMask(UINT nMask)
  2505. {
  2506. ATLASSERT(::IsWindow(this->m_hWnd));
  2507. return (BOOL)::SendMessage(this->m_hWnd, LVM_SETCALLBACKMASK, nMask, 0L);
  2508. }
  2509. BOOL GetItemPosition(int nItem, LPPOINT lpPoint) const
  2510. {
  2511. ATLASSERT(::IsWindow(this->m_hWnd));
  2512. return (BOOL)::SendMessage(this->m_hWnd, LVM_GETITEMPOSITION, nItem, (LPARAM)lpPoint);
  2513. }
  2514. BOOL SetItemPosition(int nItem, POINT pt)
  2515. {
  2516. ATLASSERT(::IsWindow(this->m_hWnd));
  2517. ATLASSERT(((this->GetStyle() & LVS_TYPEMASK) == LVS_ICON) || ((this->GetStyle() & LVS_TYPEMASK) == LVS_SMALLICON));
  2518. return (BOOL)::SendMessage(this->m_hWnd, LVM_SETITEMPOSITION32, nItem, (LPARAM)&pt);
  2519. }
  2520. BOOL SetItemPosition(int nItem, int x, int y)
  2521. {
  2522. ATLASSERT(::IsWindow(this->m_hWnd));
  2523. ATLASSERT(((this->GetStyle() & LVS_TYPEMASK) == LVS_ICON) || ((this->GetStyle() & LVS_TYPEMASK) == LVS_SMALLICON));
  2524. POINT pt = { x, y };
  2525. return (BOOL)::SendMessage(this->m_hWnd, LVM_SETITEMPOSITION32, nItem, (LPARAM)&pt);
  2526. }
  2527. int GetStringWidth(LPCTSTR lpsz) const
  2528. {
  2529. ATLASSERT(::IsWindow(this->m_hWnd));
  2530. return (int)::SendMessage(this->m_hWnd, LVM_GETSTRINGWIDTH, 0, (LPARAM)lpsz);
  2531. }
  2532. CEdit GetEditControl() const
  2533. {
  2534. ATLASSERT(::IsWindow(this->m_hWnd));
  2535. return CEdit((HWND)::SendMessage(this->m_hWnd, LVM_GETEDITCONTROL, 0, 0L));
  2536. }
  2537. BOOL GetColumn(int nCol, LVCOLUMN* pColumn) const
  2538. {
  2539. ATLASSERT(::IsWindow(this->m_hWnd));
  2540. return (BOOL)::SendMessage(this->m_hWnd, LVM_GETCOLUMN, nCol, (LPARAM)pColumn);
  2541. }
  2542. BOOL SetColumn(int nCol, const LVCOLUMN* pColumn)
  2543. {
  2544. ATLASSERT(::IsWindow(this->m_hWnd));
  2545. return (BOOL)::SendMessage(this->m_hWnd, LVM_SETCOLUMN, nCol, (LPARAM)pColumn);
  2546. }
  2547. int GetColumnWidth(int nCol) const
  2548. {
  2549. ATLASSERT(::IsWindow(this->m_hWnd));
  2550. return (int)::SendMessage(this->m_hWnd, LVM_GETCOLUMNWIDTH, nCol, 0L);
  2551. }
  2552. BOOL SetColumnWidth(int nCol, int cx)
  2553. {
  2554. ATLASSERT(::IsWindow(this->m_hWnd));
  2555. return (BOOL)::SendMessage(this->m_hWnd, LVM_SETCOLUMNWIDTH, nCol, MAKELPARAM(cx, 0));
  2556. }
  2557. BOOL GetViewRect(LPRECT lpRect) const
  2558. {
  2559. ATLASSERT(::IsWindow(this->m_hWnd));
  2560. return (BOOL)::SendMessage(this->m_hWnd, LVM_GETVIEWRECT, 0, (LPARAM)lpRect);
  2561. }
  2562. COLORREF GetTextColor() const
  2563. {
  2564. ATLASSERT(::IsWindow(this->m_hWnd));
  2565. return (COLORREF)::SendMessage(this->m_hWnd, LVM_GETTEXTCOLOR, 0, 0L);
  2566. }
  2567. BOOL SetTextColor(COLORREF cr)
  2568. {
  2569. ATLASSERT(::IsWindow(this->m_hWnd));
  2570. return (BOOL)::SendMessage(this->m_hWnd, LVM_SETTEXTCOLOR, 0, cr);
  2571. }
  2572. COLORREF GetTextBkColor() const
  2573. {
  2574. ATLASSERT(::IsWindow(this->m_hWnd));
  2575. return (COLORREF)::SendMessage(this->m_hWnd, LVM_GETTEXTBKCOLOR, 0, 0L);
  2576. }
  2577. BOOL SetTextBkColor(COLORREF cr)
  2578. {
  2579. ATLASSERT(::IsWindow(this->m_hWnd));
  2580. return (BOOL)::SendMessage(this->m_hWnd, LVM_SETTEXTBKCOLOR, 0, cr);
  2581. }
  2582. int GetTopIndex() const
  2583. {
  2584. ATLASSERT(::IsWindow(this->m_hWnd));
  2585. return (int)::SendMessage(this->m_hWnd, LVM_GETTOPINDEX, 0, 0L);
  2586. }
  2587. int GetCountPerPage() const
  2588. {
  2589. ATLASSERT(::IsWindow(this->m_hWnd));
  2590. return (int)::SendMessage(this->m_hWnd, LVM_GETCOUNTPERPAGE, 0, 0L);
  2591. }
  2592. BOOL GetOrigin(LPPOINT lpPoint) const
  2593. {
  2594. ATLASSERT(::IsWindow(this->m_hWnd));
  2595. return (BOOL)::SendMessage(this->m_hWnd, LVM_GETORIGIN, 0, (LPARAM)lpPoint);
  2596. }
  2597. UINT GetSelectedCount() const
  2598. {
  2599. ATLASSERT(::IsWindow(this->m_hWnd));
  2600. return (UINT)::SendMessage(this->m_hWnd, LVM_GETSELECTEDCOUNT, 0, 0L);
  2601. }
  2602. BOOL GetItemRect(int nItem, LPRECT lpRect, UINT nCode) const
  2603. {
  2604. ATLASSERT(::IsWindow(this->m_hWnd));
  2605. lpRect->left = nCode;
  2606. return (BOOL)::SendMessage(this->m_hWnd, LVM_GETITEMRECT, (WPARAM)nItem, (LPARAM)lpRect);
  2607. }
  2608. HCURSOR GetHotCursor() const
  2609. {
  2610. ATLASSERT(::IsWindow(this->m_hWnd));
  2611. return (HCURSOR)::SendMessage(this->m_hWnd, LVM_GETHOTCURSOR, 0, 0L);
  2612. }
  2613. HCURSOR SetHotCursor(HCURSOR hHotCursor)
  2614. {
  2615. ATLASSERT(::IsWindow(this->m_hWnd));
  2616. return (HCURSOR)::SendMessage(this->m_hWnd, LVM_SETHOTCURSOR, 0, (LPARAM)hHotCursor);
  2617. }
  2618. int GetHotItem() const
  2619. {
  2620. ATLASSERT(::IsWindow(this->m_hWnd));
  2621. return (int)::SendMessage(this->m_hWnd, LVM_GETHOTITEM, 0, 0L);
  2622. }
  2623. int SetHotItem(int nIndex)
  2624. {
  2625. ATLASSERT(::IsWindow(this->m_hWnd));
  2626. return (int)::SendMessage(this->m_hWnd, LVM_SETHOTITEM, nIndex, 0L);
  2627. }
  2628. BOOL GetColumnOrderArray(int nCount, int* lpnArray) const
  2629. {
  2630. ATLASSERT(::IsWindow(this->m_hWnd));
  2631. return (BOOL)::SendMessage(this->m_hWnd, LVM_GETCOLUMNORDERARRAY, nCount, (LPARAM)lpnArray);
  2632. }
  2633. BOOL SetColumnOrderArray(int nCount, int* lpnArray)
  2634. {
  2635. ATLASSERT(::IsWindow(this->m_hWnd));
  2636. return (BOOL)::SendMessage(this->m_hWnd, LVM_SETCOLUMNORDERARRAY, nCount, (LPARAM)lpnArray);
  2637. }
  2638. CHeaderCtrl GetHeader() const
  2639. {
  2640. ATLASSERT(::IsWindow(this->m_hWnd));
  2641. return CHeaderCtrl((HWND)::SendMessage(this->m_hWnd, LVM_GETHEADER, 0, 0L));
  2642. }
  2643. BOOL GetSubItemRect(int nItem, int nSubItem, int nFlag, LPRECT lpRect) const
  2644. {
  2645. ATLASSERT(::IsWindow(this->m_hWnd));
  2646. ATLASSERT((this->GetStyle() & LVS_TYPEMASK) == LVS_REPORT);
  2647. ATLASSERT(lpRect != NULL);
  2648. lpRect->top = nSubItem;
  2649. lpRect->left = nFlag;
  2650. return (BOOL)::SendMessage(this->m_hWnd, LVM_GETSUBITEMRECT, nItem, (LPARAM)lpRect);
  2651. }
  2652. DWORD SetIconSpacing(int cx, int cy)
  2653. {
  2654. ATLASSERT(::IsWindow(this->m_hWnd));
  2655. ATLASSERT((this->GetStyle() & LVS_TYPEMASK) == LVS_ICON);
  2656. return (DWORD)::SendMessage(this->m_hWnd, LVM_SETICONSPACING, 0, MAKELPARAM(cx, cy));
  2657. }
  2658. int GetISearchString(LPTSTR lpstr) const
  2659. {
  2660. ATLASSERT(::IsWindow(this->m_hWnd));
  2661. return (int)::SendMessage(this->m_hWnd, LVM_GETISEARCHSTRING, 0, (LPARAM)lpstr);
  2662. }
  2663. void GetItemSpacing(SIZE& sizeSpacing, BOOL bSmallIconView = FALSE) const
  2664. {
  2665. ATLASSERT(::IsWindow(this->m_hWnd));
  2666. DWORD dwRet = (DWORD)::SendMessage(this->m_hWnd, LVM_GETITEMSPACING, bSmallIconView, 0L);
  2667. sizeSpacing.cx = GET_X_LPARAM(dwRet);
  2668. sizeSpacing.cy = GET_Y_LPARAM(dwRet);
  2669. }
  2670. // single-selection only
  2671. int GetSelectedIndex() const
  2672. {
  2673. ATLASSERT(::IsWindow(this->m_hWnd));
  2674. ATLASSERT((this->GetStyle() & LVS_SINGLESEL) != 0);
  2675. return (int)::SendMessage(this->m_hWnd, LVM_GETNEXTITEM, (WPARAM)-1, MAKELPARAM(LVNI_ALL | LVNI_SELECTED, 0));
  2676. }
  2677. BOOL GetSelectedItem(LPLVITEM pItem) const
  2678. {
  2679. ATLASSERT(::IsWindow(this->m_hWnd));
  2680. ATLASSERT((this->GetStyle() & LVS_SINGLESEL) != 0);
  2681. ATLASSERT(pItem != NULL);
  2682. pItem->iItem = (int)::SendMessage(this->m_hWnd, LVM_GETNEXTITEM, (WPARAM)-1, MAKELPARAM(LVNI_ALL | LVNI_SELECTED, 0));
  2683. if(pItem->iItem == -1)
  2684. return FALSE;
  2685. return (BOOL)::SendMessage(this->m_hWnd, LVM_GETITEM, 0, (LPARAM)pItem);
  2686. }
  2687. // extended list view styles
  2688. DWORD GetExtendedListViewStyle() const
  2689. {
  2690. ATLASSERT(::IsWindow(this->m_hWnd));
  2691. return (DWORD)::SendMessage(this->m_hWnd, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0L);
  2692. }
  2693. // dwExMask = 0 means all styles
  2694. DWORD SetExtendedListViewStyle(DWORD dwExStyle, DWORD dwExMask = 0)
  2695. {
  2696. ATLASSERT(::IsWindow(this->m_hWnd));
  2697. return (DWORD)::SendMessage(this->m_hWnd, LVM_SETEXTENDEDLISTVIEWSTYLE, dwExMask, dwExStyle);
  2698. }
  2699. // checkboxes only
  2700. BOOL GetCheckState(int nIndex) const
  2701. {
  2702. ATLASSERT(::IsWindow(this->m_hWnd));
  2703. ATLASSERT((GetExtendedListViewStyle() & LVS_EX_CHECKBOXES) != 0);
  2704. UINT uRet = GetItemState(nIndex, LVIS_STATEIMAGEMASK);
  2705. return (uRet >> 12) - 1;
  2706. }
  2707. BOOL SetCheckState(int nItem, BOOL bCheck)
  2708. {
  2709. int nCheck = bCheck ? 2 : 1; // one based index
  2710. return SetItemState(nItem, INDEXTOSTATEIMAGEMASK(nCheck), LVIS_STATEIMAGEMASK);
  2711. }
  2712. // view type
  2713. DWORD GetViewType() const
  2714. {
  2715. ATLASSERT(::IsWindow(this->m_hWnd));
  2716. return (this->GetStyle() & LVS_TYPEMASK);
  2717. }
  2718. DWORD SetViewType(DWORD dwType)
  2719. {
  2720. ATLASSERT(::IsWindow(this->m_hWnd));
  2721. ATLASSERT((dwType == LVS_ICON) || (dwType == LVS_SMALLICON) || (dwType == LVS_LIST) || (dwType == LVS_REPORT));
  2722. DWORD dwOldType = GetViewType();
  2723. if(dwType != dwOldType)
  2724. this->ModifyStyle(LVS_TYPEMASK, (dwType & LVS_TYPEMASK));
  2725. return dwOldType;
  2726. }
  2727. BOOL GetBkImage(LPLVBKIMAGE plvbki) const
  2728. {
  2729. ATLASSERT(::IsWindow(this->m_hWnd));
  2730. return (BOOL)::SendMessage(this->m_hWnd, LVM_GETBKIMAGE, 0, (LPARAM)plvbki);
  2731. }
  2732. BOOL SetBkImage(LPLVBKIMAGE plvbki)
  2733. {
  2734. ATLASSERT(::IsWindow(this->m_hWnd));
  2735. return (BOOL)::SendMessage(this->m_hWnd, LVM_SETBKIMAGE, 0, (LPARAM)plvbki);
  2736. }
  2737. int GetSelectionMark() const
  2738. {
  2739. ATLASSERT(::IsWindow(this->m_hWnd));
  2740. return (int)::SendMessage(this->m_hWnd, LVM_GETSELECTIONMARK, 0, 0L);
  2741. }
  2742. int SetSelectionMark(int nIndex)
  2743. {
  2744. ATLASSERT(::IsWindow(this->m_hWnd));
  2745. return (int)::SendMessage(this->m_hWnd, LVM_SETSELECTIONMARK, 0, nIndex);
  2746. }
  2747. BOOL GetWorkAreas(int nWorkAreas, LPRECT lpRect) const
  2748. {
  2749. ATLASSERT(::IsWindow(this->m_hWnd));
  2750. return (BOOL)::SendMessage(this->m_hWnd, LVM_GETWORKAREAS, nWorkAreas, (LPARAM)lpRect);
  2751. }
  2752. BOOL SetWorkAreas(int nWorkAreas, LPRECT lpRect)
  2753. {
  2754. ATLASSERT(::IsWindow(this->m_hWnd));
  2755. return (BOOL)::SendMessage(this->m_hWnd, LVM_SETWORKAREAS, nWorkAreas, (LPARAM)lpRect);
  2756. }
  2757. DWORD GetHoverTime() const
  2758. {
  2759. ATLASSERT(::IsWindow(this->m_hWnd));
  2760. ATLASSERT((GetExtendedListViewStyle() & (LVS_EX_TRACKSELECT | LVS_EX_ONECLICKACTIVATE | LVS_EX_TWOCLICKACTIVATE)) != 0);
  2761. return (DWORD)::SendMessage(this->m_hWnd, LVM_GETHOVERTIME, 0, 0L);
  2762. }
  2763. DWORD SetHoverTime(DWORD dwHoverTime)
  2764. {
  2765. ATLASSERT(::IsWindow(this->m_hWnd));
  2766. ATLASSERT((GetExtendedListViewStyle() & (LVS_EX_TRACKSELECT | LVS_EX_ONECLICKACTIVATE | LVS_EX_TWOCLICKACTIVATE)) != 0);
  2767. return (DWORD)::SendMessage(this->m_hWnd, LVM_SETHOVERTIME, 0, dwHoverTime);
  2768. }
  2769. BOOL GetNumberOfWorkAreas(int* pnWorkAreas) const
  2770. {
  2771. ATLASSERT(::IsWindow(this->m_hWnd));
  2772. return (BOOL)::SendMessage(this->m_hWnd, LVM_GETNUMBEROFWORKAREAS, 0, (LPARAM)pnWorkAreas);
  2773. }
  2774. BOOL SetItemCountEx(int nItems, DWORD dwFlags)
  2775. {
  2776. ATLASSERT(::IsWindow(this->m_hWnd));
  2777. ATLASSERT(((this->GetStyle() & LVS_OWNERDATA) != 0) && (((this->GetStyle() & LVS_TYPEMASK) == LVS_REPORT) || ((this->GetStyle() & LVS_TYPEMASK) == LVS_LIST)));
  2778. return (BOOL)::SendMessage(this->m_hWnd, LVM_SETITEMCOUNT, nItems, dwFlags);
  2779. }
  2780. CToolTipCtrl GetToolTips() const
  2781. {
  2782. ATLASSERT(::IsWindow(this->m_hWnd));
  2783. return CToolTipCtrl((HWND)::SendMessage(this->m_hWnd, LVM_GETTOOLTIPS, 0, 0L));
  2784. }
  2785. CToolTipCtrl SetToolTips(HWND hWndTT)
  2786. {
  2787. ATLASSERT(::IsWindow(this->m_hWnd));
  2788. return CToolTipCtrl((HWND)::SendMessage(this->m_hWnd, LVM_SETTOOLTIPS, (WPARAM)hWndTT, 0L));
  2789. }
  2790. BOOL GetUnicodeFormat() const
  2791. {
  2792. ATLASSERT(::IsWindow(this->m_hWnd));
  2793. return (BOOL)::SendMessage(this->m_hWnd, LVM_GETUNICODEFORMAT, 0, 0L);
  2794. }
  2795. BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
  2796. {
  2797. ATLASSERT(::IsWindow(this->m_hWnd));
  2798. return (BOOL)::SendMessage(this->m_hWnd, LVM_SETUNICODEFORMAT, bUnicode, 0L);
  2799. }
  2800. int GetSelectedColumn() const
  2801. {
  2802. ATLASSERT(::IsWindow(this->m_hWnd));
  2803. return (int)::SendMessage(this->m_hWnd, LVM_GETSELECTEDCOLUMN, 0, 0L);
  2804. }
  2805. void SetSelectedColumn(int nColumn)
  2806. {
  2807. ATLASSERT(::IsWindow(this->m_hWnd));
  2808. ::SendMessage(this->m_hWnd, LVM_SETSELECTEDCOLUMN, nColumn, 0L);
  2809. }
  2810. DWORD GetView() const
  2811. {
  2812. ATLASSERT(::IsWindow(this->m_hWnd));
  2813. return (DWORD)::SendMessage(this->m_hWnd, LVM_GETVIEW, 0, 0L);
  2814. }
  2815. int SetView(DWORD dwView)
  2816. {
  2817. ATLASSERT(::IsWindow(this->m_hWnd));
  2818. return (int)::SendMessage(this->m_hWnd, LVM_SETVIEW, dwView, 0L);
  2819. }
  2820. BOOL IsGroupViewEnabled() const
  2821. {
  2822. ATLASSERT(::IsWindow(this->m_hWnd));
  2823. return (BOOL)::SendMessage(this->m_hWnd, LVM_ISGROUPVIEWENABLED, 0, 0L);
  2824. }
  2825. int GetGroupInfo(int nGroupID, PLVGROUP pGroup) const
  2826. {
  2827. ATLASSERT(::IsWindow(this->m_hWnd));
  2828. return (int)::SendMessage(this->m_hWnd, LVM_GETGROUPINFO, nGroupID, (LPARAM)pGroup);
  2829. }
  2830. int SetGroupInfo(int nGroupID, PLVGROUP pGroup)
  2831. {
  2832. ATLASSERT(::IsWindow(this->m_hWnd));
  2833. return (int)::SendMessage(this->m_hWnd, LVM_SETGROUPINFO, nGroupID, (LPARAM)pGroup);
  2834. }
  2835. void GetGroupMetrics(PLVGROUPMETRICS pGroupMetrics) const
  2836. {
  2837. ATLASSERT(::IsWindow(this->m_hWnd));
  2838. ::SendMessage(this->m_hWnd, LVM_GETGROUPMETRICS, 0, (LPARAM)pGroupMetrics);
  2839. }
  2840. void SetGroupMetrics(PLVGROUPMETRICS pGroupMetrics)
  2841. {
  2842. ATLASSERT(::IsWindow(this->m_hWnd));
  2843. ::SendMessage(this->m_hWnd, LVM_SETGROUPMETRICS, 0, (LPARAM)pGroupMetrics);
  2844. }
  2845. void GetTileViewInfo(PLVTILEVIEWINFO pTileViewInfo) const
  2846. {
  2847. ATLASSERT(::IsWindow(this->m_hWnd));
  2848. ::SendMessage(this->m_hWnd, LVM_GETTILEVIEWINFO, 0, (LPARAM)pTileViewInfo);
  2849. }
  2850. BOOL SetTileViewInfo(PLVTILEVIEWINFO pTileViewInfo)
  2851. {
  2852. ATLASSERT(::IsWindow(this->m_hWnd));
  2853. return (BOOL)::SendMessage(this->m_hWnd, LVM_SETTILEVIEWINFO, 0, (LPARAM)pTileViewInfo);
  2854. }
  2855. void GetTileInfo(PLVTILEINFO pTileInfo) const
  2856. {
  2857. ATLASSERT(::IsWindow(this->m_hWnd));
  2858. ::SendMessage(this->m_hWnd, LVM_GETTILEINFO, 0, (LPARAM)pTileInfo);
  2859. }
  2860. BOOL SetTileInfo(PLVTILEINFO pTileInfo)
  2861. {
  2862. ATLASSERT(::IsWindow(this->m_hWnd));
  2863. return (BOOL)::SendMessage(this->m_hWnd, LVM_SETTILEINFO, 0, (LPARAM)pTileInfo);
  2864. }
  2865. BOOL GetInsertMark(LPLVINSERTMARK pInsertMark) const
  2866. {
  2867. ATLASSERT(::IsWindow(this->m_hWnd));
  2868. return (BOOL)::SendMessage(this->m_hWnd, LVM_GETINSERTMARK, 0, (LPARAM)pInsertMark);
  2869. }
  2870. BOOL SetInsertMark(LPLVINSERTMARK pInsertMark)
  2871. {
  2872. ATLASSERT(::IsWindow(this->m_hWnd));
  2873. return (BOOL)::SendMessage(this->m_hWnd, LVM_SETINSERTMARK, 0, (LPARAM)pInsertMark);
  2874. }
  2875. int GetInsertMarkRect(LPRECT lpRect) const
  2876. {
  2877. ATLASSERT(::IsWindow(this->m_hWnd));
  2878. return (int)::SendMessage(this->m_hWnd, LVM_GETINSERTMARKRECT, 0, (LPARAM)lpRect);
  2879. }
  2880. COLORREF GetInsertMarkColor() const
  2881. {
  2882. ATLASSERT(::IsWindow(this->m_hWnd));
  2883. return (COLORREF)::SendMessage(this->m_hWnd, LVM_GETINSERTMARKCOLOR, 0, 0L);
  2884. }
  2885. COLORREF SetInsertMarkColor(COLORREF clr)
  2886. {
  2887. ATLASSERT(::IsWindow(this->m_hWnd));
  2888. return (COLORREF)::SendMessage(this->m_hWnd, LVM_SETINSERTMARKCOLOR, 0, clr);
  2889. }
  2890. COLORREF GetOutlineColor() const
  2891. {
  2892. ATLASSERT(::IsWindow(this->m_hWnd));
  2893. return (COLORREF)::SendMessage(this->m_hWnd, LVM_GETOUTLINECOLOR, 0, 0L);
  2894. }
  2895. COLORREF SetOutlineColor(COLORREF clr)
  2896. {
  2897. ATLASSERT(::IsWindow(this->m_hWnd));
  2898. return (COLORREF)::SendMessage(this->m_hWnd, LVM_SETOUTLINECOLOR, 0, clr);
  2899. }
  2900. #if (_WIN32_WINNT >= 0x0600)
  2901. int GetGroupCount() const
  2902. {
  2903. ATLASSERT(::IsWindow(this->m_hWnd));
  2904. return (int)::SendMessage(this->m_hWnd, LVM_GETGROUPCOUNT, 0, 0L);
  2905. }
  2906. BOOL GetGroupInfoByIndex(int nIndex, PLVGROUP pGroup) const
  2907. {
  2908. ATLASSERT(::IsWindow(this->m_hWnd));
  2909. return (BOOL)::SendMessage(this->m_hWnd, LVM_GETGROUPINFOBYINDEX, nIndex, (LPARAM)pGroup);
  2910. }
  2911. BOOL GetGroupRect(int nGroupID, int nType, LPRECT lpRect) const
  2912. {
  2913. ATLASSERT(::IsWindow(this->m_hWnd));
  2914. ATLASSERT(lpRect != NULL);
  2915. if(lpRect != NULL)
  2916. lpRect->top = nType;
  2917. return (BOOL)::SendMessage(this->m_hWnd, LVM_GETGROUPRECT, nGroupID, (LPARAM)lpRect);
  2918. }
  2919. UINT GetGroupState(int nGroupID, UINT uMask) const
  2920. {
  2921. ATLASSERT(::IsWindow(this->m_hWnd));
  2922. return (UINT)::SendMessage(this->m_hWnd, LVM_GETGROUPSTATE, nGroupID, (LPARAM)uMask);
  2923. }
  2924. int GetFocusedGroup() const
  2925. {
  2926. ATLASSERT(::IsWindow(this->m_hWnd));
  2927. return (int)::SendMessage(this->m_hWnd, LVM_GETFOCUSEDGROUP, 0, 0L);
  2928. }
  2929. BOOL GetEmptyText(LPWSTR lpstrText, int cchText) const
  2930. {
  2931. ATLASSERT(::IsWindow(this->m_hWnd));
  2932. return (BOOL)::SendMessage(this->m_hWnd, LVM_GETEMPTYTEXT, cchText, (LPARAM)lpstrText);
  2933. }
  2934. BOOL GetFooterRect(LPRECT lpRect) const
  2935. {
  2936. ATLASSERT(::IsWindow(this->m_hWnd));
  2937. return (BOOL)::SendMessage(this->m_hWnd, LVM_GETFOOTERRECT, 0, (LPARAM)lpRect);
  2938. }
  2939. BOOL GetFooterInfo(LPLVFOOTERINFO lpFooterInfo) const
  2940. {
  2941. ATLASSERT(::IsWindow(this->m_hWnd));
  2942. return (BOOL)::SendMessage(this->m_hWnd, LVM_GETFOOTERINFO, 0, (LPARAM)lpFooterInfo);
  2943. }
  2944. BOOL GetFooterItemRect(int nItem, LPRECT lpRect) const
  2945. {
  2946. ATLASSERT(::IsWindow(this->m_hWnd));
  2947. return (BOOL)::SendMessage(this->m_hWnd, LVM_GETFOOTERITEMRECT, nItem, (LPARAM)lpRect);
  2948. }
  2949. BOOL GetFooterItem(int nItem, LPLVFOOTERITEM lpFooterItem) const
  2950. {
  2951. ATLASSERT(::IsWindow(this->m_hWnd));
  2952. return (BOOL)::SendMessage(this->m_hWnd, LVM_GETFOOTERITEM, nItem, (LPARAM)lpFooterItem);
  2953. }
  2954. BOOL GetItemIndexRect(PLVITEMINDEX pItemIndex, int nSubItem, int nType, LPRECT lpRect) const
  2955. {
  2956. ATLASSERT(::IsWindow(this->m_hWnd));
  2957. ATLASSERT(pItemIndex != NULL);
  2958. ATLASSERT(lpRect != NULL);
  2959. if(lpRect != NULL)
  2960. {
  2961. lpRect->top = nSubItem;
  2962. lpRect->left = nType;
  2963. }
  2964. return (BOOL)::SendMessage(this->m_hWnd, LVM_GETITEMINDEXRECT, (WPARAM)pItemIndex, (LPARAM)lpRect);
  2965. }
  2966. BOOL SetItemIndexState(PLVITEMINDEX pItemIndex, UINT uState, UINT dwMask)
  2967. {
  2968. ATLASSERT(::IsWindow(this->m_hWnd));
  2969. LVITEM lvi = {};
  2970. lvi.state = uState;
  2971. lvi.stateMask = dwMask;
  2972. return (BOOL)::SendMessage(this->m_hWnd, LVM_SETITEMINDEXSTATE, (WPARAM)pItemIndex, (LPARAM)&lvi);
  2973. }
  2974. BOOL GetNextItemIndex(PLVITEMINDEX pItemIndex, WORD wFlags) const
  2975. {
  2976. ATLASSERT(::IsWindow(this->m_hWnd));
  2977. return (BOOL)::SendMessage(this->m_hWnd, LVM_GETNEXTITEMINDEX, (WPARAM)pItemIndex, MAKELPARAM(wFlags, 0));
  2978. }
  2979. #endif // (_WIN32_WINNT >= 0x0600)
  2980. // Operations
  2981. int InsertColumn(int nCol, const LVCOLUMN* pColumn)
  2982. {
  2983. ATLASSERT(::IsWindow(this->m_hWnd));
  2984. return (int)::SendMessage(this->m_hWnd, LVM_INSERTCOLUMN, nCol, (LPARAM)pColumn);
  2985. }
  2986. int InsertColumn(int nCol, LPCTSTR lpszColumnHeading, int nFormat = LVCFMT_LEFT,
  2987. int nWidth = -1, int nSubItem = -1, int iImage = -1, int iOrder = -1)
  2988. {
  2989. LVCOLUMN column = {};
  2990. column.mask = LVCF_TEXT | LVCF_FMT;
  2991. column.pszText = (LPTSTR)lpszColumnHeading;
  2992. column.fmt = nFormat;
  2993. if (nWidth != -1)
  2994. {
  2995. column.mask |= LVCF_WIDTH;
  2996. column.cx = nWidth;
  2997. }
  2998. if (nSubItem != -1)
  2999. {
  3000. column.mask |= LVCF_SUBITEM;
  3001. column.iSubItem = nSubItem;
  3002. }
  3003. if (iImage != -1)
  3004. {
  3005. column.mask |= LVCF_IMAGE;
  3006. column.iImage = iImage;
  3007. }
  3008. if (iOrder != -1)
  3009. {
  3010. column.mask |= LVCF_ORDER;
  3011. column.iOrder = iOrder;
  3012. }
  3013. return InsertColumn(nCol, &column);
  3014. }
  3015. BOOL DeleteColumn(int nCol)
  3016. {
  3017. ATLASSERT(::IsWindow(this->m_hWnd));
  3018. return (BOOL)::SendMessage(this->m_hWnd, LVM_DELETECOLUMN, nCol, 0L);
  3019. }
  3020. int InsertItem(UINT nMask, int nItem, LPCTSTR lpszItem, UINT nState, UINT nStateMask, int nImage, LPARAM lParam)
  3021. {
  3022. ATLASSERT(::IsWindow(this->m_hWnd));
  3023. LVITEM item = {};
  3024. item.mask = nMask;
  3025. item.iItem = nItem;
  3026. item.iSubItem = 0;
  3027. item.pszText = (LPTSTR)lpszItem;
  3028. item.state = nState;
  3029. item.stateMask = nStateMask;
  3030. item.iImage = nImage;
  3031. item.lParam = lParam;
  3032. return InsertItem(&item);
  3033. }
  3034. int InsertItem(const LVITEM* pItem)
  3035. {
  3036. ATLASSERT(::IsWindow(this->m_hWnd));
  3037. return (int)::SendMessage(this->m_hWnd, LVM_INSERTITEM, 0, (LPARAM)pItem);
  3038. }
  3039. int InsertItem(int nItem, LPCTSTR lpszItem)
  3040. {
  3041. ATLASSERT(::IsWindow(this->m_hWnd));
  3042. return InsertItem(LVIF_TEXT, nItem, lpszItem, 0, 0, 0, 0);
  3043. }
  3044. int InsertItem(int nItem, LPCTSTR lpszItem, int nImage)
  3045. {
  3046. ATLASSERT(::IsWindow(this->m_hWnd));
  3047. return InsertItem(LVIF_TEXT|LVIF_IMAGE, nItem, lpszItem, 0, 0, nImage, 0);
  3048. }
  3049. int GetNextItem(int nItem, int nFlags) const
  3050. {
  3051. ATLASSERT(::IsWindow(this->m_hWnd));
  3052. return (int)::SendMessage(this->m_hWnd, LVM_GETNEXTITEM, nItem, MAKELPARAM(nFlags, 0));
  3053. }
  3054. BOOL DeleteItem(int nItem)
  3055. {
  3056. ATLASSERT(::IsWindow(this->m_hWnd));
  3057. return (BOOL)::SendMessage(this->m_hWnd, LVM_DELETEITEM, nItem, 0L);
  3058. }
  3059. BOOL DeleteAllItems()
  3060. {
  3061. ATLASSERT(::IsWindow(this->m_hWnd));
  3062. return (BOOL)::SendMessage(this->m_hWnd, LVM_DELETEALLITEMS, 0, 0L);
  3063. }
  3064. int FindItem(LVFINDINFO* pFindInfo, int nStart = -1) const
  3065. {
  3066. ATLASSERT(::IsWindow(this->m_hWnd));
  3067. return (int)::SendMessage(this->m_hWnd, LVM_FINDITEM, nStart, (LPARAM)pFindInfo);
  3068. }
  3069. int FindItem(LPCTSTR lpstrFind, bool bPartial = true, bool bWrap = false, int nStart = -1) const
  3070. {
  3071. ATLASSERT(::IsWindow(this->m_hWnd));
  3072. LVFINDINFO lvfi = {};
  3073. lvfi.flags = LVFI_STRING | (bWrap ? LVFI_WRAP : 0) | (bPartial ? LVFI_PARTIAL : 0);
  3074. lvfi.psz = lpstrFind;
  3075. return (int)::SendMessage(this->m_hWnd, LVM_FINDITEM, nStart, (LPARAM)&lvfi);
  3076. }
  3077. int HitTest(LVHITTESTINFO* pHitTestInfo) const
  3078. {
  3079. ATLASSERT(::IsWindow(this->m_hWnd));
  3080. return (int)::SendMessage(this->m_hWnd, LVM_HITTEST, 0, (LPARAM)pHitTestInfo);
  3081. }
  3082. int HitTest(POINT pt, UINT* pFlags) const
  3083. {
  3084. ATLASSERT(::IsWindow(this->m_hWnd));
  3085. LVHITTESTINFO hti = {};
  3086. hti.pt = pt;
  3087. int nRes = (int)::SendMessage(this->m_hWnd, LVM_HITTEST, 0, (LPARAM)&hti);
  3088. if (pFlags != NULL)
  3089. *pFlags = hti.flags;
  3090. return nRes;
  3091. }
  3092. BOOL EnsureVisible(int nItem, BOOL bPartialOK)
  3093. {
  3094. ATLASSERT(::IsWindow(this->m_hWnd));
  3095. return (BOOL)::SendMessage(this->m_hWnd, LVM_ENSUREVISIBLE, nItem, MAKELPARAM(bPartialOK, 0));
  3096. }
  3097. BOOL Scroll(SIZE size)
  3098. {
  3099. ATLASSERT(::IsWindow(this->m_hWnd));
  3100. return (BOOL)::SendMessage(this->m_hWnd, LVM_SCROLL, size.cx, size.cy);
  3101. }
  3102. BOOL RedrawItems(int nFirst, int nLast)
  3103. {
  3104. ATLASSERT(::IsWindow(this->m_hWnd));
  3105. return (BOOL)::SendMessage(this->m_hWnd, LVM_REDRAWITEMS, nFirst, nLast);
  3106. }
  3107. BOOL Arrange(UINT nCode)
  3108. {
  3109. ATLASSERT(::IsWindow(this->m_hWnd));
  3110. return (BOOL)::SendMessage(this->m_hWnd, LVM_ARRANGE, nCode, 0L);
  3111. }
  3112. CEdit EditLabel(int nItem)
  3113. {
  3114. ATLASSERT(::IsWindow(this->m_hWnd));
  3115. return CEdit((HWND)::SendMessage(this->m_hWnd, LVM_EDITLABEL, nItem, 0L));
  3116. }
  3117. BOOL Update(int nItem)
  3118. {
  3119. ATLASSERT(::IsWindow(this->m_hWnd));
  3120. return (BOOL)::SendMessage(this->m_hWnd, LVM_UPDATE, nItem, 0L);
  3121. }
  3122. BOOL SortItems(PFNLVCOMPARE pfnCompare, LPARAM lParamSort)
  3123. {
  3124. ATLASSERT(::IsWindow(this->m_hWnd));
  3125. return (BOOL)::SendMessage(this->m_hWnd, LVM_SORTITEMS, (WPARAM)lParamSort, (LPARAM)pfnCompare);
  3126. }
  3127. CImageList RemoveImageList(int nImageList)
  3128. {
  3129. ATLASSERT(::IsWindow(this->m_hWnd));
  3130. return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, LVM_SETIMAGELIST, (WPARAM)nImageList, NULL));
  3131. }
  3132. CImageList CreateDragImage(int nItem, LPPOINT lpPoint)
  3133. {
  3134. ATLASSERT(::IsWindow(this->m_hWnd));
  3135. return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, LVM_CREATEDRAGIMAGE, nItem, (LPARAM)lpPoint));
  3136. }
  3137. DWORD ApproximateViewRect(int cx = -1, int cy = -1, int nCount = -1)
  3138. {
  3139. ATLASSERT(::IsWindow(this->m_hWnd));
  3140. return (DWORD)::SendMessage(this->m_hWnd, LVM_APPROXIMATEVIEWRECT, nCount, MAKELPARAM(cx, cy));
  3141. }
  3142. int SubItemHitTest(LPLVHITTESTINFO lpInfo) const
  3143. {
  3144. ATLASSERT(::IsWindow(this->m_hWnd));
  3145. return (int)::SendMessage(this->m_hWnd, LVM_SUBITEMHITTEST, 0, (LPARAM)lpInfo);
  3146. }
  3147. int AddColumn(LPCTSTR strColumn, int nItem, int nSubItem = -1,
  3148. int nMask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM,
  3149. int nFmt = LVCFMT_LEFT)
  3150. {
  3151. const int cxOffset = 15;
  3152. ATLASSERT(::IsWindow(this->m_hWnd));
  3153. LVCOLUMN lvc = {};
  3154. lvc.mask = nMask;
  3155. lvc.fmt = nFmt;
  3156. lvc.pszText = (LPTSTR)strColumn;
  3157. lvc.cx = GetStringWidth(lvc.pszText) + cxOffset;
  3158. if(nMask & LVCF_SUBITEM)
  3159. lvc.iSubItem = (nSubItem != -1) ? nSubItem : nItem;
  3160. return InsertColumn(nItem, &lvc);
  3161. }
  3162. int AddItem(int nItem, int nSubItem, LPCTSTR strItem, int nImageIndex = -3)
  3163. {
  3164. ATLASSERT(::IsWindow(this->m_hWnd));
  3165. LVITEM lvItem = {};
  3166. lvItem.mask = LVIF_TEXT;
  3167. lvItem.iItem = nItem;
  3168. lvItem.iSubItem = nSubItem;
  3169. lvItem.pszText = (LPTSTR)strItem;
  3170. if(nImageIndex != -3)
  3171. {
  3172. lvItem.mask |= LVIF_IMAGE;
  3173. lvItem.iImage = nImageIndex;
  3174. }
  3175. if(nSubItem == 0)
  3176. return InsertItem(&lvItem);
  3177. return SetItem(&lvItem) ? nItem : -1;
  3178. }
  3179. BOOL SortItemsEx(PFNLVCOMPARE pfnCompare, LPARAM lParamSort)
  3180. {
  3181. ATLASSERT(::IsWindow(this->m_hWnd));
  3182. return (BOOL)::SendMessage(this->m_hWnd, LVM_SORTITEMSEX, (WPARAM)lParamSort, (LPARAM)pfnCompare);
  3183. }
  3184. int InsertGroup(int nItem, PLVGROUP pGroup)
  3185. {
  3186. ATLASSERT(::IsWindow(this->m_hWnd));
  3187. return (int)::SendMessage(this->m_hWnd, LVM_INSERTGROUP, nItem, (LPARAM)pGroup);
  3188. }
  3189. int AddGroup(PLVGROUP pGroup)
  3190. {
  3191. return InsertGroup(-1, pGroup);
  3192. }
  3193. int RemoveGroup(int nGroupID)
  3194. {
  3195. ATLASSERT(::IsWindow(this->m_hWnd));
  3196. return (int)::SendMessage(this->m_hWnd, LVM_REMOVEGROUP, nGroupID, 0L);
  3197. }
  3198. void MoveGroup(int nGroupID, int nItem)
  3199. {
  3200. ATLASSERT(::IsWindow(this->m_hWnd));
  3201. ::SendMessage(this->m_hWnd, LVM_MOVEGROUP, nGroupID, nItem);
  3202. }
  3203. void MoveItemToGroup(int nItem, int nGroupID)
  3204. {
  3205. ATLASSERT(::IsWindow(this->m_hWnd));
  3206. ::SendMessage(this->m_hWnd, LVM_MOVEITEMTOGROUP, nItem, nGroupID);
  3207. }
  3208. int EnableGroupView(BOOL bEnable)
  3209. {
  3210. ATLASSERT(::IsWindow(this->m_hWnd));
  3211. return (int)::SendMessage(this->m_hWnd, LVM_ENABLEGROUPVIEW, bEnable, 0L);
  3212. }
  3213. int SortGroups(PFNLVGROUPCOMPARE pCompareFunc, LPVOID lpVoid = NULL)
  3214. {
  3215. ATLASSERT(::IsWindow(this->m_hWnd));
  3216. return (int)::SendMessage(this->m_hWnd, LVM_SORTGROUPS, (WPARAM)pCompareFunc, (LPARAM)lpVoid);
  3217. }
  3218. void InsertGroupSorted(PLVINSERTGROUPSORTED pInsertGroupSorted)
  3219. {
  3220. ATLASSERT(::IsWindow(this->m_hWnd));
  3221. ::SendMessage(this->m_hWnd, LVM_INSERTGROUPSORTED, (WPARAM)pInsertGroupSorted, 0L);
  3222. }
  3223. void RemoveAllGroups()
  3224. {
  3225. ATLASSERT(::IsWindow(this->m_hWnd));
  3226. ::SendMessage(this->m_hWnd, LVM_REMOVEALLGROUPS, 0, 0L);
  3227. }
  3228. BOOL HasGroup(int nGroupID)
  3229. {
  3230. ATLASSERT(::IsWindow(this->m_hWnd));
  3231. return (BOOL)::SendMessage(this->m_hWnd, LVM_HASGROUP, nGroupID, 0L);
  3232. }
  3233. BOOL InsertMarkHitTest(LPPOINT lpPoint, LPLVINSERTMARK pInsertMark) const
  3234. {
  3235. ATLASSERT(::IsWindow(this->m_hWnd));
  3236. return (BOOL)::SendMessage(this->m_hWnd, LVM_INSERTMARKHITTEST, (WPARAM)lpPoint, (LPARAM)pInsertMark);
  3237. }
  3238. BOOL SetInfoTip(PLVSETINFOTIP pSetInfoTip)
  3239. {
  3240. ATLASSERT(::IsWindow(this->m_hWnd));
  3241. return (BOOL)::SendMessage(this->m_hWnd, LVM_SETINFOTIP, 0, (LPARAM)pSetInfoTip);
  3242. }
  3243. void CancelEditLabel()
  3244. {
  3245. ATLASSERT(::IsWindow(this->m_hWnd));
  3246. ::SendMessage(this->m_hWnd, LVM_CANCELEDITLABEL, 0, 0L);
  3247. }
  3248. UINT MapIndexToID(int nIndex) const
  3249. {
  3250. ATLASSERT(::IsWindow(this->m_hWnd));
  3251. return (UINT)::SendMessage(this->m_hWnd, LVM_MAPINDEXTOID, nIndex, 0L);
  3252. }
  3253. int MapIDToIndex(UINT uID) const
  3254. {
  3255. ATLASSERT(::IsWindow(this->m_hWnd));
  3256. return (int)::SendMessage(this->m_hWnd, LVM_MAPIDTOINDEX, uID, 0L);
  3257. }
  3258. #if (_WIN32_WINNT >= 0x0600)
  3259. int HitTestEx(LPLVHITTESTINFO lpHitTestInfo) const
  3260. {
  3261. ATLASSERT(::IsWindow(this->m_hWnd));
  3262. return (int)::SendMessage(this->m_hWnd, LVM_HITTEST, (WPARAM)-1, (LPARAM)lpHitTestInfo);
  3263. }
  3264. int HitTestEx(POINT pt, UINT* pFlags) const
  3265. {
  3266. ATLASSERT(::IsWindow(this->m_hWnd));
  3267. LVHITTESTINFO hti = {};
  3268. hti.pt = pt;
  3269. int nRes = (int)::SendMessage(this->m_hWnd, LVM_HITTEST, (WPARAM)-1, (LPARAM)&hti);
  3270. if (pFlags != NULL)
  3271. *pFlags = hti.flags;
  3272. return nRes;
  3273. }
  3274. int SubItemHitTestEx(LPLVHITTESTINFO lpHitTestInfo) const
  3275. {
  3276. ATLASSERT(::IsWindow(this->m_hWnd));
  3277. return (int)::SendMessage(this->m_hWnd, LVM_SUBITEMHITTEST, (WPARAM)-1, (LPARAM)lpHitTestInfo);
  3278. }
  3279. #endif // (_WIN32_WINNT >= 0x0600)
  3280. // Note: selects only one item
  3281. BOOL SelectItem(int nIndex)
  3282. {
  3283. ATLASSERT(::IsWindow(this->m_hWnd));
  3284. // multi-selection only: de-select all items
  3285. if((this->GetStyle() & LVS_SINGLESEL) == 0)
  3286. SetItemState(-1, 0, LVIS_SELECTED);
  3287. BOOL bRet = SetItemState(nIndex, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
  3288. if(bRet)
  3289. {
  3290. SetSelectionMark(nIndex);
  3291. bRet = EnsureVisible(nIndex, FALSE);
  3292. }
  3293. return bRet;
  3294. }
  3295. // multi-selection only
  3296. BOOL SelectAllItems(bool bSelect = true)
  3297. {
  3298. ATLASSERT(::IsWindow(this->m_hWnd));
  3299. ATLASSERT((this->GetStyle() & LVS_SINGLESEL) == 0);
  3300. return SetItemState(-1, bSelect ? LVIS_SELECTED : 0, LVIS_SELECTED);
  3301. }
  3302. };
  3303. typedef CListViewCtrlT<ATL::CWindow> CListViewCtrl;
  3304. ///////////////////////////////////////////////////////////////////////////////
  3305. // CTreeViewCtrl
  3306. template <class TBase>
  3307. class CTreeViewCtrlT : public TBase
  3308. {
  3309. public:
  3310. // Constructors
  3311. CTreeViewCtrlT(HWND hWnd = NULL) : TBase(hWnd)
  3312. { }
  3313. CTreeViewCtrlT< TBase >& operator =(HWND hWnd)
  3314. {
  3315. this->m_hWnd = hWnd;
  3316. return *this;
  3317. }
  3318. HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  3319. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  3320. ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  3321. {
  3322. return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  3323. }
  3324. // Attributes
  3325. static LPCTSTR GetWndClassName()
  3326. {
  3327. return WC_TREEVIEW;
  3328. }
  3329. UINT GetCount() const
  3330. {
  3331. ATLASSERT(::IsWindow(this->m_hWnd));
  3332. return (UINT)::SendMessage(this->m_hWnd, TVM_GETCOUNT, 0, 0L);
  3333. }
  3334. UINT GetIndent() const
  3335. {
  3336. ATLASSERT(::IsWindow(this->m_hWnd));
  3337. return (UINT)::SendMessage(this->m_hWnd, TVM_GETINDENT, 0, 0L);
  3338. }
  3339. void SetIndent(UINT nIndent)
  3340. {
  3341. ATLASSERT(::IsWindow(this->m_hWnd));
  3342. ::SendMessage(this->m_hWnd, TVM_SETINDENT, nIndent, 0L);
  3343. }
  3344. CImageList GetImageList(int nImageListType = TVSIL_NORMAL) const
  3345. {
  3346. ATLASSERT(::IsWindow(this->m_hWnd));
  3347. return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, TVM_GETIMAGELIST, (WPARAM)nImageListType, 0L));
  3348. }
  3349. CImageList SetImageList(HIMAGELIST hImageList, int nImageListType = TVSIL_NORMAL)
  3350. {
  3351. ATLASSERT(::IsWindow(this->m_hWnd));
  3352. return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, TVM_SETIMAGELIST, (WPARAM)nImageListType, (LPARAM)hImageList));
  3353. }
  3354. BOOL GetItem(LPTVITEM pItem) const
  3355. {
  3356. ATLASSERT(::IsWindow(this->m_hWnd));
  3357. return (BOOL)::SendMessage(this->m_hWnd, TVM_GETITEM, 0, (LPARAM)pItem);
  3358. }
  3359. BOOL SetItem(LPTVITEM pItem)
  3360. {
  3361. ATLASSERT(::IsWindow(this->m_hWnd));
  3362. return (BOOL)::SendMessage(this->m_hWnd, TVM_SETITEM, 0, (LPARAM)pItem);
  3363. }
  3364. BOOL SetItem(HTREEITEM hItem, UINT nMask, LPCTSTR lpszItem, int nImage,
  3365. int nSelectedImage, UINT nState, UINT nStateMask, LPARAM lParam)
  3366. {
  3367. ATLASSERT(::IsWindow(this->m_hWnd));
  3368. TVITEM item = {};
  3369. item.hItem = hItem;
  3370. item.mask = nMask;
  3371. item.pszText = (LPTSTR) lpszItem;
  3372. item.iImage = nImage;
  3373. item.iSelectedImage = nSelectedImage;
  3374. item.state = nState;
  3375. item.stateMask = nStateMask;
  3376. item.lParam = lParam;
  3377. return (BOOL)::SendMessage(this->m_hWnd, TVM_SETITEM, 0, (LPARAM)&item);
  3378. }
  3379. BOOL GetItemText(HTREEITEM hItem, LPTSTR lpstrText, int nLen) const
  3380. {
  3381. ATLASSERT(::IsWindow(this->m_hWnd));
  3382. ATLASSERT(lpstrText != NULL);
  3383. TVITEM item = {};
  3384. item.hItem = hItem;
  3385. item.mask = TVIF_TEXT;
  3386. item.pszText = lpstrText;
  3387. item.cchTextMax = nLen;
  3388. return (BOOL)::SendMessage(this->m_hWnd, TVM_GETITEM, 0, (LPARAM)&item);
  3389. }
  3390. BOOL GetItemText(HTREEITEM hItem, BSTR& bstrText) const
  3391. {
  3392. USES_CONVERSION;
  3393. ATLASSERT(::IsWindow(this->m_hWnd));
  3394. ATLASSERT(bstrText == NULL);
  3395. TVITEM item = {};
  3396. item.hItem = hItem;
  3397. item.mask = TVIF_TEXT;
  3398. LPTSTR lpstrText = NULL;
  3399. BOOL bRet = FALSE;
  3400. for(int nLen = 256; ; nLen *= 2)
  3401. {
  3402. ATLTRY(lpstrText = new TCHAR[nLen]);
  3403. if(lpstrText == NULL)
  3404. break;
  3405. lpstrText[0] = NULL;
  3406. item.pszText = lpstrText;
  3407. item.cchTextMax = nLen;
  3408. bRet = (BOOL)::SendMessage(this->m_hWnd, TVM_GETITEM, 0, (LPARAM)&item);
  3409. if(!bRet || (lstrlen(item.pszText) < (nLen - 1)))
  3410. break;
  3411. delete [] lpstrText;
  3412. lpstrText = NULL;
  3413. }
  3414. if(lpstrText != NULL)
  3415. {
  3416. if(bRet)
  3417. bstrText = ::SysAllocString(T2OLE(lpstrText));
  3418. delete [] lpstrText;
  3419. }
  3420. return (bstrText != NULL) ? TRUE : FALSE;
  3421. }
  3422. #ifdef __ATLSTR_H__
  3423. BOOL GetItemText(HTREEITEM hItem, ATL::CString& strText) const
  3424. {
  3425. ATLASSERT(::IsWindow(this->m_hWnd));
  3426. TVITEM item = {};
  3427. item.hItem = hItem;
  3428. item.mask = TVIF_TEXT;
  3429. strText.Empty();
  3430. BOOL bRet = FALSE;
  3431. for(int nLen = 256; ; nLen *= 2)
  3432. {
  3433. item.pszText = strText.GetBufferSetLength(nLen);
  3434. if(item.pszText == NULL)
  3435. {
  3436. bRet = FALSE;
  3437. break;
  3438. }
  3439. item.cchTextMax = nLen;
  3440. bRet = (BOOL)::SendMessage(this->m_hWnd, TVM_GETITEM, 0, (LPARAM)&item);
  3441. if(!bRet || (lstrlen(item.pszText) < (nLen - 1)))
  3442. break;
  3443. }
  3444. strText.ReleaseBuffer();
  3445. return bRet;
  3446. }
  3447. #endif // __ATLSTR_H__
  3448. BOOL SetItemText(HTREEITEM hItem, LPCTSTR lpszItem)
  3449. {
  3450. ATLASSERT(::IsWindow(this->m_hWnd));
  3451. return SetItem(hItem, TVIF_TEXT, lpszItem, 0, 0, 0, 0, NULL);
  3452. }
  3453. BOOL GetItemImage(HTREEITEM hItem, int& nImage, int& nSelectedImage) const
  3454. {
  3455. ATLASSERT(::IsWindow(this->m_hWnd));
  3456. TVITEM item = {};
  3457. item.hItem = hItem;
  3458. item.mask = TVIF_IMAGE|TVIF_SELECTEDIMAGE;
  3459. BOOL bRes = (BOOL)::SendMessage(this->m_hWnd, TVM_GETITEM, 0, (LPARAM)&item);
  3460. if (bRes)
  3461. {
  3462. nImage = item.iImage;
  3463. nSelectedImage = item.iSelectedImage;
  3464. }
  3465. return bRes;
  3466. }
  3467. BOOL SetItemImage(HTREEITEM hItem, int nImage, int nSelectedImage)
  3468. {
  3469. ATLASSERT(::IsWindow(this->m_hWnd));
  3470. return SetItem(hItem, TVIF_IMAGE|TVIF_SELECTEDIMAGE, NULL, nImage, nSelectedImage, 0, 0, NULL);
  3471. }
  3472. UINT GetItemState(HTREEITEM hItem, UINT nStateMask) const
  3473. {
  3474. ATLASSERT(::IsWindow(this->m_hWnd));
  3475. return (((UINT)::SendMessage(this->m_hWnd, TVM_GETITEMSTATE, (WPARAM)hItem, (LPARAM)nStateMask)) & nStateMask);
  3476. }
  3477. BOOL SetItemState(HTREEITEM hItem, UINT nState, UINT nStateMask)
  3478. {
  3479. ATLASSERT(::IsWindow(this->m_hWnd));
  3480. return SetItem(hItem, TVIF_STATE, NULL, 0, 0, nState, nStateMask, NULL);
  3481. }
  3482. DWORD_PTR GetItemData(HTREEITEM hItem) const
  3483. {
  3484. ATLASSERT(::IsWindow(this->m_hWnd));
  3485. TVITEM item = {};
  3486. item.hItem = hItem;
  3487. item.mask = TVIF_PARAM;
  3488. BOOL bRet = (BOOL)::SendMessage(this->m_hWnd, TVM_GETITEM, 0, (LPARAM)&item);
  3489. return (DWORD_PTR)(bRet ? item.lParam : NULL);
  3490. }
  3491. BOOL SetItemData(HTREEITEM hItem, DWORD_PTR dwData)
  3492. {
  3493. ATLASSERT(::IsWindow(this->m_hWnd));
  3494. return SetItem(hItem, TVIF_PARAM, NULL, 0, 0, 0, 0, (LPARAM)dwData);
  3495. }
  3496. CEdit GetEditControl() const
  3497. {
  3498. ATLASSERT(::IsWindow(this->m_hWnd));
  3499. return CEdit((HWND)::SendMessage(this->m_hWnd, TVM_GETEDITCONTROL, 0, 0L));
  3500. }
  3501. UINT GetVisibleCount() const
  3502. {
  3503. ATLASSERT(::IsWindow(this->m_hWnd));
  3504. return (UINT)::SendMessage(this->m_hWnd, TVM_GETVISIBLECOUNT, 0, 0L);
  3505. }
  3506. BOOL GetItemRect(HTREEITEM hItem, LPRECT lpRect, BOOL bTextOnly) const
  3507. {
  3508. ATLASSERT(::IsWindow(this->m_hWnd));
  3509. *(HTREEITEM*)lpRect = hItem;
  3510. return (BOOL)::SendMessage(this->m_hWnd, TVM_GETITEMRECT, (WPARAM)bTextOnly, (LPARAM)lpRect);
  3511. }
  3512. BOOL ItemHasChildren(HTREEITEM hItem) const
  3513. {
  3514. ATLASSERT(::IsWindow(this->m_hWnd));
  3515. TVITEM item = {};
  3516. item.hItem = hItem;
  3517. item.mask = TVIF_CHILDREN;
  3518. ::SendMessage(this->m_hWnd, TVM_GETITEM, 0, (LPARAM)&item);
  3519. return item.cChildren;
  3520. }
  3521. CToolTipCtrl GetToolTips() const
  3522. {
  3523. ATLASSERT(::IsWindow(this->m_hWnd));
  3524. return CToolTipCtrl((HWND)::SendMessage(this->m_hWnd, TVM_GETTOOLTIPS, 0, 0L));
  3525. }
  3526. CToolTipCtrl SetToolTips(HWND hWndTT)
  3527. {
  3528. ATLASSERT(::IsWindow(this->m_hWnd));
  3529. return CToolTipCtrl((HWND)::SendMessage(this->m_hWnd, TVM_SETTOOLTIPS, (WPARAM)hWndTT, 0L));
  3530. }
  3531. int GetISearchString(LPTSTR lpstr) const
  3532. {
  3533. ATLASSERT(::IsWindow(this->m_hWnd));
  3534. return (int)::SendMessage(this->m_hWnd, TVM_GETISEARCHSTRING, 0, (LPARAM)lpstr);
  3535. }
  3536. // checkboxes only
  3537. BOOL GetCheckState(HTREEITEM hItem) const
  3538. {
  3539. ATLASSERT(::IsWindow(this->m_hWnd));
  3540. ATLASSERT((this->GetStyle() & TVS_CHECKBOXES) != 0);
  3541. UINT uRet = GetItemState(hItem, TVIS_STATEIMAGEMASK);
  3542. return (uRet >> 12) - 1;
  3543. }
  3544. BOOL SetCheckState(HTREEITEM hItem, BOOL bCheck)
  3545. {
  3546. int nCheck = bCheck ? 2 : 1; // one based index
  3547. return SetItemState(hItem, INDEXTOSTATEIMAGEMASK(nCheck), TVIS_STATEIMAGEMASK);
  3548. }
  3549. COLORREF GetBkColor() const
  3550. {
  3551. ATLASSERT(::IsWindow(this->m_hWnd));
  3552. return (COLORREF)::SendMessage(this->m_hWnd, TVM_GETBKCOLOR, 0, 0L);
  3553. }
  3554. COLORREF SetBkColor(COLORREF clr)
  3555. {
  3556. ATLASSERT(::IsWindow(this->m_hWnd));
  3557. return (COLORREF)::SendMessage(this->m_hWnd, TVM_SETBKCOLOR, 0, (LPARAM)clr);
  3558. }
  3559. COLORREF GetInsertMarkColor() const
  3560. {
  3561. ATLASSERT(::IsWindow(this->m_hWnd));
  3562. return (COLORREF)::SendMessage(this->m_hWnd, TVM_GETINSERTMARKCOLOR, 0, 0L);
  3563. }
  3564. COLORREF SetInsertMarkColor(COLORREF clr)
  3565. {
  3566. ATLASSERT(::IsWindow(this->m_hWnd));
  3567. return (COLORREF)::SendMessage(this->m_hWnd, TVM_SETINSERTMARKCOLOR, 0, (LPARAM)clr);
  3568. }
  3569. int GetItemHeight() const
  3570. {
  3571. ATLASSERT(::IsWindow(this->m_hWnd));
  3572. return (int)::SendMessage(this->m_hWnd, TVM_GETITEMHEIGHT, 0, 0L);
  3573. }
  3574. int SetItemHeight(int cyHeight)
  3575. {
  3576. ATLASSERT(::IsWindow(this->m_hWnd));
  3577. return (int)::SendMessage(this->m_hWnd, TVM_SETITEMHEIGHT, cyHeight, 0L);
  3578. }
  3579. int GetScrollTime() const
  3580. {
  3581. ATLASSERT(::IsWindow(this->m_hWnd));
  3582. return (int)::SendMessage(this->m_hWnd, TVM_GETSCROLLTIME, 0, 0L);
  3583. }
  3584. int SetScrollTime(int nScrollTime)
  3585. {
  3586. ATLASSERT(::IsWindow(this->m_hWnd));
  3587. return (int)::SendMessage(this->m_hWnd, TVM_SETSCROLLTIME, nScrollTime, 0L);
  3588. }
  3589. COLORREF GetTextColor() const
  3590. {
  3591. ATLASSERT(::IsWindow(this->m_hWnd));
  3592. return (COLORREF)::SendMessage(this->m_hWnd, TVM_GETTEXTCOLOR, 0, 0L);
  3593. }
  3594. COLORREF SetTextColor(COLORREF clr)
  3595. {
  3596. ATLASSERT(::IsWindow(this->m_hWnd));
  3597. return (COLORREF)::SendMessage(this->m_hWnd, TVM_SETTEXTCOLOR, 0, (LPARAM)clr);
  3598. }
  3599. BOOL GetUnicodeFormat() const
  3600. {
  3601. ATLASSERT(::IsWindow(this->m_hWnd));
  3602. return (BOOL)::SendMessage(this->m_hWnd, TVM_GETUNICODEFORMAT, 0, 0L);
  3603. }
  3604. BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
  3605. {
  3606. ATLASSERT(::IsWindow(this->m_hWnd));
  3607. return (BOOL)::SendMessage(this->m_hWnd, TVM_SETUNICODEFORMAT, bUnicode, 0L);
  3608. }
  3609. COLORREF GetLineColor() const
  3610. {
  3611. ATLASSERT(::IsWindow(this->m_hWnd));
  3612. return (COLORREF)::SendMessage(this->m_hWnd, TVM_GETLINECOLOR, 0, 0L);
  3613. }
  3614. COLORREF SetLineColor(COLORREF clrNew /*= CLR_DEFAULT*/)
  3615. {
  3616. ATLASSERT(::IsWindow(this->m_hWnd));
  3617. return (COLORREF)::SendMessage(this->m_hWnd, TVM_SETLINECOLOR, 0, (LPARAM)clrNew);
  3618. }
  3619. BOOL GetItem(LPTVITEMEX pItem) const
  3620. {
  3621. ATLASSERT(::IsWindow(this->m_hWnd));
  3622. return (BOOL)::SendMessage(this->m_hWnd, TVM_GETITEM, 0, (LPARAM)pItem);
  3623. }
  3624. BOOL SetItem(LPTVITEMEX pItem)
  3625. {
  3626. ATLASSERT(::IsWindow(this->m_hWnd));
  3627. return (BOOL)::SendMessage(this->m_hWnd, TVM_SETITEM, 0, (LPARAM)pItem);
  3628. }
  3629. DWORD GetExtendedStyle() const
  3630. {
  3631. ATLASSERT(::IsWindow(this->m_hWnd));
  3632. return (DWORD)::SendMessage(this->m_hWnd, TVM_GETEXTENDEDSTYLE, 0, 0L);
  3633. }
  3634. DWORD SetExtendedStyle(DWORD dwStyle, DWORD dwMask)
  3635. {
  3636. ATLASSERT(::IsWindow(this->m_hWnd));
  3637. return (DWORD)::SendMessage(this->m_hWnd, TVM_SETEXTENDEDSTYLE, dwMask, dwStyle);
  3638. }
  3639. #if (_WIN32_WINNT >= 0x0600)
  3640. BOOL SetAutoScrollInfo(UINT uPixPerSec, UINT uUpdateTime)
  3641. {
  3642. ATLASSERT(::IsWindow(this->m_hWnd));
  3643. return (BOOL)::SendMessage(this->m_hWnd, TVM_SETAUTOSCROLLINFO, (WPARAM)uPixPerSec, (LPARAM)uUpdateTime);
  3644. }
  3645. DWORD GetSelectedCount() const
  3646. {
  3647. ATLASSERT(::IsWindow(this->m_hWnd));
  3648. return (DWORD)::SendMessage(this->m_hWnd, TVM_GETSELECTEDCOUNT, 0, 0L);
  3649. }
  3650. BOOL GetItemPartRect(HTREEITEM hItem, TVITEMPART partID, LPRECT lpRect) const
  3651. {
  3652. ATLASSERT(::IsWindow(this->m_hWnd));
  3653. TVGETITEMPARTRECTINFO gipri = { hItem, lpRect, partID };
  3654. return (BOOL)::SendMessage(this->m_hWnd, TVM_GETITEMPARTRECT, 0, (LPARAM)&gipri);
  3655. }
  3656. #endif // (_WIN32_WINNT >= 0x0600)
  3657. // Operations
  3658. HTREEITEM InsertItem(LPTVINSERTSTRUCT lpInsertStruct)
  3659. {
  3660. ATLASSERT(::IsWindow(this->m_hWnd));
  3661. return (HTREEITEM)::SendMessage(this->m_hWnd, TVM_INSERTITEM, 0, (LPARAM)lpInsertStruct);
  3662. }
  3663. HTREEITEM InsertItem(LPCTSTR lpszItem, int nImage,
  3664. int nSelectedImage, HTREEITEM hParent, HTREEITEM hInsertAfter)
  3665. {
  3666. ATLASSERT(::IsWindow(this->m_hWnd));
  3667. return InsertItem(TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE, lpszItem, nImage, nSelectedImage, 0, 0, 0, hParent, hInsertAfter);
  3668. }
  3669. HTREEITEM InsertItem(LPCTSTR lpszItem, HTREEITEM hParent, HTREEITEM hInsertAfter)
  3670. {
  3671. ATLASSERT(::IsWindow(this->m_hWnd));
  3672. return InsertItem(TVIF_TEXT, lpszItem, 0, 0, 0, 0, 0, hParent, hInsertAfter);
  3673. }
  3674. HTREEITEM InsertItem(UINT nMask, LPCTSTR lpszItem, int nImage,
  3675. int nSelectedImage, UINT nState, UINT nStateMask, LPARAM lParam,
  3676. HTREEITEM hParent, HTREEITEM hInsertAfter)
  3677. {
  3678. ATLASSERT(::IsWindow(this->m_hWnd));
  3679. TVINSERTSTRUCT tvis = {};
  3680. tvis.hParent = hParent;
  3681. tvis.hInsertAfter = hInsertAfter;
  3682. tvis.item.mask = nMask;
  3683. tvis.item.pszText = (LPTSTR) lpszItem;
  3684. tvis.item.iImage = nImage;
  3685. tvis.item.iSelectedImage = nSelectedImage;
  3686. tvis.item.state = nState;
  3687. tvis.item.stateMask = nStateMask;
  3688. tvis.item.lParam = lParam;
  3689. return (HTREEITEM)::SendMessage(this->m_hWnd, TVM_INSERTITEM, 0, (LPARAM)&tvis);
  3690. }
  3691. BOOL DeleteItem(HTREEITEM hItem)
  3692. {
  3693. ATLASSERT(::IsWindow(this->m_hWnd));
  3694. return (BOOL)::SendMessage(this->m_hWnd, TVM_DELETEITEM, 0, (LPARAM)hItem);
  3695. }
  3696. BOOL DeleteAllItems()
  3697. {
  3698. ATLASSERT(::IsWindow(this->m_hWnd));
  3699. return (BOOL)::SendMessage(this->m_hWnd, TVM_DELETEITEM, 0, (LPARAM)TVI_ROOT);
  3700. }
  3701. BOOL Expand(HTREEITEM hItem, UINT nCode = TVE_EXPAND)
  3702. {
  3703. ATLASSERT(::IsWindow(this->m_hWnd));
  3704. return (BOOL)::SendMessage(this->m_hWnd, TVM_EXPAND, nCode, (LPARAM)hItem);
  3705. }
  3706. HTREEITEM GetNextItem(HTREEITEM hItem, UINT nCode) const
  3707. {
  3708. ATLASSERT(::IsWindow(this->m_hWnd));
  3709. return (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, nCode, (LPARAM)hItem);
  3710. }
  3711. HTREEITEM GetChildItem(HTREEITEM hItem) const
  3712. {
  3713. ATLASSERT(::IsWindow(this->m_hWnd));
  3714. return (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_CHILD, (LPARAM)hItem);
  3715. }
  3716. HTREEITEM GetNextSiblingItem(HTREEITEM hItem) const
  3717. {
  3718. ATLASSERT(::IsWindow(this->m_hWnd));
  3719. return (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_NEXT, (LPARAM)hItem);
  3720. }
  3721. HTREEITEM GetPrevSiblingItem(HTREEITEM hItem) const
  3722. {
  3723. ATLASSERT(::IsWindow(this->m_hWnd));
  3724. return (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_PREVIOUS, (LPARAM)hItem);
  3725. }
  3726. HTREEITEM GetParentItem(HTREEITEM hItem) const
  3727. {
  3728. ATLASSERT(::IsWindow(this->m_hWnd));
  3729. return (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_PARENT, (LPARAM)hItem);
  3730. }
  3731. HTREEITEM GetFirstVisibleItem() const
  3732. {
  3733. ATLASSERT(::IsWindow(this->m_hWnd));
  3734. return (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_FIRSTVISIBLE, 0L);
  3735. }
  3736. HTREEITEM GetNextVisibleItem(HTREEITEM hItem) const
  3737. {
  3738. ATLASSERT(::IsWindow(this->m_hWnd));
  3739. return (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_NEXTVISIBLE, (LPARAM)hItem);
  3740. }
  3741. HTREEITEM GetPrevVisibleItem(HTREEITEM hItem) const
  3742. {
  3743. ATLASSERT(::IsWindow(this->m_hWnd));
  3744. return (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_PREVIOUSVISIBLE, (LPARAM)hItem);
  3745. }
  3746. HTREEITEM GetSelectedItem() const
  3747. {
  3748. ATLASSERT(::IsWindow(this->m_hWnd));
  3749. return (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_CARET, 0L);
  3750. }
  3751. HTREEITEM GetDropHilightItem() const
  3752. {
  3753. ATLASSERT(::IsWindow(this->m_hWnd));
  3754. return (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_DROPHILITE, 0L);
  3755. }
  3756. HTREEITEM GetRootItem() const
  3757. {
  3758. ATLASSERT(::IsWindow(this->m_hWnd));
  3759. return (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_ROOT, 0L);
  3760. }
  3761. HTREEITEM GetLastVisibleItem() const
  3762. {
  3763. ATLASSERT(::IsWindow(this->m_hWnd));
  3764. return (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_LASTVISIBLE, 0L);
  3765. }
  3766. HTREEITEM GetNextSelectedItem() const
  3767. {
  3768. ATLASSERT(::IsWindow(this->m_hWnd));
  3769. return (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_NEXTSELECTED, 0L);
  3770. }
  3771. BOOL Select(HTREEITEM hItem, UINT nCode)
  3772. {
  3773. ATLASSERT(::IsWindow(this->m_hWnd));
  3774. return (BOOL)::SendMessage(this->m_hWnd, TVM_SELECTITEM, nCode, (LPARAM)hItem);
  3775. }
  3776. BOOL SelectItem(HTREEITEM hItem)
  3777. {
  3778. ATLASSERT(::IsWindow(this->m_hWnd));
  3779. return (BOOL)::SendMessage(this->m_hWnd, TVM_SELECTITEM, TVGN_CARET, (LPARAM)hItem);
  3780. }
  3781. BOOL SelectDropTarget(HTREEITEM hItem)
  3782. {
  3783. ATLASSERT(::IsWindow(this->m_hWnd));
  3784. return (BOOL)::SendMessage(this->m_hWnd, TVM_SELECTITEM, TVGN_DROPHILITE, (LPARAM)hItem);
  3785. }
  3786. BOOL SelectSetFirstVisible(HTREEITEM hItem)
  3787. {
  3788. ATLASSERT(::IsWindow(this->m_hWnd));
  3789. return (BOOL)::SendMessage(this->m_hWnd, TVM_SELECTITEM, TVGN_FIRSTVISIBLE, (LPARAM)hItem);
  3790. }
  3791. CEdit EditLabel(HTREEITEM hItem)
  3792. {
  3793. ATLASSERT(::IsWindow(this->m_hWnd));
  3794. return CEdit((HWND)::SendMessage(this->m_hWnd, TVM_EDITLABEL, 0, (LPARAM)hItem));
  3795. }
  3796. BOOL EndEditLabelNow(BOOL bCancel)
  3797. {
  3798. ATLASSERT(::IsWindow(this->m_hWnd));
  3799. return (BOOL)::SendMessage(this->m_hWnd, TVM_ENDEDITLABELNOW, bCancel, 0L);
  3800. }
  3801. HTREEITEM HitTest(TVHITTESTINFO* pHitTestInfo) const
  3802. {
  3803. ATLASSERT(::IsWindow(this->m_hWnd));
  3804. return (HTREEITEM)::SendMessage(this->m_hWnd, TVM_HITTEST, 0, (LPARAM)pHitTestInfo);
  3805. }
  3806. HTREEITEM HitTest(POINT pt, UINT* pFlags) const
  3807. {
  3808. ATLASSERT(::IsWindow(this->m_hWnd));
  3809. TVHITTESTINFO hti = {};
  3810. hti.pt = pt;
  3811. HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(this->m_hWnd, TVM_HITTEST, 0, (LPARAM)&hti);
  3812. if (pFlags != NULL)
  3813. *pFlags = hti.flags;
  3814. return hTreeItem;
  3815. }
  3816. BOOL SortChildren(HTREEITEM hItem, BOOL bRecurse = FALSE)
  3817. {
  3818. ATLASSERT(::IsWindow(this->m_hWnd));
  3819. return (BOOL)::SendMessage(this->m_hWnd, TVM_SORTCHILDREN, (WPARAM)bRecurse, (LPARAM)hItem);
  3820. }
  3821. BOOL EnsureVisible(HTREEITEM hItem)
  3822. {
  3823. ATLASSERT(::IsWindow(this->m_hWnd));
  3824. return (BOOL)::SendMessage(this->m_hWnd, TVM_ENSUREVISIBLE, 0, (LPARAM)hItem);
  3825. }
  3826. BOOL SortChildrenCB(LPTVSORTCB pSort, BOOL bRecurse = FALSE)
  3827. {
  3828. ATLASSERT(::IsWindow(this->m_hWnd));
  3829. return (BOOL)::SendMessage(this->m_hWnd, TVM_SORTCHILDRENCB, (WPARAM)bRecurse, (LPARAM)pSort);
  3830. }
  3831. CImageList RemoveImageList(int nImageList)
  3832. {
  3833. ATLASSERT(::IsWindow(this->m_hWnd));
  3834. return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, TVM_SETIMAGELIST, (WPARAM)nImageList, NULL));
  3835. }
  3836. CImageList CreateDragImage(HTREEITEM hItem)
  3837. {
  3838. ATLASSERT(::IsWindow(this->m_hWnd));
  3839. return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, TVM_CREATEDRAGIMAGE, 0, (LPARAM)hItem));
  3840. }
  3841. BOOL SetInsertMark(HTREEITEM hTreeItem, BOOL bAfter)
  3842. {
  3843. ATLASSERT(::IsWindow(this->m_hWnd));
  3844. return (BOOL)::SendMessage(this->m_hWnd, TVM_SETINSERTMARK, bAfter, (LPARAM)hTreeItem);
  3845. }
  3846. BOOL RemoveInsertMark()
  3847. {
  3848. ATLASSERT(::IsWindow(this->m_hWnd));
  3849. return (BOOL)::SendMessage(this->m_hWnd, TVM_SETINSERTMARK, 0, 0L);
  3850. }
  3851. HTREEITEM MapAccIDToHTREEITEM(UINT uID) const
  3852. {
  3853. ATLASSERT(::IsWindow(this->m_hWnd));
  3854. return (HTREEITEM)::SendMessage(this->m_hWnd, TVM_MAPACCIDTOHTREEITEM, uID, 0L);
  3855. }
  3856. UINT MapHTREEITEMToAccID(HTREEITEM hTreeItem) const
  3857. {
  3858. ATLASSERT(::IsWindow(this->m_hWnd));
  3859. return (UINT)::SendMessage(this->m_hWnd, TVM_MAPHTREEITEMTOACCID, (WPARAM)hTreeItem, 0L);
  3860. }
  3861. #if (_WIN32_WINNT >= 0x0600)
  3862. void ShowInfoTip(HTREEITEM hItem)
  3863. {
  3864. ATLASSERT(::IsWindow(this->m_hWnd));
  3865. ::SendMessage(this->m_hWnd, TVM_SHOWINFOTIP, 0, (LPARAM)hItem);
  3866. }
  3867. #endif // (_WIN32_WINNT >= 0x0600)
  3868. };
  3869. typedef CTreeViewCtrlT<ATL::CWindow> CTreeViewCtrl;
  3870. ///////////////////////////////////////////////////////////////////////////////
  3871. // CTreeViewCtrlEx
  3872. // forward declaration
  3873. template <class TBase> class CTreeViewCtrlExT;
  3874. // Note: TBase here is for CTreeViewCtrlExT, and not for CTreeItemT itself
  3875. template <class TBase>
  3876. class CTreeItemT
  3877. {
  3878. public:
  3879. HTREEITEM m_hTreeItem;
  3880. CTreeViewCtrlExT<TBase>* m_pTreeView;
  3881. // Construction
  3882. CTreeItemT(HTREEITEM hTreeItem = NULL, CTreeViewCtrlExT<TBase>* pTreeView = NULL) : m_hTreeItem(hTreeItem), m_pTreeView(pTreeView)
  3883. { }
  3884. CTreeItemT(const CTreeItemT<TBase>& posSrc)
  3885. {
  3886. *this = posSrc;
  3887. }
  3888. operator HTREEITEM() { return m_hTreeItem; }
  3889. CTreeItemT<TBase>& operator =(const CTreeItemT<TBase>& itemSrc)
  3890. {
  3891. m_hTreeItem = itemSrc.m_hTreeItem;
  3892. m_pTreeView = itemSrc.m_pTreeView;
  3893. return *this;
  3894. }
  3895. // Attributes
  3896. CTreeViewCtrlExT<TBase>* GetTreeView() const { return m_pTreeView; }
  3897. BOOL operator !() const { return m_hTreeItem == NULL; }
  3898. BOOL IsNull() const { return m_hTreeItem == NULL; }
  3899. BOOL GetRect(LPRECT lpRect, BOOL bTextOnly) const;
  3900. BOOL GetText(LPTSTR lpstrText, int nLen) const;
  3901. BOOL GetText(BSTR& bstrText) const;
  3902. #ifdef __ATLSTR_H__
  3903. BOOL GetText(ATL::CString& strText) const;
  3904. #endif // __ATLSTR_H__
  3905. BOOL SetText(LPCTSTR lpszItem);
  3906. BOOL GetImage(int& nImage, int& nSelectedImage) const;
  3907. BOOL SetImage(int nImage, int nSelectedImage);
  3908. UINT GetState(UINT nStateMask) const;
  3909. BOOL SetState(UINT nState, UINT nStateMask);
  3910. DWORD_PTR GetData() const;
  3911. BOOL SetData(DWORD_PTR dwData);
  3912. BOOL SetItem(UINT nMask, LPCTSTR lpszItem, int nImage, int nSelectedImage, UINT nState, UINT nStateMask, LPARAM lParam);
  3913. // Operations
  3914. CTreeItemT<TBase> InsertAfter(LPCTSTR lpstrItem, HTREEITEM hItemAfter, int nImageIndex)
  3915. {
  3916. return _Insert(lpstrItem, nImageIndex, hItemAfter);
  3917. }
  3918. CTreeItemT<TBase> AddHead(LPCTSTR lpstrItem, int nImageIndex)
  3919. {
  3920. return _Insert(lpstrItem, nImageIndex, TVI_FIRST);
  3921. }
  3922. CTreeItemT<TBase> AddTail(LPCTSTR lpstrItem, int nImageIndex)
  3923. {
  3924. return _Insert(lpstrItem, nImageIndex, TVI_LAST);
  3925. }
  3926. CTreeItemT<TBase> GetChild() const;
  3927. CTreeItemT<TBase> GetNext(UINT nCode) const;
  3928. CTreeItemT<TBase> GetNextSibling() const;
  3929. CTreeItemT<TBase> GetPrevSibling() const;
  3930. CTreeItemT<TBase> GetParent() const;
  3931. CTreeItemT<TBase> GetFirstVisible() const;
  3932. CTreeItemT<TBase> GetNextVisible() const;
  3933. CTreeItemT<TBase> GetPrevVisible() const;
  3934. CTreeItemT<TBase> GetSelected() const;
  3935. CTreeItemT<TBase> GetDropHilight() const;
  3936. CTreeItemT<TBase> GetRoot() const;
  3937. CTreeItemT<TBase> GetLastVisible() const;
  3938. CTreeItemT<TBase> GetNextSelected() const;
  3939. BOOL HasChildren() const;
  3940. BOOL Delete();
  3941. BOOL Expand(UINT nCode = TVE_EXPAND);
  3942. BOOL Select(UINT nCode);
  3943. BOOL Select();
  3944. BOOL SelectDropTarget();
  3945. BOOL SelectSetFirstVisible();
  3946. HWND EditLabel();
  3947. HIMAGELIST CreateDragImage();
  3948. BOOL SortChildren(BOOL bRecurse = FALSE);
  3949. BOOL EnsureVisible();
  3950. CTreeItemT<TBase> _Insert(LPCTSTR lpstrItem, int nImageIndex, HTREEITEM hItemAfter);
  3951. int GetImageIndex() const;
  3952. BOOL SetInsertMark(BOOL bAfter);
  3953. UINT MapHTREEITEMToAccID() const;
  3954. #if (_WIN32_WINNT >= 0x0600)
  3955. void ShowInfoTip();
  3956. BOOL GetPartRect(TVITEMPART partID, LPRECT lpRect) const;
  3957. #endif // (_WIN32_WINNT >= 0x0600)
  3958. };
  3959. typedef CTreeItemT<ATL::CWindow> CTreeItem;
  3960. template <class TBase>
  3961. class CTreeViewCtrlExT : public CTreeViewCtrlT< TBase >
  3962. {
  3963. public:
  3964. // Constructors
  3965. CTreeViewCtrlExT(HWND hWnd = NULL) : CTreeViewCtrlT< TBase >(hWnd)
  3966. { }
  3967. CTreeViewCtrlExT< TBase >& operator =(HWND hWnd)
  3968. {
  3969. this->m_hWnd = hWnd;
  3970. return *this;
  3971. }
  3972. // Operations (overides that return CTreeItem)
  3973. CTreeItemT<TBase> InsertItem(LPTVINSERTSTRUCT lpInsertStruct)
  3974. {
  3975. ATLASSERT(::IsWindow(this->m_hWnd));
  3976. HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(this->m_hWnd, TVM_INSERTITEM, 0, (LPARAM)lpInsertStruct);
  3977. return CTreeItemT<TBase>(hTreeItem, this);
  3978. }
  3979. CTreeItemT<TBase> InsertItem(LPCTSTR lpszItem, int nImage,
  3980. int nSelectedImage, HTREEITEM hParent, HTREEITEM hInsertAfter)
  3981. {
  3982. ATLASSERT(::IsWindow(this->m_hWnd));
  3983. return InsertItem(TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE, lpszItem, nImage, nSelectedImage, 0, 0, 0, hParent, hInsertAfter);
  3984. }
  3985. CTreeItemT<TBase> InsertItem(LPCTSTR lpszItem, HTREEITEM hParent, HTREEITEM hInsertAfter)
  3986. {
  3987. ATLASSERT(::IsWindow(this->m_hWnd));
  3988. return InsertItem(TVIF_TEXT, lpszItem, 0, 0, 0, 0, 0, hParent, hInsertAfter);
  3989. }
  3990. CTreeItemT<TBase> GetNextItem(HTREEITEM hItem, UINT nCode) const
  3991. {
  3992. ATLASSERT(::IsWindow(this->m_hWnd));
  3993. HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, nCode, (LPARAM)hItem);
  3994. return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
  3995. }
  3996. CTreeItemT<TBase> GetChildItem(HTREEITEM hItem) const
  3997. {
  3998. ATLASSERT(::IsWindow(this->m_hWnd));
  3999. HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_CHILD, (LPARAM)hItem);
  4000. return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
  4001. }
  4002. CTreeItemT<TBase> GetNextSiblingItem(HTREEITEM hItem) const
  4003. {
  4004. ATLASSERT(::IsWindow(this->m_hWnd));
  4005. HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_NEXT, (LPARAM)hItem);
  4006. return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
  4007. }
  4008. CTreeItemT<TBase> GetPrevSiblingItem(HTREEITEM hItem) const
  4009. {
  4010. ATLASSERT(::IsWindow(this->m_hWnd));
  4011. HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_PREVIOUS, (LPARAM)hItem);
  4012. return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
  4013. }
  4014. CTreeItemT<TBase> GetParentItem(HTREEITEM hItem) const
  4015. {
  4016. ATLASSERT(::IsWindow(this->m_hWnd));
  4017. HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_PARENT, (LPARAM)hItem);
  4018. return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
  4019. }
  4020. CTreeItemT<TBase> GetFirstVisibleItem() const
  4021. {
  4022. ATLASSERT(::IsWindow(this->m_hWnd));
  4023. HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_FIRSTVISIBLE, 0L);
  4024. return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
  4025. }
  4026. CTreeItemT<TBase> GetNextVisibleItem(HTREEITEM hItem) const
  4027. {
  4028. ATLASSERT(::IsWindow(this->m_hWnd));
  4029. HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_NEXTVISIBLE, (LPARAM)hItem);
  4030. return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
  4031. }
  4032. CTreeItemT<TBase> GetPrevVisibleItem(HTREEITEM hItem) const
  4033. {
  4034. ATLASSERT(::IsWindow(this->m_hWnd));
  4035. HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_PREVIOUSVISIBLE, (LPARAM)hItem);
  4036. return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
  4037. }
  4038. CTreeItemT<TBase> GetSelectedItem() const
  4039. {
  4040. ATLASSERT(::IsWindow(this->m_hWnd));
  4041. HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_CARET, 0L);
  4042. return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
  4043. }
  4044. CTreeItemT<TBase> GetDropHilightItem() const
  4045. {
  4046. ATLASSERT(::IsWindow(this->m_hWnd));
  4047. HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_DROPHILITE, 0L);
  4048. return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
  4049. }
  4050. CTreeItemT<TBase> GetRootItem() const
  4051. {
  4052. ATLASSERT(::IsWindow(this->m_hWnd));
  4053. HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_ROOT, 0L);
  4054. return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
  4055. }
  4056. CTreeItemT<TBase> GetLastVisibleItem() const
  4057. {
  4058. ATLASSERT(::IsWindow(this->m_hWnd));
  4059. HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_LASTVISIBLE, 0L);
  4060. return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
  4061. }
  4062. CTreeItemT<TBase> GetNextSelectedItem() const
  4063. {
  4064. ATLASSERT(::IsWindow(this->m_hWnd));
  4065. HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_NEXTSELECTED, 0L);
  4066. return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
  4067. }
  4068. CTreeItemT<TBase> HitTest(TVHITTESTINFO* pHitTestInfo) const
  4069. {
  4070. ATLASSERT(::IsWindow(this->m_hWnd));
  4071. HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(this->m_hWnd, TVM_HITTEST, 0, (LPARAM)pHitTestInfo);
  4072. return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
  4073. }
  4074. CTreeItemT<TBase> InsertItem(UINT nMask, LPCTSTR lpszItem, int nImage,
  4075. int nSelectedImage, UINT nState, UINT nStateMask, LPARAM lParam,
  4076. HTREEITEM hParent, HTREEITEM hInsertAfter)
  4077. {
  4078. ATLASSERT(::IsWindow(this->m_hWnd));
  4079. TVINSERTSTRUCT tvis = {};
  4080. tvis.hParent = hParent;
  4081. tvis.hInsertAfter = hInsertAfter;
  4082. tvis.item.mask = nMask;
  4083. tvis.item.pszText = (LPTSTR) lpszItem;
  4084. tvis.item.iImage = nImage;
  4085. tvis.item.iSelectedImage = nSelectedImage;
  4086. tvis.item.state = nState;
  4087. tvis.item.stateMask = nStateMask;
  4088. tvis.item.lParam = lParam;
  4089. HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(this->m_hWnd, TVM_INSERTITEM, 0, (LPARAM)&tvis);
  4090. return CTreeItemT<TBase>(hTreeItem, this);
  4091. }
  4092. CTreeItemT<TBase> HitTest(POINT pt, UINT* pFlags) const
  4093. {
  4094. ATLASSERT(::IsWindow(this->m_hWnd));
  4095. TVHITTESTINFO hti = {};
  4096. hti.pt = pt;
  4097. HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(this->m_hWnd, TVM_HITTEST, 0, (LPARAM)&hti);
  4098. if (pFlags != NULL)
  4099. *pFlags = hti.flags;
  4100. return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
  4101. }
  4102. CTreeItemT<TBase> MapAccIDToHTREEITEM(UINT uID) const
  4103. {
  4104. ATLASSERT(::IsWindow(this->m_hWnd));
  4105. HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(this->m_hWnd, TVM_MAPACCIDTOHTREEITEM, uID, 0L);
  4106. return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
  4107. }
  4108. };
  4109. typedef CTreeViewCtrlExT<ATL::CWindow> CTreeViewCtrlEx;
  4110. // CTreeItem inline methods
  4111. template <class TBase>
  4112. inline BOOL CTreeItemT<TBase>::GetRect(LPRECT lpRect, BOOL bTextOnly) const
  4113. {
  4114. ATLASSERT(m_pTreeView != NULL);
  4115. return m_pTreeView->GetItemRect(m_hTreeItem,lpRect,bTextOnly);
  4116. }
  4117. template <class TBase>
  4118. inline CTreeItemT<TBase> CTreeItemT<TBase>::GetNext(UINT nCode) const
  4119. {
  4120. ATLASSERT(m_pTreeView != NULL);
  4121. return m_pTreeView->GetNextItem(m_hTreeItem,nCode);
  4122. }
  4123. template <class TBase>
  4124. inline CTreeItemT<TBase> CTreeItemT<TBase>::GetChild() const
  4125. {
  4126. ATLASSERT(m_pTreeView != NULL);
  4127. return m_pTreeView->GetChildItem(m_hTreeItem);
  4128. }
  4129. template <class TBase>
  4130. inline CTreeItemT<TBase> CTreeItemT<TBase>::GetNextSibling() const
  4131. {
  4132. ATLASSERT(m_pTreeView != NULL);
  4133. return m_pTreeView->GetNextSiblingItem(m_hTreeItem);
  4134. }
  4135. template <class TBase>
  4136. inline CTreeItemT<TBase> CTreeItemT<TBase>::GetPrevSibling() const
  4137. {
  4138. ATLASSERT(m_pTreeView != NULL);
  4139. return m_pTreeView->GetPrevSiblingItem(m_hTreeItem);
  4140. }
  4141. template <class TBase>
  4142. inline CTreeItemT<TBase> CTreeItemT<TBase>::GetParent() const
  4143. {
  4144. ATLASSERT(m_pTreeView != NULL);
  4145. return m_pTreeView->GetParentItem(m_hTreeItem);
  4146. }
  4147. template <class TBase>
  4148. inline CTreeItemT<TBase> CTreeItemT<TBase>::GetFirstVisible() const
  4149. {
  4150. ATLASSERT(m_pTreeView != NULL);
  4151. return m_pTreeView->GetFirstVisibleItem();
  4152. }
  4153. template <class TBase>
  4154. inline CTreeItemT<TBase> CTreeItemT<TBase>::GetNextVisible() const
  4155. {
  4156. ATLASSERT(m_pTreeView != NULL);
  4157. return m_pTreeView->GetNextVisibleItem(m_hTreeItem);
  4158. }
  4159. template <class TBase>
  4160. inline CTreeItemT<TBase> CTreeItemT<TBase>::GetPrevVisible() const
  4161. {
  4162. ATLASSERT(m_pTreeView != NULL);
  4163. return m_pTreeView->GetPrevVisibleItem(m_hTreeItem);
  4164. }
  4165. template <class TBase>
  4166. inline CTreeItemT<TBase> CTreeItemT<TBase>::GetSelected() const
  4167. {
  4168. ATLASSERT(m_pTreeView != NULL);
  4169. return m_pTreeView->GetSelectedItem();
  4170. }
  4171. template <class TBase>
  4172. inline CTreeItemT<TBase> CTreeItemT<TBase>::GetDropHilight() const
  4173. {
  4174. ATLASSERT(m_pTreeView != NULL);
  4175. return m_pTreeView->GetDropHilightItem();
  4176. }
  4177. template <class TBase>
  4178. inline CTreeItemT<TBase> CTreeItemT<TBase>::GetRoot() const
  4179. {
  4180. ATLASSERT(m_pTreeView != NULL);
  4181. return m_pTreeView->GetRootItem();
  4182. }
  4183. template <class TBase>
  4184. inline CTreeItemT<TBase> CTreeItemT<TBase>::GetLastVisible() const
  4185. {
  4186. ATLASSERT(m_pTreeView != NULL);
  4187. return m_pTreeView->GetLastVisibleItem();
  4188. }
  4189. template <class TBase>
  4190. inline CTreeItemT<TBase> CTreeItemT<TBase>::GetNextSelected() const
  4191. {
  4192. ATLASSERT(m_pTreeView != NULL);
  4193. return m_pTreeView->GetNextSelectedItem();
  4194. }
  4195. template <class TBase>
  4196. inline BOOL CTreeItemT<TBase>::GetText(LPTSTR lpstrText, int nLen) const
  4197. {
  4198. ATLASSERT(m_pTreeView != NULL);
  4199. return m_pTreeView->GetItemText(m_hTreeItem, lpstrText, nLen);
  4200. }
  4201. #ifdef _OLEAUTO_H_
  4202. template <class TBase>
  4203. inline BOOL CTreeItemT<TBase>::GetText(BSTR& bstrText) const
  4204. {
  4205. ATLASSERT(m_pTreeView != NULL);
  4206. return m_pTreeView->GetItemText(m_hTreeItem, bstrText);
  4207. }
  4208. #endif // _OLEAUTO_H_
  4209. #ifdef __ATLSTR_H__
  4210. template <class TBase>
  4211. inline BOOL CTreeItemT<TBase>::GetText(ATL::CString& strText) const
  4212. {
  4213. ATLASSERT(m_pTreeView != NULL);
  4214. return m_pTreeView->GetItemText(m_hTreeItem, strText);
  4215. }
  4216. #endif // __ATLSTR_H__
  4217. template <class TBase>
  4218. inline BOOL CTreeItemT<TBase>::GetImage(int& nImage, int& nSelectedImage) const
  4219. {
  4220. ATLASSERT(m_pTreeView != NULL);
  4221. return m_pTreeView->GetItemImage(m_hTreeItem,nImage,nSelectedImage);
  4222. }
  4223. template <class TBase>
  4224. inline UINT CTreeItemT<TBase>::GetState(UINT nStateMask) const
  4225. {
  4226. ATLASSERT(m_pTreeView != NULL);
  4227. return m_pTreeView->GetItemState(m_hTreeItem,nStateMask);
  4228. }
  4229. template <class TBase>
  4230. inline DWORD_PTR CTreeItemT<TBase>::GetData() const
  4231. {
  4232. ATLASSERT(m_pTreeView != NULL);
  4233. return m_pTreeView->GetItemData(m_hTreeItem);
  4234. }
  4235. template <class TBase>
  4236. inline BOOL CTreeItemT<TBase>::SetItem(UINT nMask, LPCTSTR lpszItem, int nImage,
  4237. int nSelectedImage, UINT nState, UINT nStateMask, LPARAM lParam)
  4238. {
  4239. ATLASSERT(m_pTreeView != NULL);
  4240. return m_pTreeView->SetItem(m_hTreeItem, nMask, lpszItem, nImage, nSelectedImage, nState, nStateMask, lParam);
  4241. }
  4242. template <class TBase>
  4243. inline BOOL CTreeItemT<TBase>::SetText(LPCTSTR lpszItem)
  4244. {
  4245. ATLASSERT(m_pTreeView != NULL);
  4246. return m_pTreeView->SetItemText(m_hTreeItem,lpszItem);
  4247. }
  4248. template <class TBase>
  4249. inline BOOL CTreeItemT<TBase>::SetImage(int nImage, int nSelectedImage)
  4250. {
  4251. ATLASSERT(m_pTreeView != NULL);
  4252. return m_pTreeView->SetItemImage(m_hTreeItem,nImage,nSelectedImage);
  4253. }
  4254. template <class TBase>
  4255. inline BOOL CTreeItemT<TBase>::SetState(UINT nState, UINT nStateMask)
  4256. {
  4257. ATLASSERT(m_pTreeView != NULL);
  4258. return m_pTreeView->SetItemState(m_hTreeItem,nState,nStateMask);
  4259. }
  4260. template <class TBase>
  4261. inline BOOL CTreeItemT<TBase>::SetData(DWORD_PTR dwData)
  4262. {
  4263. ATLASSERT(m_pTreeView != NULL);
  4264. return m_pTreeView->SetItemData(m_hTreeItem,dwData);
  4265. }
  4266. template <class TBase>
  4267. inline BOOL CTreeItemT<TBase>::HasChildren() const
  4268. {
  4269. ATLASSERT(m_pTreeView != NULL);
  4270. return m_pTreeView->ItemHasChildren(m_hTreeItem);
  4271. }
  4272. template <class TBase>
  4273. inline BOOL CTreeItemT<TBase>::Delete()
  4274. {
  4275. ATLASSERT(m_pTreeView != NULL);
  4276. return m_pTreeView->DeleteItem(m_hTreeItem);
  4277. }
  4278. template <class TBase>
  4279. inline BOOL CTreeItemT<TBase>::Expand(UINT nCode /*= TVE_EXPAND*/)
  4280. {
  4281. ATLASSERT(m_pTreeView != NULL);
  4282. return m_pTreeView->Expand(m_hTreeItem,nCode);
  4283. }
  4284. template <class TBase>
  4285. inline BOOL CTreeItemT<TBase>::Select(UINT nCode)
  4286. {
  4287. ATLASSERT(m_pTreeView != NULL);
  4288. return m_pTreeView->Select(m_hTreeItem,nCode);
  4289. }
  4290. template <class TBase>
  4291. inline BOOL CTreeItemT<TBase>::Select()
  4292. {
  4293. ATLASSERT(m_pTreeView != NULL);
  4294. return m_pTreeView->SelectItem(m_hTreeItem);
  4295. }
  4296. template <class TBase>
  4297. inline BOOL CTreeItemT<TBase>::SelectDropTarget()
  4298. {
  4299. ATLASSERT(m_pTreeView != NULL);
  4300. return m_pTreeView->SelectDropTarget(m_hTreeItem);
  4301. }
  4302. template <class TBase>
  4303. inline BOOL CTreeItemT<TBase>::SelectSetFirstVisible()
  4304. {
  4305. ATLASSERT(m_pTreeView != NULL);
  4306. return m_pTreeView->SelectSetFirstVisible(m_hTreeItem);
  4307. }
  4308. template <class TBase>
  4309. inline HWND CTreeItemT<TBase>::EditLabel()
  4310. {
  4311. ATLASSERT(m_pTreeView != NULL);
  4312. return m_pTreeView->EditLabel(m_hTreeItem);
  4313. }
  4314. template <class TBase>
  4315. inline HIMAGELIST CTreeItemT<TBase>::CreateDragImage()
  4316. {
  4317. ATLASSERT(m_pTreeView != NULL);
  4318. return m_pTreeView->CreateDragImage(m_hTreeItem);
  4319. }
  4320. template <class TBase>
  4321. inline BOOL CTreeItemT<TBase>::SortChildren(BOOL bRecurse /*= FALSE*/)
  4322. {
  4323. ATLASSERT(m_pTreeView != NULL);
  4324. return m_pTreeView->SortChildren(m_hTreeItem, bRecurse);
  4325. }
  4326. template <class TBase>
  4327. inline BOOL CTreeItemT<TBase>::EnsureVisible()
  4328. {
  4329. ATLASSERT(m_pTreeView != NULL);
  4330. return m_pTreeView->EnsureVisible(m_hTreeItem);
  4331. }
  4332. template <class TBase>
  4333. inline CTreeItemT<TBase> CTreeItemT<TBase>::_Insert(LPCTSTR lpstrItem, int nImageIndex, HTREEITEM hItemAfter)
  4334. {
  4335. ATLASSERT(m_pTreeView != NULL);
  4336. TVINSERTSTRUCT ins = {};
  4337. ins.hParent = m_hTreeItem;
  4338. ins.hInsertAfter = hItemAfter;
  4339. ins.item.mask = TVIF_TEXT;
  4340. ins.item.pszText = (LPTSTR)lpstrItem;
  4341. if(nImageIndex != -1)
  4342. {
  4343. ins.item.mask |= TVIF_IMAGE | TVIF_SELECTEDIMAGE;
  4344. ins.item.iImage = nImageIndex;
  4345. ins.item.iSelectedImage = nImageIndex;
  4346. }
  4347. return CTreeItemT<TBase>(m_pTreeView->InsertItem(&ins), m_pTreeView);
  4348. }
  4349. template <class TBase>
  4350. inline int CTreeItemT<TBase>::GetImageIndex() const
  4351. {
  4352. ATLASSERT(m_pTreeView != NULL);
  4353. TVITEM item = {};
  4354. item.mask = TVIF_HANDLE | TVIF_IMAGE;
  4355. item.hItem = m_hTreeItem;
  4356. m_pTreeView->GetItem(&item);
  4357. return item.iImage;
  4358. }
  4359. template <class TBase>
  4360. inline BOOL CTreeItemT<TBase>::SetInsertMark(BOOL bAfter)
  4361. {
  4362. ATLASSERT(m_pTreeView != NULL);
  4363. return m_pTreeView->SetInsertMark(m_hTreeItem, bAfter);
  4364. }
  4365. template <class TBase>
  4366. inline UINT CTreeItemT<TBase>::MapHTREEITEMToAccID() const
  4367. {
  4368. ATLASSERT(m_pTreeView != NULL);
  4369. return m_pTreeView->MapHTREEITEMToAccID(m_hTreeItem);
  4370. }
  4371. #if (_WIN32_WINNT >= 0x0600)
  4372. template <class TBase>
  4373. inline void CTreeItemT<TBase>::ShowInfoTip()
  4374. {
  4375. ATLASSERT(m_pTreeView != NULL);
  4376. m_pTreeView->ShowInfoTip(m_hTreeItem);
  4377. }
  4378. template <class TBase>
  4379. inline BOOL CTreeItemT<TBase>::GetPartRect(TVITEMPART partID, LPRECT lpRect) const
  4380. {
  4381. ATLASSERT(m_pTreeView != NULL);
  4382. return m_pTreeView->GetItemPartRect(m_hTreeItem, partID, lpRect);
  4383. }
  4384. #endif // (_WIN32_WINNT >= 0x0600)
  4385. ///////////////////////////////////////////////////////////////////////////////
  4386. // CToolBarCtrl
  4387. template <class TBase>
  4388. class CToolBarCtrlT : public TBase
  4389. {
  4390. public:
  4391. // Construction
  4392. CToolBarCtrlT(HWND hWnd = NULL) : TBase(hWnd)
  4393. { }
  4394. CToolBarCtrlT< TBase >& operator =(HWND hWnd)
  4395. {
  4396. this->m_hWnd = hWnd;
  4397. return *this;
  4398. }
  4399. HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  4400. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  4401. ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  4402. {
  4403. return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  4404. }
  4405. // Attributes
  4406. static LPCTSTR GetWndClassName()
  4407. {
  4408. return TOOLBARCLASSNAME;
  4409. }
  4410. BOOL IsButtonEnabled(int nID) const
  4411. {
  4412. ATLASSERT(::IsWindow(this->m_hWnd));
  4413. return (BOOL)::SendMessage(this->m_hWnd, TB_ISBUTTONENABLED, nID, 0L);
  4414. }
  4415. BOOL IsButtonChecked(int nID) const
  4416. {
  4417. ATLASSERT(::IsWindow(this->m_hWnd));
  4418. return (BOOL)::SendMessage(this->m_hWnd, TB_ISBUTTONCHECKED, nID, 0L);
  4419. }
  4420. BOOL IsButtonPressed(int nID) const
  4421. {
  4422. ATLASSERT(::IsWindow(this->m_hWnd));
  4423. return (BOOL)::SendMessage(this->m_hWnd, TB_ISBUTTONPRESSED, nID, 0L);
  4424. }
  4425. BOOL IsButtonHidden(int nID) const
  4426. {
  4427. ATLASSERT(::IsWindow(this->m_hWnd));
  4428. return(BOOL) ::SendMessage(this->m_hWnd, TB_ISBUTTONHIDDEN, nID, 0L);
  4429. }
  4430. BOOL IsButtonIndeterminate(int nID) const
  4431. {
  4432. ATLASSERT(::IsWindow(this->m_hWnd));
  4433. return (BOOL)::SendMessage(this->m_hWnd, TB_ISBUTTONINDETERMINATE, nID, 0L);
  4434. }
  4435. int GetState(int nID) const
  4436. {
  4437. ATLASSERT(::IsWindow(this->m_hWnd));
  4438. return (int)::SendMessage(this->m_hWnd, TB_GETSTATE, nID, 0L);
  4439. }
  4440. BOOL SetState(int nID, UINT nState)
  4441. {
  4442. ATLASSERT(::IsWindow(this->m_hWnd));
  4443. return (BOOL)::SendMessage(this->m_hWnd, TB_SETSTATE, nID, MAKELPARAM(nState, 0));
  4444. }
  4445. BOOL GetButton(int nIndex, LPTBBUTTON lpButton) const
  4446. {
  4447. ATLASSERT(::IsWindow(this->m_hWnd));
  4448. return (BOOL)::SendMessage(this->m_hWnd, TB_GETBUTTON, nIndex, (LPARAM)lpButton);
  4449. }
  4450. int GetButtonCount() const
  4451. {
  4452. ATLASSERT(::IsWindow(this->m_hWnd));
  4453. return (int)::SendMessage(this->m_hWnd, TB_BUTTONCOUNT, 0, 0L);
  4454. }
  4455. BOOL GetItemRect(int nIndex, LPRECT lpRect) const
  4456. {
  4457. ATLASSERT(::IsWindow(this->m_hWnd));
  4458. return (BOOL)::SendMessage(this->m_hWnd, TB_GETITEMRECT, nIndex, (LPARAM)lpRect);
  4459. }
  4460. void SetButtonStructSize(int nSize = sizeof(TBBUTTON))
  4461. {
  4462. ATLASSERT(::IsWindow(this->m_hWnd));
  4463. ::SendMessage(this->m_hWnd, TB_BUTTONSTRUCTSIZE, nSize, 0L);
  4464. }
  4465. BOOL SetButtonSize(SIZE size)
  4466. {
  4467. ATLASSERT(::IsWindow(this->m_hWnd));
  4468. return (BOOL)::SendMessage(this->m_hWnd, TB_SETBUTTONSIZE, 0, MAKELPARAM(size.cx, size.cy));
  4469. }
  4470. BOOL SetButtonSize(int cx, int cy)
  4471. {
  4472. ATLASSERT(::IsWindow(this->m_hWnd));
  4473. return (BOOL)::SendMessage(this->m_hWnd, TB_SETBUTTONSIZE, 0, MAKELPARAM(cx, cy));
  4474. }
  4475. BOOL SetBitmapSize(SIZE size)
  4476. {
  4477. ATLASSERT(::IsWindow(this->m_hWnd));
  4478. return (BOOL)::SendMessage(this->m_hWnd, TB_SETBITMAPSIZE, 0, MAKELPARAM(size.cx, size.cy));
  4479. }
  4480. BOOL SetBitmapSize(int cx, int cy)
  4481. {
  4482. ATLASSERT(::IsWindow(this->m_hWnd));
  4483. return (BOOL)::SendMessage(this->m_hWnd, TB_SETBITMAPSIZE, 0, MAKELPARAM(cx, cy));
  4484. }
  4485. CToolTipCtrl GetToolTips() const
  4486. {
  4487. ATLASSERT(::IsWindow(this->m_hWnd));
  4488. return CToolTipCtrl((HWND)::SendMessage(this->m_hWnd, TB_GETTOOLTIPS, 0, 0L));
  4489. }
  4490. void SetToolTips(HWND hWndToolTip)
  4491. {
  4492. ATLASSERT(::IsWindow(this->m_hWnd));
  4493. ::SendMessage(this->m_hWnd, TB_SETTOOLTIPS, (WPARAM)hWndToolTip, 0L);
  4494. }
  4495. void SetNotifyWnd(HWND hWnd)
  4496. {
  4497. ATLASSERT(::IsWindow(this->m_hWnd));
  4498. ::SendMessage(this->m_hWnd, TB_SETPARENT, (WPARAM)hWnd, 0L);
  4499. }
  4500. int GetRows() const
  4501. {
  4502. ATLASSERT(::IsWindow(this->m_hWnd));
  4503. return (int)::SendMessage(this->m_hWnd, TB_GETROWS, 0, 0L);
  4504. }
  4505. void SetRows(int nRows, BOOL bLarger, LPRECT lpRect)
  4506. {
  4507. ATLASSERT(::IsWindow(this->m_hWnd));
  4508. ::SendMessage(this->m_hWnd, TB_SETROWS, MAKELPARAM(nRows, bLarger), (LPARAM)lpRect);
  4509. }
  4510. BOOL SetCmdID(int nIndex, UINT nID)
  4511. {
  4512. ATLASSERT(::IsWindow(this->m_hWnd));
  4513. return (BOOL)::SendMessage(this->m_hWnd, TB_SETCMDID, nIndex, nID);
  4514. }
  4515. DWORD GetBitmapFlags() const
  4516. {
  4517. ATLASSERT(::IsWindow(this->m_hWnd));
  4518. return (DWORD)::SendMessage(this->m_hWnd, TB_GETBITMAPFLAGS, 0, 0L);
  4519. }
  4520. int GetBitmap(int nID) const
  4521. {
  4522. ATLASSERT(::IsWindow(this->m_hWnd));
  4523. return (int)::SendMessage(this->m_hWnd, TB_GETBITMAP, nID, 0L);
  4524. }
  4525. int GetButtonText(int nID, LPTSTR lpstrText) const
  4526. {
  4527. ATLASSERT(::IsWindow(this->m_hWnd));
  4528. return (int)::SendMessage(this->m_hWnd, TB_GETBUTTONTEXT, nID, (LPARAM)lpstrText);
  4529. }
  4530. // nIndex - IE5 or higher only
  4531. CImageList GetImageList(int nIndex = 0) const
  4532. {
  4533. ATLASSERT(::IsWindow(this->m_hWnd));
  4534. return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, TB_GETIMAGELIST, nIndex, 0L));
  4535. }
  4536. // nIndex - IE5 or higher only
  4537. CImageList SetImageList(HIMAGELIST hImageList, int nIndex = 0)
  4538. {
  4539. ATLASSERT(::IsWindow(this->m_hWnd));
  4540. return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, TB_SETIMAGELIST, nIndex, (LPARAM)hImageList));
  4541. }
  4542. // nIndex - IE5 or higher only
  4543. CImageList GetDisabledImageList(int nIndex = 0) const
  4544. {
  4545. ATLASSERT(::IsWindow(this->m_hWnd));
  4546. return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, TB_GETDISABLEDIMAGELIST, nIndex, 0L));
  4547. }
  4548. // nIndex - IE5 or higher only
  4549. CImageList SetDisabledImageList(HIMAGELIST hImageList, int nIndex = 0)
  4550. {
  4551. ATLASSERT(::IsWindow(this->m_hWnd));
  4552. return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, TB_SETDISABLEDIMAGELIST, nIndex, (LPARAM)hImageList));
  4553. }
  4554. // nIndex - IE5 or higher only
  4555. CImageList GetHotImageList(int nIndex = 0) const
  4556. {
  4557. ATLASSERT(::IsWindow(this->m_hWnd));
  4558. return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, TB_GETHOTIMAGELIST, nIndex, 0L));
  4559. }
  4560. // nIndex - IE5 or higher only
  4561. CImageList SetHotImageList(HIMAGELIST hImageList, int nIndex = 0)
  4562. {
  4563. ATLASSERT(::IsWindow(this->m_hWnd));
  4564. return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, TB_SETHOTIMAGELIST, nIndex, (LPARAM)hImageList));
  4565. }
  4566. DWORD GetStyle() const
  4567. {
  4568. ATLASSERT(::IsWindow(this->m_hWnd));
  4569. return (DWORD)::SendMessage(this->m_hWnd, TB_GETSTYLE, 0, 0L);
  4570. }
  4571. void SetStyle(DWORD dwStyle)
  4572. {
  4573. ATLASSERT(::IsWindow(this->m_hWnd));
  4574. ::SendMessage(this->m_hWnd, TB_SETSTYLE, 0, dwStyle);
  4575. }
  4576. DWORD GetButtonSize() const
  4577. {
  4578. ATLASSERT(::IsWindow(this->m_hWnd));
  4579. return (DWORD)::SendMessage(this->m_hWnd, TB_GETBUTTONSIZE, 0, 0L);
  4580. }
  4581. void GetButtonSize(SIZE& size) const
  4582. {
  4583. ATLASSERT(::IsWindow(this->m_hWnd));
  4584. DWORD dwRet = (DWORD)::SendMessage(this->m_hWnd, TB_GETBUTTONSIZE, 0, 0L);
  4585. size.cx = LOWORD(dwRet);
  4586. size.cy = HIWORD(dwRet);
  4587. }
  4588. BOOL GetRect(int nID, LPRECT lpRect) const
  4589. {
  4590. ATLASSERT(::IsWindow(this->m_hWnd));
  4591. return (BOOL)::SendMessage(this->m_hWnd, TB_GETRECT, nID, (LPARAM)lpRect);
  4592. }
  4593. int GetTextRows() const
  4594. {
  4595. ATLASSERT(::IsWindow(this->m_hWnd));
  4596. return (int)::SendMessage(this->m_hWnd, TB_GETTEXTROWS, 0, 0L);
  4597. }
  4598. BOOL SetButtonWidth(int cxMin, int cxMax)
  4599. {
  4600. ATLASSERT(::IsWindow(this->m_hWnd));
  4601. return (BOOL)::SendMessage(this->m_hWnd, TB_SETBUTTONWIDTH, 0, MAKELPARAM(cxMin, cxMax));
  4602. }
  4603. BOOL SetIndent(int nIndent)
  4604. {
  4605. ATLASSERT(::IsWindow(this->m_hWnd));
  4606. return (BOOL)::SendMessage(this->m_hWnd, TB_SETINDENT, nIndent, 0L);
  4607. }
  4608. BOOL SetMaxTextRows(int nMaxTextRows)
  4609. {
  4610. ATLASSERT(::IsWindow(this->m_hWnd));
  4611. return (BOOL)::SendMessage(this->m_hWnd, TB_SETMAXTEXTROWS, nMaxTextRows, 0L);
  4612. }
  4613. BOOL GetAnchorHighlight() const
  4614. {
  4615. ATLASSERT(::IsWindow(this->m_hWnd));
  4616. return (BOOL)::SendMessage(this->m_hWnd, TB_GETANCHORHIGHLIGHT, 0, 0L);
  4617. }
  4618. BOOL SetAnchorHighlight(BOOL bEnable = TRUE)
  4619. {
  4620. ATLASSERT(::IsWindow(this->m_hWnd));
  4621. return (BOOL)::SendMessage(this->m_hWnd, TB_SETANCHORHIGHLIGHT, bEnable, 0L);
  4622. }
  4623. int GetButtonInfo(int nID, LPTBBUTTONINFO lptbbi) const
  4624. {
  4625. ATLASSERT(::IsWindow(this->m_hWnd));
  4626. return (int)::SendMessage(this->m_hWnd, TB_GETBUTTONINFO, nID, (LPARAM)lptbbi);
  4627. }
  4628. BOOL SetButtonInfo(int nID, LPTBBUTTONINFO lptbbi)
  4629. {
  4630. ATLASSERT(::IsWindow(this->m_hWnd));
  4631. return (BOOL)::SendMessage(this->m_hWnd, TB_SETBUTTONINFO, nID, (LPARAM)lptbbi);
  4632. }
  4633. BOOL SetButtonInfo(int nID, DWORD dwMask, BYTE Style, BYTE State, LPCTSTR lpszItem,
  4634. int iImage, WORD cx, int iCommand, DWORD_PTR lParam)
  4635. {
  4636. ATLASSERT(::IsWindow(this->m_hWnd));
  4637. TBBUTTONINFO tbbi = {};
  4638. tbbi.cbSize = sizeof(TBBUTTONINFO);
  4639. tbbi.dwMask = dwMask;
  4640. tbbi.idCommand = iCommand;
  4641. tbbi.iImage = iImage;
  4642. tbbi.fsState = State;
  4643. tbbi.fsStyle = Style;
  4644. tbbi.cx = cx;
  4645. tbbi.pszText = (LPTSTR) lpszItem;
  4646. tbbi.lParam = lParam;
  4647. return (BOOL)::SendMessage(this->m_hWnd, TB_SETBUTTONINFO, nID, (LPARAM)&tbbi);
  4648. }
  4649. int GetHotItem() const
  4650. {
  4651. ATLASSERT(::IsWindow(this->m_hWnd));
  4652. return (int)::SendMessage(this->m_hWnd, TB_GETHOTITEM, 0, 0L);
  4653. }
  4654. int SetHotItem(int nItem)
  4655. {
  4656. ATLASSERT(::IsWindow(this->m_hWnd));
  4657. return (int)::SendMessage(this->m_hWnd, TB_SETHOTITEM, nItem, 0L);
  4658. }
  4659. BOOL IsButtonHighlighted(int nButtonID) const
  4660. {
  4661. ATLASSERT(::IsWindow(this->m_hWnd));
  4662. return (BOOL)::SendMessage(this->m_hWnd, TB_ISBUTTONHIGHLIGHTED, nButtonID, 0L);
  4663. }
  4664. DWORD SetDrawTextFlags(DWORD dwMask, DWORD dwFlags)
  4665. {
  4666. ATLASSERT(::IsWindow(this->m_hWnd));
  4667. return (DWORD)::SendMessage(this->m_hWnd, TB_SETDRAWTEXTFLAGS, dwMask, dwFlags);
  4668. }
  4669. BOOL GetColorScheme(LPCOLORSCHEME lpcs) const
  4670. {
  4671. ATLASSERT(::IsWindow(this->m_hWnd));
  4672. return (BOOL)::SendMessage(this->m_hWnd, TB_GETCOLORSCHEME, 0, (LPARAM)lpcs);
  4673. }
  4674. void SetColorScheme(LPCOLORSCHEME lpcs)
  4675. {
  4676. ATLASSERT(::IsWindow(this->m_hWnd));
  4677. ::SendMessage(this->m_hWnd, TB_SETCOLORSCHEME, 0, (LPARAM)lpcs);
  4678. }
  4679. DWORD GetExtendedStyle() const
  4680. {
  4681. ATLASSERT(::IsWindow(this->m_hWnd));
  4682. return (DWORD)::SendMessage(this->m_hWnd, TB_GETEXTENDEDSTYLE, 0, 0L);
  4683. }
  4684. DWORD SetExtendedStyle(DWORD dwStyle)
  4685. {
  4686. ATLASSERT(::IsWindow(this->m_hWnd));
  4687. return (DWORD)::SendMessage(this->m_hWnd, TB_SETEXTENDEDSTYLE, 0, dwStyle);
  4688. }
  4689. void GetInsertMark(LPTBINSERTMARK lptbim) const
  4690. {
  4691. ATLASSERT(::IsWindow(this->m_hWnd));
  4692. ::SendMessage(this->m_hWnd, TB_GETINSERTMARK, 0, (LPARAM)lptbim);
  4693. }
  4694. void SetInsertMark(LPTBINSERTMARK lptbim)
  4695. {
  4696. ATLASSERT(::IsWindow(this->m_hWnd));
  4697. ::SendMessage(this->m_hWnd, TB_SETINSERTMARK, 0, (LPARAM)lptbim);
  4698. }
  4699. COLORREF GetInsertMarkColor() const
  4700. {
  4701. ATLASSERT(::IsWindow(this->m_hWnd));
  4702. return (COLORREF)::SendMessage(this->m_hWnd, TB_GETINSERTMARKCOLOR, 0, 0L);
  4703. }
  4704. COLORREF SetInsertMarkColor(COLORREF clr)
  4705. {
  4706. ATLASSERT(::IsWindow(this->m_hWnd));
  4707. return (COLORREF)::SendMessage(this->m_hWnd, TB_SETINSERTMARKCOLOR, 0, (LPARAM)clr);
  4708. }
  4709. BOOL GetMaxSize(LPSIZE lpSize) const
  4710. {
  4711. ATLASSERT(::IsWindow(this->m_hWnd));
  4712. return (BOOL)::SendMessage(this->m_hWnd, TB_GETMAXSIZE, 0, (LPARAM)lpSize);
  4713. }
  4714. void GetPadding(LPSIZE lpSizePadding) const
  4715. {
  4716. ATLASSERT(::IsWindow(this->m_hWnd));
  4717. ATLASSERT(lpSizePadding != NULL);
  4718. DWORD dwRet = (DWORD)::SendMessage(this->m_hWnd, TB_GETPADDING, 0, 0L);
  4719. lpSizePadding->cx = GET_X_LPARAM(dwRet);
  4720. lpSizePadding->cy = GET_Y_LPARAM(dwRet);
  4721. }
  4722. void SetPadding(int cx, int cy, LPSIZE lpSizePadding = NULL)
  4723. {
  4724. ATLASSERT(::IsWindow(this->m_hWnd));
  4725. DWORD dwRet = (DWORD)::SendMessage(this->m_hWnd, TB_SETPADDING, 0, MAKELPARAM(cx, cy));
  4726. if(lpSizePadding != NULL)
  4727. {
  4728. lpSizePadding->cx = GET_X_LPARAM(dwRet);
  4729. lpSizePadding->cy = GET_Y_LPARAM(dwRet);
  4730. }
  4731. }
  4732. BOOL GetUnicodeFormat() const
  4733. {
  4734. ATLASSERT(::IsWindow(this->m_hWnd));
  4735. return (BOOL)::SendMessage(this->m_hWnd, TB_GETUNICODEFORMAT, 0, 0L);
  4736. }
  4737. BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
  4738. {
  4739. ATLASSERT(::IsWindow(this->m_hWnd));
  4740. return (BOOL)::SendMessage(this->m_hWnd, TB_SETUNICODEFORMAT, bUnicode, 0L);
  4741. }
  4742. int GetString(int nString, LPTSTR lpstrString, int cchMaxLen) const
  4743. {
  4744. ATLASSERT(::IsWindow(this->m_hWnd));
  4745. return (int)::SendMessage(this->m_hWnd, TB_GETSTRING, MAKEWPARAM(cchMaxLen, nString), (LPARAM)lpstrString);
  4746. }
  4747. int GetStringBSTR(int nString, BSTR& bstrString) const
  4748. {
  4749. USES_CONVERSION;
  4750. ATLASSERT(::IsWindow(this->m_hWnd));
  4751. ATLASSERT(bstrString == NULL);
  4752. int nLength = (int)(short)LOWORD(::SendMessage(this->m_hWnd, TB_GETSTRING, MAKEWPARAM(0, nString), NULL));
  4753. if(nLength != -1)
  4754. {
  4755. ATL::CTempBuffer<TCHAR, _WTL_STACK_ALLOC_THRESHOLD> buff;
  4756. LPTSTR lpstrText = buff.Allocate(nLength + 1);
  4757. if(lpstrText != NULL)
  4758. {
  4759. nLength = (int)::SendMessage(this->m_hWnd, TB_GETSTRING, MAKEWPARAM(nLength + 1, nString), (LPARAM)lpstrText);
  4760. if(nLength != -1)
  4761. bstrString = ::SysAllocString(T2OLE(lpstrText));
  4762. }
  4763. else
  4764. {
  4765. nLength = -1;
  4766. }
  4767. }
  4768. return nLength;
  4769. }
  4770. #ifdef __ATLSTR_H__
  4771. int GetString(int nString, ATL::CString& str) const
  4772. {
  4773. ATLASSERT(::IsWindow(this->m_hWnd));
  4774. int nLength = (int)(short)LOWORD(::SendMessage(this->m_hWnd, TB_GETSTRING, MAKEWPARAM(0, nString), NULL));
  4775. if(nLength != -1)
  4776. {
  4777. LPTSTR lpstr = str.GetBufferSetLength(nLength + 1);
  4778. if(lpstr != NULL)
  4779. nLength = (int)::SendMessage(this->m_hWnd, TB_GETSTRING, MAKEWPARAM(nLength + 1, nString), (LPARAM)lpstr);
  4780. else
  4781. nLength = -1;
  4782. str.ReleaseBuffer();
  4783. }
  4784. return nLength;
  4785. }
  4786. #endif // __ATLSTR_H__
  4787. void GetMetrics(LPTBMETRICS lptbm) const
  4788. {
  4789. ATLASSERT(::IsWindow(this->m_hWnd));
  4790. ::SendMessage(this->m_hWnd, TB_GETMETRICS, 0, (LPARAM)lptbm);
  4791. }
  4792. void SetMetrics(LPTBMETRICS lptbm)
  4793. {
  4794. ATLASSERT(::IsWindow(this->m_hWnd));
  4795. ::SendMessage(this->m_hWnd, TB_SETMETRICS, 0, (LPARAM)lptbm);
  4796. }
  4797. void SetWindowTheme(LPCWSTR lpstrTheme)
  4798. {
  4799. ATLASSERT(::IsWindow(this->m_hWnd));
  4800. ::SendMessage(this->m_hWnd, TB_SETWINDOWTHEME, 0, (LPARAM)lpstrTheme);
  4801. }
  4802. #if (_WIN32_WINNT >= 0x0600)
  4803. CImageList GetPressedImageList(int nIndex = 0) const
  4804. {
  4805. ATLASSERT(::IsWindow(this->m_hWnd));
  4806. return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, TB_GETPRESSEDIMAGELIST, nIndex, 0L));
  4807. }
  4808. CImageList SetPressedImageList(HIMAGELIST hImageList, int nIndex = 0)
  4809. {
  4810. ATLASSERT(::IsWindow(this->m_hWnd));
  4811. return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, TB_SETPRESSEDIMAGELIST, nIndex, (LPARAM)hImageList));
  4812. }
  4813. void GetItemDropDownRect(int nIndex, LPRECT lpRect) const
  4814. {
  4815. #ifndef TB_GETITEMDROPDOWNRECT
  4816. const int TB_GETITEMDROPDOWNRECT = WM_USER + 103;
  4817. #endif
  4818. ATLASSERT(::IsWindow(this->m_hWnd));
  4819. BOOL bRet = (BOOL)::SendMessage(this->m_hWnd, TB_GETITEMDROPDOWNRECT, nIndex, (LPARAM)lpRect);
  4820. (void)bRet; // avoid level 4 warning
  4821. ATLASSERT(bRet != FALSE);
  4822. }
  4823. #endif // (_WIN32_WINNT >= 0x0600)
  4824. // Operations
  4825. BOOL EnableButton(int nID, BOOL bEnable = TRUE)
  4826. {
  4827. ATLASSERT(::IsWindow(this->m_hWnd));
  4828. return (BOOL)::SendMessage(this->m_hWnd, TB_ENABLEBUTTON, nID, MAKELPARAM(bEnable, 0));
  4829. }
  4830. BOOL CheckButton(int nID, BOOL bCheck = TRUE)
  4831. {
  4832. ATLASSERT(::IsWindow(this->m_hWnd));
  4833. return (BOOL)::SendMessage(this->m_hWnd, TB_CHECKBUTTON, nID, MAKELPARAM(bCheck, 0));
  4834. }
  4835. BOOL PressButton(int nID, BOOL bPress = TRUE)
  4836. {
  4837. ATLASSERT(::IsWindow(this->m_hWnd));
  4838. return (BOOL)::SendMessage(this->m_hWnd, TB_PRESSBUTTON, nID, MAKELPARAM(bPress, 0));
  4839. }
  4840. BOOL HideButton(int nID, BOOL bHide = TRUE)
  4841. {
  4842. ATLASSERT(::IsWindow(this->m_hWnd));
  4843. return (BOOL)::SendMessage(this->m_hWnd, TB_HIDEBUTTON, nID, MAKELPARAM(bHide, 0));
  4844. }
  4845. BOOL Indeterminate(int nID, BOOL bIndeterminate = TRUE)
  4846. {
  4847. ATLASSERT(::IsWindow(this->m_hWnd));
  4848. return (BOOL)::SendMessage(this->m_hWnd, TB_INDETERMINATE, nID, MAKELPARAM(bIndeterminate, 0));
  4849. }
  4850. int AddBitmap(int nNumButtons, UINT nBitmapID)
  4851. {
  4852. ATLASSERT(::IsWindow(this->m_hWnd));
  4853. TBADDBITMAP tbab = {};
  4854. tbab.hInst = ModuleHelper::GetResourceInstance();
  4855. ATLASSERT(tbab.hInst != NULL);
  4856. tbab.nID = nBitmapID;
  4857. return (int)::SendMessage(this->m_hWnd, TB_ADDBITMAP, (WPARAM)nNumButtons, (LPARAM)&tbab);
  4858. }
  4859. int AddBitmap(int nNumButtons, HBITMAP hBitmap)
  4860. {
  4861. ATLASSERT(::IsWindow(this->m_hWnd));
  4862. TBADDBITMAP tbab = {};
  4863. tbab.hInst = NULL;
  4864. tbab.nID = (UINT_PTR)hBitmap;
  4865. return (int)::SendMessage(this->m_hWnd, TB_ADDBITMAP, (WPARAM)nNumButtons, (LPARAM)&tbab);
  4866. }
  4867. BOOL AddButtons(int nNumButtons, LPCTBBUTTON lpButtons)
  4868. {
  4869. ATLASSERT(::IsWindow(this->m_hWnd));
  4870. return (BOOL)::SendMessage(this->m_hWnd, TB_ADDBUTTONS, nNumButtons, (LPARAM)lpButtons);
  4871. }
  4872. BOOL InsertButton(int nIndex, LPCTBBUTTON lpButton)
  4873. {
  4874. ATLASSERT(::IsWindow(this->m_hWnd));
  4875. return (BOOL)::SendMessage(this->m_hWnd, TB_INSERTBUTTON, nIndex, (LPARAM)lpButton);
  4876. }
  4877. BOOL InsertButton(int nIndex, int iCommand, BYTE Style, BYTE State, int iBitmap,
  4878. INT_PTR iString, DWORD_PTR lParam)
  4879. {
  4880. ATLASSERT(::IsWindow(this->m_hWnd));
  4881. TBBUTTON tbb = {};
  4882. tbb.fsStyle = Style;
  4883. tbb.fsState = State;
  4884. tbb.idCommand = iCommand;
  4885. tbb.iBitmap = iBitmap;
  4886. tbb.iString = iString;
  4887. tbb.dwData = lParam;
  4888. return (BOOL)::SendMessage(this->m_hWnd, TB_INSERTBUTTON, nIndex, (LPARAM)&tbb);
  4889. }
  4890. BOOL InsertButton(int nIndex, int iCommand, BYTE Style, BYTE State, int iBitmap,
  4891. LPCTSTR lpszItem, DWORD_PTR lParam)
  4892. {
  4893. return InsertButton(nIndex, iCommand, Style, State, iBitmap, (INT_PTR)lpszItem, lParam);
  4894. }
  4895. BOOL AddButton(LPTBBUTTON lpButton)
  4896. {
  4897. return InsertButton(-1, lpButton);
  4898. }
  4899. BOOL AddButton(int iCommand, BYTE Style, BYTE State, int iBitmap, INT_PTR iString, DWORD_PTR lParam)
  4900. {
  4901. return InsertButton(-1, iCommand, Style, State, iBitmap, iString, lParam);
  4902. }
  4903. BOOL AddButton(int iCommand, BYTE Style, BYTE State, int iBitmap, LPCTSTR lpszItem, DWORD_PTR lParam)
  4904. {
  4905. return InsertButton(-1, iCommand, Style, State, iBitmap, lpszItem, lParam);
  4906. }
  4907. BOOL DeleteButton(int nIndex)
  4908. {
  4909. ATLASSERT(::IsWindow(this->m_hWnd));
  4910. return (BOOL)::SendMessage(this->m_hWnd, TB_DELETEBUTTON, nIndex, 0L);
  4911. }
  4912. BOOL InsertSeparator(int nIndex, int cxWidth = 8)
  4913. {
  4914. return InsertButton(nIndex, 0, BTNS_SEP, 0, cxWidth, (INT_PTR)0, 0);
  4915. }
  4916. BOOL AddSeparator(int cxWidth = 8)
  4917. {
  4918. return AddButton(0, BTNS_SEP, 0, cxWidth, (INT_PTR)0, 0);
  4919. }
  4920. int CommandToIndex(UINT nID) const
  4921. {
  4922. ATLASSERT(::IsWindow(this->m_hWnd));
  4923. return (int)::SendMessage(this->m_hWnd, TB_COMMANDTOINDEX, nID, 0L);
  4924. }
  4925. void SaveState(HKEY hKeyRoot, LPCTSTR lpszSubKey, LPCTSTR lpszValueName)
  4926. {
  4927. ATLASSERT(::IsWindow(this->m_hWnd));
  4928. TBSAVEPARAMS tbs = {};
  4929. tbs.hkr = hKeyRoot;
  4930. tbs.pszSubKey = lpszSubKey;
  4931. tbs.pszValueName = lpszValueName;
  4932. ::SendMessage(this->m_hWnd, TB_SAVERESTORE, (WPARAM)TRUE, (LPARAM)&tbs);
  4933. }
  4934. void RestoreState(HKEY hKeyRoot, LPCTSTR lpszSubKey, LPCTSTR lpszValueName)
  4935. {
  4936. ATLASSERT(::IsWindow(this->m_hWnd));
  4937. TBSAVEPARAMS tbs = {};
  4938. tbs.hkr = hKeyRoot;
  4939. tbs.pszSubKey = lpszSubKey;
  4940. tbs.pszValueName = lpszValueName;
  4941. ::SendMessage(this->m_hWnd, TB_SAVERESTORE, (WPARAM)FALSE, (LPARAM)&tbs);
  4942. }
  4943. void Customize()
  4944. {
  4945. ATLASSERT(::IsWindow(this->m_hWnd));
  4946. ::SendMessage(this->m_hWnd, TB_CUSTOMIZE, 0, 0L);
  4947. }
  4948. int AddString(UINT nStringID)
  4949. {
  4950. ATLASSERT(::IsWindow(this->m_hWnd));
  4951. return (int)::SendMessage(this->m_hWnd, TB_ADDSTRING, (WPARAM)ModuleHelper::GetResourceInstance(), (LPARAM)nStringID);
  4952. }
  4953. int AddStrings(LPCTSTR lpszStrings)
  4954. {
  4955. ATLASSERT(::IsWindow(this->m_hWnd));
  4956. return (int)::SendMessage(this->m_hWnd, TB_ADDSTRING, 0, (LPARAM)lpszStrings);
  4957. }
  4958. void AutoSize()
  4959. {
  4960. ATLASSERT(::IsWindow(this->m_hWnd));
  4961. ::SendMessage(this->m_hWnd, TB_AUTOSIZE, 0, 0L);
  4962. }
  4963. BOOL ChangeBitmap(int nID, int nBitmap)
  4964. {
  4965. ATLASSERT(::IsWindow(this->m_hWnd));
  4966. return (BOOL)::SendMessage(this->m_hWnd, TB_CHANGEBITMAP, nID, MAKELPARAM(nBitmap, 0));
  4967. }
  4968. int LoadImages(int nBitmapID)
  4969. {
  4970. ATLASSERT(::IsWindow(this->m_hWnd));
  4971. return (int)::SendMessage(this->m_hWnd, TB_LOADIMAGES, nBitmapID, (LPARAM)ModuleHelper::GetResourceInstance());
  4972. }
  4973. int LoadStdImages(int nBitmapID)
  4974. {
  4975. ATLASSERT(::IsWindow(this->m_hWnd));
  4976. return (int)::SendMessage(this->m_hWnd, TB_LOADIMAGES, nBitmapID, (LPARAM)HINST_COMMCTRL);
  4977. }
  4978. BOOL ReplaceBitmap(LPTBREPLACEBITMAP ptbrb)
  4979. {
  4980. ATLASSERT(::IsWindow(this->m_hWnd));
  4981. return (BOOL)::SendMessage(this->m_hWnd, TB_REPLACEBITMAP, 0, (LPARAM)ptbrb);
  4982. }
  4983. int HitTest(LPPOINT lpPoint) const
  4984. {
  4985. ATLASSERT(::IsWindow(this->m_hWnd));
  4986. return (int)::SendMessage(this->m_hWnd, TB_HITTEST, 0, (LPARAM)lpPoint);
  4987. }
  4988. BOOL InsertMarkHitTest(LPPOINT lpPoint, LPTBINSERTMARK lptbim) const
  4989. {
  4990. ATLASSERT(::IsWindow(this->m_hWnd));
  4991. return (BOOL)::SendMessage(this->m_hWnd, TB_INSERTMARKHITTEST, (WPARAM)lpPoint, (LPARAM)lptbim);
  4992. }
  4993. BOOL InsertMarkHitTest(int x, int y, LPTBINSERTMARK lptbim) const
  4994. {
  4995. ATLASSERT(::IsWindow(this->m_hWnd));
  4996. POINT pt = { x, y };
  4997. return (BOOL)::SendMessage(this->m_hWnd, TB_INSERTMARKHITTEST, (WPARAM)&pt, (LPARAM)lptbim);
  4998. }
  4999. BOOL MapAccelerator(TCHAR chAccel, int& nID) const
  5000. {
  5001. ATLASSERT(::IsWindow(this->m_hWnd));
  5002. return (BOOL)::SendMessage(this->m_hWnd, TB_MAPACCELERATOR, (WPARAM)chAccel, (LPARAM)&nID);
  5003. }
  5004. BOOL MarkButton(int nID, BOOL bHighlight = TRUE)
  5005. {
  5006. ATLASSERT(::IsWindow(this->m_hWnd));
  5007. return (BOOL)::SendMessage(this->m_hWnd, TB_MARKBUTTON, nID, MAKELPARAM(bHighlight, 0));
  5008. }
  5009. BOOL MoveButton(int nOldPos, int nNewPos)
  5010. {
  5011. ATLASSERT(::IsWindow(this->m_hWnd));
  5012. return (BOOL)::SendMessage(this->m_hWnd, TB_MOVEBUTTON, nOldPos, nNewPos);
  5013. }
  5014. HRESULT GetObject(REFIID iid, LPVOID* ppvObject)
  5015. {
  5016. ATLASSERT(::IsWindow(this->m_hWnd));
  5017. return (HRESULT)::SendMessage(this->m_hWnd, TB_GETOBJECT, (WPARAM)&iid, (LPARAM)ppvObject);
  5018. }
  5019. };
  5020. typedef CToolBarCtrlT<ATL::CWindow> CToolBarCtrl;
  5021. ///////////////////////////////////////////////////////////////////////////////
  5022. // CStatusBarCtrl
  5023. template <class TBase>
  5024. class CStatusBarCtrlT : public TBase
  5025. {
  5026. public:
  5027. // Constructors
  5028. CStatusBarCtrlT(HWND hWnd = NULL) : TBase(hWnd)
  5029. { }
  5030. CStatusBarCtrlT< TBase >& operator =(HWND hWnd)
  5031. {
  5032. this->m_hWnd = hWnd;
  5033. return *this;
  5034. }
  5035. HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  5036. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  5037. ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  5038. {
  5039. return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  5040. }
  5041. // Methods
  5042. static LPCTSTR GetWndClassName()
  5043. {
  5044. return STATUSCLASSNAME;
  5045. }
  5046. int GetParts(int nParts, int* pParts) const
  5047. {
  5048. ATLASSERT(::IsWindow(this->m_hWnd));
  5049. return (int)::SendMessage(this->m_hWnd, SB_GETPARTS, nParts, (LPARAM)pParts);
  5050. }
  5051. BOOL SetParts(int nParts, int* pWidths)
  5052. {
  5053. ATLASSERT(::IsWindow(this->m_hWnd));
  5054. return (BOOL)::SendMessage(this->m_hWnd, SB_SETPARTS, nParts, (LPARAM)pWidths);
  5055. }
  5056. int GetTextLength(int nPane, int* pType = NULL) const
  5057. {
  5058. ATLASSERT(::IsWindow(this->m_hWnd));
  5059. ATLASSERT(nPane < 256);
  5060. DWORD dwRet = (DWORD)::SendMessage(this->m_hWnd, SB_GETTEXTLENGTH, (WPARAM)nPane, 0L);
  5061. if (pType != NULL)
  5062. *pType = (int)(short)HIWORD(dwRet);
  5063. return (int)(short)LOWORD(dwRet);
  5064. }
  5065. int GetText(int nPane, LPTSTR lpszText, int* pType = NULL) const
  5066. {
  5067. ATLASSERT(::IsWindow(this->m_hWnd));
  5068. ATLASSERT(nPane < 256);
  5069. DWORD dwRet = (DWORD)::SendMessage(this->m_hWnd, SB_GETTEXT, (WPARAM)nPane, (LPARAM)lpszText);
  5070. if(pType != NULL)
  5071. *pType = (int)(short)HIWORD(dwRet);
  5072. return (int)(short)LOWORD(dwRet);
  5073. }
  5074. BOOL GetTextBSTR(int nPane, BSTR& bstrText, int* pType = NULL) const
  5075. {
  5076. USES_CONVERSION;
  5077. ATLASSERT(::IsWindow(this->m_hWnd));
  5078. ATLASSERT(nPane < 256);
  5079. ATLASSERT(bstrText == NULL);
  5080. int nLength = (int)(short)LOWORD(::SendMessage(this->m_hWnd, SB_GETTEXTLENGTH, (WPARAM)nPane, 0L));
  5081. if(nLength == 0)
  5082. return FALSE;
  5083. ATL::CTempBuffer<TCHAR, _WTL_STACK_ALLOC_THRESHOLD> buff;
  5084. LPTSTR lpstrText = buff.Allocate(nLength + 1);
  5085. if(lpstrText == NULL)
  5086. return FALSE;
  5087. if(!GetText(nPane, lpstrText, pType))
  5088. return FALSE;
  5089. bstrText = ::SysAllocString(T2OLE(lpstrText));
  5090. return (bstrText != NULL) ? TRUE : FALSE;
  5091. }
  5092. #ifdef __ATLSTR_H__
  5093. int GetText(int nPane, ATL::CString& strText, int* pType = NULL) const
  5094. {
  5095. ATLASSERT(::IsWindow(this->m_hWnd));
  5096. ATLASSERT(nPane < 256);
  5097. int nLength = (int)(short)LOWORD(::SendMessage(this->m_hWnd, SB_GETTEXTLENGTH, (WPARAM)nPane, 0L));
  5098. if(nLength == 0)
  5099. return 0;
  5100. LPTSTR lpstr = strText.GetBufferSetLength(nLength);
  5101. if(lpstr == NULL)
  5102. return 0;
  5103. return GetText(nPane, lpstr, pType);
  5104. }
  5105. #endif // __ATLSTR_H__
  5106. BOOL SetText(int nPane, LPCTSTR lpszText, int nType = 0)
  5107. {
  5108. ATLASSERT(::IsWindow(this->m_hWnd));
  5109. ATLASSERT(nPane < 256);
  5110. return (BOOL)::SendMessage(this->m_hWnd, SB_SETTEXT, (nPane | nType), (LPARAM)lpszText);
  5111. }
  5112. BOOL GetRect(int nPane, LPRECT lpRect) const
  5113. {
  5114. ATLASSERT(::IsWindow(this->m_hWnd));
  5115. ATLASSERT(nPane < 256);
  5116. return (BOOL)::SendMessage(this->m_hWnd, SB_GETRECT, nPane, (LPARAM)lpRect);
  5117. }
  5118. BOOL GetBorders(int* pBorders) const
  5119. {
  5120. ATLASSERT(::IsWindow(this->m_hWnd));
  5121. return (BOOL)::SendMessage(this->m_hWnd, SB_GETBORDERS, 0, (LPARAM)pBorders);
  5122. }
  5123. BOOL GetBorders(int& nHorz, int& nVert, int& nSpacing) const
  5124. {
  5125. ATLASSERT(::IsWindow(this->m_hWnd));
  5126. int borders[3] = {};
  5127. BOOL bResult = (BOOL)::SendMessage(this->m_hWnd, SB_GETBORDERS, 0, (LPARAM)&borders);
  5128. if(bResult)
  5129. {
  5130. nHorz = borders[0];
  5131. nVert = borders[1];
  5132. nSpacing = borders[2];
  5133. }
  5134. return bResult;
  5135. }
  5136. void SetMinHeight(int nMin)
  5137. {
  5138. ATLASSERT(::IsWindow(this->m_hWnd));
  5139. ::SendMessage(this->m_hWnd, SB_SETMINHEIGHT, nMin, 0L);
  5140. }
  5141. BOOL SetSimple(BOOL bSimple = TRUE)
  5142. {
  5143. ATLASSERT(::IsWindow(this->m_hWnd));
  5144. return (BOOL)::SendMessage(this->m_hWnd, SB_SIMPLE, bSimple, 0L);
  5145. }
  5146. BOOL IsSimple() const
  5147. {
  5148. ATLASSERT(::IsWindow(this->m_hWnd));
  5149. return (BOOL)::SendMessage(this->m_hWnd, SB_ISSIMPLE, 0, 0L);
  5150. }
  5151. BOOL GetUnicodeFormat() const
  5152. {
  5153. ATLASSERT(::IsWindow(this->m_hWnd));
  5154. return (BOOL)::SendMessage(this->m_hWnd, SB_GETUNICODEFORMAT, 0, 0L);
  5155. }
  5156. BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
  5157. {
  5158. ATLASSERT(::IsWindow(this->m_hWnd));
  5159. return (BOOL)::SendMessage(this->m_hWnd, SB_SETUNICODEFORMAT, bUnicode, 0L);
  5160. }
  5161. void GetTipText(int nPane, LPTSTR lpstrText, int nSize) const
  5162. {
  5163. ATLASSERT(::IsWindow(this->m_hWnd));
  5164. ATLASSERT(nPane < 256);
  5165. ::SendMessage(this->m_hWnd, SB_GETTIPTEXT, MAKEWPARAM(nPane, nSize), (LPARAM)lpstrText);
  5166. }
  5167. void SetTipText(int nPane, LPCTSTR lpstrText)
  5168. {
  5169. ATLASSERT(::IsWindow(this->m_hWnd));
  5170. ATLASSERT(nPane < 256);
  5171. ::SendMessage(this->m_hWnd, SB_SETTIPTEXT, nPane, (LPARAM)lpstrText);
  5172. }
  5173. COLORREF SetBkColor(COLORREF clrBk)
  5174. {
  5175. ATLASSERT(::IsWindow(this->m_hWnd));
  5176. return (COLORREF)::SendMessage(this->m_hWnd, SB_SETBKCOLOR, 0, (LPARAM)clrBk);
  5177. }
  5178. HICON GetIcon(int nPane) const
  5179. {
  5180. ATLASSERT(::IsWindow(this->m_hWnd));
  5181. ATLASSERT(nPane < 256);
  5182. return (HICON)::SendMessage(this->m_hWnd, SB_GETICON, nPane, 0L);
  5183. }
  5184. BOOL SetIcon(int nPane, HICON hIcon)
  5185. {
  5186. ATLASSERT(::IsWindow(this->m_hWnd));
  5187. ATLASSERT(nPane < 256);
  5188. return (BOOL)::SendMessage(this->m_hWnd, SB_SETICON, nPane, (LPARAM)hIcon);
  5189. }
  5190. };
  5191. typedef CStatusBarCtrlT<ATL::CWindow> CStatusBarCtrl;
  5192. ///////////////////////////////////////////////////////////////////////////////
  5193. // CTabCtrl
  5194. template <class TBase>
  5195. class CTabCtrlT : public TBase
  5196. {
  5197. public:
  5198. // Constructors
  5199. CTabCtrlT(HWND hWnd = NULL) : TBase(hWnd)
  5200. { }
  5201. CTabCtrlT< TBase >& operator =(HWND hWnd)
  5202. {
  5203. this->m_hWnd = hWnd;
  5204. return *this;
  5205. }
  5206. HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  5207. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  5208. ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  5209. {
  5210. return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  5211. }
  5212. // Attributes
  5213. static LPCTSTR GetWndClassName()
  5214. {
  5215. return WC_TABCONTROL;
  5216. }
  5217. CImageList GetImageList() const
  5218. {
  5219. ATLASSERT(::IsWindow(this->m_hWnd));
  5220. return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, TCM_GETIMAGELIST, 0, 0L));
  5221. }
  5222. CImageList SetImageList(HIMAGELIST hImageList)
  5223. {
  5224. ATLASSERT(::IsWindow(this->m_hWnd));
  5225. return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, TCM_SETIMAGELIST, 0, (LPARAM)hImageList));
  5226. }
  5227. int GetItemCount() const
  5228. {
  5229. ATLASSERT(::IsWindow(this->m_hWnd));
  5230. return (int)::SendMessage(this->m_hWnd, TCM_GETITEMCOUNT, 0, 0L);
  5231. }
  5232. BOOL GetItem(int nItem, LPTCITEM pTabCtrlItem) const
  5233. {
  5234. ATLASSERT(::IsWindow(this->m_hWnd));
  5235. return (BOOL)::SendMessage(this->m_hWnd, TCM_GETITEM, nItem, (LPARAM)pTabCtrlItem);
  5236. }
  5237. BOOL SetItem(int nItem, LPTCITEM pTabCtrlItem)
  5238. {
  5239. ATLASSERT(::IsWindow(this->m_hWnd));
  5240. return (BOOL)::SendMessage(this->m_hWnd, TCM_SETITEM, nItem, (LPARAM)pTabCtrlItem);
  5241. }
  5242. int SetItem(int nItem, UINT mask, LPCTSTR lpszItem, DWORD dwState, DWORD dwStateMask, int iImage, LPARAM lParam)
  5243. {
  5244. ATLASSERT(::IsWindow(this->m_hWnd));
  5245. TCITEM tci = {};
  5246. tci.mask = mask;
  5247. tci.pszText = (LPTSTR) lpszItem;
  5248. tci.dwState = dwState;
  5249. tci.dwStateMask = dwStateMask;
  5250. tci.iImage = iImage;
  5251. tci.lParam = lParam;
  5252. return (int)::SendMessage(this->m_hWnd, TCM_SETITEM, nItem, (LPARAM)&tci);
  5253. }
  5254. BOOL GetItemRect(int nItem, LPRECT lpRect) const
  5255. {
  5256. ATLASSERT(::IsWindow(this->m_hWnd));
  5257. return (BOOL)::SendMessage(this->m_hWnd, TCM_GETITEMRECT, nItem, (LPARAM)lpRect);
  5258. }
  5259. int GetCurSel() const
  5260. {
  5261. ATLASSERT(::IsWindow(this->m_hWnd));
  5262. return (int)::SendMessage(this->m_hWnd, TCM_GETCURSEL, 0, 0L);
  5263. }
  5264. int SetCurSel(int nItem)
  5265. {
  5266. ATLASSERT(::IsWindow(this->m_hWnd));
  5267. return (int)::SendMessage(this->m_hWnd, TCM_SETCURSEL, nItem, 0L);
  5268. }
  5269. SIZE SetItemSize(SIZE size)
  5270. {
  5271. ATLASSERT(::IsWindow(this->m_hWnd));
  5272. DWORD dwSize = (DWORD)::SendMessage(this->m_hWnd, TCM_SETITEMSIZE, 0, MAKELPARAM(size.cx, size.cy));
  5273. SIZE sizeRet = { GET_X_LPARAM(dwSize), GET_Y_LPARAM(dwSize) };
  5274. return sizeRet;
  5275. }
  5276. void SetItemSize(int cx, int cy)
  5277. {
  5278. ATLASSERT(::IsWindow(this->m_hWnd));
  5279. ::SendMessage(this->m_hWnd, TCM_SETITEMSIZE, 0, MAKELPARAM(cx, cy));
  5280. }
  5281. void SetPadding(SIZE size)
  5282. {
  5283. ATLASSERT(::IsWindow(this->m_hWnd));
  5284. ::SendMessage(this->m_hWnd, TCM_SETPADDING, 0, MAKELPARAM(size.cx, size.cy));
  5285. }
  5286. int GetRowCount() const
  5287. {
  5288. ATLASSERT(::IsWindow(this->m_hWnd));
  5289. return (int)::SendMessage(this->m_hWnd, TCM_GETROWCOUNT, 0, 0L);
  5290. }
  5291. CToolTipCtrl GetToolTips() const
  5292. {
  5293. ATLASSERT(::IsWindow(this->m_hWnd));
  5294. return CToolTipCtrl((HWND)::SendMessage(this->m_hWnd, TCM_GETTOOLTIPS, 0, 0L));
  5295. }
  5296. // this method is deprecated, please use GetToolTips
  5297. CToolTipCtrl GetTooltips() const { return GetToolTips(); }
  5298. void SetToolTips(HWND hWndToolTip)
  5299. {
  5300. ATLASSERT(::IsWindow(this->m_hWnd));
  5301. ::SendMessage(this->m_hWnd, TCM_SETTOOLTIPS, (WPARAM)hWndToolTip, 0L);
  5302. }
  5303. // this method is deprecated, please use SetToolTips
  5304. void SetTooltips(HWND hWndToolTip) { SetToolTips(hWndToolTip); }
  5305. int GetCurFocus() const
  5306. {
  5307. ATLASSERT(::IsWindow(this->m_hWnd));
  5308. return (int)::SendMessage(this->m_hWnd, TCM_GETCURFOCUS, 0, 0L);
  5309. }
  5310. void SetCurFocus(int nItem)
  5311. {
  5312. ATLASSERT(::IsWindow(this->m_hWnd));
  5313. ::SendMessage(this->m_hWnd, TCM_SETCURFOCUS, nItem, 0L);
  5314. }
  5315. BOOL SetItemExtra(int cbExtra)
  5316. {
  5317. ATLASSERT(::IsWindow(this->m_hWnd));
  5318. ATLASSERT(GetItemCount() == 0); // must be empty
  5319. return (BOOL)::SendMessage(this->m_hWnd, TCM_SETITEMEXTRA, cbExtra, 0L);
  5320. }
  5321. int SetMinTabWidth(int nWidth = -1)
  5322. {
  5323. ATLASSERT(::IsWindow(this->m_hWnd));
  5324. return (int)::SendMessage(this->m_hWnd, TCM_SETMINTABWIDTH, 0, nWidth);
  5325. }
  5326. DWORD GetExtendedStyle() const
  5327. {
  5328. ATLASSERT(::IsWindow(this->m_hWnd));
  5329. return (DWORD)::SendMessage(this->m_hWnd, TCM_GETEXTENDEDSTYLE, 0, 0L);
  5330. }
  5331. DWORD SetExtendedStyle(DWORD dwExMask, DWORD dwExStyle)
  5332. {
  5333. ATLASSERT(::IsWindow(this->m_hWnd));
  5334. return (DWORD)::SendMessage(this->m_hWnd, TCM_SETEXTENDEDSTYLE, dwExMask, dwExStyle);
  5335. }
  5336. BOOL GetUnicodeFormat() const
  5337. {
  5338. ATLASSERT(::IsWindow(this->m_hWnd));
  5339. return (BOOL)::SendMessage(this->m_hWnd, TCM_GETUNICODEFORMAT, 0, 0L);
  5340. }
  5341. BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
  5342. {
  5343. ATLASSERT(::IsWindow(this->m_hWnd));
  5344. return (BOOL)::SendMessage(this->m_hWnd, TCM_SETUNICODEFORMAT, bUnicode, 0L);
  5345. }
  5346. // Operations
  5347. int InsertItem(int nItem, LPTCITEM pTabCtrlItem)
  5348. {
  5349. ATLASSERT(::IsWindow(this->m_hWnd));
  5350. return (int)::SendMessage(this->m_hWnd, TCM_INSERTITEM, nItem, (LPARAM)pTabCtrlItem);
  5351. }
  5352. int InsertItem(int nItem, UINT mask, LPCTSTR lpszItem, int iImage, LPARAM lParam)
  5353. {
  5354. ATLASSERT(::IsWindow(this->m_hWnd));
  5355. TCITEM tci = {};
  5356. tci.mask = mask;
  5357. tci.pszText = (LPTSTR) lpszItem;
  5358. tci.iImage = iImage;
  5359. tci.lParam = lParam;
  5360. return (int)::SendMessage(this->m_hWnd, TCM_INSERTITEM, nItem, (LPARAM)&tci);
  5361. }
  5362. int InsertItem(int nItem, LPCTSTR lpszItem)
  5363. {
  5364. ATLASSERT(::IsWindow(this->m_hWnd));
  5365. TCITEM tci = {};
  5366. tci.mask = TCIF_TEXT;
  5367. tci.pszText = (LPTSTR) lpszItem;
  5368. return (int)::SendMessage(this->m_hWnd, TCM_INSERTITEM, nItem, (LPARAM)&tci);
  5369. }
  5370. int AddItem(LPTCITEM pTabCtrlItem)
  5371. {
  5372. return InsertItem(GetItemCount(), pTabCtrlItem);
  5373. }
  5374. int AddItem(UINT mask, LPCTSTR lpszItem, int iImage, LPARAM lParam)
  5375. {
  5376. return InsertItem(GetItemCount(), mask, lpszItem, iImage, lParam);
  5377. }
  5378. int AddItem(LPCTSTR lpszItem)
  5379. {
  5380. return InsertItem(GetItemCount(), lpszItem);
  5381. }
  5382. BOOL DeleteItem(int nItem)
  5383. {
  5384. ATLASSERT(::IsWindow(this->m_hWnd));
  5385. return (BOOL)::SendMessage(this->m_hWnd, TCM_DELETEITEM, nItem, 0L);
  5386. }
  5387. BOOL DeleteAllItems()
  5388. {
  5389. ATLASSERT(::IsWindow(this->m_hWnd));
  5390. return (BOOL)::SendMessage(this->m_hWnd, TCM_DELETEALLITEMS, 0, 0L);
  5391. }
  5392. void AdjustRect(BOOL bLarger, LPRECT lpRect)
  5393. {
  5394. ATLASSERT(::IsWindow(this->m_hWnd));
  5395. ::SendMessage(this->m_hWnd, TCM_ADJUSTRECT, bLarger, (LPARAM)lpRect);
  5396. }
  5397. void RemoveImage(int nImage)
  5398. {
  5399. ATLASSERT(::IsWindow(this->m_hWnd));
  5400. ::SendMessage(this->m_hWnd, TCM_REMOVEIMAGE, nImage, 0L);
  5401. }
  5402. int HitTest(TC_HITTESTINFO* pHitTestInfo) const
  5403. {
  5404. ATLASSERT(::IsWindow(this->m_hWnd));
  5405. return (int)::SendMessage(this->m_hWnd, TCM_HITTEST, 0, (LPARAM)pHitTestInfo);
  5406. }
  5407. void DeselectAll(BOOL bExcludeFocus = TRUE)
  5408. {
  5409. ATLASSERT(::IsWindow(this->m_hWnd));
  5410. ::SendMessage(this->m_hWnd, TCM_DESELECTALL, bExcludeFocus, 0L);
  5411. }
  5412. BOOL HighlightItem(int nIndex, BOOL bHighlight = TRUE)
  5413. {
  5414. ATLASSERT(::IsWindow(this->m_hWnd));
  5415. return (BOOL)::SendMessage(this->m_hWnd, TCM_HIGHLIGHTITEM, nIndex, MAKELPARAM(bHighlight, 0));
  5416. }
  5417. };
  5418. typedef CTabCtrlT<ATL::CWindow> CTabCtrl;
  5419. ///////////////////////////////////////////////////////////////////////////////
  5420. // CTrackBarCtrl
  5421. template <class TBase>
  5422. class CTrackBarCtrlT : public TBase
  5423. {
  5424. public:
  5425. // Constructors
  5426. CTrackBarCtrlT(HWND hWnd = NULL) : TBase(hWnd)
  5427. { }
  5428. CTrackBarCtrlT< TBase >& operator =(HWND hWnd)
  5429. {
  5430. this->m_hWnd = hWnd;
  5431. return *this;
  5432. }
  5433. HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  5434. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  5435. ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  5436. {
  5437. return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  5438. }
  5439. // Attributes
  5440. static LPCTSTR GetWndClassName()
  5441. {
  5442. return TRACKBAR_CLASS;
  5443. }
  5444. int GetLineSize() const
  5445. {
  5446. ATLASSERT(::IsWindow(this->m_hWnd));
  5447. return (int)::SendMessage(this->m_hWnd, TBM_GETLINESIZE, 0, 0L);
  5448. }
  5449. int SetLineSize(int nSize)
  5450. {
  5451. ATLASSERT(::IsWindow(this->m_hWnd));
  5452. return (int)::SendMessage(this->m_hWnd, TBM_SETLINESIZE, 0, nSize);
  5453. }
  5454. int GetPageSize() const
  5455. {
  5456. ATLASSERT(::IsWindow(this->m_hWnd));
  5457. return (int)::SendMessage(this->m_hWnd, TBM_GETPAGESIZE, 0, 0L);
  5458. }
  5459. int SetPageSize(int nSize)
  5460. {
  5461. ATLASSERT(::IsWindow(this->m_hWnd));
  5462. return (int)::SendMessage(this->m_hWnd, TBM_SETPAGESIZE, 0, nSize);
  5463. }
  5464. int GetRangeMin() const
  5465. {
  5466. ATLASSERT(::IsWindow(this->m_hWnd));
  5467. return (int)::SendMessage(this->m_hWnd, TBM_GETRANGEMIN, 0, 0L);
  5468. }
  5469. void SetRangeMin(int nMin, BOOL bRedraw = FALSE)
  5470. {
  5471. ATLASSERT(::IsWindow(this->m_hWnd));
  5472. ::SendMessage(this->m_hWnd, TBM_SETRANGEMIN, bRedraw, nMin);
  5473. }
  5474. int GetRangeMax() const
  5475. {
  5476. ATLASSERT(::IsWindow(this->m_hWnd));
  5477. return (int)::SendMessage(this->m_hWnd, TBM_GETRANGEMAX, 0, 0L);
  5478. }
  5479. void SetRangeMax(int nMax, BOOL bRedraw = FALSE)
  5480. {
  5481. ATLASSERT(::IsWindow(this->m_hWnd));
  5482. ::SendMessage(this->m_hWnd, TBM_SETRANGEMAX, bRedraw, nMax);
  5483. }
  5484. void GetRange(int& nMin, int& nMax) const
  5485. {
  5486. nMin = GetRangeMin();
  5487. nMax = GetRangeMax();
  5488. }
  5489. void SetRange(int nMin, int nMax, BOOL bRedraw = TRUE)
  5490. {
  5491. ATLASSERT(::IsWindow(this->m_hWnd));
  5492. ::SendMessage(this->m_hWnd, TBM_SETRANGE, bRedraw, MAKELPARAM(nMin, nMax));
  5493. }
  5494. int GetSelStart() const
  5495. {
  5496. ATLASSERT(::IsWindow(this->m_hWnd));
  5497. return (int)::SendMessage(this->m_hWnd, TBM_GETSELSTART, 0, 0L);
  5498. }
  5499. void SetSelStart(int nMin, BOOL bRedraw = FALSE)
  5500. {
  5501. ATLASSERT(::IsWindow(this->m_hWnd));
  5502. ::SendMessage(this->m_hWnd, TBM_SETSELSTART, bRedraw, (LPARAM)nMin);
  5503. }
  5504. int GetSelEnd() const
  5505. {
  5506. ATLASSERT(::IsWindow(this->m_hWnd));
  5507. return (int)::SendMessage(this->m_hWnd, TBM_GETSELEND, 0, 0L);
  5508. }
  5509. void SetSelEnd(int nMax, BOOL bRedraw = FALSE)
  5510. {
  5511. ATLASSERT(::IsWindow(this->m_hWnd));
  5512. ::SendMessage(this->m_hWnd, TBM_SETSELEND, bRedraw, (LPARAM)nMax);
  5513. }
  5514. void GetSelection(int& nMin, int& nMax) const
  5515. {
  5516. nMin = GetSelStart();
  5517. nMax = GetSelEnd();
  5518. }
  5519. void SetSelection(int nMin, int nMax, BOOL bRedraw = TRUE)
  5520. {
  5521. SetSelStart(nMin, FALSE);
  5522. SetSelEnd(nMax, bRedraw);
  5523. }
  5524. void GetChannelRect(LPRECT lprc) const
  5525. {
  5526. ATLASSERT(::IsWindow(this->m_hWnd));
  5527. ::SendMessage(this->m_hWnd, TBM_GETCHANNELRECT, 0, (LPARAM)lprc);
  5528. }
  5529. void GetThumbRect(LPRECT lprc) const
  5530. {
  5531. ATLASSERT(::IsWindow(this->m_hWnd));
  5532. ::SendMessage(this->m_hWnd, TBM_GETTHUMBRECT, 0, (LPARAM)lprc);
  5533. }
  5534. int GetPos() const
  5535. {
  5536. ATLASSERT(::IsWindow(this->m_hWnd));
  5537. return (int)::SendMessage(this->m_hWnd, TBM_GETPOS, 0, 0L);
  5538. }
  5539. void SetPos(int nPos)
  5540. {
  5541. ATLASSERT(::IsWindow(this->m_hWnd));
  5542. ::SendMessage(this->m_hWnd, TBM_SETPOS, TRUE, nPos);
  5543. }
  5544. UINT GetNumTics() const
  5545. {
  5546. ATLASSERT(::IsWindow(this->m_hWnd));
  5547. return (UINT)::SendMessage(this->m_hWnd, TBM_GETNUMTICS, 0, 0L);
  5548. }
  5549. DWORD* GetTicArray() const
  5550. {
  5551. ATLASSERT(::IsWindow(this->m_hWnd));
  5552. return (DWORD*)::SendMessage(this->m_hWnd, TBM_GETPTICS, 0, 0L);
  5553. }
  5554. int GetTic(int nTic) const
  5555. {
  5556. ATLASSERT(::IsWindow(this->m_hWnd));
  5557. return (int)::SendMessage(this->m_hWnd, TBM_GETTIC, nTic, 0L);
  5558. }
  5559. BOOL SetTic(int nTic)
  5560. {
  5561. ATLASSERT(::IsWindow(this->m_hWnd));
  5562. return (BOOL)::SendMessage(this->m_hWnd, TBM_SETTIC, 0, nTic);
  5563. }
  5564. int GetTicPos(int nTic) const
  5565. {
  5566. ATLASSERT(::IsWindow(this->m_hWnd));
  5567. return (int)::SendMessage(this->m_hWnd, TBM_GETTICPOS, nTic, 0L);
  5568. }
  5569. void SetTicFreq(int nFreq)
  5570. {
  5571. ATLASSERT(::IsWindow(this->m_hWnd));
  5572. ::SendMessage(this->m_hWnd, TBM_SETTICFREQ, nFreq, 0L);
  5573. }
  5574. int GetThumbLength() const
  5575. {
  5576. ATLASSERT(::IsWindow(this->m_hWnd));
  5577. return (int)::SendMessage(this->m_hWnd, TBM_GETTHUMBLENGTH, 0, 0L);
  5578. }
  5579. void SetThumbLength(int nLength)
  5580. {
  5581. ATLASSERT(::IsWindow(this->m_hWnd));
  5582. ::SendMessage(this->m_hWnd, TBM_SETTHUMBLENGTH, nLength, 0L);
  5583. }
  5584. void SetSel(int nStart, int nEnd, BOOL bRedraw = TRUE)
  5585. {
  5586. ATLASSERT(::IsWindow(this->m_hWnd));
  5587. ATLASSERT((this->GetStyle() & TBS_ENABLESELRANGE) != 0);
  5588. ::SendMessage(this->m_hWnd, TBM_SETSEL, bRedraw, MAKELPARAM(nStart, nEnd));
  5589. }
  5590. ATL::CWindow GetBuddy(BOOL bLeft = TRUE) const
  5591. {
  5592. ATLASSERT(::IsWindow(this->m_hWnd));
  5593. return ATL::CWindow((HWND)::SendMessage(this->m_hWnd, TBM_GETBUDDY, bLeft, 0L));
  5594. }
  5595. ATL::CWindow SetBuddy(HWND hWndBuddy, BOOL bLeft = TRUE)
  5596. {
  5597. ATLASSERT(::IsWindow(this->m_hWnd));
  5598. return ATL::CWindow((HWND)::SendMessage(this->m_hWnd, TBM_SETBUDDY, bLeft, (LPARAM)hWndBuddy));
  5599. }
  5600. CToolTipCtrl GetToolTips() const
  5601. {
  5602. ATLASSERT(::IsWindow(this->m_hWnd));
  5603. return CToolTipCtrl((HWND)::SendMessage(this->m_hWnd, TBM_GETTOOLTIPS, 0, 0L));
  5604. }
  5605. void SetToolTips(HWND hWndTT)
  5606. {
  5607. ATLASSERT(::IsWindow(this->m_hWnd));
  5608. ::SendMessage(this->m_hWnd, TBM_SETTOOLTIPS, (WPARAM)hWndTT, 0L);
  5609. }
  5610. int SetTipSide(int nSide)
  5611. {
  5612. ATLASSERT(::IsWindow(this->m_hWnd));
  5613. return (int)::SendMessage(this->m_hWnd, TBM_SETTIPSIDE, nSide, 0L);
  5614. }
  5615. BOOL GetUnicodeFormat() const
  5616. {
  5617. ATLASSERT(::IsWindow(this->m_hWnd));
  5618. return (BOOL)::SendMessage(this->m_hWnd, TBM_GETUNICODEFORMAT, 0, 0L);
  5619. }
  5620. BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
  5621. {
  5622. ATLASSERT(::IsWindow(this->m_hWnd));
  5623. return (BOOL)::SendMessage(this->m_hWnd, TBM_SETUNICODEFORMAT, bUnicode, 0L);
  5624. }
  5625. // Operations
  5626. void ClearSel(BOOL bRedraw = FALSE)
  5627. {
  5628. ATLASSERT(::IsWindow(this->m_hWnd));
  5629. ::SendMessage(this->m_hWnd, TBM_CLEARSEL, bRedraw, 0L);
  5630. }
  5631. void VerifyPos()
  5632. {
  5633. ATLASSERT(::IsWindow(this->m_hWnd));
  5634. ::SendMessage(this->m_hWnd, TBM_SETPOS, FALSE, 0L);
  5635. }
  5636. void ClearTics(BOOL bRedraw = FALSE)
  5637. {
  5638. ATLASSERT(::IsWindow(this->m_hWnd));
  5639. ::SendMessage(this->m_hWnd, TBM_CLEARTICS, bRedraw, 0L);
  5640. }
  5641. };
  5642. typedef CTrackBarCtrlT<ATL::CWindow> CTrackBarCtrl;
  5643. ///////////////////////////////////////////////////////////////////////////////
  5644. // CUpDownCtrl
  5645. template <class TBase>
  5646. class CUpDownCtrlT : public TBase
  5647. {
  5648. public:
  5649. // Constructors
  5650. CUpDownCtrlT(HWND hWnd = NULL) : TBase(hWnd)
  5651. { }
  5652. CUpDownCtrlT< TBase >& operator =(HWND hWnd)
  5653. {
  5654. this->m_hWnd = hWnd;
  5655. return *this;
  5656. }
  5657. HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  5658. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  5659. ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  5660. {
  5661. return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  5662. }
  5663. // Attributes
  5664. static LPCTSTR GetWndClassName()
  5665. {
  5666. return UPDOWN_CLASS;
  5667. }
  5668. UINT GetAccel(int nAccel, UDACCEL* pAccel) const
  5669. {
  5670. ATLASSERT(::IsWindow(this->m_hWnd));
  5671. return (UINT)LOWORD(::SendMessage(this->m_hWnd, UDM_GETACCEL, nAccel, (LPARAM)pAccel));
  5672. }
  5673. BOOL SetAccel(int nAccel, UDACCEL* pAccel)
  5674. {
  5675. ATLASSERT(::IsWindow(this->m_hWnd));
  5676. return (BOOL)LOWORD(::SendMessage(this->m_hWnd, UDM_SETACCEL, nAccel, (LPARAM)pAccel));
  5677. }
  5678. UINT GetBase() const
  5679. {
  5680. ATLASSERT(::IsWindow(this->m_hWnd));
  5681. return (UINT)LOWORD(::SendMessage(this->m_hWnd, UDM_GETBASE, 0, 0L));
  5682. }
  5683. int SetBase(int nBase)
  5684. {
  5685. ATLASSERT(::IsWindow(this->m_hWnd));
  5686. return (int)::SendMessage(this->m_hWnd, UDM_SETBASE, nBase, 0L);
  5687. }
  5688. ATL::CWindow GetBuddy() const
  5689. {
  5690. ATLASSERT(::IsWindow(this->m_hWnd));
  5691. return ATL::CWindow((HWND)::SendMessage(this->m_hWnd, UDM_GETBUDDY, 0, 0L));
  5692. }
  5693. ATL::CWindow SetBuddy(HWND hWndBuddy)
  5694. {
  5695. ATLASSERT(::IsWindow(this->m_hWnd));
  5696. return ATL::CWindow((HWND)::SendMessage(this->m_hWnd, UDM_SETBUDDY, (WPARAM)hWndBuddy, 0L));
  5697. }
  5698. int GetPos(LPBOOL lpbError = NULL) const
  5699. {
  5700. ATLASSERT(::IsWindow(this->m_hWnd));
  5701. DWORD dwRet = (DWORD)::SendMessage(this->m_hWnd, UDM_GETPOS, 0, 0L);
  5702. // Note: Seems that Windows always sets error to TRUE if
  5703. // UDS_SETBUDDYINT style is not used
  5704. if(lpbError != NULL)
  5705. *lpbError = (HIWORD(dwRet) != 0) ? TRUE : FALSE;
  5706. return (int)(short)LOWORD(dwRet);
  5707. }
  5708. int SetPos(int nPos)
  5709. {
  5710. ATLASSERT(::IsWindow(this->m_hWnd));
  5711. return (int)(short)LOWORD(::SendMessage(this->m_hWnd, UDM_SETPOS, 0, MAKELPARAM(nPos, 0)));
  5712. }
  5713. DWORD GetRange() const
  5714. {
  5715. ATLASSERT(::IsWindow(this->m_hWnd));
  5716. return (DWORD)::SendMessage(this->m_hWnd, UDM_GETRANGE, 0, 0L);
  5717. }
  5718. void GetRange(int& nLower, int& nUpper) const
  5719. {
  5720. ATLASSERT(::IsWindow(this->m_hWnd));
  5721. DWORD dwRet = (DWORD)::SendMessage(this->m_hWnd, UDM_GETRANGE, 0, 0L);
  5722. nLower = (int)(short)HIWORD(dwRet);
  5723. nUpper = (int)(short)LOWORD(dwRet);
  5724. }
  5725. void SetRange(int nLower, int nUpper)
  5726. {
  5727. ATLASSERT(::IsWindow(this->m_hWnd));
  5728. ::SendMessage(this->m_hWnd, UDM_SETRANGE, 0, MAKELPARAM(nUpper, nLower));
  5729. }
  5730. void SetRange32(int nLower, int nUpper)
  5731. {
  5732. ATLASSERT(::IsWindow(this->m_hWnd));
  5733. ::SendMessage(this->m_hWnd, UDM_SETRANGE32, nLower, nUpper);
  5734. }
  5735. void GetRange32(int& nLower, int& nUpper) const
  5736. {
  5737. ATLASSERT(::IsWindow(this->m_hWnd));
  5738. ::SendMessage(this->m_hWnd, UDM_GETRANGE32, (WPARAM)&nLower, (LPARAM)&nUpper);
  5739. }
  5740. BOOL GetUnicodeFormat() const
  5741. {
  5742. ATLASSERT(::IsWindow(this->m_hWnd));
  5743. return (BOOL)::SendMessage(this->m_hWnd, UDM_GETUNICODEFORMAT, 0, 0L);
  5744. }
  5745. BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
  5746. {
  5747. ATLASSERT(::IsWindow(this->m_hWnd));
  5748. return (BOOL)::SendMessage(this->m_hWnd, UDM_SETUNICODEFORMAT, bUnicode, 0L);
  5749. }
  5750. int GetPos32(LPBOOL lpbError = NULL) const
  5751. {
  5752. ATLASSERT(::IsWindow(this->m_hWnd));
  5753. // Note: Seems that Windows always sets error to TRUE if
  5754. // UDS_SETBUDDYINT style is not used
  5755. return (int)::SendMessage(this->m_hWnd, UDM_GETPOS32, 0, (LPARAM)lpbError);
  5756. }
  5757. int SetPos32(int nPos)
  5758. {
  5759. ATLASSERT(::IsWindow(this->m_hWnd));
  5760. return (int)::SendMessage(this->m_hWnd, UDM_SETPOS32, 0, (LPARAM)nPos);
  5761. }
  5762. };
  5763. typedef CUpDownCtrlT<ATL::CWindow> CUpDownCtrl;
  5764. ///////////////////////////////////////////////////////////////////////////////
  5765. // CProgressBarCtrl
  5766. template <class TBase>
  5767. class CProgressBarCtrlT : public TBase
  5768. {
  5769. public:
  5770. // Constructors
  5771. CProgressBarCtrlT(HWND hWnd = NULL) : TBase(hWnd)
  5772. { }
  5773. CProgressBarCtrlT< TBase >& operator =(HWND hWnd)
  5774. {
  5775. this->m_hWnd = hWnd;
  5776. return *this;
  5777. }
  5778. HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  5779. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  5780. ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  5781. {
  5782. return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  5783. }
  5784. // Attributes
  5785. static LPCTSTR GetWndClassName()
  5786. {
  5787. return PROGRESS_CLASS;
  5788. }
  5789. DWORD SetRange(int nLower, int nUpper)
  5790. {
  5791. ATLASSERT(::IsWindow(this->m_hWnd));
  5792. return (DWORD)::SendMessage(this->m_hWnd, PBM_SETRANGE, 0, MAKELPARAM(nLower, nUpper));
  5793. }
  5794. int SetPos(int nPos)
  5795. {
  5796. ATLASSERT(::IsWindow(this->m_hWnd));
  5797. return (int)(short)LOWORD(::SendMessage(this->m_hWnd, PBM_SETPOS, nPos, 0L));
  5798. }
  5799. int OffsetPos(int nPos)
  5800. {
  5801. ATLASSERT(::IsWindow(this->m_hWnd));
  5802. return (int)(short)LOWORD(::SendMessage(this->m_hWnd, PBM_DELTAPOS, nPos, 0L));
  5803. }
  5804. int SetStep(int nStep)
  5805. {
  5806. ATLASSERT(::IsWindow(this->m_hWnd));
  5807. return (int)(short)LOWORD(::SendMessage(this->m_hWnd, PBM_SETSTEP, nStep, 0L));
  5808. }
  5809. UINT GetPos() const
  5810. {
  5811. ATLASSERT(::IsWindow(this->m_hWnd));
  5812. return (UINT)::SendMessage(this->m_hWnd, PBM_GETPOS, 0, 0L);
  5813. }
  5814. void GetRange(PPBRANGE pPBRange) const
  5815. {
  5816. ATLASSERT(::IsWindow(this->m_hWnd));
  5817. ATLASSERT(pPBRange != NULL);
  5818. ::SendMessage(this->m_hWnd, PBM_GETRANGE, TRUE, (LPARAM)pPBRange);
  5819. }
  5820. void GetRange(int& nLower, int& nUpper) const
  5821. {
  5822. ATLASSERT(::IsWindow(this->m_hWnd));
  5823. PBRANGE range = {};
  5824. ::SendMessage(this->m_hWnd, PBM_GETRANGE, TRUE, (LPARAM)&range);
  5825. nLower = range.iLow;
  5826. nUpper = range.iHigh;
  5827. }
  5828. int GetRangeLimit(BOOL bLowLimit) const
  5829. {
  5830. ATLASSERT(::IsWindow(this->m_hWnd));
  5831. return (int)::SendMessage(this->m_hWnd, PBM_GETRANGE, bLowLimit, (LPARAM)NULL);
  5832. }
  5833. DWORD SetRange32(int nMin, int nMax)
  5834. {
  5835. ATLASSERT(::IsWindow(this->m_hWnd));
  5836. return (DWORD)::SendMessage(this->m_hWnd, PBM_SETRANGE32, nMin, nMax);
  5837. }
  5838. COLORREF SetBarColor(COLORREF clr)
  5839. {
  5840. ATLASSERT(::IsWindow(this->m_hWnd));
  5841. return (COLORREF)::SendMessage(this->m_hWnd, PBM_SETBARCOLOR, 0, (LPARAM)clr);
  5842. }
  5843. COLORREF SetBkColor(COLORREF clr)
  5844. {
  5845. ATLASSERT(::IsWindow(this->m_hWnd));
  5846. return (COLORREF)::SendMessage(this->m_hWnd, PBM_SETBKCOLOR, 0, (LPARAM)clr);
  5847. }
  5848. #ifdef PBM_SETMARQUEE
  5849. BOOL SetMarquee(BOOL bMarquee, UINT uUpdateTime = 0U)
  5850. {
  5851. ATLASSERT(::IsWindow(this->m_hWnd));
  5852. return (BOOL)::SendMessage(this->m_hWnd, PBM_SETMARQUEE, (WPARAM)bMarquee, (LPARAM)uUpdateTime);
  5853. }
  5854. #endif
  5855. #if (_WIN32_WINNT >= 0x0600)
  5856. int GetStep() const
  5857. {
  5858. ATLASSERT(::IsWindow(this->m_hWnd));
  5859. return (int)::SendMessage(this->m_hWnd, PBM_GETSTEP, 0, 0L);
  5860. }
  5861. COLORREF GetBkColor() const
  5862. {
  5863. ATLASSERT(::IsWindow(this->m_hWnd));
  5864. return (COLORREF)::SendMessage(this->m_hWnd, PBM_GETBKCOLOR, 0, 0L);
  5865. }
  5866. COLORREF GetBarColor() const
  5867. {
  5868. ATLASSERT(::IsWindow(this->m_hWnd));
  5869. return (COLORREF)::SendMessage(this->m_hWnd, PBM_GETBARCOLOR, 0, 0L);
  5870. }
  5871. int GetState() const
  5872. {
  5873. ATLASSERT(::IsWindow(this->m_hWnd));
  5874. return (int)::SendMessage(this->m_hWnd, PBM_GETSTATE, 0, 0L);
  5875. }
  5876. int SetState(int nState)
  5877. {
  5878. ATLASSERT(::IsWindow(this->m_hWnd));
  5879. return (int)::SendMessage(this->m_hWnd, PBM_SETSTATE, nState, 0L);
  5880. }
  5881. #endif // (_WIN32_WINNT >= 0x0600)
  5882. // Operations
  5883. int StepIt()
  5884. {
  5885. ATLASSERT(::IsWindow(this->m_hWnd));
  5886. return (int)(short)LOWORD(::SendMessage(this->m_hWnd, PBM_STEPIT, 0, 0L));
  5887. }
  5888. };
  5889. typedef CProgressBarCtrlT<ATL::CWindow> CProgressBarCtrl;
  5890. ///////////////////////////////////////////////////////////////////////////////
  5891. // CHotKeyCtrl
  5892. template <class TBase>
  5893. class CHotKeyCtrlT : public TBase
  5894. {
  5895. public:
  5896. // Constructors
  5897. CHotKeyCtrlT(HWND hWnd = NULL) : TBase(hWnd)
  5898. { }
  5899. CHotKeyCtrlT< TBase >& operator =(HWND hWnd)
  5900. {
  5901. this->m_hWnd = hWnd;
  5902. return *this;
  5903. }
  5904. HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  5905. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  5906. ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  5907. {
  5908. return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  5909. }
  5910. // Attributes
  5911. static LPCTSTR GetWndClassName()
  5912. {
  5913. return HOTKEY_CLASS;
  5914. }
  5915. DWORD GetHotKey() const
  5916. {
  5917. ATLASSERT(::IsWindow(this->m_hWnd));
  5918. return (DWORD)::SendMessage(this->m_hWnd, HKM_GETHOTKEY, 0, 0L);
  5919. }
  5920. void GetHotKey(WORD &wVirtualKeyCode, WORD &wModifiers) const
  5921. {
  5922. ATLASSERT(::IsWindow(this->m_hWnd));
  5923. DWORD dw = (DWORD)::SendMessage(this->m_hWnd, HKM_GETHOTKEY, 0, 0L);
  5924. wVirtualKeyCode = LOBYTE(LOWORD(dw));
  5925. wModifiers = HIBYTE(LOWORD(dw));
  5926. }
  5927. void SetHotKey(WORD wVirtualKeyCode, WORD wModifiers)
  5928. {
  5929. ATLASSERT(::IsWindow(this->m_hWnd));
  5930. ::SendMessage(this->m_hWnd, HKM_SETHOTKEY, MAKEWORD(wVirtualKeyCode, wModifiers), 0L);
  5931. }
  5932. void SetRules(WORD wInvalidComb, WORD wModifiers)
  5933. {
  5934. ATLASSERT(::IsWindow(this->m_hWnd));
  5935. ::SendMessage(this->m_hWnd, HKM_SETRULES, wInvalidComb, MAKELPARAM(wModifiers, 0));
  5936. }
  5937. };
  5938. typedef CHotKeyCtrlT<ATL::CWindow> CHotKeyCtrl;
  5939. ///////////////////////////////////////////////////////////////////////////////
  5940. // CAnimateCtrl
  5941. template <class TBase>
  5942. class CAnimateCtrlT : public TBase
  5943. {
  5944. public:
  5945. // Constructors
  5946. CAnimateCtrlT(HWND hWnd = NULL) : TBase(hWnd)
  5947. { }
  5948. CAnimateCtrlT< TBase >& operator =(HWND hWnd)
  5949. {
  5950. this->m_hWnd = hWnd;
  5951. return *this;
  5952. }
  5953. HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  5954. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  5955. ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  5956. {
  5957. return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  5958. }
  5959. // Attributes
  5960. static LPCTSTR GetWndClassName()
  5961. {
  5962. return ANIMATE_CLASS;
  5963. }
  5964. // Operations
  5965. BOOL Open(ATL::_U_STRINGorID FileName)
  5966. {
  5967. ATLASSERT(::IsWindow(this->m_hWnd));
  5968. return (BOOL)::SendMessage(this->m_hWnd, ACM_OPEN, 0, (LPARAM)FileName.m_lpstr);
  5969. }
  5970. BOOL Play(UINT nFrom, UINT nTo, UINT nRep)
  5971. {
  5972. ATLASSERT(::IsWindow(this->m_hWnd));
  5973. return (BOOL)::SendMessage(this->m_hWnd, ACM_PLAY, nRep, MAKELPARAM(nFrom, nTo));
  5974. }
  5975. BOOL Stop()
  5976. {
  5977. ATLASSERT(::IsWindow(this->m_hWnd));
  5978. return (BOOL)::SendMessage(this->m_hWnd, ACM_STOP, 0, 0L);
  5979. }
  5980. BOOL Close()
  5981. {
  5982. ATLASSERT(::IsWindow(this->m_hWnd));
  5983. return (BOOL)::SendMessage(this->m_hWnd, ACM_OPEN, 0, 0L);
  5984. }
  5985. BOOL Seek(UINT nTo)
  5986. {
  5987. ATLASSERT(::IsWindow(this->m_hWnd));
  5988. return (BOOL)::SendMessage(this->m_hWnd, ACM_PLAY, 0, MAKELPARAM(nTo, nTo));
  5989. }
  5990. // Vista only
  5991. BOOL IsPlaying() const
  5992. {
  5993. ATLASSERT(::IsWindow(this->m_hWnd));
  5994. return (BOOL)::SendMessage(this->m_hWnd, ACM_ISPLAYING, 0, 0L);
  5995. }
  5996. };
  5997. typedef CAnimateCtrlT<ATL::CWindow> CAnimateCtrl;
  5998. ///////////////////////////////////////////////////////////////////////////////
  5999. // CRichEditCtrl
  6000. #if !defined(_UNICODE) && (_RICHEDIT_VER >= 0x0500)
  6001. #undef MSFTEDIT_CLASS
  6002. #define MSFTEDIT_CLASS "RICHEDIT50W"
  6003. #endif
  6004. template <class TBase>
  6005. class CRichEditCtrlT : public TBase
  6006. {
  6007. public:
  6008. // Constructors
  6009. CRichEditCtrlT(HWND hWnd = NULL) : TBase(hWnd)
  6010. { }
  6011. CRichEditCtrlT< TBase >& operator =(HWND hWnd)
  6012. {
  6013. this->m_hWnd = hWnd;
  6014. return *this;
  6015. }
  6016. HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  6017. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  6018. ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  6019. {
  6020. return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  6021. }
  6022. // Attributes
  6023. static LPCTSTR GetWndClassName()
  6024. {
  6025. #if (_RICHEDIT_VER >= 0x0500)
  6026. return MSFTEDIT_CLASS;
  6027. #else
  6028. return RICHEDIT_CLASS;
  6029. #endif
  6030. }
  6031. static LPCTSTR GetLibraryName()
  6032. {
  6033. #if (_RICHEDIT_VER >= 0x0500)
  6034. return _T("MSFTEDIT.DLL");
  6035. #else
  6036. return _T("RICHED20.DLL");
  6037. #endif
  6038. }
  6039. int GetLineCount() const
  6040. {
  6041. ATLASSERT(::IsWindow(this->m_hWnd));
  6042. return (int)::SendMessage(this->m_hWnd, EM_GETLINECOUNT, 0, 0L);
  6043. }
  6044. BOOL GetModify() const
  6045. {
  6046. ATLASSERT(::IsWindow(this->m_hWnd));
  6047. return (BOOL)::SendMessage(this->m_hWnd, EM_GETMODIFY, 0, 0L);
  6048. }
  6049. void SetModify(BOOL bModified = TRUE)
  6050. {
  6051. ATLASSERT(::IsWindow(this->m_hWnd));
  6052. ::SendMessage(this->m_hWnd, EM_SETMODIFY, bModified, 0L);
  6053. }
  6054. void GetRect(LPRECT lpRect) const
  6055. {
  6056. ATLASSERT(::IsWindow(this->m_hWnd));
  6057. ::SendMessage(this->m_hWnd, EM_GETRECT, 0, (LPARAM)lpRect);
  6058. }
  6059. DWORD GetOptions() const
  6060. {
  6061. ATLASSERT(::IsWindow(this->m_hWnd));
  6062. return (DWORD)::SendMessage(this->m_hWnd, EM_GETOPTIONS, 0, 0L);
  6063. }
  6064. DWORD SetOptions(WORD wOperation, DWORD dwOptions)
  6065. {
  6066. ATLASSERT(::IsWindow(this->m_hWnd));
  6067. return (DWORD)::SendMessage(this->m_hWnd, EM_SETOPTIONS, wOperation, dwOptions);
  6068. }
  6069. // NOTE: first word in lpszBuffer must contain the size of the buffer!
  6070. int GetLine(int nIndex, LPTSTR lpszBuffer) const
  6071. {
  6072. ATLASSERT(::IsWindow(this->m_hWnd));
  6073. return (int)::SendMessage(this->m_hWnd, EM_GETLINE, nIndex, (LPARAM)lpszBuffer);
  6074. }
  6075. int GetLine(int nIndex, LPTSTR lpszBuffer, int nMaxLength) const
  6076. {
  6077. ATLASSERT(::IsWindow(this->m_hWnd));
  6078. *(LPWORD)lpszBuffer = (WORD)nMaxLength;
  6079. return (int)::SendMessage(this->m_hWnd, EM_GETLINE, nIndex, (LPARAM)lpszBuffer);
  6080. }
  6081. BOOL CanUndo() const
  6082. {
  6083. ATLASSERT(::IsWindow(this->m_hWnd));
  6084. return (BOOL)::SendMessage(this->m_hWnd, EM_CANUNDO, 0, 0L);
  6085. }
  6086. BOOL CanPaste(UINT nFormat = 0) const
  6087. {
  6088. ATLASSERT(::IsWindow(this->m_hWnd));
  6089. return (BOOL)::SendMessage(this->m_hWnd, EM_CANPASTE, nFormat, 0L);
  6090. }
  6091. void GetSel(LONG& nStartChar, LONG& nEndChar) const
  6092. {
  6093. ATLASSERT(::IsWindow(this->m_hWnd));
  6094. CHARRANGE cr = {};
  6095. ::SendMessage(this->m_hWnd, EM_EXGETSEL, 0, (LPARAM)&cr);
  6096. nStartChar = cr.cpMin;
  6097. nEndChar = cr.cpMax;
  6098. }
  6099. void GetSel(CHARRANGE &cr) const
  6100. {
  6101. ATLASSERT(::IsWindow(this->m_hWnd));
  6102. ::SendMessage(this->m_hWnd, EM_EXGETSEL, 0, (LPARAM)&cr);
  6103. }
  6104. int SetSel(LONG nStartChar, LONG nEndChar)
  6105. {
  6106. ATLASSERT(::IsWindow(this->m_hWnd));
  6107. CHARRANGE cr = { nStartChar, nEndChar };
  6108. return (int)::SendMessage(this->m_hWnd, EM_EXSETSEL, 0, (LPARAM)&cr);
  6109. }
  6110. int SetSel(CHARRANGE &cr)
  6111. {
  6112. ATLASSERT(::IsWindow(this->m_hWnd));
  6113. return (int)::SendMessage(this->m_hWnd, EM_EXSETSEL, 0, (LPARAM)&cr);
  6114. }
  6115. int SetSelAll()
  6116. {
  6117. return SetSel(0, -1);
  6118. }
  6119. int SetSelNone()
  6120. {
  6121. return SetSel(-1, 0);
  6122. }
  6123. DWORD GetDefaultCharFormat(CHARFORMAT& cf) const
  6124. {
  6125. ATLASSERT(::IsWindow(this->m_hWnd));
  6126. cf.cbSize = sizeof(CHARFORMAT);
  6127. return (DWORD)::SendMessage(this->m_hWnd, EM_GETCHARFORMAT, 0, (LPARAM)&cf);
  6128. }
  6129. DWORD GetSelectionCharFormat(CHARFORMAT& cf) const
  6130. {
  6131. ATLASSERT(::IsWindow(this->m_hWnd));
  6132. cf.cbSize = sizeof(CHARFORMAT);
  6133. return (DWORD)::SendMessage(this->m_hWnd, EM_GETCHARFORMAT, 1, (LPARAM)&cf);
  6134. }
  6135. DWORD GetEventMask() const
  6136. {
  6137. ATLASSERT(::IsWindow(this->m_hWnd));
  6138. return (DWORD)::SendMessage(this->m_hWnd, EM_GETEVENTMASK, 0, 0L);
  6139. }
  6140. LONG GetLimitText() const
  6141. {
  6142. ATLASSERT(::IsWindow(this->m_hWnd));
  6143. return (LONG)::SendMessage(this->m_hWnd, EM_GETLIMITTEXT, 0, 0L);
  6144. }
  6145. DWORD GetParaFormat(PARAFORMAT& pf) const
  6146. {
  6147. ATLASSERT(::IsWindow(this->m_hWnd));
  6148. pf.cbSize = sizeof(PARAFORMAT);
  6149. return (DWORD)::SendMessage(this->m_hWnd, EM_GETPARAFORMAT, 0, (LPARAM)&pf);
  6150. }
  6151. LONG GetSelText(LPTSTR lpstrBuff) const
  6152. {
  6153. ATLASSERT(::IsWindow(this->m_hWnd));
  6154. return (LONG)::SendMessage(this->m_hWnd, EM_GETSELTEXT, 0, (LPARAM)lpstrBuff);
  6155. }
  6156. BOOL GetSelTextBSTR(BSTR& bstrText) const
  6157. {
  6158. USES_CONVERSION;
  6159. ATLASSERT(::IsWindow(this->m_hWnd));
  6160. ATLASSERT(bstrText == NULL);
  6161. CHARRANGE cr = {};
  6162. ::SendMessage(this->m_hWnd, EM_EXGETSEL, 0, (LPARAM)&cr);
  6163. ATL::CTempBuffer<TCHAR, _WTL_STACK_ALLOC_THRESHOLD> buff;
  6164. LPTSTR lpstrText = buff.Allocate(cr.cpMax - cr.cpMin + 1);
  6165. if(lpstrText == NULL)
  6166. return FALSE;
  6167. if(::SendMessage(this->m_hWnd, EM_GETSELTEXT, 0, (LPARAM)lpstrText) == 0)
  6168. return FALSE;
  6169. bstrText = ::SysAllocString(T2W(lpstrText));
  6170. return (bstrText != NULL) ? TRUE : FALSE;
  6171. }
  6172. #ifdef __ATLSTR_H__
  6173. LONG GetSelText(ATL::CString& strText) const
  6174. {
  6175. ATLASSERT(::IsWindow(this->m_hWnd));
  6176. CHARRANGE cr = {};
  6177. ::SendMessage(this->m_hWnd, EM_EXGETSEL, 0, (LPARAM)&cr);
  6178. LONG lLen = 0;
  6179. LPTSTR lpstrText = strText.GetBufferSetLength(cr.cpMax - cr.cpMin);
  6180. if(lpstrText != NULL)
  6181. {
  6182. lLen = (LONG)::SendMessage(this->m_hWnd, EM_GETSELTEXT, 0, (LPARAM)lpstrText);
  6183. strText.ReleaseBuffer();
  6184. }
  6185. return lLen;
  6186. }
  6187. #endif // __ATLSTR_H__
  6188. WORD GetSelectionType() const
  6189. {
  6190. ATLASSERT(::IsWindow(this->m_hWnd));
  6191. return (WORD)::SendMessage(this->m_hWnd, EM_SELECTIONTYPE, 0, 0L);
  6192. }
  6193. COLORREF SetBackgroundColor(COLORREF cr)
  6194. {
  6195. ATLASSERT(::IsWindow(this->m_hWnd));
  6196. return (COLORREF)::SendMessage(this->m_hWnd, EM_SETBKGNDCOLOR, 0, cr);
  6197. }
  6198. COLORREF SetBackgroundColor() // sets to system background
  6199. {
  6200. ATLASSERT(::IsWindow(this->m_hWnd));
  6201. return (COLORREF)::SendMessage(this->m_hWnd, EM_SETBKGNDCOLOR, 1, 0);
  6202. }
  6203. BOOL SetCharFormat(CHARFORMAT& cf, WORD wFlags)
  6204. {
  6205. ATLASSERT(::IsWindow(this->m_hWnd));
  6206. cf.cbSize = sizeof(CHARFORMAT);
  6207. return (BOOL)::SendMessage(this->m_hWnd, EM_SETCHARFORMAT, (WPARAM)wFlags, (LPARAM)&cf);
  6208. }
  6209. BOOL SetDefaultCharFormat(CHARFORMAT& cf)
  6210. {
  6211. ATLASSERT(::IsWindow(this->m_hWnd));
  6212. cf.cbSize = sizeof(CHARFORMAT);
  6213. return (BOOL)::SendMessage(this->m_hWnd, EM_SETCHARFORMAT, 0, (LPARAM)&cf);
  6214. }
  6215. BOOL SetSelectionCharFormat(CHARFORMAT& cf)
  6216. {
  6217. ATLASSERT(::IsWindow(this->m_hWnd));
  6218. cf.cbSize = sizeof(CHARFORMAT);
  6219. return (BOOL)::SendMessage(this->m_hWnd, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf);
  6220. }
  6221. BOOL SetWordCharFormat(CHARFORMAT& cf)
  6222. {
  6223. ATLASSERT(::IsWindow(this->m_hWnd));
  6224. cf.cbSize = sizeof(CHARFORMAT);
  6225. return (BOOL)::SendMessage(this->m_hWnd, EM_SETCHARFORMAT, SCF_SELECTION | SCF_WORD, (LPARAM)&cf);
  6226. }
  6227. DWORD SetEventMask(DWORD dwEventMask)
  6228. {
  6229. ATLASSERT(::IsWindow(this->m_hWnd));
  6230. return (DWORD)::SendMessage(this->m_hWnd, EM_SETEVENTMASK, 0, dwEventMask);
  6231. }
  6232. BOOL SetParaFormat(PARAFORMAT& pf)
  6233. {
  6234. ATLASSERT(::IsWindow(this->m_hWnd));
  6235. pf.cbSize = sizeof(PARAFORMAT);
  6236. return (BOOL)::SendMessage(this->m_hWnd, EM_SETPARAFORMAT, 0, (LPARAM)&pf);
  6237. }
  6238. BOOL SetTargetDevice(HDC hDC, int cxLineWidth)
  6239. {
  6240. ATLASSERT(::IsWindow(this->m_hWnd));
  6241. return (BOOL)::SendMessage(this->m_hWnd, EM_SETTARGETDEVICE, (WPARAM)hDC, cxLineWidth);
  6242. }
  6243. int GetTextLength() const
  6244. {
  6245. ATLASSERT(::IsWindow(this->m_hWnd));
  6246. return (int)::SendMessage(this->m_hWnd, WM_GETTEXTLENGTH, 0, 0L);
  6247. }
  6248. BOOL SetReadOnly(BOOL bReadOnly = TRUE)
  6249. {
  6250. ATLASSERT(::IsWindow(this->m_hWnd));
  6251. return (BOOL)::SendMessage(this->m_hWnd, EM_SETREADONLY, bReadOnly, 0L);
  6252. }
  6253. int GetFirstVisibleLine() const
  6254. {
  6255. ATLASSERT(::IsWindow(this->m_hWnd));
  6256. return (int)::SendMessage(this->m_hWnd, EM_GETFIRSTVISIBLELINE, 0, 0L);
  6257. }
  6258. int GetTextRange(TEXTRANGE* pTextRange) const
  6259. {
  6260. ATLASSERT(::IsWindow(this->m_hWnd));
  6261. return (int)::SendMessage(this->m_hWnd, EM_GETTEXTRANGE, 0, (LPARAM)pTextRange);
  6262. }
  6263. int GetTextRange(LONG nStartChar, LONG nEndChar, LPTSTR lpstrText) const
  6264. {
  6265. ATLASSERT(::IsWindow(this->m_hWnd));
  6266. TEXTRANGE tr = {};
  6267. tr.chrg.cpMin = nStartChar;
  6268. tr.chrg.cpMax = nEndChar;
  6269. tr.lpstrText = lpstrText;
  6270. return (int)::SendMessage(this->m_hWnd, EM_GETTEXTRANGE, 0, (LPARAM)&tr);
  6271. }
  6272. DWORD GetDefaultCharFormat(CHARFORMAT2& cf) const
  6273. {
  6274. ATLASSERT(::IsWindow(this->m_hWnd));
  6275. cf.cbSize = sizeof(CHARFORMAT2);
  6276. return (DWORD)::SendMessage(this->m_hWnd, EM_GETCHARFORMAT, 0, (LPARAM)&cf);
  6277. }
  6278. BOOL SetCharFormat(CHARFORMAT2& cf, WORD wFlags)
  6279. {
  6280. ATLASSERT(::IsWindow(this->m_hWnd));
  6281. cf.cbSize = sizeof(CHARFORMAT2);
  6282. return (BOOL)::SendMessage(this->m_hWnd, EM_SETCHARFORMAT, (WPARAM)wFlags, (LPARAM)&cf);
  6283. }
  6284. BOOL SetDefaultCharFormat(CHARFORMAT2& cf)
  6285. {
  6286. ATLASSERT(::IsWindow(this->m_hWnd));
  6287. cf.cbSize = sizeof(CHARFORMAT2);
  6288. return (BOOL)::SendMessage(this->m_hWnd, EM_SETCHARFORMAT, 0, (LPARAM)&cf);
  6289. }
  6290. DWORD GetSelectionCharFormat(CHARFORMAT2& cf) const
  6291. {
  6292. ATLASSERT(::IsWindow(this->m_hWnd));
  6293. cf.cbSize = sizeof(CHARFORMAT2);
  6294. return (DWORD)::SendMessage(this->m_hWnd, EM_GETCHARFORMAT, 1, (LPARAM)&cf);
  6295. }
  6296. BOOL SetSelectionCharFormat(CHARFORMAT2& cf)
  6297. {
  6298. ATLASSERT(::IsWindow(this->m_hWnd));
  6299. cf.cbSize = sizeof(CHARFORMAT2);
  6300. return (BOOL)::SendMessage(this->m_hWnd, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf);
  6301. }
  6302. BOOL SetWordCharFormat(CHARFORMAT2& cf)
  6303. {
  6304. ATLASSERT(::IsWindow(this->m_hWnd));
  6305. cf.cbSize = sizeof(CHARFORMAT2);
  6306. return (BOOL)::SendMessage(this->m_hWnd, EM_SETCHARFORMAT, SCF_SELECTION | SCF_WORD, (LPARAM)&cf);
  6307. }
  6308. DWORD GetParaFormat(PARAFORMAT2& pf) const
  6309. {
  6310. ATLASSERT(::IsWindow(this->m_hWnd));
  6311. pf.cbSize = sizeof(PARAFORMAT2);
  6312. return (DWORD)::SendMessage(this->m_hWnd, EM_GETPARAFORMAT, 0, (LPARAM)&pf);
  6313. }
  6314. BOOL SetParaFormat(PARAFORMAT2& pf)
  6315. {
  6316. ATLASSERT(::IsWindow(this->m_hWnd));
  6317. pf.cbSize = sizeof(PARAFORMAT2);
  6318. return (BOOL)::SendMessage(this->m_hWnd, EM_SETPARAFORMAT, 0, (LPARAM)&pf);
  6319. }
  6320. TEXTMODE GetTextMode() const
  6321. {
  6322. ATLASSERT(::IsWindow(this->m_hWnd));
  6323. return (TEXTMODE)::SendMessage(this->m_hWnd, EM_GETTEXTMODE, 0, 0L);
  6324. }
  6325. BOOL SetTextMode(TEXTMODE enumTextMode)
  6326. {
  6327. ATLASSERT(::IsWindow(this->m_hWnd));
  6328. return !(BOOL)::SendMessage(this->m_hWnd, EM_SETTEXTMODE, enumTextMode, 0L);
  6329. }
  6330. UNDONAMEID GetUndoName() const
  6331. {
  6332. ATLASSERT(::IsWindow(this->m_hWnd));
  6333. return (UNDONAMEID)::SendMessage(this->m_hWnd, EM_GETUNDONAME, 0, 0L);
  6334. }
  6335. UNDONAMEID GetRedoName() const
  6336. {
  6337. ATLASSERT(::IsWindow(this->m_hWnd));
  6338. return (UNDONAMEID)::SendMessage(this->m_hWnd, EM_GETREDONAME, 0, 0L);
  6339. }
  6340. BOOL CanRedo() const
  6341. {
  6342. ATLASSERT(::IsWindow(this->m_hWnd));
  6343. return (BOOL)::SendMessage(this->m_hWnd, EM_CANREDO, 0, 0L);
  6344. }
  6345. BOOL GetAutoURLDetect() const
  6346. {
  6347. ATLASSERT(::IsWindow(this->m_hWnd));
  6348. return (BOOL)::SendMessage(this->m_hWnd, EM_GETAUTOURLDETECT, 0, 0L);
  6349. }
  6350. BOOL SetAutoURLDetect(BOOL bAutoDetect = TRUE)
  6351. {
  6352. ATLASSERT(::IsWindow(this->m_hWnd));
  6353. return !(BOOL)::SendMessage(this->m_hWnd, EM_AUTOURLDETECT, bAutoDetect, 0L);
  6354. }
  6355. // this method is deprecated, please use SetAutoURLDetect
  6356. BOOL EnableAutoURLDetect(BOOL bEnable = TRUE) { return SetAutoURLDetect(bEnable); }
  6357. UINT SetUndoLimit(UINT uUndoLimit)
  6358. {
  6359. ATLASSERT(::IsWindow(this->m_hWnd));
  6360. return (UINT)::SendMessage(this->m_hWnd, EM_SETUNDOLIMIT, uUndoLimit, 0L);
  6361. }
  6362. void SetPalette(HPALETTE hPalette)
  6363. {
  6364. ATLASSERT(::IsWindow(this->m_hWnd));
  6365. ::SendMessage(this->m_hWnd, EM_SETPALETTE, (WPARAM)hPalette, 0L);
  6366. }
  6367. int GetTextEx(GETTEXTEX* pGetTextEx, LPTSTR lpstrText) const
  6368. {
  6369. ATLASSERT(::IsWindow(this->m_hWnd));
  6370. return (int)::SendMessage(this->m_hWnd, EM_GETTEXTEX, (WPARAM)pGetTextEx, (LPARAM)lpstrText);
  6371. }
  6372. int GetTextEx(LPTSTR lpstrText, int nTextLen, DWORD dwFlags = GT_DEFAULT, UINT uCodePage = CP_ACP, LPCSTR lpDefaultChar = NULL, LPBOOL lpUsedDefChar = NULL) const
  6373. {
  6374. ATLASSERT(::IsWindow(this->m_hWnd));
  6375. GETTEXTEX gte = {};
  6376. gte.cb = nTextLen * sizeof(TCHAR);
  6377. gte.codepage = uCodePage;
  6378. gte.flags = dwFlags;
  6379. gte.lpDefaultChar = lpDefaultChar;
  6380. gte.lpUsedDefChar = lpUsedDefChar;
  6381. return (int)::SendMessage(this->m_hWnd, EM_GETTEXTEX, (WPARAM)&gte, (LPARAM)lpstrText);
  6382. }
  6383. int GetTextLengthEx(GETTEXTLENGTHEX* pGetTextLengthEx) const
  6384. {
  6385. ATLASSERT(::IsWindow(this->m_hWnd));
  6386. return (int)::SendMessage(this->m_hWnd, EM_GETTEXTLENGTHEX, (WPARAM)pGetTextLengthEx, 0L);
  6387. }
  6388. int GetTextLengthEx(DWORD dwFlags = GTL_DEFAULT, UINT uCodePage = CP_ACP) const
  6389. {
  6390. ATLASSERT(::IsWindow(this->m_hWnd));
  6391. GETTEXTLENGTHEX gtle = {};
  6392. gtle.codepage = uCodePage;
  6393. gtle.flags = dwFlags;
  6394. return (int)::SendMessage(this->m_hWnd, EM_GETTEXTLENGTHEX, (WPARAM)&gtle, 0L);
  6395. }
  6396. EDITWORDBREAKPROC GetWordBreakProc() const
  6397. {
  6398. ATLASSERT(::IsWindow(this->m_hWnd));
  6399. return (EDITWORDBREAKPROC)::SendMessage(this->m_hWnd, EM_GETWORDBREAKPROC, 0, 0L);
  6400. }
  6401. void SetWordBreakProc(EDITWORDBREAKPROC ewbprc)
  6402. {
  6403. ATLASSERT(::IsWindow(this->m_hWnd));
  6404. ::SendMessage(this->m_hWnd, EM_SETWORDBREAKPROC, 0, (LPARAM)ewbprc);
  6405. }
  6406. int SetTextEx(SETTEXTEX* pSetTextEx, LPCTSTR lpstrText)
  6407. {
  6408. ATLASSERT(::IsWindow(this->m_hWnd));
  6409. return (int)::SendMessage(this->m_hWnd, EM_SETTEXTEX, (WPARAM)pSetTextEx, (LPARAM)lpstrText);
  6410. }
  6411. int SetTextEx(LPCTSTR lpstrText, DWORD dwFlags = ST_DEFAULT, UINT uCodePage = CP_ACP)
  6412. {
  6413. ATLASSERT(::IsWindow(this->m_hWnd));
  6414. SETTEXTEX ste = {};
  6415. ste.flags = dwFlags;
  6416. ste.codepage = uCodePage;
  6417. return (int)::SendMessage(this->m_hWnd, EM_SETTEXTEX, (WPARAM)&ste, (LPARAM)lpstrText);
  6418. }
  6419. int GetEditStyle() const
  6420. {
  6421. ATLASSERT(::IsWindow(this->m_hWnd));
  6422. return (int)::SendMessage(this->m_hWnd, EM_GETEDITSTYLE, 0, 0L);
  6423. }
  6424. int SetEditStyle(int nStyle, int nMask = -1)
  6425. {
  6426. ATLASSERT(::IsWindow(this->m_hWnd));
  6427. if(nMask == -1)
  6428. nMask = nStyle; // set everything specified
  6429. return (int)::SendMessage(this->m_hWnd, EM_SETEDITSTYLE, nStyle, nMask);
  6430. }
  6431. BOOL SetFontSize(int nFontSizeDelta)
  6432. {
  6433. ATLASSERT(::IsWindow(this->m_hWnd));
  6434. ATLASSERT((nFontSizeDelta >= -1637) && (nFontSizeDelta <= 1638));
  6435. return (BOOL)::SendMessage(this->m_hWnd, EM_SETFONTSIZE, nFontSizeDelta, 0L);
  6436. }
  6437. void GetScrollPos(LPPOINT lpPoint) const
  6438. {
  6439. ATLASSERT(::IsWindow(this->m_hWnd));
  6440. ATLASSERT(lpPoint != NULL);
  6441. ::SendMessage(this->m_hWnd, EM_GETSCROLLPOS, 0, (LPARAM)lpPoint);
  6442. }
  6443. void SetScrollPos(LPPOINT lpPoint)
  6444. {
  6445. ATLASSERT(::IsWindow(this->m_hWnd));
  6446. ATLASSERT(lpPoint != NULL);
  6447. ::SendMessage(this->m_hWnd, EM_SETSCROLLPOS, 0, (LPARAM)lpPoint);
  6448. }
  6449. BOOL GetZoom(int& nNum, int& nDen) const
  6450. {
  6451. ATLASSERT(::IsWindow(this->m_hWnd));
  6452. return (BOOL)::SendMessage(this->m_hWnd, EM_GETZOOM, (WPARAM)&nNum, (LPARAM)&nDen);
  6453. }
  6454. BOOL SetZoom(int nNum, int nDen)
  6455. {
  6456. ATLASSERT(::IsWindow(this->m_hWnd));
  6457. ATLASSERT((nNum >= 0) && (nNum <= 64));
  6458. ATLASSERT((nDen >= 0) && (nDen <= 64));
  6459. return (BOOL)::SendMessage(this->m_hWnd, EM_SETZOOM, nNum, nDen);
  6460. }
  6461. BOOL SetZoomOff()
  6462. {
  6463. ATLASSERT(::IsWindow(this->m_hWnd));
  6464. return (BOOL)::SendMessage(this->m_hWnd, EM_SETZOOM, 0, 0L);
  6465. }
  6466. void SetMargins(UINT nLeft, UINT nRight, WORD wFlags = EC_LEFTMARGIN | EC_RIGHTMARGIN)
  6467. {
  6468. ATLASSERT(::IsWindow(this->m_hWnd));
  6469. ::SendMessage(this->m_hWnd, EM_SETMARGINS, wFlags, MAKELONG(nLeft, nRight));
  6470. }
  6471. WORD GetTypographyOptions() const
  6472. {
  6473. ATLASSERT(::IsWindow(this->m_hWnd));
  6474. return (WORD)::SendMessage(this->m_hWnd, EM_GETTYPOGRAPHYOPTIONS, 0, 0L);
  6475. }
  6476. BOOL SetTypographyOptions(WORD wOptions, WORD wMask) const
  6477. {
  6478. ATLASSERT(::IsWindow(this->m_hWnd));
  6479. return (BOOL)::SendMessage(this->m_hWnd, EM_SETTYPOGRAPHYOPTIONS, wOptions, wMask);
  6480. }
  6481. // Operations
  6482. void LimitText(LONG nChars = 0)
  6483. {
  6484. ATLASSERT(::IsWindow(this->m_hWnd));
  6485. ::SendMessage(this->m_hWnd, EM_EXLIMITTEXT, 0, nChars);
  6486. }
  6487. int LineFromChar(LONG nIndex) const
  6488. {
  6489. ATLASSERT(::IsWindow(this->m_hWnd));
  6490. return (int)::SendMessage(this->m_hWnd, EM_EXLINEFROMCHAR, 0, nIndex);
  6491. }
  6492. POINT PosFromChar(LONG nChar) const
  6493. {
  6494. ATLASSERT(::IsWindow(this->m_hWnd));
  6495. POINT point = {};
  6496. ::SendMessage(this->m_hWnd, EM_POSFROMCHAR, (WPARAM)&point, nChar);
  6497. return point;
  6498. }
  6499. int CharFromPos(POINT pt) const
  6500. {
  6501. ATLASSERT(::IsWindow(this->m_hWnd));
  6502. POINTL ptl = { pt.x, pt.y };
  6503. return (int)::SendMessage(this->m_hWnd, EM_CHARFROMPOS, 0, (LPARAM)&ptl);
  6504. }
  6505. void EmptyUndoBuffer()
  6506. {
  6507. ATLASSERT(::IsWindow(this->m_hWnd));
  6508. ::SendMessage(this->m_hWnd, EM_EMPTYUNDOBUFFER, 0, 0L);
  6509. }
  6510. int LineIndex(int nLine = -1) const
  6511. {
  6512. ATLASSERT(::IsWindow(this->m_hWnd));
  6513. return (int)::SendMessage(this->m_hWnd, EM_LINEINDEX, nLine, 0L);
  6514. }
  6515. int LineLength(int nLine = -1) const
  6516. {
  6517. ATLASSERT(::IsWindow(this->m_hWnd));
  6518. return (int)::SendMessage(this->m_hWnd, EM_LINELENGTH, nLine, 0L);
  6519. }
  6520. BOOL LineScroll(int nLines)
  6521. {
  6522. ATLASSERT(::IsWindow(this->m_hWnd));
  6523. return (BOOL)::SendMessage(this->m_hWnd, EM_LINESCROLL, 0, nLines);
  6524. }
  6525. void ReplaceSel(LPCTSTR lpszNewText, BOOL bCanUndo = FALSE)
  6526. {
  6527. ATLASSERT(::IsWindow(this->m_hWnd));
  6528. ::SendMessage(this->m_hWnd, EM_REPLACESEL, (WPARAM) bCanUndo, (LPARAM)lpszNewText);
  6529. }
  6530. void SetRect(LPCRECT lpRect)
  6531. {
  6532. ATLASSERT(::IsWindow(this->m_hWnd));
  6533. ::SendMessage(this->m_hWnd, EM_SETRECT, 0, (LPARAM)lpRect);
  6534. }
  6535. BOOL DisplayBand(LPRECT pDisplayRect)
  6536. {
  6537. ATLASSERT(::IsWindow(this->m_hWnd));
  6538. return (BOOL)::SendMessage(this->m_hWnd, EM_DISPLAYBAND, 0, (LPARAM)pDisplayRect);
  6539. }
  6540. LONG FindText(DWORD dwFlags, FINDTEXT& ft) const
  6541. {
  6542. ATLASSERT(::IsWindow(this->m_hWnd));
  6543. #ifdef _UNICODE
  6544. return (LONG)::SendMessage(this->m_hWnd, EM_FINDTEXTW, dwFlags, (LPARAM)&ft);
  6545. #else
  6546. return (LONG)::SendMessage(this->m_hWnd, EM_FINDTEXT, dwFlags, (LPARAM)&ft);
  6547. #endif
  6548. }
  6549. LONG FindText(DWORD dwFlags, FINDTEXTEX& ft) const
  6550. {
  6551. ATLASSERT(::IsWindow(this->m_hWnd));
  6552. #ifdef _UNICODE
  6553. return (LONG)::SendMessage(this->m_hWnd, EM_FINDTEXTEXW, dwFlags, (LPARAM)&ft);
  6554. #else
  6555. return (LONG)::SendMessage(this->m_hWnd, EM_FINDTEXTEX, dwFlags, (LPARAM)&ft);
  6556. #endif
  6557. }
  6558. LONG FormatRange(FORMATRANGE& fr, BOOL bDisplay = TRUE)
  6559. {
  6560. ATLASSERT(::IsWindow(this->m_hWnd));
  6561. return (LONG)::SendMessage(this->m_hWnd, EM_FORMATRANGE, bDisplay, (LPARAM)&fr);
  6562. }
  6563. LONG FormatRange(FORMATRANGE* pFormatRange, BOOL bDisplay = TRUE)
  6564. {
  6565. ATLASSERT(::IsWindow(this->m_hWnd));
  6566. return (LONG)::SendMessage(this->m_hWnd, EM_FORMATRANGE, bDisplay, (LPARAM)pFormatRange);
  6567. }
  6568. void HideSelection(BOOL bHide = TRUE, BOOL bChangeStyle = FALSE)
  6569. {
  6570. ATLASSERT(::IsWindow(this->m_hWnd));
  6571. ::SendMessage(this->m_hWnd, EM_HIDESELECTION, bHide, bChangeStyle);
  6572. }
  6573. void PasteSpecial(UINT uClipFormat, DWORD dwAspect = 0, HMETAFILE hMF = 0)
  6574. {
  6575. ATLASSERT(::IsWindow(this->m_hWnd));
  6576. REPASTESPECIAL reps = { dwAspect, (DWORD_PTR)hMF };
  6577. ::SendMessage(this->m_hWnd, EM_PASTESPECIAL, uClipFormat, (LPARAM)&reps);
  6578. }
  6579. void RequestResize()
  6580. {
  6581. ATLASSERT(::IsWindow(this->m_hWnd));
  6582. ::SendMessage(this->m_hWnd, EM_REQUESTRESIZE, 0, 0L);
  6583. }
  6584. LONG StreamIn(UINT uFormat, EDITSTREAM& es)
  6585. {
  6586. ATLASSERT(::IsWindow(this->m_hWnd));
  6587. return (LONG)::SendMessage(this->m_hWnd, EM_STREAMIN, uFormat, (LPARAM)&es);
  6588. }
  6589. LONG StreamOut(UINT uFormat, EDITSTREAM& es)
  6590. {
  6591. ATLASSERT(::IsWindow(this->m_hWnd));
  6592. return (LONG)::SendMessage(this->m_hWnd, EM_STREAMOUT, uFormat, (LPARAM)&es);
  6593. }
  6594. DWORD FindWordBreak(int nCode, LONG nStartChar)
  6595. {
  6596. ATLASSERT(::IsWindow(this->m_hWnd));
  6597. return (DWORD)::SendMessage(this->m_hWnd, EM_FINDWORDBREAK, nCode, nStartChar);
  6598. }
  6599. // Additional operations
  6600. void ScrollCaret()
  6601. {
  6602. ATLASSERT(::IsWindow(this->m_hWnd));
  6603. ::SendMessage(this->m_hWnd, EM_SCROLLCARET, 0, 0L);
  6604. }
  6605. int InsertText(long nInsertAfterChar, LPCTSTR lpstrText, BOOL bCanUndo = FALSE)
  6606. {
  6607. int nRet = SetSel(nInsertAfterChar, nInsertAfterChar);
  6608. ReplaceSel(lpstrText, bCanUndo);
  6609. return nRet;
  6610. }
  6611. int AppendText(LPCTSTR lpstrText, BOOL bCanUndo = FALSE)
  6612. {
  6613. return InsertText(this->GetWindowTextLength(), lpstrText, bCanUndo);
  6614. }
  6615. // Clipboard operations
  6616. BOOL Undo()
  6617. {
  6618. ATLASSERT(::IsWindow(this->m_hWnd));
  6619. return (BOOL)::SendMessage(this->m_hWnd, EM_UNDO, 0, 0L);
  6620. }
  6621. void Clear()
  6622. {
  6623. ATLASSERT(::IsWindow(this->m_hWnd));
  6624. ::SendMessage(this->m_hWnd, WM_CLEAR, 0, 0L);
  6625. }
  6626. void Copy()
  6627. {
  6628. ATLASSERT(::IsWindow(this->m_hWnd));
  6629. ::SendMessage(this->m_hWnd, WM_COPY, 0, 0L);
  6630. }
  6631. void Cut()
  6632. {
  6633. ATLASSERT(::IsWindow(this->m_hWnd));
  6634. ::SendMessage(this->m_hWnd, WM_CUT, 0, 0L);
  6635. }
  6636. void Paste()
  6637. {
  6638. ATLASSERT(::IsWindow(this->m_hWnd));
  6639. ::SendMessage(this->m_hWnd, WM_PASTE, 0, 0L);
  6640. }
  6641. // OLE support
  6642. IRichEditOle* GetOleInterface() const
  6643. {
  6644. ATLASSERT(::IsWindow(this->m_hWnd));
  6645. IRichEditOle *pRichEditOle = NULL;
  6646. ::SendMessage(this->m_hWnd, EM_GETOLEINTERFACE, 0, (LPARAM)&pRichEditOle);
  6647. return pRichEditOle;
  6648. }
  6649. BOOL SetOleCallback(IRichEditOleCallback* pCallback)
  6650. {
  6651. ATLASSERT(::IsWindow(this->m_hWnd));
  6652. return (BOOL)::SendMessage(this->m_hWnd, EM_SETOLECALLBACK, 0, (LPARAM)pCallback);
  6653. }
  6654. BOOL Redo()
  6655. {
  6656. ATLASSERT(::IsWindow(this->m_hWnd));
  6657. return (BOOL)::SendMessage(this->m_hWnd, EM_REDO, 0, 0L);
  6658. }
  6659. void StopGroupTyping()
  6660. {
  6661. ATLASSERT(::IsWindow(this->m_hWnd));
  6662. ::SendMessage(this->m_hWnd, EM_STOPGROUPTYPING, 0, 0L);
  6663. }
  6664. void ShowScrollBar(int nBarType, BOOL bVisible = TRUE)
  6665. {
  6666. ATLASSERT(::IsWindow(this->m_hWnd));
  6667. ::SendMessage(this->m_hWnd, EM_SHOWSCROLLBAR, nBarType, bVisible);
  6668. }
  6669. BOOL SetTabStops(int nTabStops, LPINT rgTabStops)
  6670. {
  6671. ATLASSERT(::IsWindow(this->m_hWnd));
  6672. return (BOOL)::SendMessage(this->m_hWnd, EM_SETTABSTOPS, nTabStops, (LPARAM)rgTabStops);
  6673. }
  6674. BOOL SetTabStops()
  6675. {
  6676. ATLASSERT(::IsWindow(this->m_hWnd));
  6677. return (BOOL)::SendMessage(this->m_hWnd, EM_SETTABSTOPS, 0, 0L);
  6678. }
  6679. BOOL SetTabStops(const int& cxEachStop) // takes an 'int'
  6680. {
  6681. ATLASSERT(::IsWindow(this->m_hWnd));
  6682. return (BOOL)::SendMessage(this->m_hWnd, EM_SETTABSTOPS, 1, (LPARAM)(LPINT)&cxEachStop);
  6683. }
  6684. #if (_RICHEDIT_VER >= 0x0800)
  6685. AutoCorrectProc GetAutoCorrectProc() const
  6686. {
  6687. ATLASSERT(::IsWindow(this->m_hWnd));
  6688. return (AutoCorrectProc)::SendMessage(this->m_hWnd, EM_GETAUTOCORRECTPROC, 0, 0L);
  6689. }
  6690. BOOL SetAutoCorrectProc(AutoCorrectProc pfn)
  6691. {
  6692. ATLASSERT(::IsWindow(this->m_hWnd));
  6693. return (BOOL)::SendMessage(this->m_hWnd, EM_SETAUTOCORRECTPROC, (WPARAM)pfn, 0L);
  6694. }
  6695. BOOL CallAutoCorrectProc(WCHAR ch)
  6696. {
  6697. ATLASSERT(::IsWindow(this->m_hWnd));
  6698. return (BOOL)::SendMessage(this->m_hWnd, EM_CALLAUTOCORRECTPROC, (WPARAM)ch, 0L);
  6699. }
  6700. DWORD GetEditStyleEx() const
  6701. {
  6702. ATLASSERT(::IsWindow(this->m_hWnd));
  6703. return (DWORD)::SendMessage(this->m_hWnd, EM_GETEDITSTYLEEX, 0, 0L);
  6704. }
  6705. DWORD SetEditStyleEx(DWORD dwStyleEx, DWORD dwMask)
  6706. {
  6707. ATLASSERT(::IsWindow(this->m_hWnd));
  6708. return (DWORD)::SendMessage(this->m_hWnd, EM_SETEDITSTYLEEX, dwStyleEx, dwMask);
  6709. }
  6710. DWORD GetStoryType(int nStoryIndex) const
  6711. {
  6712. ATLASSERT(::IsWindow(this->m_hWnd));
  6713. return (DWORD)::SendMessage(this->m_hWnd, EM_GETSTORYTYPE, nStoryIndex, 0L);
  6714. }
  6715. DWORD SetStoryType(int nStoryIndex, DWORD dwStoryType)
  6716. {
  6717. ATLASSERT(::IsWindow(this->m_hWnd));
  6718. return (DWORD)::SendMessage(this->m_hWnd, EM_SETSTORYTYPE, nStoryIndex, dwStoryType);
  6719. }
  6720. DWORD GetEllipsisMode() const
  6721. {
  6722. ATLASSERT(::IsWindow(this->m_hWnd));
  6723. DWORD dwMode = 0;
  6724. BOOL bRet = (BOOL)::SendMessage(this->m_hWnd, EM_GETELLIPSISMODE, 0, (LPARAM)&dwMode);
  6725. (void)bRet; // avoid level 4 warning
  6726. ATLASSERT(bRet != FALSE);
  6727. return dwMode;
  6728. }
  6729. BOOL SetEllipsisMode(DWORD dwEllipsisMode)
  6730. {
  6731. ATLASSERT(::IsWindow(this->m_hWnd));
  6732. return (BOOL)::SendMessage(this->m_hWnd, EM_SETELLIPSISMODE, 0, dwEllipsisMode);
  6733. }
  6734. BOOL GetEllipsisState() const
  6735. {
  6736. ATLASSERT(::IsWindow(this->m_hWnd));
  6737. return (BOOL)::SendMessage(this->m_hWnd, EM_GETELLIPSISSTATE, 0, 0L);
  6738. }
  6739. BOOL GetTouchOptions(int nTouchOptions) const
  6740. {
  6741. ATLASSERT(::IsWindow(this->m_hWnd));
  6742. return (BOOL)::SendMessage(this->m_hWnd, EM_GETTOUCHOPTIONS, nTouchOptions, 0L);
  6743. }
  6744. void SetTouchOptions(int nTouchOptions, BOOL bEnable)
  6745. {
  6746. ATLASSERT(::IsWindow(this->m_hWnd));
  6747. ::SendMessage(this->m_hWnd, EM_SETTOUCHOPTIONS, nTouchOptions, bEnable);
  6748. }
  6749. HRESULT InsertTable(TABLEROWPARMS* pRowParams, TABLECELLPARMS* pCellParams)
  6750. {
  6751. ATLASSERT(::IsWindow(this->m_hWnd));
  6752. return (HRESULT)::SendMessage(this->m_hWnd, EM_INSERTTABLE, (WPARAM)pRowParams, (LPARAM)pCellParams);
  6753. }
  6754. HRESULT GetTableParams(TABLEROWPARMS* pRowParams, TABLECELLPARMS* pCellParams) const
  6755. {
  6756. ATLASSERT(::IsWindow(this->m_hWnd));
  6757. return (HRESULT)::SendMessage(this->m_hWnd, EM_GETTABLEPARMS, (WPARAM)pRowParams, (LPARAM)pCellParams);
  6758. }
  6759. HRESULT SetTableParams(TABLEROWPARMS* pRowParams, TABLECELLPARMS* pCellParams)
  6760. {
  6761. ATLASSERT(::IsWindow(this->m_hWnd));
  6762. return (HRESULT)::SendMessage(this->m_hWnd, EM_SETTABLEPARMS, (WPARAM)pRowParams, (LPARAM)pCellParams);
  6763. }
  6764. HRESULT InsertImage(RICHEDIT_IMAGE_PARAMETERS* pParams)
  6765. {
  6766. ATLASSERT(::IsWindow(this->m_hWnd));
  6767. return (HRESULT)::SendMessage(this->m_hWnd, EM_INSERTIMAGE, 0, (LPARAM)pParams);
  6768. }
  6769. BOOL SetUiaName(LPCTSTR lpstrName)
  6770. {
  6771. ATLASSERT(::IsWindow(this->m_hWnd));
  6772. return (BOOL)::SendMessage(this->m_hWnd, EM_SETUIANAME, 0, (LPARAM)lpstrName);
  6773. }
  6774. #endif // (_RICHEDIT_VER >= 0x0800)
  6775. };
  6776. typedef CRichEditCtrlT<ATL::CWindow> CRichEditCtrl;
  6777. ///////////////////////////////////////////////////////////////////////////////
  6778. // CRichEditCommands - message handlers for standard EDIT commands
  6779. // Chain to CRichEditCommands message map. Your class must also derive from CRichEditCtrl.
  6780. // Example:
  6781. // class CMyRichEdit : public CWindowImpl<CMyRichEdit, CRichEditCtrl>,
  6782. // public CRichEditCommands<CMyRichEdit>
  6783. // {
  6784. // public:
  6785. // BEGIN_MSG_MAP(CMyRichEdit)
  6786. // // your handlers...
  6787. // CHAIN_MSG_MAP_ALT(CRichEditCommands<CMyRichEdit>, 1)
  6788. // END_MSG_MAP()
  6789. // // other stuff...
  6790. // };
  6791. template <class T>
  6792. class CRichEditCommands : public CEditCommands< T >
  6793. {
  6794. public:
  6795. BEGIN_MSG_MAP(CRichEditCommands< T >)
  6796. ALT_MSG_MAP(1)
  6797. COMMAND_ID_HANDLER(ID_EDIT_CLEAR, CEditCommands< T >::OnEditClear)
  6798. COMMAND_ID_HANDLER(ID_EDIT_CLEAR_ALL, CEditCommands< T >::OnEditClearAll)
  6799. COMMAND_ID_HANDLER(ID_EDIT_COPY, CEditCommands< T >::OnEditCopy)
  6800. COMMAND_ID_HANDLER(ID_EDIT_CUT, CEditCommands< T >::OnEditCut)
  6801. COMMAND_ID_HANDLER(ID_EDIT_PASTE, CEditCommands< T >::OnEditPaste)
  6802. COMMAND_ID_HANDLER(ID_EDIT_SELECT_ALL, CEditCommands< T >::OnEditSelectAll)
  6803. COMMAND_ID_HANDLER(ID_EDIT_UNDO, CEditCommands< T >::OnEditUndo)
  6804. COMMAND_ID_HANDLER(ID_EDIT_REDO, OnEditRedo)
  6805. END_MSG_MAP()
  6806. LRESULT OnEditRedo(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  6807. {
  6808. T* pT = static_cast<T*>(this);
  6809. pT->Redo();
  6810. return 0;
  6811. }
  6812. // State (update UI) helpers
  6813. BOOL CanCut() const
  6814. { return HasSelection(); }
  6815. BOOL CanCopy() const
  6816. { return HasSelection(); }
  6817. BOOL CanClear() const
  6818. { return HasSelection(); }
  6819. // Implementation
  6820. BOOL HasSelection() const
  6821. {
  6822. const T* pT = static_cast<const T*>(this);
  6823. return (pT->GetSelectionType() != SEL_EMPTY);
  6824. }
  6825. };
  6826. ///////////////////////////////////////////////////////////////////////////////
  6827. // CDragListBox
  6828. template <class TBase>
  6829. class CDragListBoxT : public CListBoxT< TBase >
  6830. {
  6831. public:
  6832. // Constructors
  6833. CDragListBoxT(HWND hWnd = NULL) : CListBoxT< TBase >(hWnd)
  6834. { }
  6835. CDragListBoxT< TBase >& operator =(HWND hWnd)
  6836. {
  6837. this->m_hWnd = hWnd;
  6838. return *this;
  6839. }
  6840. HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  6841. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  6842. ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  6843. {
  6844. HWND hWnd = TBase::Create(TBase::GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  6845. if(hWnd != NULL)
  6846. MakeDragList();
  6847. return hWnd;
  6848. }
  6849. // Operations
  6850. BOOL MakeDragList()
  6851. {
  6852. ATLASSERT(::IsWindow(this->m_hWnd));
  6853. ATLASSERT((this->GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) == 0);
  6854. return ::MakeDragList(this->m_hWnd);
  6855. }
  6856. int LBItemFromPt(POINT pt, BOOL bAutoScroll = TRUE)
  6857. {
  6858. ATLASSERT(::IsWindow(this->m_hWnd));
  6859. return ::LBItemFromPt(this->m_hWnd, pt, bAutoScroll);
  6860. }
  6861. void DrawInsert(int nItem)
  6862. {
  6863. ATLASSERT(::IsWindow(this->m_hWnd));
  6864. ::DrawInsert(this->GetParent(), this->m_hWnd, nItem);
  6865. }
  6866. static UINT GetDragListMessage()
  6867. {
  6868. static UINT uDragListMessage = 0;
  6869. if(uDragListMessage == 0)
  6870. {
  6871. CStaticDataInitCriticalSectionLock lock;
  6872. if(FAILED(lock.Lock()))
  6873. {
  6874. ATLTRACE2(atlTraceUI, 0, _T("ERROR : Unable to lock critical section in CDragListBox::GetDragListMessage.\n"));
  6875. ATLASSERT(FALSE);
  6876. return 0;
  6877. }
  6878. if(uDragListMessage == 0)
  6879. uDragListMessage = ::RegisterWindowMessage(DRAGLISTMSGSTRING);
  6880. lock.Unlock();
  6881. }
  6882. ATLASSERT(uDragListMessage != 0);
  6883. return uDragListMessage;
  6884. }
  6885. };
  6886. typedef CDragListBoxT<ATL::CWindow> CDragListBox;
  6887. template <class T>
  6888. class CDragListNotifyImpl
  6889. {
  6890. public:
  6891. BEGIN_MSG_MAP(CDragListNotifyImpl< T >)
  6892. MESSAGE_HANDLER(CDragListBox::GetDragListMessage(), OnDragListNotify)
  6893. END_MSG_MAP()
  6894. LRESULT OnDragListNotify(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  6895. {
  6896. (void)uMsg; // avoid level 4 warning
  6897. ATLASSERT(uMsg == CDragListBox::GetDragListMessage());
  6898. T* pT = static_cast<T*>(this);
  6899. LPDRAGLISTINFO lpDragListInfo = (LPDRAGLISTINFO)lParam;
  6900. LRESULT lRet = 0;
  6901. switch(lpDragListInfo->uNotification)
  6902. {
  6903. case DL_BEGINDRAG:
  6904. lRet = (LPARAM)pT->OnBeginDrag((int)wParam, lpDragListInfo->hWnd, lpDragListInfo->ptCursor);
  6905. break;
  6906. case DL_CANCELDRAG:
  6907. pT->OnCancelDrag((int)wParam, lpDragListInfo->hWnd, lpDragListInfo->ptCursor);
  6908. break;
  6909. case DL_DRAGGING:
  6910. lRet = (LPARAM)pT->OnDragging((int)wParam, lpDragListInfo->hWnd, lpDragListInfo->ptCursor);
  6911. break;
  6912. case DL_DROPPED:
  6913. pT->OnDropped((int)wParam, lpDragListInfo->hWnd, lpDragListInfo->ptCursor);
  6914. break;
  6915. default:
  6916. ATLTRACE2(atlTraceUI, 0, _T("Unknown DragListBox notification\n"));
  6917. bHandled = FALSE; // don't handle it
  6918. break;
  6919. }
  6920. return lRet;
  6921. }
  6922. // Overrideables
  6923. BOOL OnBeginDrag(int /*nCtlID*/, HWND /*hWndDragList*/, POINT /*ptCursor*/)
  6924. {
  6925. return TRUE; // allow dragging
  6926. }
  6927. void OnCancelDrag(int /*nCtlID*/, HWND /*hWndDragList*/, POINT /*ptCursor*/)
  6928. {
  6929. // nothing to do
  6930. }
  6931. int OnDragging(int /*nCtlID*/, HWND /*hWndDragList*/, POINT /*ptCursor*/)
  6932. {
  6933. return 0; // don't change cursor
  6934. }
  6935. void OnDropped(int /*nCtlID*/, HWND /*hWndDragList*/, POINT /*ptCursor*/)
  6936. {
  6937. // nothing to do
  6938. }
  6939. };
  6940. ///////////////////////////////////////////////////////////////////////////////
  6941. // CReBarCtrl
  6942. template <class TBase>
  6943. class CReBarCtrlT : public TBase
  6944. {
  6945. public:
  6946. // Constructors
  6947. CReBarCtrlT(HWND hWnd = NULL) : TBase(hWnd)
  6948. { }
  6949. CReBarCtrlT< TBase >& operator =(HWND hWnd)
  6950. {
  6951. this->m_hWnd = hWnd;
  6952. return *this;
  6953. }
  6954. HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  6955. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  6956. ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  6957. {
  6958. return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  6959. }
  6960. // Attributes
  6961. static LPCTSTR GetWndClassName()
  6962. {
  6963. return REBARCLASSNAME;
  6964. }
  6965. UINT GetBandCount() const
  6966. {
  6967. ATLASSERT(::IsWindow(this->m_hWnd));
  6968. return (UINT)::SendMessage(this->m_hWnd, RB_GETBANDCOUNT, 0, 0L);
  6969. }
  6970. BOOL GetBandInfo(int nBand, LPREBARBANDINFO lprbbi) const
  6971. {
  6972. ATLASSERT(::IsWindow(this->m_hWnd));
  6973. return (BOOL)::SendMessage(this->m_hWnd, RB_GETBANDINFO, nBand, (LPARAM)lprbbi);
  6974. }
  6975. BOOL SetBandInfo(int nBand, LPREBARBANDINFO lprbbi)
  6976. {
  6977. ATLASSERT(::IsWindow(this->m_hWnd));
  6978. return (BOOL)::SendMessage(this->m_hWnd, RB_SETBANDINFO, nBand, (LPARAM)lprbbi);
  6979. }
  6980. BOOL GetBarInfo(LPREBARINFO lprbi) const
  6981. {
  6982. ATLASSERT(::IsWindow(this->m_hWnd));
  6983. return (BOOL)::SendMessage(this->m_hWnd, RB_GETBARINFO, 0, (LPARAM)lprbi);
  6984. }
  6985. BOOL SetBarInfo(LPREBARINFO lprbi)
  6986. {
  6987. ATLASSERT(::IsWindow(this->m_hWnd));
  6988. return (BOOL)::SendMessage(this->m_hWnd, RB_SETBARINFO, 0, (LPARAM)lprbi);
  6989. }
  6990. CImageList GetImageList() const
  6991. {
  6992. ATLASSERT(::IsWindow(this->m_hWnd));
  6993. REBARINFO rbi = {};
  6994. rbi.cbSize = sizeof(REBARINFO);
  6995. rbi.fMask = RBIM_IMAGELIST;
  6996. BOOL bRet = (BOOL)::SendMessage(this->m_hWnd, RB_GETBARINFO, 0, (LPARAM)&rbi);
  6997. return CImageList((bRet != FALSE) ? rbi.himl : NULL);
  6998. }
  6999. BOOL SetImageList(HIMAGELIST hImageList)
  7000. {
  7001. ATLASSERT(::IsWindow(this->m_hWnd));
  7002. REBARINFO rbi = {};
  7003. rbi.cbSize = sizeof(REBARINFO);
  7004. rbi.fMask = RBIM_IMAGELIST;
  7005. rbi.himl = hImageList;
  7006. return (BOOL)::SendMessage(this->m_hWnd, RB_SETBARINFO, 0, (LPARAM)&rbi);
  7007. }
  7008. UINT GetRowCount() const
  7009. {
  7010. ATLASSERT(::IsWindow(this->m_hWnd));
  7011. return (UINT)::SendMessage(this->m_hWnd, RB_GETROWCOUNT, 0, 0L);
  7012. }
  7013. UINT GetRowHeight(int nBand) const
  7014. {
  7015. ATLASSERT(::IsWindow(this->m_hWnd));
  7016. return (UINT)::SendMessage(this->m_hWnd, RB_GETROWHEIGHT, nBand, 0L);
  7017. }
  7018. COLORREF GetTextColor() const
  7019. {
  7020. ATLASSERT(::IsWindow(this->m_hWnd));
  7021. return (COLORREF)::SendMessage(this->m_hWnd, RB_GETTEXTCOLOR, 0, 0L);
  7022. }
  7023. COLORREF SetTextColor(COLORREF clr)
  7024. {
  7025. ATLASSERT(::IsWindow(this->m_hWnd));
  7026. return (COLORREF)::SendMessage(this->m_hWnd, RB_SETTEXTCOLOR, 0, (LPARAM)clr);
  7027. }
  7028. COLORREF GetBkColor() const
  7029. {
  7030. ATLASSERT(::IsWindow(this->m_hWnd));
  7031. return (COLORREF)::SendMessage(this->m_hWnd, RB_GETBKCOLOR, 0, 0L);
  7032. }
  7033. COLORREF SetBkColor(COLORREF clr)
  7034. {
  7035. ATLASSERT(::IsWindow(this->m_hWnd));
  7036. return (COLORREF)::SendMessage(this->m_hWnd, RB_SETBKCOLOR, 0, (LPARAM)clr);
  7037. }
  7038. UINT GetBarHeight() const
  7039. {
  7040. ATLASSERT(::IsWindow(this->m_hWnd));
  7041. return (UINT)::SendMessage(this->m_hWnd, RB_GETBARHEIGHT, 0, 0L);
  7042. }
  7043. BOOL GetRect(int nBand, LPRECT lpRect) const
  7044. {
  7045. ATLASSERT(::IsWindow(this->m_hWnd));
  7046. return (BOOL)::SendMessage(this->m_hWnd, RB_GETRECT, nBand, (LPARAM)lpRect);
  7047. }
  7048. CToolTipCtrl GetToolTips() const
  7049. {
  7050. ATLASSERT(::IsWindow(this->m_hWnd));
  7051. return CToolTipCtrl((HWND)::SendMessage(this->m_hWnd, RB_GETTOOLTIPS, 0, 0L));
  7052. }
  7053. void SetToolTips(HWND hwndToolTip)
  7054. {
  7055. ATLASSERT(::IsWindow(this->m_hWnd));
  7056. ::SendMessage(this->m_hWnd, RB_SETTOOLTIPS, (WPARAM)hwndToolTip, 0L);
  7057. }
  7058. void GetBandBorders(int nBand, LPRECT lpRect) const
  7059. {
  7060. ATLASSERT(::IsWindow(this->m_hWnd));
  7061. ATLASSERT(lpRect != NULL);
  7062. ::SendMessage(this->m_hWnd, RB_GETBANDBORDERS, nBand, (LPARAM)lpRect);
  7063. }
  7064. BOOL GetColorScheme(LPCOLORSCHEME lpColorScheme) const
  7065. {
  7066. ATLASSERT(::IsWindow(this->m_hWnd));
  7067. ATLASSERT(lpColorScheme != NULL);
  7068. return (BOOL)::SendMessage(this->m_hWnd, RB_GETCOLORSCHEME, 0, (LPARAM)lpColorScheme);
  7069. }
  7070. void SetColorScheme(LPCOLORSCHEME lpColorScheme)
  7071. {
  7072. ATLASSERT(::IsWindow(this->m_hWnd));
  7073. ATLASSERT(lpColorScheme != NULL);
  7074. ::SendMessage(this->m_hWnd, RB_SETCOLORSCHEME, 0, (LPARAM)lpColorScheme);
  7075. }
  7076. HPALETTE GetPalette() const
  7077. {
  7078. ATLASSERT(::IsWindow(this->m_hWnd));
  7079. return (HPALETTE)::SendMessage(this->m_hWnd, RB_GETPALETTE, 0, 0L);
  7080. }
  7081. HPALETTE SetPalette(HPALETTE hPalette)
  7082. {
  7083. ATLASSERT(::IsWindow(this->m_hWnd));
  7084. return (HPALETTE)::SendMessage(this->m_hWnd, RB_SETPALETTE, 0, (LPARAM)hPalette);
  7085. }
  7086. BOOL GetUnicodeFormat() const
  7087. {
  7088. ATLASSERT(::IsWindow(this->m_hWnd));
  7089. return (BOOL)::SendMessage(this->m_hWnd, RB_GETUNICODEFORMAT, 0, 0L);
  7090. }
  7091. BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
  7092. {
  7093. ATLASSERT(::IsWindow(this->m_hWnd));
  7094. return (BOOL)::SendMessage(this->m_hWnd, RB_SETUNICODEFORMAT, bUnicode, 0L);
  7095. }
  7096. // requires uxtheme.h to be included to use MARGINS struct
  7097. #ifndef _UXTHEME_H_
  7098. typedef struct _MARGINS* PMARGINS;
  7099. #endif // !_UXTHEME_H_
  7100. void GetBandMargins(PMARGINS pMargins) const
  7101. {
  7102. ATLASSERT(::IsWindow(this->m_hWnd));
  7103. ::SendMessage(this->m_hWnd, RB_GETBANDMARGINS, 0, (LPARAM)pMargins);
  7104. }
  7105. void SetWindowTheme(LPCWSTR lpstrTheme)
  7106. {
  7107. ATLASSERT(::IsWindow(this->m_hWnd));
  7108. ::SendMessage(this->m_hWnd, RB_SETWINDOWTHEME, 0, (LPARAM)lpstrTheme);
  7109. }
  7110. DWORD GetExtendedStyle() const
  7111. {
  7112. ATLASSERT(::IsWindow(this->m_hWnd));
  7113. return (DWORD)::SendMessage(this->m_hWnd, RB_GETEXTENDEDSTYLE, 0, 0L);
  7114. }
  7115. DWORD SetExtendedStyle(DWORD dwStyle, DWORD dwMask)
  7116. {
  7117. ATLASSERT(::IsWindow(this->m_hWnd));
  7118. return (DWORD)::SendMessage(this->m_hWnd, RB_SETEXTENDEDSTYLE, dwMask, dwStyle);
  7119. }
  7120. // Operations
  7121. BOOL InsertBand(int nBand, LPREBARBANDINFO lprbbi)
  7122. {
  7123. ATLASSERT(::IsWindow(this->m_hWnd));
  7124. return (BOOL)::SendMessage(this->m_hWnd, RB_INSERTBAND, nBand, (LPARAM)lprbbi);
  7125. }
  7126. BOOL AddBand(LPREBARBANDINFO lprbbi)
  7127. {
  7128. return InsertBand(-1, lprbbi);
  7129. }
  7130. BOOL DeleteBand(int nBand)
  7131. {
  7132. ATLASSERT(::IsWindow(this->m_hWnd));
  7133. return (BOOL)::SendMessage(this->m_hWnd, RB_DELETEBAND, nBand, 0L);
  7134. }
  7135. ATL::CWindow SetNotifyWnd(HWND hWnd)
  7136. {
  7137. ATLASSERT(::IsWindow(this->m_hWnd));
  7138. return ATL::CWindow((HWND)::SendMessage(this->m_hWnd, RB_SETPARENT, (WPARAM)hWnd, 0L));
  7139. }
  7140. void BeginDrag(int nBand, DWORD dwPos)
  7141. {
  7142. ATLASSERT(::IsWindow(this->m_hWnd));
  7143. ::SendMessage(this->m_hWnd, RB_BEGINDRAG, nBand, dwPos);
  7144. }
  7145. void BeginDrag(int nBand, int xPos, int yPos)
  7146. {
  7147. ATLASSERT(::IsWindow(this->m_hWnd));
  7148. ::SendMessage(this->m_hWnd, RB_BEGINDRAG, nBand, MAKELPARAM(xPos, yPos));
  7149. }
  7150. void EndDrag()
  7151. {
  7152. ATLASSERT(::IsWindow(this->m_hWnd));
  7153. ::SendMessage(this->m_hWnd, RB_ENDDRAG, 0, 0L);
  7154. }
  7155. void DragMove(DWORD dwPos)
  7156. {
  7157. ATLASSERT(::IsWindow(this->m_hWnd));
  7158. ::SendMessage(this->m_hWnd, RB_DRAGMOVE, 0, dwPos);
  7159. }
  7160. void DragMove(int xPos, int yPos)
  7161. {
  7162. ATLASSERT(::IsWindow(this->m_hWnd));
  7163. ::SendMessage(this->m_hWnd, RB_DRAGMOVE, 0, MAKELPARAM(xPos, yPos));
  7164. }
  7165. void GetDropTarget(IDropTarget** ppDropTarget) const
  7166. {
  7167. ATLASSERT(::IsWindow(this->m_hWnd));
  7168. ::SendMessage(this->m_hWnd, RB_GETDROPTARGET, 0, (LPARAM)ppDropTarget);
  7169. }
  7170. void MaximizeBand(int nBand, BOOL bIdeal = FALSE)
  7171. {
  7172. ATLASSERT(::IsWindow(this->m_hWnd));
  7173. ::SendMessage(this->m_hWnd, RB_MAXIMIZEBAND, nBand, bIdeal);
  7174. }
  7175. void MinimizeBand(int nBand)
  7176. {
  7177. ATLASSERT(::IsWindow(this->m_hWnd));
  7178. ::SendMessage(this->m_hWnd, RB_MINIMIZEBAND, nBand, 0L);
  7179. }
  7180. BOOL SizeToRect(LPRECT lpRect)
  7181. {
  7182. ATLASSERT(::IsWindow(this->m_hWnd));
  7183. return (BOOL)::SendMessage(this->m_hWnd, RB_SIZETORECT, 0, (LPARAM)lpRect);
  7184. }
  7185. int IdToIndex(UINT uBandID) const
  7186. {
  7187. ATLASSERT(::IsWindow(this->m_hWnd));
  7188. return (int)::SendMessage(this->m_hWnd, RB_IDTOINDEX, uBandID, 0L);
  7189. }
  7190. int HitTest(LPRBHITTESTINFO lprbht) const
  7191. {
  7192. ATLASSERT(::IsWindow(this->m_hWnd));
  7193. return (int)::SendMessage(this->m_hWnd, RB_HITTEST, 0, (LPARAM)lprbht);
  7194. }
  7195. BOOL ShowBand(int nBand, BOOL bShow)
  7196. {
  7197. ATLASSERT(::IsWindow(this->m_hWnd));
  7198. return (BOOL)::SendMessage(this->m_hWnd, RB_SHOWBAND, nBand, bShow);
  7199. }
  7200. BOOL MoveBand(int nBand, int nNewPos)
  7201. {
  7202. ATLASSERT(::IsWindow(this->m_hWnd));
  7203. ATLASSERT((nNewPos >= 0) && (nNewPos <= ((int)GetBandCount() - 1)));
  7204. return (BOOL)::SendMessage(this->m_hWnd, RB_MOVEBAND, nBand, nNewPos);
  7205. }
  7206. void PushChevron(int nBand, LPARAM lAppValue)
  7207. {
  7208. ATLASSERT(::IsWindow(this->m_hWnd));
  7209. ::SendMessage(this->m_hWnd, RB_PUSHCHEVRON, nBand, lAppValue);
  7210. }
  7211. // Extra operations
  7212. void LockBands(bool bLock)
  7213. {
  7214. int nBandCount = GetBandCount();
  7215. for(int i =0; i < nBandCount; i++)
  7216. {
  7217. REBARBANDINFO rbbi = { RunTimeHelper::SizeOf_REBARBANDINFO() };
  7218. rbbi.fMask = RBBIM_STYLE;
  7219. BOOL bRet = GetBandInfo(i, &rbbi);
  7220. ATLASSERT(bRet);
  7221. if((rbbi.fStyle & RBBS_GRIPPERALWAYS) == 0)
  7222. {
  7223. rbbi.fStyle |= RBBS_GRIPPERALWAYS;
  7224. bRet = SetBandInfo(i, &rbbi);
  7225. ATLASSERT(bRet);
  7226. rbbi.fStyle &= ~RBBS_GRIPPERALWAYS;
  7227. }
  7228. if(bLock)
  7229. rbbi.fStyle |= RBBS_NOGRIPPER;
  7230. else
  7231. rbbi.fStyle &= ~RBBS_NOGRIPPER;
  7232. bRet = SetBandInfo(i, &rbbi);
  7233. ATLASSERT(bRet);
  7234. }
  7235. }
  7236. #if (_WIN32_WINNT >= 0x0600)
  7237. BOOL SetBandWidth(int nBand, int cxWidth)
  7238. {
  7239. ATLASSERT(::IsWindow(this->m_hWnd));
  7240. return (BOOL)::SendMessage(this->m_hWnd, RB_SETBANDWIDTH, nBand, cxWidth);
  7241. }
  7242. #endif // (_WIN32_WINNT >= 0x0600)
  7243. };
  7244. typedef CReBarCtrlT<ATL::CWindow> CReBarCtrl;
  7245. ///////////////////////////////////////////////////////////////////////////////
  7246. // CComboBoxEx
  7247. template <class TBase>
  7248. class CComboBoxExT : public CComboBoxT< TBase >
  7249. {
  7250. public:
  7251. // Constructors
  7252. CComboBoxExT(HWND hWnd = NULL) : CComboBoxT< TBase >(hWnd)
  7253. { }
  7254. CComboBoxExT< TBase >& operator =(HWND hWnd)
  7255. {
  7256. this->m_hWnd = hWnd;
  7257. return *this;
  7258. }
  7259. HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  7260. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  7261. ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  7262. {
  7263. return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  7264. }
  7265. // Attributes
  7266. static LPCTSTR GetWndClassName()
  7267. {
  7268. return WC_COMBOBOXEX;
  7269. }
  7270. CImageList GetImageList() const
  7271. {
  7272. ATLASSERT(::IsWindow(this->m_hWnd));
  7273. return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, CBEM_GETIMAGELIST, 0, 0L));
  7274. }
  7275. CImageList SetImageList(HIMAGELIST hImageList)
  7276. {
  7277. ATLASSERT(::IsWindow(this->m_hWnd));
  7278. return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, CBEM_SETIMAGELIST, 0, (LPARAM)hImageList));
  7279. }
  7280. DWORD GetExtendedStyle() const
  7281. {
  7282. ATLASSERT(::IsWindow(this->m_hWnd));
  7283. return (DWORD)::SendMessage(this->m_hWnd, CBEM_GETEXTENDEDSTYLE, 0, 0L);
  7284. }
  7285. DWORD SetExtendedStyle(DWORD dwExMask, DWORD dwExStyle)
  7286. {
  7287. ATLASSERT(::IsWindow(this->m_hWnd));
  7288. return (DWORD)::SendMessage(this->m_hWnd, CBEM_SETEXTENDEDSTYLE, dwExMask, dwExStyle);
  7289. }
  7290. BOOL GetUnicodeFormat() const
  7291. {
  7292. ATLASSERT(::IsWindow(this->m_hWnd));
  7293. return (BOOL)::SendMessage(this->m_hWnd, CBEM_GETUNICODEFORMAT, 0, 0L);
  7294. }
  7295. BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
  7296. {
  7297. ATLASSERT(::IsWindow(this->m_hWnd));
  7298. return (BOOL)::SendMessage(this->m_hWnd, CBEM_SETUNICODEFORMAT, bUnicode, 0L);
  7299. }
  7300. void SetWindowTheme(LPCWSTR lpstrTheme)
  7301. {
  7302. ATLASSERT(::IsWindow(this->m_hWnd));
  7303. ::SendMessage(this->m_hWnd, CBEM_SETWINDOWTHEME, 0, (LPARAM)lpstrTheme);
  7304. }
  7305. // Operations
  7306. int InsertItem(const COMBOBOXEXITEM* lpcCBItem)
  7307. {
  7308. ATLASSERT(::IsWindow(this->m_hWnd));
  7309. return (int)::SendMessage(this->m_hWnd, CBEM_INSERTITEM, 0, (LPARAM)lpcCBItem);
  7310. }
  7311. int InsertItem(UINT nMask, int nIndex, LPCTSTR lpszItem, int nImage, int nSelImage,
  7312. int iIndent, int iOverlay, LPARAM lParam)
  7313. {
  7314. ATLASSERT(::IsWindow(this->m_hWnd));
  7315. COMBOBOXEXITEM cbex = {};
  7316. cbex.mask = nMask;
  7317. cbex.iItem = nIndex;
  7318. cbex.pszText = (LPTSTR) lpszItem;
  7319. cbex.iImage = nImage;
  7320. cbex.iSelectedImage = nSelImage;
  7321. cbex.iIndent = iIndent;
  7322. cbex.iOverlay = iOverlay;
  7323. cbex.lParam = lParam;
  7324. return (int)::SendMessage(this->m_hWnd, CBEM_INSERTITEM, 0, (LPARAM)&cbex);
  7325. }
  7326. int InsertItem(int nIndex, LPCTSTR lpszItem, int nImage, int nSelImage, int iIndent, LPARAM lParam = 0)
  7327. {
  7328. ATLASSERT(::IsWindow(this->m_hWnd));
  7329. COMBOBOXEXITEM cbex = {};
  7330. cbex.mask = CBEIF_TEXT | CBEIF_IMAGE | CBEIF_SELECTEDIMAGE | CBEIF_INDENT | CBEIF_LPARAM;
  7331. cbex.iItem = nIndex;
  7332. cbex.pszText = (LPTSTR) lpszItem;
  7333. cbex.iImage = nImage;
  7334. cbex.iSelectedImage = nSelImage;
  7335. cbex.iIndent = iIndent;
  7336. cbex.lParam = lParam;
  7337. return (int)::SendMessage(this->m_hWnd, CBEM_INSERTITEM, 0, (LPARAM)&cbex);
  7338. }
  7339. int AddItem(UINT nMask, LPCTSTR lpszItem, int nImage, int nSelImage, int iIndent, int iOverlay, LPARAM lParam)
  7340. {
  7341. return InsertItem(nMask, -1, lpszItem, nImage, nSelImage, iIndent, iOverlay, lParam);
  7342. }
  7343. int AddItem(LPCTSTR lpszItem, int nImage, int nSelImage, int iIndent, LPARAM lParam = 0)
  7344. {
  7345. return InsertItem(-1, lpszItem, nImage, nSelImage, iIndent, lParam);
  7346. }
  7347. int DeleteItem(int nIndex)
  7348. {
  7349. ATLASSERT(::IsWindow(this->m_hWnd));
  7350. return (int)::SendMessage(this->m_hWnd, CBEM_DELETEITEM, nIndex, 0L);
  7351. }
  7352. BOOL GetItem(PCOMBOBOXEXITEM pCBItem) const
  7353. {
  7354. ATLASSERT(::IsWindow(this->m_hWnd));
  7355. return (BOOL)::SendMessage(this->m_hWnd, CBEM_GETITEM, 0, (LPARAM)pCBItem);
  7356. }
  7357. BOOL SetItem(const COMBOBOXEXITEM* lpcCBItem)
  7358. {
  7359. ATLASSERT(::IsWindow(this->m_hWnd));
  7360. return (BOOL)::SendMessage(this->m_hWnd, CBEM_SETITEM, 0, (LPARAM)lpcCBItem);
  7361. }
  7362. int SetItem(int nIndex, UINT nMask, LPCTSTR lpszItem, int nImage, int nSelImage,
  7363. int iIndent, int iOverlay, LPARAM lParam)
  7364. {
  7365. ATLASSERT(::IsWindow(this->m_hWnd));
  7366. COMBOBOXEXITEM cbex = {};
  7367. cbex.mask = nMask;
  7368. cbex.iItem = nIndex;
  7369. cbex.pszText = (LPTSTR) lpszItem;
  7370. cbex.iImage = nImage;
  7371. cbex.iSelectedImage = nSelImage;
  7372. cbex.iIndent = iIndent;
  7373. cbex.iOverlay = iOverlay;
  7374. cbex.lParam = lParam;
  7375. return (int)::SendMessage(this->m_hWnd, CBEM_SETITEM, 0, (LPARAM)&cbex);
  7376. }
  7377. BOOL GetItemText(int nIndex, LPTSTR lpszItem, int nLen) const
  7378. {
  7379. ATLASSERT(::IsWindow(this->m_hWnd));
  7380. ATLASSERT(lpszItem != NULL);
  7381. COMBOBOXEXITEM cbex = {};
  7382. cbex.mask = CBEIF_TEXT;
  7383. cbex.iItem = nIndex;
  7384. cbex.pszText = lpszItem;
  7385. cbex.cchTextMax = nLen;
  7386. return (BOOL)::SendMessage(this->m_hWnd, CBEM_GETITEM, 0, (LPARAM)&cbex);
  7387. }
  7388. BOOL GetItemText(int nIndex, BSTR& bstrText) const
  7389. {
  7390. USES_CONVERSION;
  7391. ATLASSERT(::IsWindow(this->m_hWnd));
  7392. ATLASSERT(bstrText == NULL);
  7393. COMBOBOXEXITEM cbex = {};
  7394. cbex.mask = CBEIF_TEXT;
  7395. cbex.iItem = nIndex;
  7396. LPTSTR lpstrText = NULL;
  7397. BOOL bRet = FALSE;
  7398. for(int nLen = 256; ; nLen *= 2)
  7399. {
  7400. ATLTRY(lpstrText = new TCHAR[nLen]);
  7401. if(lpstrText == NULL)
  7402. break;
  7403. lpstrText[0] = NULL;
  7404. cbex.pszText = lpstrText;
  7405. cbex.cchTextMax = nLen;
  7406. bRet = (BOOL)::SendMessage(this->m_hWnd, CBEM_GETITEM, 0, (LPARAM)&cbex);
  7407. if(!bRet || (lstrlen(cbex.pszText) < (nLen - 1)))
  7408. break;
  7409. delete [] lpstrText;
  7410. lpstrText = NULL;
  7411. }
  7412. if(lpstrText != NULL)
  7413. {
  7414. if(bRet)
  7415. bstrText = ::SysAllocString(T2OLE(lpstrText));
  7416. delete [] lpstrText;
  7417. }
  7418. return (bstrText != NULL) ? TRUE : FALSE;
  7419. }
  7420. #ifdef __ATLSTR_H__
  7421. BOOL GetItemText(int nIndex, ATL::CString& strText) const
  7422. {
  7423. ATLASSERT(::IsWindow(this->m_hWnd));
  7424. COMBOBOXEXITEM cbex = {};
  7425. cbex.mask = CBEIF_TEXT;
  7426. cbex.iItem = nIndex;
  7427. strText.Empty();
  7428. BOOL bRet = FALSE;
  7429. for(int nLen = 256; ; nLen *= 2)
  7430. {
  7431. cbex.pszText = strText.GetBufferSetLength(nLen);
  7432. if(cbex.pszText == NULL)
  7433. {
  7434. bRet = FALSE;
  7435. break;
  7436. }
  7437. cbex.cchTextMax = nLen;
  7438. bRet = (BOOL)::SendMessage(this->m_hWnd, CBEM_GETITEM, 0, (LPARAM)&cbex);
  7439. if(!bRet || (lstrlen(cbex.pszText) < (nLen - 1)))
  7440. break;
  7441. }
  7442. strText.ReleaseBuffer();
  7443. return bRet;
  7444. }
  7445. #endif // __ATLSTR_H__
  7446. BOOL SetItemText(int nIndex, LPCTSTR lpszItem)
  7447. {
  7448. ATLASSERT(::IsWindow(this->m_hWnd));
  7449. return SetItem(nIndex, CBEIF_TEXT, lpszItem, 0, 0, 0, 0, 0);
  7450. }
  7451. CComboBox GetComboCtrl() const
  7452. {
  7453. ATLASSERT(::IsWindow(this->m_hWnd));
  7454. return CComboBox((HWND)::SendMessage(this->m_hWnd, CBEM_GETCOMBOCONTROL, 0, 0L));
  7455. }
  7456. CEdit GetEditCtrl() const
  7457. {
  7458. ATLASSERT(::IsWindow(this->m_hWnd));
  7459. return CEdit((HWND)::SendMessage(this->m_hWnd, CBEM_GETEDITCONTROL, 0, 0L));
  7460. }
  7461. BOOL HasEditChanged() const
  7462. {
  7463. ATLASSERT(::IsWindow(this->m_hWnd));
  7464. return (BOOL)::SendMessage(this->m_hWnd, CBEM_HASEDITCHANGED, 0, 0L);
  7465. }
  7466. // Non-functional
  7467. int AddString(LPCTSTR /*lpszItem*/)
  7468. {
  7469. ATLASSERT(FALSE); // Not available in CComboBoxEx; use InsertItem
  7470. return 0;
  7471. }
  7472. int InsertString(int /*nIndex*/, LPCTSTR /*lpszString*/)
  7473. {
  7474. ATLASSERT(FALSE); // Not available in CComboBoxEx; use InsertItem
  7475. return 0;
  7476. }
  7477. int Dir(UINT /*attr*/, LPCTSTR /*lpszWildCard*/)
  7478. {
  7479. ATLASSERT(FALSE); // Not available in CComboBoxEx
  7480. return 0;
  7481. }
  7482. int FindString(int /*nStartAfter*/, LPCTSTR /*lpszString*/) const
  7483. {
  7484. ATLASSERT(FALSE); // Not available in CComboBoxEx; try FindStringExact
  7485. return 0;
  7486. }
  7487. };
  7488. typedef CComboBoxExT<ATL::CWindow> CComboBoxEx;
  7489. ///////////////////////////////////////////////////////////////////////////////
  7490. // CMonthCalendarCtrl
  7491. template <class TBase>
  7492. class CMonthCalendarCtrlT : public TBase
  7493. {
  7494. public:
  7495. // Constructors
  7496. CMonthCalendarCtrlT(HWND hWnd = NULL) : TBase(hWnd)
  7497. { }
  7498. CMonthCalendarCtrlT< TBase >& operator =(HWND hWnd)
  7499. {
  7500. this->m_hWnd = hWnd;
  7501. return *this;
  7502. }
  7503. HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  7504. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  7505. ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  7506. {
  7507. return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  7508. }
  7509. // Attributes
  7510. static LPCTSTR GetWndClassName()
  7511. {
  7512. return MONTHCAL_CLASS;
  7513. }
  7514. COLORREF GetColor(int nColorType) const
  7515. {
  7516. ATLASSERT(::IsWindow(this->m_hWnd));
  7517. return (COLORREF)::SendMessage(this->m_hWnd, MCM_GETCOLOR, nColorType, 0L);
  7518. }
  7519. COLORREF SetColor(int nColorType, COLORREF clr)
  7520. {
  7521. ATLASSERT(::IsWindow(this->m_hWnd));
  7522. return (COLORREF)::SendMessage(this->m_hWnd, MCM_SETCOLOR, nColorType, clr);
  7523. }
  7524. BOOL GetCurSel(LPSYSTEMTIME lpSysTime) const
  7525. {
  7526. ATLASSERT(::IsWindow(this->m_hWnd));
  7527. return (BOOL)::SendMessage(this->m_hWnd, MCM_GETCURSEL, 0, (LPARAM)lpSysTime);
  7528. }
  7529. BOOL SetCurSel(LPSYSTEMTIME lpSysTime)
  7530. {
  7531. ATLASSERT(::IsWindow(this->m_hWnd));
  7532. return (BOOL)::SendMessage(this->m_hWnd, MCM_SETCURSEL, 0, (LPARAM)lpSysTime);
  7533. }
  7534. int GetFirstDayOfWeek(BOOL* pbLocaleVal = NULL) const
  7535. {
  7536. ATLASSERT(::IsWindow(this->m_hWnd));
  7537. DWORD dwRet = (DWORD)::SendMessage(this->m_hWnd, MCM_GETFIRSTDAYOFWEEK, 0, 0L);
  7538. if(pbLocaleVal != NULL)
  7539. *pbLocaleVal = (BOOL)HIWORD(dwRet);
  7540. return (int)(short)LOWORD(dwRet);
  7541. }
  7542. int SetFirstDayOfWeek(int nDay, BOOL* pbLocaleVal = NULL)
  7543. {
  7544. ATLASSERT(::IsWindow(this->m_hWnd));
  7545. DWORD dwRet = (DWORD)::SendMessage(this->m_hWnd, MCM_SETFIRSTDAYOFWEEK, 0, nDay);
  7546. if(pbLocaleVal != NULL)
  7547. *pbLocaleVal = (BOOL)HIWORD(dwRet);
  7548. return (int)(short)LOWORD(dwRet);
  7549. }
  7550. int GetMaxSelCount() const
  7551. {
  7552. ATLASSERT(::IsWindow(this->m_hWnd));
  7553. return (int)::SendMessage(this->m_hWnd, MCM_GETMAXSELCOUNT, 0, 0L);
  7554. }
  7555. BOOL SetMaxSelCount(int nMax)
  7556. {
  7557. ATLASSERT(::IsWindow(this->m_hWnd));
  7558. return (BOOL)::SendMessage(this->m_hWnd, MCM_SETMAXSELCOUNT, nMax, 0L);
  7559. }
  7560. int GetMonthDelta() const
  7561. {
  7562. ATLASSERT(::IsWindow(this->m_hWnd));
  7563. return (int)::SendMessage(this->m_hWnd, MCM_GETMONTHDELTA, 0, 0L);
  7564. }
  7565. int SetMonthDelta(int nDelta)
  7566. {
  7567. ATLASSERT(::IsWindow(this->m_hWnd));
  7568. return (int)::SendMessage(this->m_hWnd, MCM_SETMONTHDELTA, nDelta, 0L);
  7569. }
  7570. DWORD GetRange(LPSYSTEMTIME lprgSysTimeArray) const
  7571. {
  7572. ATLASSERT(::IsWindow(this->m_hWnd));
  7573. return (DWORD)::SendMessage(this->m_hWnd, MCM_GETRANGE, 0, (LPARAM)lprgSysTimeArray);
  7574. }
  7575. BOOL SetRange(DWORD dwFlags, LPSYSTEMTIME lprgSysTimeArray)
  7576. {
  7577. ATLASSERT(::IsWindow(this->m_hWnd));
  7578. return (BOOL)::SendMessage(this->m_hWnd, MCM_SETRANGE, dwFlags, (LPARAM)lprgSysTimeArray);
  7579. }
  7580. BOOL GetSelRange(LPSYSTEMTIME lprgSysTimeArray) const
  7581. {
  7582. ATLASSERT(::IsWindow(this->m_hWnd));
  7583. return (BOOL)::SendMessage(this->m_hWnd, MCM_GETSELRANGE, 0, (LPARAM)lprgSysTimeArray);
  7584. }
  7585. BOOL SetSelRange(LPSYSTEMTIME lprgSysTimeArray)
  7586. {
  7587. ATLASSERT(::IsWindow(this->m_hWnd));
  7588. return (BOOL)::SendMessage(this->m_hWnd, MCM_SETSELRANGE, 0, (LPARAM)lprgSysTimeArray);
  7589. }
  7590. BOOL GetToday(LPSYSTEMTIME lpSysTime) const
  7591. {
  7592. ATLASSERT(::IsWindow(this->m_hWnd));
  7593. return (BOOL)::SendMessage(this->m_hWnd, MCM_GETTODAY, 0, (LPARAM)lpSysTime);
  7594. }
  7595. void SetToday(LPSYSTEMTIME lpSysTime)
  7596. {
  7597. ATLASSERT(::IsWindow(this->m_hWnd));
  7598. ::SendMessage(this->m_hWnd, MCM_SETTODAY, 0, (LPARAM)lpSysTime);
  7599. }
  7600. BOOL GetMinReqRect(LPRECT lpRectInfo) const
  7601. {
  7602. ATLASSERT(::IsWindow(this->m_hWnd));
  7603. return (BOOL)::SendMessage(this->m_hWnd, MCM_GETMINREQRECT, 0, (LPARAM)lpRectInfo);
  7604. }
  7605. int GetMaxTodayWidth() const
  7606. {
  7607. ATLASSERT(::IsWindow(this->m_hWnd));
  7608. return (int)::SendMessage(this->m_hWnd, MCM_GETMAXTODAYWIDTH, 0, 0L);
  7609. }
  7610. BOOL GetUnicodeFormat() const
  7611. {
  7612. ATLASSERT(::IsWindow(this->m_hWnd));
  7613. return (BOOL)::SendMessage(this->m_hWnd, MCM_GETUNICODEFORMAT, 0, 0L);
  7614. }
  7615. BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
  7616. {
  7617. ATLASSERT(::IsWindow(this->m_hWnd));
  7618. return (BOOL)::SendMessage(this->m_hWnd, MCM_SETUNICODEFORMAT, bUnicode, 0L);
  7619. }
  7620. #if defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN)
  7621. DWORD GetCurrentView() const
  7622. {
  7623. ATLASSERT(::IsWindow(this->m_hWnd));
  7624. return (DWORD)::SendMessage(this->m_hWnd, MCM_GETCURRENTVIEW, 0, 0L);
  7625. }
  7626. BOOL SetCurrentView(DWORD dwView)
  7627. {
  7628. ATLASSERT(::IsWindow(this->m_hWnd));
  7629. return (BOOL)::SendMessage(this->m_hWnd, MCM_SETCURRENTVIEW, 0, dwView);
  7630. }
  7631. DWORD GetCalendarCount() const
  7632. {
  7633. ATLASSERT(::IsWindow(this->m_hWnd));
  7634. return (DWORD)::SendMessage(this->m_hWnd, MCM_GETCALENDARCOUNT, 0, 0L);
  7635. }
  7636. BOOL GetCalendarGridInfo(PMCGRIDINFO pGridInfo) const
  7637. {
  7638. ATLASSERT(::IsWindow(this->m_hWnd));
  7639. return (BOOL)::SendMessage(this->m_hWnd, MCM_GETCALENDARGRIDINFO, 0, (LPARAM)pGridInfo);
  7640. }
  7641. CALID GetCALID() const
  7642. {
  7643. ATLASSERT(::IsWindow(this->m_hWnd));
  7644. return (CALID)::SendMessage(this->m_hWnd, MCM_GETCALID, 0, 0L);
  7645. }
  7646. void SetCALID(CALID calid)
  7647. {
  7648. ATLASSERT(::IsWindow(this->m_hWnd));
  7649. ::SendMessage(this->m_hWnd, MCM_SETCALID, (LPARAM)calid, 0L);
  7650. }
  7651. int GetCalendarBorder() const
  7652. {
  7653. ATLASSERT(::IsWindow(this->m_hWnd));
  7654. return (int)::SendMessage(this->m_hWnd, MCM_GETCALENDARBORDER, 0, 0L);
  7655. }
  7656. void SetCalendarBorder(int cxyBorder, BOOL bSet = TRUE)
  7657. {
  7658. ATLASSERT(::IsWindow(this->m_hWnd));
  7659. ::SendMessage(this->m_hWnd, MCM_SETCALENDARBORDER, (WPARAM)bSet, (LPARAM)cxyBorder);
  7660. }
  7661. #endif // defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN)
  7662. // Operations
  7663. int GetMonthRange(DWORD dwFlags, LPSYSTEMTIME lprgSysTimeArray) const
  7664. {
  7665. ATLASSERT(::IsWindow(this->m_hWnd));
  7666. return (int)::SendMessage(this->m_hWnd, MCM_GETMONTHRANGE, dwFlags, (LPARAM)lprgSysTimeArray);
  7667. }
  7668. BOOL SetDayState(int nMonths, LPMONTHDAYSTATE lpDayStateArray)
  7669. {
  7670. ATLASSERT(::IsWindow(this->m_hWnd));
  7671. return (BOOL)::SendMessage(this->m_hWnd, MCM_SETDAYSTATE, nMonths, (LPARAM)lpDayStateArray);
  7672. }
  7673. DWORD HitTest(PMCHITTESTINFO pMCHitTest) const
  7674. {
  7675. ATLASSERT(::IsWindow(this->m_hWnd));
  7676. return (DWORD)::SendMessage(this->m_hWnd, MCM_HITTEST, 0, (LPARAM)pMCHitTest);
  7677. }
  7678. #if defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN)
  7679. void SizeRectToMin(LPRECT lpRect)
  7680. {
  7681. ATLASSERT(::IsWindow(this->m_hWnd));
  7682. ::SendMessage(this->m_hWnd, MCM_SIZERECTTOMIN, 0, (LPARAM)lpRect);
  7683. }
  7684. #endif // defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN)
  7685. };
  7686. typedef CMonthCalendarCtrlT<ATL::CWindow> CMonthCalendarCtrl;
  7687. ///////////////////////////////////////////////////////////////////////////////
  7688. // CDateTimePickerCtrl
  7689. template <class TBase>
  7690. class CDateTimePickerCtrlT : public TBase
  7691. {
  7692. public:
  7693. // Constructors
  7694. CDateTimePickerCtrlT(HWND hWnd = NULL) : TBase(hWnd)
  7695. { }
  7696. CDateTimePickerCtrlT< TBase >& operator =(HWND hWnd)
  7697. {
  7698. this->m_hWnd = hWnd;
  7699. return *this;
  7700. }
  7701. HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  7702. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  7703. ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  7704. {
  7705. return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  7706. }
  7707. // Operations
  7708. static LPCTSTR GetWndClassName()
  7709. {
  7710. return DATETIMEPICK_CLASS;
  7711. }
  7712. BOOL SetFormat(LPCTSTR lpszFormat)
  7713. {
  7714. ATLASSERT(::IsWindow(this->m_hWnd));
  7715. return (BOOL)::SendMessage(this->m_hWnd, DTM_SETFORMAT, 0, (LPARAM)lpszFormat);
  7716. }
  7717. COLORREF GetMonthCalColor(int nColorType) const
  7718. {
  7719. ATLASSERT(::IsWindow(this->m_hWnd));
  7720. return (COLORREF)::SendMessage(this->m_hWnd, DTM_GETMCCOLOR, nColorType, 0L);
  7721. }
  7722. COLORREF SetMonthCalColor(int nColorType, COLORREF clr)
  7723. {
  7724. ATLASSERT(::IsWindow(this->m_hWnd));
  7725. return (COLORREF)::SendMessage(this->m_hWnd, DTM_SETMCCOLOR, nColorType, clr);
  7726. }
  7727. DWORD GetRange(LPSYSTEMTIME lpSysTimeArray) const
  7728. {
  7729. ATLASSERT(::IsWindow(this->m_hWnd));
  7730. return (DWORD)::SendMessage(this->m_hWnd, DTM_GETRANGE, 0, (LPARAM)lpSysTimeArray);
  7731. }
  7732. BOOL SetRange(DWORD dwFlags, LPSYSTEMTIME lpSysTimeArray)
  7733. {
  7734. ATLASSERT(::IsWindow(this->m_hWnd));
  7735. return (BOOL)::SendMessage(this->m_hWnd, DTM_SETRANGE, dwFlags, (LPARAM)lpSysTimeArray);
  7736. }
  7737. DWORD GetSystemTime(LPSYSTEMTIME lpSysTime) const
  7738. {
  7739. ATLASSERT(::IsWindow(this->m_hWnd));
  7740. return (DWORD)::SendMessage(this->m_hWnd, DTM_GETSYSTEMTIME, 0, (LPARAM)lpSysTime);
  7741. }
  7742. BOOL SetSystemTime(DWORD dwFlags, LPSYSTEMTIME lpSysTime)
  7743. {
  7744. ATLASSERT(::IsWindow(this->m_hWnd));
  7745. return (BOOL)::SendMessage(this->m_hWnd, DTM_SETSYSTEMTIME, dwFlags, (LPARAM)lpSysTime);
  7746. }
  7747. CMonthCalendarCtrl GetMonthCal() const
  7748. {
  7749. ATLASSERT(::IsWindow(this->m_hWnd));
  7750. return CMonthCalendarCtrl((HWND)::SendMessage(this->m_hWnd, DTM_GETMONTHCAL, 0, 0L));
  7751. }
  7752. CFontHandle GetMonthCalFont() const
  7753. {
  7754. ATLASSERT(::IsWindow(this->m_hWnd));
  7755. return CFontHandle((HFONT)::SendMessage(this->m_hWnd, DTM_GETMCFONT, 0, 0L));
  7756. }
  7757. void SetMonthCalFont(HFONT hFont, BOOL bRedraw = TRUE)
  7758. {
  7759. ATLASSERT(::IsWindow(this->m_hWnd));
  7760. ::SendMessage(this->m_hWnd, DTM_SETMCFONT, (WPARAM)hFont, MAKELPARAM(bRedraw, 0));
  7761. }
  7762. #if defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN)
  7763. DWORD GetMonthCalStyle() const
  7764. {
  7765. ATLASSERT(::IsWindow(this->m_hWnd));
  7766. return (DWORD)::SendMessage(this->m_hWnd, DTM_GETMCSTYLE, 0, 0L);
  7767. }
  7768. DWORD SetMonthCalStyle(DWORD dwStyle)
  7769. {
  7770. ATLASSERT(::IsWindow(this->m_hWnd));
  7771. return (DWORD)::SendMessage(this->m_hWnd, DTM_SETMCSTYLE, 0, (LPARAM)dwStyle);
  7772. }
  7773. void GetDateTimePickerInfo(LPDATETIMEPICKERINFO lpPickerInfo) const
  7774. {
  7775. ATLASSERT(::IsWindow(this->m_hWnd));
  7776. ::SendMessage(this->m_hWnd, DTM_GETDATETIMEPICKERINFO, 0, (LPARAM)lpPickerInfo);
  7777. }
  7778. BOOL GetIdealSize(LPSIZE lpSize) const
  7779. {
  7780. ATLASSERT(::IsWindow(this->m_hWnd));
  7781. return (BOOL)::SendMessage(this->m_hWnd, DTM_GETIDEALSIZE, 0, (LPARAM)lpSize);
  7782. }
  7783. void CloseMonthCal()
  7784. {
  7785. ATLASSERT(::IsWindow(this->m_hWnd));
  7786. ::SendMessage(this->m_hWnd, DTM_CLOSEMONTHCAL, 0, 0L);
  7787. }
  7788. #endif // defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN)
  7789. };
  7790. typedef CDateTimePickerCtrlT<ATL::CWindow> CDateTimePickerCtrl;
  7791. ///////////////////////////////////////////////////////////////////////////////
  7792. // CFlatScrollBarImpl - support for flat scroll bars
  7793. template <class T>
  7794. class CFlatScrollBarImpl
  7795. {
  7796. public:
  7797. // Initialization
  7798. BOOL FlatSB_Initialize()
  7799. {
  7800. T* pT = static_cast<T*>(this);
  7801. ATLASSERT(::IsWindow(pT->m_hWnd));
  7802. return ::InitializeFlatSB(pT->m_hWnd);
  7803. }
  7804. HRESULT FlatSB_Uninitialize()
  7805. {
  7806. T* pT = static_cast<T*>(this);
  7807. ATLASSERT(::IsWindow(pT->m_hWnd));
  7808. return ::UninitializeFlatSB(pT->m_hWnd);
  7809. }
  7810. // Flat scroll bar properties
  7811. BOOL FlatSB_GetScrollProp(UINT uIndex, LPINT lpnValue) const
  7812. {
  7813. const T* pT = static_cast<const T*>(this);
  7814. ATLASSERT(::IsWindow(pT->m_hWnd));
  7815. return ::FlatSB_GetScrollProp(pT->m_hWnd, uIndex, lpnValue);
  7816. }
  7817. BOOL FlatSB_SetScrollProp(UINT uIndex, int nValue, BOOL bRedraw = TRUE)
  7818. {
  7819. T* pT = static_cast<T*>(this);
  7820. ATLASSERT(::IsWindow(pT->m_hWnd));
  7821. return ::FlatSB_SetScrollProp(pT->m_hWnd, uIndex, nValue, bRedraw);
  7822. }
  7823. // Attributes
  7824. int FlatSB_GetScrollPos(int nBar) const
  7825. {
  7826. const T* pT = static_cast<const T*>(this);
  7827. ATLASSERT(::IsWindow(pT->m_hWnd));
  7828. return ::FlatSB_GetScrollPos(pT->m_hWnd, nBar);
  7829. }
  7830. int FlatSB_SetScrollPos(int nBar, int nPos, BOOL bRedraw = TRUE)
  7831. {
  7832. T* pT = static_cast<T*>(this);
  7833. ATLASSERT(::IsWindow(pT->m_hWnd));
  7834. return ::FlatSB_SetScrollPos(pT->m_hWnd, nBar, nPos, bRedraw);
  7835. }
  7836. BOOL FlatSB_GetScrollRange(int nBar, LPINT lpMinPos, LPINT lpMaxPos) const
  7837. {
  7838. const T* pT = static_cast<const T*>(this);
  7839. ATLASSERT(::IsWindow(pT->m_hWnd));
  7840. return ::FlatSB_GetScrollRange(pT->m_hWnd, nBar, lpMinPos, lpMaxPos);
  7841. }
  7842. BOOL FlatSB_SetScrollRange(int nBar, int nMinPos, int nMaxPos, BOOL bRedraw = TRUE)
  7843. {
  7844. T* pT = static_cast<T*>(this);
  7845. ATLASSERT(::IsWindow(pT->m_hWnd));
  7846. return ::FlatSB_SetScrollRange(pT->m_hWnd, nBar, nMinPos, nMaxPos, bRedraw);
  7847. }
  7848. BOOL FlatSB_GetScrollInfo(int nBar, LPSCROLLINFO lpScrollInfo) const
  7849. {
  7850. const T* pT = static_cast<const T*>(this);
  7851. ATLASSERT(::IsWindow(pT->m_hWnd));
  7852. return ::FlatSB_GetScrollInfo(pT->m_hWnd, nBar, lpScrollInfo);
  7853. }
  7854. int FlatSB_SetScrollInfo(int nBar, LPSCROLLINFO lpScrollInfo, BOOL bRedraw = TRUE)
  7855. {
  7856. T* pT = static_cast<T*>(this);
  7857. ATLASSERT(::IsWindow(pT->m_hWnd));
  7858. return ::FlatSB_SetScrollInfo(pT->m_hWnd, nBar, lpScrollInfo, bRedraw);
  7859. }
  7860. // Operations
  7861. BOOL FlatSB_ShowScrollBar(UINT nBar, BOOL bShow = TRUE)
  7862. {
  7863. T* pT = static_cast<T*>(this);
  7864. ATLASSERT(::IsWindow(pT->m_hWnd));
  7865. return ::FlatSB_ShowScrollBar(pT->m_hWnd, nBar, bShow);
  7866. }
  7867. BOOL FlatSB_EnableScrollBar(UINT uSBFlags, UINT uArrowFlags = ESB_ENABLE_BOTH)
  7868. {
  7869. T* pT = static_cast<T*>(this);
  7870. ATLASSERT(::IsWindow(pT->m_hWnd));
  7871. return ::FlatSB_EnableScrollBar(pT->m_hWnd, uSBFlags, uArrowFlags);
  7872. }
  7873. };
  7874. template <class TBase>
  7875. class CFlatScrollBarT : public TBase, public CFlatScrollBarImpl<CFlatScrollBarT< TBase > >
  7876. {
  7877. public:
  7878. CFlatScrollBarT(HWND hWnd = NULL) : TBase(hWnd)
  7879. { }
  7880. CFlatScrollBarT< TBase >& operator =(HWND hWnd)
  7881. {
  7882. this->m_hWnd = hWnd;
  7883. return *this;
  7884. }
  7885. };
  7886. typedef CFlatScrollBarT<ATL::CWindow> CFlatScrollBar;
  7887. ///////////////////////////////////////////////////////////////////////////////
  7888. // CIPAddressCtrl
  7889. template <class TBase>
  7890. class CIPAddressCtrlT : public TBase
  7891. {
  7892. public:
  7893. // Constructors
  7894. CIPAddressCtrlT(HWND hWnd = NULL) : TBase(hWnd)
  7895. { }
  7896. CIPAddressCtrlT< TBase >& operator =(HWND hWnd)
  7897. {
  7898. this->m_hWnd = hWnd;
  7899. return *this;
  7900. }
  7901. HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  7902. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  7903. ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  7904. {
  7905. return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  7906. }
  7907. // Atteributes
  7908. static LPCTSTR GetWndClassName()
  7909. {
  7910. return WC_IPADDRESS;
  7911. }
  7912. BOOL IsBlank() const
  7913. {
  7914. ATLASSERT(::IsWindow(this->m_hWnd));
  7915. return (BOOL)::SendMessage(this->m_hWnd, IPM_ISBLANK, 0, 0L);
  7916. }
  7917. int GetAddress(LPDWORD lpdwAddress) const
  7918. {
  7919. ATLASSERT(::IsWindow(this->m_hWnd));
  7920. return (int)::SendMessage(this->m_hWnd, IPM_GETADDRESS, 0, (LPARAM)lpdwAddress);
  7921. }
  7922. void SetAddress(DWORD dwAddress)
  7923. {
  7924. ATLASSERT(::IsWindow(this->m_hWnd));
  7925. ::SendMessage(this->m_hWnd, IPM_SETADDRESS, 0, dwAddress);
  7926. }
  7927. void ClearAddress()
  7928. {
  7929. ATLASSERT(::IsWindow(this->m_hWnd));
  7930. ::SendMessage(this->m_hWnd, IPM_CLEARADDRESS, 0, 0L);
  7931. }
  7932. void SetRange(int nField, WORD wRange)
  7933. {
  7934. ATLASSERT(::IsWindow(this->m_hWnd));
  7935. ::SendMessage(this->m_hWnd, IPM_SETRANGE, nField, wRange);
  7936. }
  7937. void SetRange(int nField, BYTE nMin, BYTE nMax)
  7938. {
  7939. ATLASSERT(::IsWindow(this->m_hWnd));
  7940. ::SendMessage(this->m_hWnd, IPM_SETRANGE, nField, MAKEIPRANGE(nMin, nMax));
  7941. }
  7942. void SetFocus(int nField)
  7943. {
  7944. ATLASSERT(::IsWindow(this->m_hWnd));
  7945. ::SendMessage(this->m_hWnd, IPM_SETFOCUS, nField, 0L);
  7946. }
  7947. };
  7948. typedef CIPAddressCtrlT<ATL::CWindow> CIPAddressCtrl;
  7949. ///////////////////////////////////////////////////////////////////////////////
  7950. // CPagerCtrl
  7951. template <class TBase>
  7952. class CPagerCtrlT : public TBase
  7953. {
  7954. public:
  7955. // Constructors
  7956. CPagerCtrlT(HWND hWnd = NULL) : TBase(hWnd)
  7957. { }
  7958. CPagerCtrlT< TBase >& operator =(HWND hWnd)
  7959. {
  7960. this->m_hWnd = hWnd;
  7961. return *this;
  7962. }
  7963. HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  7964. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  7965. ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  7966. {
  7967. return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  7968. }
  7969. // Attributes
  7970. static LPCTSTR GetWndClassName()
  7971. {
  7972. return WC_PAGESCROLLER;
  7973. }
  7974. int GetButtonSize() const
  7975. {
  7976. ATLASSERT(::IsWindow(this->m_hWnd));
  7977. return (int)::SendMessage(this->m_hWnd, PGM_GETBUTTONSIZE, 0, 0L);
  7978. }
  7979. int SetButtonSize(int nButtonSize)
  7980. {
  7981. ATLASSERT(::IsWindow(this->m_hWnd));
  7982. return (int)::SendMessage(this->m_hWnd, PGM_SETBUTTONSIZE, 0, nButtonSize);
  7983. }
  7984. DWORD GetButtonState(int nButton) const
  7985. {
  7986. ATLASSERT(::IsWindow(this->m_hWnd));
  7987. ATLASSERT((nButton == PGB_TOPORLEFT) || (nButton == PGB_BOTTOMORRIGHT));
  7988. return (DWORD)::SendMessage(this->m_hWnd, PGM_GETBUTTONSTATE, 0, nButton);
  7989. }
  7990. COLORREF GetBkColor() const
  7991. {
  7992. ATLASSERT(::IsWindow(this->m_hWnd));
  7993. return (COLORREF)::SendMessage(this->m_hWnd, PGM_GETBKCOLOR, 0, 0L);
  7994. }
  7995. COLORREF SetBkColor(COLORREF clrBk)
  7996. {
  7997. ATLASSERT(::IsWindow(this->m_hWnd));
  7998. return (COLORREF)::SendMessage(this->m_hWnd, PGM_SETBKCOLOR, 0, (LPARAM)clrBk);
  7999. }
  8000. int GetBorder() const
  8001. {
  8002. ATLASSERT(::IsWindow(this->m_hWnd));
  8003. return (int)::SendMessage(this->m_hWnd, PGM_GETBORDER, 0, 0L);
  8004. }
  8005. int SetBorder(int nBorderSize)
  8006. {
  8007. ATLASSERT(::IsWindow(this->m_hWnd));
  8008. return (int)::SendMessage(this->m_hWnd, PGM_SETBORDER, 0, nBorderSize);
  8009. }
  8010. int GetPos() const
  8011. {
  8012. ATLASSERT(::IsWindow(this->m_hWnd));
  8013. return (int)::SendMessage(this->m_hWnd, PGM_GETPOS, 0, 0L);
  8014. }
  8015. int SetPos(int nPos)
  8016. {
  8017. ATLASSERT(::IsWindow(this->m_hWnd));
  8018. return (int)::SendMessage(this->m_hWnd, PGM_SETPOS, 0, nPos);
  8019. }
  8020. // Operations
  8021. void SetChild(HWND hWndChild)
  8022. {
  8023. ATLASSERT(::IsWindow(this->m_hWnd));
  8024. ::SendMessage(this->m_hWnd, PGM_SETCHILD, 0, (LPARAM)hWndChild);
  8025. }
  8026. void ForwardMouse(BOOL bForward = TRUE)
  8027. {
  8028. ATLASSERT(::IsWindow(this->m_hWnd));
  8029. ::SendMessage(this->m_hWnd, PGM_FORWARDMOUSE, bForward, 0L);
  8030. }
  8031. void RecalcSize()
  8032. {
  8033. ATLASSERT(::IsWindow(this->m_hWnd));
  8034. ::SendMessage(this->m_hWnd, PGM_RECALCSIZE, 0, 0L);
  8035. }
  8036. void GetDropTarget(IDropTarget** ppDropTarget)
  8037. {
  8038. ATLASSERT(::IsWindow(this->m_hWnd));
  8039. ATLASSERT(ppDropTarget != NULL);
  8040. ::SendMessage(this->m_hWnd, PGM_GETDROPTARGET, 0, (LPARAM)ppDropTarget);
  8041. }
  8042. };
  8043. typedef CPagerCtrlT<ATL::CWindow> CPagerCtrl;
  8044. ///////////////////////////////////////////////////////////////////////////////
  8045. // CLinkCtrl - Windows SYSLINK control
  8046. template <class TBase>
  8047. class CLinkCtrlT : public TBase
  8048. {
  8049. public:
  8050. // Constructors
  8051. CLinkCtrlT(HWND hWnd = NULL) : TBase(hWnd)
  8052. { }
  8053. CLinkCtrlT< TBase >& operator =(HWND hWnd)
  8054. {
  8055. this->m_hWnd = hWnd;
  8056. return *this;
  8057. }
  8058. HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  8059. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  8060. ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  8061. {
  8062. return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  8063. }
  8064. // Attributes
  8065. static LPCTSTR GetWndClassName()
  8066. {
  8067. #ifdef _UNICODE
  8068. return WC_LINK;
  8069. #else // !_UNICODE
  8070. return "SysLink";
  8071. #endif // !_UNICODE
  8072. }
  8073. int GetIdealHeight(int cxMaxWidth = 0) const
  8074. {
  8075. ATLASSERT(::IsWindow(this->m_hWnd));
  8076. return (int)::SendMessage(this->m_hWnd, LM_GETIDEALHEIGHT, cxMaxWidth, 0L);
  8077. }
  8078. BOOL GetItem(PLITEM pLItem) const
  8079. {
  8080. ATLASSERT(::IsWindow(this->m_hWnd));
  8081. return (BOOL)::SendMessage(this->m_hWnd, LM_GETITEM, 0, (LPARAM)pLItem);
  8082. }
  8083. BOOL SetItem(PLITEM pLItem)
  8084. {
  8085. ATLASSERT(::IsWindow(this->m_hWnd));
  8086. return (BOOL)::SendMessage(this->m_hWnd, LM_SETITEM, 0, (LPARAM)pLItem);
  8087. }
  8088. // Vista only
  8089. int GetIdealSize(SIZE& size, int cxMaxWidth = 0) const
  8090. {
  8091. ATLASSERT(::IsWindow(this->m_hWnd));
  8092. return (int)::SendMessage(this->m_hWnd, LM_GETIDEALSIZE, cxMaxWidth, (LPARAM)&size);
  8093. }
  8094. // Operations
  8095. BOOL HitTest(PLHITTESTINFO pLHitTestInfo) const
  8096. {
  8097. ATLASSERT(::IsWindow(this->m_hWnd));
  8098. return (BOOL)::SendMessage(this->m_hWnd, LM_HITTEST, 0, (LPARAM)pLHitTestInfo);
  8099. }
  8100. };
  8101. typedef CLinkCtrlT<ATL::CWindow> CLinkCtrl;
  8102. ///////////////////////////////////////////////////////////////////////////////
  8103. // CCustomDraw - MI class for custom-draw support
  8104. template <class T>
  8105. class CCustomDraw
  8106. {
  8107. public:
  8108. // Message map and handlers
  8109. BEGIN_MSG_MAP(CCustomDraw< T >)
  8110. NOTIFY_CODE_HANDLER(NM_CUSTOMDRAW, OnCustomDraw)
  8111. ALT_MSG_MAP(1)
  8112. REFLECTED_NOTIFY_CODE_HANDLER(NM_CUSTOMDRAW, OnCustomDraw)
  8113. END_MSG_MAP()
  8114. // message handler
  8115. LRESULT OnCustomDraw(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
  8116. {
  8117. T* pT = static_cast<T*>(this);
  8118. pT->SetMsgHandled(TRUE);
  8119. LPNMCUSTOMDRAW lpNMCustomDraw = (LPNMCUSTOMDRAW)pnmh;
  8120. DWORD dwRet = 0;
  8121. switch(lpNMCustomDraw->dwDrawStage)
  8122. {
  8123. case CDDS_PREPAINT:
  8124. dwRet = pT->OnPrePaint(idCtrl, lpNMCustomDraw);
  8125. break;
  8126. case CDDS_POSTPAINT:
  8127. dwRet = pT->OnPostPaint(idCtrl, lpNMCustomDraw);
  8128. break;
  8129. case CDDS_PREERASE:
  8130. dwRet = pT->OnPreErase(idCtrl, lpNMCustomDraw);
  8131. break;
  8132. case CDDS_POSTERASE:
  8133. dwRet = pT->OnPostErase(idCtrl, lpNMCustomDraw);
  8134. break;
  8135. case CDDS_ITEMPREPAINT:
  8136. dwRet = pT->OnItemPrePaint(idCtrl, lpNMCustomDraw);
  8137. break;
  8138. case CDDS_ITEMPOSTPAINT:
  8139. dwRet = pT->OnItemPostPaint(idCtrl, lpNMCustomDraw);
  8140. break;
  8141. case CDDS_ITEMPREERASE:
  8142. dwRet = pT->OnItemPreErase(idCtrl, lpNMCustomDraw);
  8143. break;
  8144. case CDDS_ITEMPOSTERASE:
  8145. dwRet = pT->OnItemPostErase(idCtrl, lpNMCustomDraw);
  8146. break;
  8147. case (CDDS_ITEMPREPAINT | CDDS_SUBITEM):
  8148. dwRet = pT->OnSubItemPrePaint(idCtrl, lpNMCustomDraw);
  8149. break;
  8150. default:
  8151. pT->SetMsgHandled(FALSE);
  8152. break;
  8153. }
  8154. bHandled = pT->IsMsgHandled();
  8155. return dwRet;
  8156. }
  8157. // Overrideables
  8158. DWORD OnPrePaint(int /*idCtrl*/, LPNMCUSTOMDRAW /*lpNMCustomDraw*/)
  8159. {
  8160. return CDRF_DODEFAULT;
  8161. }
  8162. DWORD OnPostPaint(int /*idCtrl*/, LPNMCUSTOMDRAW /*lpNMCustomDraw*/)
  8163. {
  8164. return CDRF_DODEFAULT;
  8165. }
  8166. DWORD OnPreErase(int /*idCtrl*/, LPNMCUSTOMDRAW /*lpNMCustomDraw*/)
  8167. {
  8168. return CDRF_DODEFAULT;
  8169. }
  8170. DWORD OnPostErase(int /*idCtrl*/, LPNMCUSTOMDRAW /*lpNMCustomDraw*/)
  8171. {
  8172. return CDRF_DODEFAULT;
  8173. }
  8174. DWORD OnItemPrePaint(int /*idCtrl*/, LPNMCUSTOMDRAW /*lpNMCustomDraw*/)
  8175. {
  8176. return CDRF_DODEFAULT;
  8177. }
  8178. DWORD OnItemPostPaint(int /*idCtrl*/, LPNMCUSTOMDRAW /*lpNMCustomDraw*/)
  8179. {
  8180. return CDRF_DODEFAULT;
  8181. }
  8182. DWORD OnItemPreErase(int /*idCtrl*/, LPNMCUSTOMDRAW /*lpNMCustomDraw*/)
  8183. {
  8184. return CDRF_DODEFAULT;
  8185. }
  8186. DWORD OnItemPostErase(int /*idCtrl*/, LPNMCUSTOMDRAW /*lpNMCustomDraw*/)
  8187. {
  8188. return CDRF_DODEFAULT;
  8189. }
  8190. DWORD OnSubItemPrePaint(int /*idCtrl*/, LPNMCUSTOMDRAW /*lpNMCustomDraw*/)
  8191. {
  8192. return CDRF_DODEFAULT;
  8193. }
  8194. };
  8195. } // namespace WTL
  8196. #endif // __ATLCTRLS_H__