atlctrls.h 259 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764
  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_VER >= 0x0300
  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(int cx, int cy)
  3098. {
  3099. ATLASSERT(::IsWindow(this->m_hWnd));
  3100. return (BOOL)::SendMessage(this->m_hWnd, LVM_SCROLL, cx, cy);
  3101. }
  3102. BOOL Scroll(SIZE size)
  3103. {
  3104. ATLASSERT(::IsWindow(this->m_hWnd));
  3105. return (BOOL)::SendMessage(this->m_hWnd, LVM_SCROLL, size.cx, size.cy);
  3106. }
  3107. BOOL RedrawItems(int nFirst, int nLast)
  3108. {
  3109. ATLASSERT(::IsWindow(this->m_hWnd));
  3110. return (BOOL)::SendMessage(this->m_hWnd, LVM_REDRAWITEMS, nFirst, nLast);
  3111. }
  3112. BOOL Arrange(UINT nCode)
  3113. {
  3114. ATLASSERT(::IsWindow(this->m_hWnd));
  3115. return (BOOL)::SendMessage(this->m_hWnd, LVM_ARRANGE, nCode, 0L);
  3116. }
  3117. CEdit EditLabel(int nItem)
  3118. {
  3119. ATLASSERT(::IsWindow(this->m_hWnd));
  3120. return CEdit((HWND)::SendMessage(this->m_hWnd, LVM_EDITLABEL, nItem, 0L));
  3121. }
  3122. BOOL Update(int nItem)
  3123. {
  3124. ATLASSERT(::IsWindow(this->m_hWnd));
  3125. return (BOOL)::SendMessage(this->m_hWnd, LVM_UPDATE, nItem, 0L);
  3126. }
  3127. BOOL SortItems(PFNLVCOMPARE pfnCompare, LPARAM lParamSort)
  3128. {
  3129. ATLASSERT(::IsWindow(this->m_hWnd));
  3130. return (BOOL)::SendMessage(this->m_hWnd, LVM_SORTITEMS, (WPARAM)lParamSort, (LPARAM)pfnCompare);
  3131. }
  3132. CImageList RemoveImageList(int nImageList)
  3133. {
  3134. ATLASSERT(::IsWindow(this->m_hWnd));
  3135. return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, LVM_SETIMAGELIST, (WPARAM)nImageList, NULL));
  3136. }
  3137. CImageList CreateDragImage(int nItem, LPPOINT lpPoint)
  3138. {
  3139. ATLASSERT(::IsWindow(this->m_hWnd));
  3140. return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, LVM_CREATEDRAGIMAGE, nItem, (LPARAM)lpPoint));
  3141. }
  3142. DWORD ApproximateViewRect(int cx = -1, int cy = -1, int nCount = -1)
  3143. {
  3144. ATLASSERT(::IsWindow(this->m_hWnd));
  3145. return (DWORD)::SendMessage(this->m_hWnd, LVM_APPROXIMATEVIEWRECT, nCount, MAKELPARAM(cx, cy));
  3146. }
  3147. int SubItemHitTest(LPLVHITTESTINFO lpInfo) const
  3148. {
  3149. ATLASSERT(::IsWindow(this->m_hWnd));
  3150. return (int)::SendMessage(this->m_hWnd, LVM_SUBITEMHITTEST, 0, (LPARAM)lpInfo);
  3151. }
  3152. int AddColumn(LPCTSTR strColumn, int nItem, int nSubItem = -1,
  3153. int nMask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM,
  3154. int nFmt = LVCFMT_LEFT)
  3155. {
  3156. const int cxOffset = 15;
  3157. ATLASSERT(::IsWindow(this->m_hWnd));
  3158. LVCOLUMN lvc = {};
  3159. lvc.mask = nMask;
  3160. lvc.fmt = nFmt;
  3161. lvc.pszText = (LPTSTR)strColumn;
  3162. lvc.cx = GetStringWidth(lvc.pszText) + cxOffset;
  3163. if(nMask & LVCF_SUBITEM)
  3164. lvc.iSubItem = (nSubItem != -1) ? nSubItem : nItem;
  3165. return InsertColumn(nItem, &lvc);
  3166. }
  3167. int AddItem(int nItem, int nSubItem, LPCTSTR strItem, int nImageIndex = -3)
  3168. {
  3169. ATLASSERT(::IsWindow(this->m_hWnd));
  3170. LVITEM lvItem = {};
  3171. lvItem.mask = LVIF_TEXT;
  3172. lvItem.iItem = nItem;
  3173. lvItem.iSubItem = nSubItem;
  3174. lvItem.pszText = (LPTSTR)strItem;
  3175. if(nImageIndex != -3)
  3176. {
  3177. lvItem.mask |= LVIF_IMAGE;
  3178. lvItem.iImage = nImageIndex;
  3179. }
  3180. if(nSubItem == 0)
  3181. return InsertItem(&lvItem);
  3182. return SetItem(&lvItem) ? nItem : -1;
  3183. }
  3184. BOOL SortItemsEx(PFNLVCOMPARE pfnCompare, LPARAM lParamSort)
  3185. {
  3186. ATLASSERT(::IsWindow(this->m_hWnd));
  3187. return (BOOL)::SendMessage(this->m_hWnd, LVM_SORTITEMSEX, (WPARAM)lParamSort, (LPARAM)pfnCompare);
  3188. }
  3189. int InsertGroup(int nItem, PLVGROUP pGroup)
  3190. {
  3191. ATLASSERT(::IsWindow(this->m_hWnd));
  3192. return (int)::SendMessage(this->m_hWnd, LVM_INSERTGROUP, nItem, (LPARAM)pGroup);
  3193. }
  3194. int AddGroup(PLVGROUP pGroup)
  3195. {
  3196. return InsertGroup(-1, pGroup);
  3197. }
  3198. int RemoveGroup(int nGroupID)
  3199. {
  3200. ATLASSERT(::IsWindow(this->m_hWnd));
  3201. return (int)::SendMessage(this->m_hWnd, LVM_REMOVEGROUP, nGroupID, 0L);
  3202. }
  3203. void MoveGroup(int nGroupID, int nItem)
  3204. {
  3205. ATLASSERT(::IsWindow(this->m_hWnd));
  3206. ::SendMessage(this->m_hWnd, LVM_MOVEGROUP, nGroupID, nItem);
  3207. }
  3208. void MoveItemToGroup(int nItem, int nGroupID)
  3209. {
  3210. ATLASSERT(::IsWindow(this->m_hWnd));
  3211. ::SendMessage(this->m_hWnd, LVM_MOVEITEMTOGROUP, nItem, nGroupID);
  3212. }
  3213. int EnableGroupView(BOOL bEnable)
  3214. {
  3215. ATLASSERT(::IsWindow(this->m_hWnd));
  3216. return (int)::SendMessage(this->m_hWnd, LVM_ENABLEGROUPVIEW, bEnable, 0L);
  3217. }
  3218. int SortGroups(PFNLVGROUPCOMPARE pCompareFunc, LPVOID lpVoid = NULL)
  3219. {
  3220. ATLASSERT(::IsWindow(this->m_hWnd));
  3221. return (int)::SendMessage(this->m_hWnd, LVM_SORTGROUPS, (WPARAM)pCompareFunc, (LPARAM)lpVoid);
  3222. }
  3223. void InsertGroupSorted(PLVINSERTGROUPSORTED pInsertGroupSorted)
  3224. {
  3225. ATLASSERT(::IsWindow(this->m_hWnd));
  3226. ::SendMessage(this->m_hWnd, LVM_INSERTGROUPSORTED, (WPARAM)pInsertGroupSorted, 0L);
  3227. }
  3228. void RemoveAllGroups()
  3229. {
  3230. ATLASSERT(::IsWindow(this->m_hWnd));
  3231. ::SendMessage(this->m_hWnd, LVM_REMOVEALLGROUPS, 0, 0L);
  3232. }
  3233. BOOL HasGroup(int nGroupID)
  3234. {
  3235. ATLASSERT(::IsWindow(this->m_hWnd));
  3236. return (BOOL)::SendMessage(this->m_hWnd, LVM_HASGROUP, nGroupID, 0L);
  3237. }
  3238. BOOL InsertMarkHitTest(LPPOINT lpPoint, LPLVINSERTMARK pInsertMark) const
  3239. {
  3240. ATLASSERT(::IsWindow(this->m_hWnd));
  3241. return (BOOL)::SendMessage(this->m_hWnd, LVM_INSERTMARKHITTEST, (WPARAM)lpPoint, (LPARAM)pInsertMark);
  3242. }
  3243. BOOL SetInfoTip(PLVSETINFOTIP pSetInfoTip)
  3244. {
  3245. ATLASSERT(::IsWindow(this->m_hWnd));
  3246. return (BOOL)::SendMessage(this->m_hWnd, LVM_SETINFOTIP, 0, (LPARAM)pSetInfoTip);
  3247. }
  3248. void CancelEditLabel()
  3249. {
  3250. ATLASSERT(::IsWindow(this->m_hWnd));
  3251. ::SendMessage(this->m_hWnd, LVM_CANCELEDITLABEL, 0, 0L);
  3252. }
  3253. UINT MapIndexToID(int nIndex) const
  3254. {
  3255. ATLASSERT(::IsWindow(this->m_hWnd));
  3256. return (UINT)::SendMessage(this->m_hWnd, LVM_MAPINDEXTOID, nIndex, 0L);
  3257. }
  3258. int MapIDToIndex(UINT uID) const
  3259. {
  3260. ATLASSERT(::IsWindow(this->m_hWnd));
  3261. return (int)::SendMessage(this->m_hWnd, LVM_MAPIDTOINDEX, uID, 0L);
  3262. }
  3263. BOOL IsItemVisible(int nItem) const
  3264. {
  3265. ATLASSERT(::IsWindow(this->m_hWnd));
  3266. return (BOOL)::SendMessage(this->m_hWnd, LVM_ISITEMVISIBLE, nItem, 0L);
  3267. }
  3268. #if (_WIN32_WINNT >= 0x0600)
  3269. int HitTestEx(LPLVHITTESTINFO lpHitTestInfo) const
  3270. {
  3271. ATLASSERT(::IsWindow(this->m_hWnd));
  3272. return (int)::SendMessage(this->m_hWnd, LVM_HITTEST, (WPARAM)-1, (LPARAM)lpHitTestInfo);
  3273. }
  3274. int HitTestEx(POINT pt, UINT* pFlags) const
  3275. {
  3276. ATLASSERT(::IsWindow(this->m_hWnd));
  3277. LVHITTESTINFO hti = {};
  3278. hti.pt = pt;
  3279. int nRes = (int)::SendMessage(this->m_hWnd, LVM_HITTEST, (WPARAM)-1, (LPARAM)&hti);
  3280. if (pFlags != NULL)
  3281. *pFlags = hti.flags;
  3282. return nRes;
  3283. }
  3284. int SubItemHitTestEx(LPLVHITTESTINFO lpHitTestInfo) const
  3285. {
  3286. ATLASSERT(::IsWindow(this->m_hWnd));
  3287. return (int)::SendMessage(this->m_hWnd, LVM_SUBITEMHITTEST, (WPARAM)-1, (LPARAM)lpHitTestInfo);
  3288. }
  3289. #endif // (_WIN32_WINNT >= 0x0600)
  3290. // Note: selects only one item
  3291. BOOL SelectItem(int nIndex) // -1 to select none
  3292. {
  3293. ATLASSERT(::IsWindow(this->m_hWnd));
  3294. BOOL bRet = FALSE;
  3295. if(nIndex != -1)
  3296. {
  3297. // multi-selection only: de-select all items
  3298. if((this->GetStyle() & LVS_SINGLESEL) == 0)
  3299. SetItemState(-1, 0, LVIS_SELECTED);
  3300. bRet = SetItemState(nIndex, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
  3301. if(bRet)
  3302. {
  3303. SetSelectionMark(nIndex);
  3304. bRet = EnsureVisible(nIndex, FALSE);
  3305. }
  3306. }
  3307. else // no item specified, just de-select
  3308. {
  3309. bRet = SetItemState(-1, 0, LVIS_SELECTED);
  3310. }
  3311. return bRet;
  3312. }
  3313. // multi-selection only
  3314. BOOL SelectAllItems(bool bSelect = true)
  3315. {
  3316. ATLASSERT(::IsWindow(this->m_hWnd));
  3317. ATLASSERT((this->GetStyle() & LVS_SINGLESEL) == 0);
  3318. return SetItemState(-1, bSelect ? LVIS_SELECTED : 0, LVIS_SELECTED);
  3319. }
  3320. };
  3321. typedef CListViewCtrlT<ATL::CWindow> CListViewCtrl;
  3322. ///////////////////////////////////////////////////////////////////////////////
  3323. // CTreeViewCtrl
  3324. template <class TBase>
  3325. class CTreeViewCtrlT : public TBase
  3326. {
  3327. public:
  3328. // Constructors
  3329. CTreeViewCtrlT(HWND hWnd = NULL) : TBase(hWnd)
  3330. { }
  3331. CTreeViewCtrlT< TBase >& operator =(HWND hWnd)
  3332. {
  3333. this->m_hWnd = hWnd;
  3334. return *this;
  3335. }
  3336. HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  3337. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  3338. ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  3339. {
  3340. return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  3341. }
  3342. // Attributes
  3343. static LPCTSTR GetWndClassName()
  3344. {
  3345. return WC_TREEVIEW;
  3346. }
  3347. UINT GetCount() const
  3348. {
  3349. ATLASSERT(::IsWindow(this->m_hWnd));
  3350. return (UINT)::SendMessage(this->m_hWnd, TVM_GETCOUNT, 0, 0L);
  3351. }
  3352. UINT GetIndent() const
  3353. {
  3354. ATLASSERT(::IsWindow(this->m_hWnd));
  3355. return (UINT)::SendMessage(this->m_hWnd, TVM_GETINDENT, 0, 0L);
  3356. }
  3357. void SetIndent(UINT nIndent)
  3358. {
  3359. ATLASSERT(::IsWindow(this->m_hWnd));
  3360. ::SendMessage(this->m_hWnd, TVM_SETINDENT, nIndent, 0L);
  3361. }
  3362. CImageList GetImageList(int nImageListType = TVSIL_NORMAL) const
  3363. {
  3364. ATLASSERT(::IsWindow(this->m_hWnd));
  3365. return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, TVM_GETIMAGELIST, (WPARAM)nImageListType, 0L));
  3366. }
  3367. CImageList SetImageList(HIMAGELIST hImageList, int nImageListType = TVSIL_NORMAL)
  3368. {
  3369. ATLASSERT(::IsWindow(this->m_hWnd));
  3370. return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, TVM_SETIMAGELIST, (WPARAM)nImageListType, (LPARAM)hImageList));
  3371. }
  3372. BOOL GetItem(LPTVITEM pItem) const
  3373. {
  3374. ATLASSERT(::IsWindow(this->m_hWnd));
  3375. return (BOOL)::SendMessage(this->m_hWnd, TVM_GETITEM, 0, (LPARAM)pItem);
  3376. }
  3377. BOOL SetItem(LPTVITEM pItem)
  3378. {
  3379. ATLASSERT(::IsWindow(this->m_hWnd));
  3380. return (BOOL)::SendMessage(this->m_hWnd, TVM_SETITEM, 0, (LPARAM)pItem);
  3381. }
  3382. BOOL SetItem(HTREEITEM hItem, UINT nMask, LPCTSTR lpszItem, int nImage,
  3383. int nSelectedImage, UINT nState, UINT nStateMask, LPARAM lParam)
  3384. {
  3385. ATLASSERT(::IsWindow(this->m_hWnd));
  3386. TVITEM item = {};
  3387. item.hItem = hItem;
  3388. item.mask = nMask;
  3389. item.pszText = (LPTSTR) lpszItem;
  3390. item.iImage = nImage;
  3391. item.iSelectedImage = nSelectedImage;
  3392. item.state = nState;
  3393. item.stateMask = nStateMask;
  3394. item.lParam = lParam;
  3395. return (BOOL)::SendMessage(this->m_hWnd, TVM_SETITEM, 0, (LPARAM)&item);
  3396. }
  3397. BOOL GetItemText(HTREEITEM hItem, LPTSTR lpstrText, int nLen) const
  3398. {
  3399. ATLASSERT(::IsWindow(this->m_hWnd));
  3400. ATLASSERT(lpstrText != NULL);
  3401. TVITEM item = {};
  3402. item.hItem = hItem;
  3403. item.mask = TVIF_TEXT;
  3404. item.pszText = lpstrText;
  3405. item.cchTextMax = nLen;
  3406. return (BOOL)::SendMessage(this->m_hWnd, TVM_GETITEM, 0, (LPARAM)&item);
  3407. }
  3408. BOOL GetItemText(HTREEITEM hItem, BSTR& bstrText) const
  3409. {
  3410. USES_CONVERSION;
  3411. ATLASSERT(::IsWindow(this->m_hWnd));
  3412. ATLASSERT(bstrText == NULL);
  3413. TVITEM item = {};
  3414. item.hItem = hItem;
  3415. item.mask = TVIF_TEXT;
  3416. LPTSTR lpstrText = NULL;
  3417. BOOL bRet = FALSE;
  3418. for(int nLen = 256; ; nLen *= 2)
  3419. {
  3420. ATLTRY(lpstrText = new TCHAR[nLen]);
  3421. if(lpstrText == NULL)
  3422. break;
  3423. lpstrText[0] = NULL;
  3424. item.pszText = lpstrText;
  3425. item.cchTextMax = nLen;
  3426. bRet = (BOOL)::SendMessage(this->m_hWnd, TVM_GETITEM, 0, (LPARAM)&item);
  3427. if(!bRet || (lstrlen(item.pszText) < (nLen - 1)))
  3428. break;
  3429. delete [] lpstrText;
  3430. lpstrText = NULL;
  3431. }
  3432. if(lpstrText != NULL)
  3433. {
  3434. if(bRet)
  3435. bstrText = ::SysAllocString(T2OLE(lpstrText));
  3436. delete [] lpstrText;
  3437. }
  3438. return (bstrText != NULL) ? TRUE : FALSE;
  3439. }
  3440. #ifdef __ATLSTR_H__
  3441. BOOL GetItemText(HTREEITEM hItem, ATL::CString& strText) const
  3442. {
  3443. ATLASSERT(::IsWindow(this->m_hWnd));
  3444. TVITEM item = {};
  3445. item.hItem = hItem;
  3446. item.mask = TVIF_TEXT;
  3447. strText.Empty();
  3448. BOOL bRet = FALSE;
  3449. for(int nLen = 256; ; nLen *= 2)
  3450. {
  3451. item.pszText = strText.GetBufferSetLength(nLen);
  3452. if(item.pszText == NULL)
  3453. {
  3454. bRet = FALSE;
  3455. break;
  3456. }
  3457. item.cchTextMax = nLen;
  3458. bRet = (BOOL)::SendMessage(this->m_hWnd, TVM_GETITEM, 0, (LPARAM)&item);
  3459. if(!bRet || (lstrlen(item.pszText) < (nLen - 1)))
  3460. break;
  3461. }
  3462. strText.ReleaseBuffer();
  3463. return bRet;
  3464. }
  3465. #endif // __ATLSTR_H__
  3466. BOOL SetItemText(HTREEITEM hItem, LPCTSTR lpszItem)
  3467. {
  3468. ATLASSERT(::IsWindow(this->m_hWnd));
  3469. return SetItem(hItem, TVIF_TEXT, lpszItem, 0, 0, 0, 0, NULL);
  3470. }
  3471. BOOL GetItemImage(HTREEITEM hItem, int& nImage, int& nSelectedImage) const
  3472. {
  3473. ATLASSERT(::IsWindow(this->m_hWnd));
  3474. TVITEM item = {};
  3475. item.hItem = hItem;
  3476. item.mask = TVIF_IMAGE|TVIF_SELECTEDIMAGE;
  3477. BOOL bRes = (BOOL)::SendMessage(this->m_hWnd, TVM_GETITEM, 0, (LPARAM)&item);
  3478. if (bRes)
  3479. {
  3480. nImage = item.iImage;
  3481. nSelectedImage = item.iSelectedImage;
  3482. }
  3483. return bRes;
  3484. }
  3485. BOOL SetItemImage(HTREEITEM hItem, int nImage, int nSelectedImage)
  3486. {
  3487. ATLASSERT(::IsWindow(this->m_hWnd));
  3488. return SetItem(hItem, TVIF_IMAGE|TVIF_SELECTEDIMAGE, NULL, nImage, nSelectedImage, 0, 0, NULL);
  3489. }
  3490. UINT GetItemState(HTREEITEM hItem, UINT nStateMask) const
  3491. {
  3492. ATLASSERT(::IsWindow(this->m_hWnd));
  3493. return (((UINT)::SendMessage(this->m_hWnd, TVM_GETITEMSTATE, (WPARAM)hItem, (LPARAM)nStateMask)) & nStateMask);
  3494. }
  3495. BOOL SetItemState(HTREEITEM hItem, UINT nState, UINT nStateMask)
  3496. {
  3497. ATLASSERT(::IsWindow(this->m_hWnd));
  3498. return SetItem(hItem, TVIF_STATE, NULL, 0, 0, nState, nStateMask, NULL);
  3499. }
  3500. DWORD_PTR GetItemData(HTREEITEM hItem) const
  3501. {
  3502. ATLASSERT(::IsWindow(this->m_hWnd));
  3503. TVITEM item = {};
  3504. item.hItem = hItem;
  3505. item.mask = TVIF_PARAM;
  3506. BOOL bRet = (BOOL)::SendMessage(this->m_hWnd, TVM_GETITEM, 0, (LPARAM)&item);
  3507. return (DWORD_PTR)(bRet ? item.lParam : NULL);
  3508. }
  3509. BOOL SetItemData(HTREEITEM hItem, DWORD_PTR dwData)
  3510. {
  3511. ATLASSERT(::IsWindow(this->m_hWnd));
  3512. return SetItem(hItem, TVIF_PARAM, NULL, 0, 0, 0, 0, (LPARAM)dwData);
  3513. }
  3514. CEdit GetEditControl() const
  3515. {
  3516. ATLASSERT(::IsWindow(this->m_hWnd));
  3517. return CEdit((HWND)::SendMessage(this->m_hWnd, TVM_GETEDITCONTROL, 0, 0L));
  3518. }
  3519. UINT GetVisibleCount() const
  3520. {
  3521. ATLASSERT(::IsWindow(this->m_hWnd));
  3522. return (UINT)::SendMessage(this->m_hWnd, TVM_GETVISIBLECOUNT, 0, 0L);
  3523. }
  3524. BOOL GetItemRect(HTREEITEM hItem, LPRECT lpRect, BOOL bTextOnly) const
  3525. {
  3526. ATLASSERT(::IsWindow(this->m_hWnd));
  3527. *(HTREEITEM*)lpRect = hItem;
  3528. return (BOOL)::SendMessage(this->m_hWnd, TVM_GETITEMRECT, (WPARAM)bTextOnly, (LPARAM)lpRect);
  3529. }
  3530. BOOL ItemHasChildren(HTREEITEM hItem) const
  3531. {
  3532. ATLASSERT(::IsWindow(this->m_hWnd));
  3533. TVITEM item = {};
  3534. item.hItem = hItem;
  3535. item.mask = TVIF_CHILDREN;
  3536. ::SendMessage(this->m_hWnd, TVM_GETITEM, 0, (LPARAM)&item);
  3537. return item.cChildren;
  3538. }
  3539. CToolTipCtrl GetToolTips() const
  3540. {
  3541. ATLASSERT(::IsWindow(this->m_hWnd));
  3542. return CToolTipCtrl((HWND)::SendMessage(this->m_hWnd, TVM_GETTOOLTIPS, 0, 0L));
  3543. }
  3544. CToolTipCtrl SetToolTips(HWND hWndTT)
  3545. {
  3546. ATLASSERT(::IsWindow(this->m_hWnd));
  3547. return CToolTipCtrl((HWND)::SendMessage(this->m_hWnd, TVM_SETTOOLTIPS, (WPARAM)hWndTT, 0L));
  3548. }
  3549. int GetISearchString(LPTSTR lpstr) const
  3550. {
  3551. ATLASSERT(::IsWindow(this->m_hWnd));
  3552. return (int)::SendMessage(this->m_hWnd, TVM_GETISEARCHSTRING, 0, (LPARAM)lpstr);
  3553. }
  3554. // checkboxes only
  3555. BOOL GetCheckState(HTREEITEM hItem) const
  3556. {
  3557. ATLASSERT(::IsWindow(this->m_hWnd));
  3558. ATLASSERT((this->GetStyle() & TVS_CHECKBOXES) != 0);
  3559. UINT uRet = GetItemState(hItem, TVIS_STATEIMAGEMASK);
  3560. return (uRet >> 12) - 1;
  3561. }
  3562. BOOL SetCheckState(HTREEITEM hItem, BOOL bCheck)
  3563. {
  3564. ATLASSERT(::IsWindow(this->m_hWnd));
  3565. ATLASSERT((this->GetStyle() & TVS_CHECKBOXES) != 0);
  3566. int nCheck = bCheck ? 2 : 1; // one based index
  3567. return SetItemState(hItem, INDEXTOSTATEIMAGEMASK(nCheck), TVIS_STATEIMAGEMASK);
  3568. }
  3569. // for standard and extended checkboxes (0 = no checkbox, 1 = unchecked, 2 = checked, >2 = optional extended check states)
  3570. UINT GetCheckStateEx(HTREEITEM hItem) const
  3571. {
  3572. ATLASSERT(::IsWindow(this->m_hWnd));
  3573. ATLASSERT(this->GetImageList(TVSIL_STATE) != NULL);
  3574. UINT uRet = GetItemState(hItem, TVIS_STATEIMAGEMASK);
  3575. return (uRet >> 12);
  3576. }
  3577. BOOL SetCheckStateEx(HTREEITEM hItem, UINT uCheckState)
  3578. {
  3579. ATLASSERT(::IsWindow(this->m_hWnd));
  3580. ATLASSERT(this->GetImageList(TVSIL_STATE) != NULL);
  3581. ATLASSERT(uCheckState < (UINT)::ImageList_GetImageCount(this->GetImageList(TVSIL_STATE)));
  3582. return SetItemState(hItem, INDEXTOSTATEIMAGEMASK(uCheckState), TVIS_STATEIMAGEMASK);
  3583. }
  3584. COLORREF GetBkColor() const
  3585. {
  3586. ATLASSERT(::IsWindow(this->m_hWnd));
  3587. return (COLORREF)::SendMessage(this->m_hWnd, TVM_GETBKCOLOR, 0, 0L);
  3588. }
  3589. COLORREF SetBkColor(COLORREF clr)
  3590. {
  3591. ATLASSERT(::IsWindow(this->m_hWnd));
  3592. return (COLORREF)::SendMessage(this->m_hWnd, TVM_SETBKCOLOR, 0, (LPARAM)clr);
  3593. }
  3594. COLORREF GetInsertMarkColor() const
  3595. {
  3596. ATLASSERT(::IsWindow(this->m_hWnd));
  3597. return (COLORREF)::SendMessage(this->m_hWnd, TVM_GETINSERTMARKCOLOR, 0, 0L);
  3598. }
  3599. COLORREF SetInsertMarkColor(COLORREF clr)
  3600. {
  3601. ATLASSERT(::IsWindow(this->m_hWnd));
  3602. return (COLORREF)::SendMessage(this->m_hWnd, TVM_SETINSERTMARKCOLOR, 0, (LPARAM)clr);
  3603. }
  3604. int GetItemHeight() const
  3605. {
  3606. ATLASSERT(::IsWindow(this->m_hWnd));
  3607. return (int)::SendMessage(this->m_hWnd, TVM_GETITEMHEIGHT, 0, 0L);
  3608. }
  3609. int SetItemHeight(int cyHeight)
  3610. {
  3611. ATLASSERT(::IsWindow(this->m_hWnd));
  3612. return (int)::SendMessage(this->m_hWnd, TVM_SETITEMHEIGHT, cyHeight, 0L);
  3613. }
  3614. int GetScrollTime() const
  3615. {
  3616. ATLASSERT(::IsWindow(this->m_hWnd));
  3617. return (int)::SendMessage(this->m_hWnd, TVM_GETSCROLLTIME, 0, 0L);
  3618. }
  3619. int SetScrollTime(int nScrollTime)
  3620. {
  3621. ATLASSERT(::IsWindow(this->m_hWnd));
  3622. return (int)::SendMessage(this->m_hWnd, TVM_SETSCROLLTIME, nScrollTime, 0L);
  3623. }
  3624. COLORREF GetTextColor() const
  3625. {
  3626. ATLASSERT(::IsWindow(this->m_hWnd));
  3627. return (COLORREF)::SendMessage(this->m_hWnd, TVM_GETTEXTCOLOR, 0, 0L);
  3628. }
  3629. COLORREF SetTextColor(COLORREF clr)
  3630. {
  3631. ATLASSERT(::IsWindow(this->m_hWnd));
  3632. return (COLORREF)::SendMessage(this->m_hWnd, TVM_SETTEXTCOLOR, 0, (LPARAM)clr);
  3633. }
  3634. BOOL GetUnicodeFormat() const
  3635. {
  3636. ATLASSERT(::IsWindow(this->m_hWnd));
  3637. return (BOOL)::SendMessage(this->m_hWnd, TVM_GETUNICODEFORMAT, 0, 0L);
  3638. }
  3639. BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
  3640. {
  3641. ATLASSERT(::IsWindow(this->m_hWnd));
  3642. return (BOOL)::SendMessage(this->m_hWnd, TVM_SETUNICODEFORMAT, bUnicode, 0L);
  3643. }
  3644. COLORREF GetLineColor() const
  3645. {
  3646. ATLASSERT(::IsWindow(this->m_hWnd));
  3647. return (COLORREF)::SendMessage(this->m_hWnd, TVM_GETLINECOLOR, 0, 0L);
  3648. }
  3649. COLORREF SetLineColor(COLORREF clrNew /*= CLR_DEFAULT*/)
  3650. {
  3651. ATLASSERT(::IsWindow(this->m_hWnd));
  3652. return (COLORREF)::SendMessage(this->m_hWnd, TVM_SETLINECOLOR, 0, (LPARAM)clrNew);
  3653. }
  3654. BOOL GetItem(LPTVITEMEX pItem) const
  3655. {
  3656. ATLASSERT(::IsWindow(this->m_hWnd));
  3657. return (BOOL)::SendMessage(this->m_hWnd, TVM_GETITEM, 0, (LPARAM)pItem);
  3658. }
  3659. BOOL SetItem(LPTVITEMEX pItem)
  3660. {
  3661. ATLASSERT(::IsWindow(this->m_hWnd));
  3662. return (BOOL)::SendMessage(this->m_hWnd, TVM_SETITEM, 0, (LPARAM)pItem);
  3663. }
  3664. DWORD GetExtendedStyle() const
  3665. {
  3666. ATLASSERT(::IsWindow(this->m_hWnd));
  3667. return (DWORD)::SendMessage(this->m_hWnd, TVM_GETEXTENDEDSTYLE, 0, 0L);
  3668. }
  3669. DWORD SetExtendedStyle(DWORD dwStyle, DWORD dwMask)
  3670. {
  3671. ATLASSERT(::IsWindow(this->m_hWnd));
  3672. return (DWORD)::SendMessage(this->m_hWnd, TVM_SETEXTENDEDSTYLE, dwMask, dwStyle);
  3673. }
  3674. #if (_WIN32_WINNT >= 0x0600)
  3675. BOOL SetAutoScrollInfo(UINT uPixPerSec, UINT uUpdateTime)
  3676. {
  3677. ATLASSERT(::IsWindow(this->m_hWnd));
  3678. return (BOOL)::SendMessage(this->m_hWnd, TVM_SETAUTOSCROLLINFO, (WPARAM)uPixPerSec, (LPARAM)uUpdateTime);
  3679. }
  3680. DWORD GetSelectedCount() const
  3681. {
  3682. ATLASSERT(::IsWindow(this->m_hWnd));
  3683. return (DWORD)::SendMessage(this->m_hWnd, TVM_GETSELECTEDCOUNT, 0, 0L);
  3684. }
  3685. BOOL GetItemPartRect(HTREEITEM hItem, TVITEMPART partID, LPRECT lpRect) const
  3686. {
  3687. ATLASSERT(::IsWindow(this->m_hWnd));
  3688. TVGETITEMPARTRECTINFO gipri = { hItem, lpRect, partID };
  3689. return (BOOL)::SendMessage(this->m_hWnd, TVM_GETITEMPARTRECT, 0, (LPARAM)&gipri);
  3690. }
  3691. #endif // (_WIN32_WINNT >= 0x0600)
  3692. // Operations
  3693. HTREEITEM InsertItem(LPTVINSERTSTRUCT lpInsertStruct)
  3694. {
  3695. ATLASSERT(::IsWindow(this->m_hWnd));
  3696. return (HTREEITEM)::SendMessage(this->m_hWnd, TVM_INSERTITEM, 0, (LPARAM)lpInsertStruct);
  3697. }
  3698. HTREEITEM InsertItem(LPCTSTR lpszItem, int nImage,
  3699. int nSelectedImage, HTREEITEM hParent, HTREEITEM hInsertAfter)
  3700. {
  3701. ATLASSERT(::IsWindow(this->m_hWnd));
  3702. return InsertItem(TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE, lpszItem, nImage, nSelectedImage, 0, 0, 0, hParent, hInsertAfter);
  3703. }
  3704. HTREEITEM InsertItem(LPCTSTR lpszItem, HTREEITEM hParent, HTREEITEM hInsertAfter)
  3705. {
  3706. ATLASSERT(::IsWindow(this->m_hWnd));
  3707. return InsertItem(TVIF_TEXT, lpszItem, 0, 0, 0, 0, 0, hParent, hInsertAfter);
  3708. }
  3709. HTREEITEM InsertItem(UINT nMask, LPCTSTR lpszItem, int nImage,
  3710. int nSelectedImage, UINT nState, UINT nStateMask, LPARAM lParam,
  3711. HTREEITEM hParent, HTREEITEM hInsertAfter)
  3712. {
  3713. ATLASSERT(::IsWindow(this->m_hWnd));
  3714. TVINSERTSTRUCT tvis = {};
  3715. tvis.hParent = hParent;
  3716. tvis.hInsertAfter = hInsertAfter;
  3717. tvis.item.mask = nMask;
  3718. tvis.item.pszText = (LPTSTR) lpszItem;
  3719. tvis.item.iImage = nImage;
  3720. tvis.item.iSelectedImage = nSelectedImage;
  3721. tvis.item.state = nState;
  3722. tvis.item.stateMask = nStateMask;
  3723. tvis.item.lParam = lParam;
  3724. return (HTREEITEM)::SendMessage(this->m_hWnd, TVM_INSERTITEM, 0, (LPARAM)&tvis);
  3725. }
  3726. BOOL DeleteItem(HTREEITEM hItem)
  3727. {
  3728. ATLASSERT(::IsWindow(this->m_hWnd));
  3729. return (BOOL)::SendMessage(this->m_hWnd, TVM_DELETEITEM, 0, (LPARAM)hItem);
  3730. }
  3731. BOOL DeleteAllItems()
  3732. {
  3733. ATLASSERT(::IsWindow(this->m_hWnd));
  3734. return (BOOL)::SendMessage(this->m_hWnd, TVM_DELETEITEM, 0, (LPARAM)TVI_ROOT);
  3735. }
  3736. BOOL Expand(HTREEITEM hItem, UINT nCode = TVE_EXPAND)
  3737. {
  3738. ATLASSERT(::IsWindow(this->m_hWnd));
  3739. return (BOOL)::SendMessage(this->m_hWnd, TVM_EXPAND, nCode, (LPARAM)hItem);
  3740. }
  3741. HTREEITEM GetNextItem(HTREEITEM hItem, UINT nCode) const
  3742. {
  3743. ATLASSERT(::IsWindow(this->m_hWnd));
  3744. return (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, nCode, (LPARAM)hItem);
  3745. }
  3746. HTREEITEM GetChildItem(HTREEITEM hItem) const
  3747. {
  3748. ATLASSERT(::IsWindow(this->m_hWnd));
  3749. return (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_CHILD, (LPARAM)hItem);
  3750. }
  3751. HTREEITEM GetNextSiblingItem(HTREEITEM hItem) const
  3752. {
  3753. ATLASSERT(::IsWindow(this->m_hWnd));
  3754. return (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_NEXT, (LPARAM)hItem);
  3755. }
  3756. HTREEITEM GetPrevSiblingItem(HTREEITEM hItem) const
  3757. {
  3758. ATLASSERT(::IsWindow(this->m_hWnd));
  3759. return (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_PREVIOUS, (LPARAM)hItem);
  3760. }
  3761. HTREEITEM GetParentItem(HTREEITEM hItem) const
  3762. {
  3763. ATLASSERT(::IsWindow(this->m_hWnd));
  3764. return (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_PARENT, (LPARAM)hItem);
  3765. }
  3766. HTREEITEM GetFirstVisibleItem() const
  3767. {
  3768. ATLASSERT(::IsWindow(this->m_hWnd));
  3769. return (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_FIRSTVISIBLE, 0L);
  3770. }
  3771. HTREEITEM GetNextVisibleItem(HTREEITEM hItem) const
  3772. {
  3773. ATLASSERT(::IsWindow(this->m_hWnd));
  3774. return (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_NEXTVISIBLE, (LPARAM)hItem);
  3775. }
  3776. HTREEITEM GetPrevVisibleItem(HTREEITEM hItem) const
  3777. {
  3778. ATLASSERT(::IsWindow(this->m_hWnd));
  3779. return (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_PREVIOUSVISIBLE, (LPARAM)hItem);
  3780. }
  3781. HTREEITEM GetSelectedItem() const
  3782. {
  3783. ATLASSERT(::IsWindow(this->m_hWnd));
  3784. return (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_CARET, 0L);
  3785. }
  3786. HTREEITEM GetDropHilightItem() const
  3787. {
  3788. ATLASSERT(::IsWindow(this->m_hWnd));
  3789. return (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_DROPHILITE, 0L);
  3790. }
  3791. HTREEITEM GetRootItem() const
  3792. {
  3793. ATLASSERT(::IsWindow(this->m_hWnd));
  3794. return (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_ROOT, 0L);
  3795. }
  3796. HTREEITEM GetLastVisibleItem() const
  3797. {
  3798. ATLASSERT(::IsWindow(this->m_hWnd));
  3799. return (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_LASTVISIBLE, 0L);
  3800. }
  3801. HTREEITEM GetNextSelectedItem(HTREEITEM hItem) const
  3802. {
  3803. ATLASSERT(::IsWindow(this->m_hWnd));
  3804. return (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_NEXTSELECTED, (LPARAM)hItem);
  3805. }
  3806. BOOL Select(HTREEITEM hItem, UINT nCode)
  3807. {
  3808. ATLASSERT(::IsWindow(this->m_hWnd));
  3809. return (BOOL)::SendMessage(this->m_hWnd, TVM_SELECTITEM, nCode, (LPARAM)hItem);
  3810. }
  3811. BOOL SelectItem(HTREEITEM hItem)
  3812. {
  3813. ATLASSERT(::IsWindow(this->m_hWnd));
  3814. return (BOOL)::SendMessage(this->m_hWnd, TVM_SELECTITEM, TVGN_CARET, (LPARAM)hItem);
  3815. }
  3816. BOOL SelectDropTarget(HTREEITEM hItem)
  3817. {
  3818. ATLASSERT(::IsWindow(this->m_hWnd));
  3819. return (BOOL)::SendMessage(this->m_hWnd, TVM_SELECTITEM, TVGN_DROPHILITE, (LPARAM)hItem);
  3820. }
  3821. BOOL SelectSetFirstVisible(HTREEITEM hItem)
  3822. {
  3823. ATLASSERT(::IsWindow(this->m_hWnd));
  3824. return (BOOL)::SendMessage(this->m_hWnd, TVM_SELECTITEM, TVGN_FIRSTVISIBLE, (LPARAM)hItem);
  3825. }
  3826. CEdit EditLabel(HTREEITEM hItem)
  3827. {
  3828. ATLASSERT(::IsWindow(this->m_hWnd));
  3829. return CEdit((HWND)::SendMessage(this->m_hWnd, TVM_EDITLABEL, 0, (LPARAM)hItem));
  3830. }
  3831. BOOL EndEditLabelNow(BOOL bCancel)
  3832. {
  3833. ATLASSERT(::IsWindow(this->m_hWnd));
  3834. return (BOOL)::SendMessage(this->m_hWnd, TVM_ENDEDITLABELNOW, bCancel, 0L);
  3835. }
  3836. HTREEITEM HitTest(TVHITTESTINFO* pHitTestInfo) const
  3837. {
  3838. ATLASSERT(::IsWindow(this->m_hWnd));
  3839. return (HTREEITEM)::SendMessage(this->m_hWnd, TVM_HITTEST, 0, (LPARAM)pHitTestInfo);
  3840. }
  3841. HTREEITEM HitTest(POINT pt, UINT* pFlags) const
  3842. {
  3843. ATLASSERT(::IsWindow(this->m_hWnd));
  3844. TVHITTESTINFO hti = {};
  3845. hti.pt = pt;
  3846. HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(this->m_hWnd, TVM_HITTEST, 0, (LPARAM)&hti);
  3847. if (pFlags != NULL)
  3848. *pFlags = hti.flags;
  3849. return hTreeItem;
  3850. }
  3851. BOOL SortChildren(HTREEITEM hItem, BOOL bRecurse = FALSE)
  3852. {
  3853. ATLASSERT(::IsWindow(this->m_hWnd));
  3854. return (BOOL)::SendMessage(this->m_hWnd, TVM_SORTCHILDREN, (WPARAM)bRecurse, (LPARAM)hItem);
  3855. }
  3856. BOOL EnsureVisible(HTREEITEM hItem)
  3857. {
  3858. ATLASSERT(::IsWindow(this->m_hWnd));
  3859. return (BOOL)::SendMessage(this->m_hWnd, TVM_ENSUREVISIBLE, 0, (LPARAM)hItem);
  3860. }
  3861. BOOL SortChildrenCB(LPTVSORTCB pSort, BOOL bRecurse = FALSE)
  3862. {
  3863. ATLASSERT(::IsWindow(this->m_hWnd));
  3864. return (BOOL)::SendMessage(this->m_hWnd, TVM_SORTCHILDRENCB, (WPARAM)bRecurse, (LPARAM)pSort);
  3865. }
  3866. CImageList RemoveImageList(int nImageList)
  3867. {
  3868. ATLASSERT(::IsWindow(this->m_hWnd));
  3869. return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, TVM_SETIMAGELIST, (WPARAM)nImageList, NULL));
  3870. }
  3871. CImageList CreateDragImage(HTREEITEM hItem)
  3872. {
  3873. ATLASSERT(::IsWindow(this->m_hWnd));
  3874. return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, TVM_CREATEDRAGIMAGE, 0, (LPARAM)hItem));
  3875. }
  3876. BOOL SetInsertMark(HTREEITEM hTreeItem, BOOL bAfter)
  3877. {
  3878. ATLASSERT(::IsWindow(this->m_hWnd));
  3879. return (BOOL)::SendMessage(this->m_hWnd, TVM_SETINSERTMARK, bAfter, (LPARAM)hTreeItem);
  3880. }
  3881. BOOL RemoveInsertMark()
  3882. {
  3883. ATLASSERT(::IsWindow(this->m_hWnd));
  3884. return (BOOL)::SendMessage(this->m_hWnd, TVM_SETINSERTMARK, 0, 0L);
  3885. }
  3886. HTREEITEM MapAccIDToHTREEITEM(UINT uID) const
  3887. {
  3888. ATLASSERT(::IsWindow(this->m_hWnd));
  3889. return (HTREEITEM)::SendMessage(this->m_hWnd, TVM_MAPACCIDTOHTREEITEM, uID, 0L);
  3890. }
  3891. UINT MapHTREEITEMToAccID(HTREEITEM hTreeItem) const
  3892. {
  3893. ATLASSERT(::IsWindow(this->m_hWnd));
  3894. return (UINT)::SendMessage(this->m_hWnd, TVM_MAPHTREEITEMTOACCID, (WPARAM)hTreeItem, 0L);
  3895. }
  3896. #if (_WIN32_WINNT >= 0x0600)
  3897. void ShowInfoTip(HTREEITEM hItem)
  3898. {
  3899. ATLASSERT(::IsWindow(this->m_hWnd));
  3900. ::SendMessage(this->m_hWnd, TVM_SHOWINFOTIP, 0, (LPARAM)hItem);
  3901. }
  3902. #endif // (_WIN32_WINNT >= 0x0600)
  3903. };
  3904. typedef CTreeViewCtrlT<ATL::CWindow> CTreeViewCtrl;
  3905. ///////////////////////////////////////////////////////////////////////////////
  3906. // CTreeViewCtrlEx
  3907. // forward declaration
  3908. template <class TBase> class CTreeViewCtrlExT;
  3909. // Note: TBase here is for CTreeViewCtrlExT, and not for CTreeItemT itself
  3910. template <class TBase>
  3911. class CTreeItemT
  3912. {
  3913. public:
  3914. HTREEITEM m_hTreeItem;
  3915. CTreeViewCtrlExT<TBase>* m_pTreeView;
  3916. // Construction
  3917. CTreeItemT(HTREEITEM hTreeItem = NULL, CTreeViewCtrlExT<TBase>* pTreeView = NULL) : m_hTreeItem(hTreeItem), m_pTreeView(pTreeView)
  3918. { }
  3919. CTreeItemT(const CTreeItemT<TBase>& posSrc)
  3920. {
  3921. *this = posSrc;
  3922. }
  3923. operator HTREEITEM() { return m_hTreeItem; }
  3924. CTreeItemT<TBase>& operator =(const CTreeItemT<TBase>& itemSrc)
  3925. {
  3926. m_hTreeItem = itemSrc.m_hTreeItem;
  3927. m_pTreeView = itemSrc.m_pTreeView;
  3928. return *this;
  3929. }
  3930. // Attributes
  3931. CTreeViewCtrlExT<TBase>* GetTreeView() const { return m_pTreeView; }
  3932. BOOL operator !() const { return m_hTreeItem == NULL; }
  3933. BOOL IsNull() const { return m_hTreeItem == NULL; }
  3934. BOOL GetRect(LPRECT lpRect, BOOL bTextOnly) const;
  3935. BOOL GetText(LPTSTR lpstrText, int nLen) const;
  3936. BOOL GetText(BSTR& bstrText) const;
  3937. #ifdef __ATLSTR_H__
  3938. BOOL GetText(ATL::CString& strText) const;
  3939. #endif // __ATLSTR_H__
  3940. BOOL SetText(LPCTSTR lpszItem);
  3941. BOOL GetImage(int& nImage, int& nSelectedImage) const;
  3942. BOOL SetImage(int nImage, int nSelectedImage);
  3943. UINT GetState(UINT nStateMask) const;
  3944. BOOL SetState(UINT nState, UINT nStateMask);
  3945. DWORD_PTR GetData() const;
  3946. BOOL SetData(DWORD_PTR dwData);
  3947. BOOL SetItem(UINT nMask, LPCTSTR lpszItem, int nImage, int nSelectedImage, UINT nState, UINT nStateMask, LPARAM lParam);
  3948. // Operations
  3949. CTreeItemT<TBase> InsertAfter(LPCTSTR lpstrItem, HTREEITEM hItemAfter, int nImageIndex)
  3950. {
  3951. return _Insert(lpstrItem, nImageIndex, hItemAfter);
  3952. }
  3953. CTreeItemT<TBase> AddHead(LPCTSTR lpstrItem, int nImageIndex)
  3954. {
  3955. return _Insert(lpstrItem, nImageIndex, TVI_FIRST);
  3956. }
  3957. CTreeItemT<TBase> AddTail(LPCTSTR lpstrItem, int nImageIndex)
  3958. {
  3959. return _Insert(lpstrItem, nImageIndex, TVI_LAST);
  3960. }
  3961. CTreeItemT<TBase> GetChild() const;
  3962. CTreeItemT<TBase> GetNext(UINT nCode) const;
  3963. CTreeItemT<TBase> GetNextSibling() const;
  3964. CTreeItemT<TBase> GetPrevSibling() const;
  3965. CTreeItemT<TBase> GetParent() const;
  3966. CTreeItemT<TBase> GetFirstVisible() const;
  3967. CTreeItemT<TBase> GetNextVisible() const;
  3968. CTreeItemT<TBase> GetPrevVisible() const;
  3969. CTreeItemT<TBase> GetSelected() const;
  3970. CTreeItemT<TBase> GetDropHilight() const;
  3971. CTreeItemT<TBase> GetRoot() const;
  3972. CTreeItemT<TBase> GetLastVisible() const;
  3973. CTreeItemT<TBase> GetNextSelected() const;
  3974. BOOL HasChildren() const;
  3975. BOOL Delete();
  3976. BOOL Expand(UINT nCode = TVE_EXPAND);
  3977. BOOL Select(UINT nCode);
  3978. BOOL Select();
  3979. BOOL SelectDropTarget();
  3980. BOOL SelectSetFirstVisible();
  3981. HWND EditLabel();
  3982. HIMAGELIST CreateDragImage();
  3983. BOOL SortChildren(BOOL bRecurse = FALSE);
  3984. BOOL EnsureVisible();
  3985. CTreeItemT<TBase> _Insert(LPCTSTR lpstrItem, int nImageIndex, HTREEITEM hItemAfter);
  3986. int GetImageIndex() const;
  3987. BOOL SetInsertMark(BOOL bAfter);
  3988. UINT MapHTREEITEMToAccID() const;
  3989. #if (_WIN32_WINNT >= 0x0600)
  3990. void ShowInfoTip();
  3991. BOOL GetPartRect(TVITEMPART partID, LPRECT lpRect) const;
  3992. #endif // (_WIN32_WINNT >= 0x0600)
  3993. };
  3994. typedef CTreeItemT<ATL::CWindow> CTreeItem;
  3995. template <class TBase>
  3996. class CTreeViewCtrlExT : public CTreeViewCtrlT< TBase >
  3997. {
  3998. public:
  3999. // Constructors
  4000. CTreeViewCtrlExT(HWND hWnd = NULL) : CTreeViewCtrlT< TBase >(hWnd)
  4001. { }
  4002. CTreeViewCtrlExT< TBase >& operator =(HWND hWnd)
  4003. {
  4004. this->m_hWnd = hWnd;
  4005. return *this;
  4006. }
  4007. // Operations (overides that return CTreeItem)
  4008. CTreeItemT<TBase> InsertItem(LPTVINSERTSTRUCT lpInsertStruct)
  4009. {
  4010. ATLASSERT(::IsWindow(this->m_hWnd));
  4011. HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(this->m_hWnd, TVM_INSERTITEM, 0, (LPARAM)lpInsertStruct);
  4012. return CTreeItemT<TBase>(hTreeItem, this);
  4013. }
  4014. CTreeItemT<TBase> InsertItem(LPCTSTR lpszItem, int nImage,
  4015. int nSelectedImage, HTREEITEM hParent, HTREEITEM hInsertAfter)
  4016. {
  4017. ATLASSERT(::IsWindow(this->m_hWnd));
  4018. return InsertItem(TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE, lpszItem, nImage, nSelectedImage, 0, 0, 0, hParent, hInsertAfter);
  4019. }
  4020. CTreeItemT<TBase> InsertItem(LPCTSTR lpszItem, HTREEITEM hParent, HTREEITEM hInsertAfter)
  4021. {
  4022. ATLASSERT(::IsWindow(this->m_hWnd));
  4023. return InsertItem(TVIF_TEXT, lpszItem, 0, 0, 0, 0, 0, hParent, hInsertAfter);
  4024. }
  4025. CTreeItemT<TBase> GetNextItem(HTREEITEM hItem, UINT nCode) const
  4026. {
  4027. ATLASSERT(::IsWindow(this->m_hWnd));
  4028. HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, nCode, (LPARAM)hItem);
  4029. return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
  4030. }
  4031. CTreeItemT<TBase> GetChildItem(HTREEITEM hItem) const
  4032. {
  4033. ATLASSERT(::IsWindow(this->m_hWnd));
  4034. HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_CHILD, (LPARAM)hItem);
  4035. return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
  4036. }
  4037. CTreeItemT<TBase> GetNextSiblingItem(HTREEITEM hItem) const
  4038. {
  4039. ATLASSERT(::IsWindow(this->m_hWnd));
  4040. HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_NEXT, (LPARAM)hItem);
  4041. return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
  4042. }
  4043. CTreeItemT<TBase> GetPrevSiblingItem(HTREEITEM hItem) const
  4044. {
  4045. ATLASSERT(::IsWindow(this->m_hWnd));
  4046. HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_PREVIOUS, (LPARAM)hItem);
  4047. return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
  4048. }
  4049. CTreeItemT<TBase> GetParentItem(HTREEITEM hItem) const
  4050. {
  4051. ATLASSERT(::IsWindow(this->m_hWnd));
  4052. HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_PARENT, (LPARAM)hItem);
  4053. return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
  4054. }
  4055. CTreeItemT<TBase> GetFirstVisibleItem() const
  4056. {
  4057. ATLASSERT(::IsWindow(this->m_hWnd));
  4058. HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_FIRSTVISIBLE, 0L);
  4059. return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
  4060. }
  4061. CTreeItemT<TBase> GetNextVisibleItem(HTREEITEM hItem) const
  4062. {
  4063. ATLASSERT(::IsWindow(this->m_hWnd));
  4064. HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_NEXTVISIBLE, (LPARAM)hItem);
  4065. return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
  4066. }
  4067. CTreeItemT<TBase> GetPrevVisibleItem(HTREEITEM hItem) const
  4068. {
  4069. ATLASSERT(::IsWindow(this->m_hWnd));
  4070. HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_PREVIOUSVISIBLE, (LPARAM)hItem);
  4071. return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
  4072. }
  4073. CTreeItemT<TBase> GetSelectedItem() const
  4074. {
  4075. ATLASSERT(::IsWindow(this->m_hWnd));
  4076. HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_CARET, 0L);
  4077. return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
  4078. }
  4079. CTreeItemT<TBase> GetDropHilightItem() const
  4080. {
  4081. ATLASSERT(::IsWindow(this->m_hWnd));
  4082. HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_DROPHILITE, 0L);
  4083. return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
  4084. }
  4085. CTreeItemT<TBase> GetRootItem() const
  4086. {
  4087. ATLASSERT(::IsWindow(this->m_hWnd));
  4088. HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_ROOT, 0L);
  4089. return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
  4090. }
  4091. CTreeItemT<TBase> GetLastVisibleItem() const
  4092. {
  4093. ATLASSERT(::IsWindow(this->m_hWnd));
  4094. HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_LASTVISIBLE, 0L);
  4095. return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
  4096. }
  4097. CTreeItemT<TBase> GetNextSelectedItem(HTREEITEM hItem) const
  4098. {
  4099. ATLASSERT(::IsWindow(this->m_hWnd));
  4100. HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(this->m_hWnd, TVM_GETNEXTITEM, TVGN_NEXTSELECTED, (LPARAM)hItem);
  4101. return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
  4102. }
  4103. CTreeItemT<TBase> HitTest(TVHITTESTINFO* pHitTestInfo) const
  4104. {
  4105. ATLASSERT(::IsWindow(this->m_hWnd));
  4106. HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(this->m_hWnd, TVM_HITTEST, 0, (LPARAM)pHitTestInfo);
  4107. return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
  4108. }
  4109. CTreeItemT<TBase> InsertItem(UINT nMask, LPCTSTR lpszItem, int nImage,
  4110. int nSelectedImage, UINT nState, UINT nStateMask, LPARAM lParam,
  4111. HTREEITEM hParent, HTREEITEM hInsertAfter)
  4112. {
  4113. ATLASSERT(::IsWindow(this->m_hWnd));
  4114. TVINSERTSTRUCT tvis = {};
  4115. tvis.hParent = hParent;
  4116. tvis.hInsertAfter = hInsertAfter;
  4117. tvis.item.mask = nMask;
  4118. tvis.item.pszText = (LPTSTR) lpszItem;
  4119. tvis.item.iImage = nImage;
  4120. tvis.item.iSelectedImage = nSelectedImage;
  4121. tvis.item.state = nState;
  4122. tvis.item.stateMask = nStateMask;
  4123. tvis.item.lParam = lParam;
  4124. HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(this->m_hWnd, TVM_INSERTITEM, 0, (LPARAM)&tvis);
  4125. return CTreeItemT<TBase>(hTreeItem, this);
  4126. }
  4127. CTreeItemT<TBase> HitTest(POINT pt, UINT* pFlags) const
  4128. {
  4129. ATLASSERT(::IsWindow(this->m_hWnd));
  4130. TVHITTESTINFO hti = {};
  4131. hti.pt = pt;
  4132. HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(this->m_hWnd, TVM_HITTEST, 0, (LPARAM)&hti);
  4133. if (pFlags != NULL)
  4134. *pFlags = hti.flags;
  4135. return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
  4136. }
  4137. CTreeItemT<TBase> MapAccIDToHTREEITEM(UINT uID) const
  4138. {
  4139. ATLASSERT(::IsWindow(this->m_hWnd));
  4140. HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(this->m_hWnd, TVM_MAPACCIDTOHTREEITEM, uID, 0L);
  4141. return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
  4142. }
  4143. };
  4144. typedef CTreeViewCtrlExT<ATL::CWindow> CTreeViewCtrlEx;
  4145. // CTreeItem inline methods
  4146. template <class TBase>
  4147. inline BOOL CTreeItemT<TBase>::GetRect(LPRECT lpRect, BOOL bTextOnly) const
  4148. {
  4149. ATLASSERT(m_pTreeView != NULL);
  4150. return m_pTreeView->GetItemRect(m_hTreeItem,lpRect,bTextOnly);
  4151. }
  4152. template <class TBase>
  4153. inline CTreeItemT<TBase> CTreeItemT<TBase>::GetNext(UINT nCode) const
  4154. {
  4155. ATLASSERT(m_pTreeView != NULL);
  4156. return m_pTreeView->GetNextItem(m_hTreeItem,nCode);
  4157. }
  4158. template <class TBase>
  4159. inline CTreeItemT<TBase> CTreeItemT<TBase>::GetChild() const
  4160. {
  4161. ATLASSERT(m_pTreeView != NULL);
  4162. return m_pTreeView->GetChildItem(m_hTreeItem);
  4163. }
  4164. template <class TBase>
  4165. inline CTreeItemT<TBase> CTreeItemT<TBase>::GetNextSibling() const
  4166. {
  4167. ATLASSERT(m_pTreeView != NULL);
  4168. return m_pTreeView->GetNextSiblingItem(m_hTreeItem);
  4169. }
  4170. template <class TBase>
  4171. inline CTreeItemT<TBase> CTreeItemT<TBase>::GetPrevSibling() const
  4172. {
  4173. ATLASSERT(m_pTreeView != NULL);
  4174. return m_pTreeView->GetPrevSiblingItem(m_hTreeItem);
  4175. }
  4176. template <class TBase>
  4177. inline CTreeItemT<TBase> CTreeItemT<TBase>::GetParent() const
  4178. {
  4179. ATLASSERT(m_pTreeView != NULL);
  4180. return m_pTreeView->GetParentItem(m_hTreeItem);
  4181. }
  4182. template <class TBase>
  4183. inline CTreeItemT<TBase> CTreeItemT<TBase>::GetFirstVisible() const
  4184. {
  4185. ATLASSERT(m_pTreeView != NULL);
  4186. return m_pTreeView->GetFirstVisibleItem();
  4187. }
  4188. template <class TBase>
  4189. inline CTreeItemT<TBase> CTreeItemT<TBase>::GetNextVisible() const
  4190. {
  4191. ATLASSERT(m_pTreeView != NULL);
  4192. return m_pTreeView->GetNextVisibleItem(m_hTreeItem);
  4193. }
  4194. template <class TBase>
  4195. inline CTreeItemT<TBase> CTreeItemT<TBase>::GetPrevVisible() const
  4196. {
  4197. ATLASSERT(m_pTreeView != NULL);
  4198. return m_pTreeView->GetPrevVisibleItem(m_hTreeItem);
  4199. }
  4200. template <class TBase>
  4201. inline CTreeItemT<TBase> CTreeItemT<TBase>::GetSelected() const
  4202. {
  4203. ATLASSERT(m_pTreeView != NULL);
  4204. return m_pTreeView->GetSelectedItem();
  4205. }
  4206. template <class TBase>
  4207. inline CTreeItemT<TBase> CTreeItemT<TBase>::GetDropHilight() const
  4208. {
  4209. ATLASSERT(m_pTreeView != NULL);
  4210. return m_pTreeView->GetDropHilightItem();
  4211. }
  4212. template <class TBase>
  4213. inline CTreeItemT<TBase> CTreeItemT<TBase>::GetRoot() const
  4214. {
  4215. ATLASSERT(m_pTreeView != NULL);
  4216. return m_pTreeView->GetRootItem();
  4217. }
  4218. template <class TBase>
  4219. inline CTreeItemT<TBase> CTreeItemT<TBase>::GetLastVisible() const
  4220. {
  4221. ATLASSERT(m_pTreeView != NULL);
  4222. return m_pTreeView->GetLastVisibleItem();
  4223. }
  4224. template <class TBase>
  4225. inline CTreeItemT<TBase> CTreeItemT<TBase>::GetNextSelected() const
  4226. {
  4227. ATLASSERT(m_pTreeView != NULL);
  4228. return m_pTreeView->GetNextSelectedItem(m_hTreeItem);
  4229. }
  4230. template <class TBase>
  4231. inline BOOL CTreeItemT<TBase>::GetText(LPTSTR lpstrText, int nLen) const
  4232. {
  4233. ATLASSERT(m_pTreeView != NULL);
  4234. return m_pTreeView->GetItemText(m_hTreeItem, lpstrText, nLen);
  4235. }
  4236. #ifdef _OLEAUTO_H_
  4237. template <class TBase>
  4238. inline BOOL CTreeItemT<TBase>::GetText(BSTR& bstrText) const
  4239. {
  4240. ATLASSERT(m_pTreeView != NULL);
  4241. return m_pTreeView->GetItemText(m_hTreeItem, bstrText);
  4242. }
  4243. #endif // _OLEAUTO_H_
  4244. #ifdef __ATLSTR_H__
  4245. template <class TBase>
  4246. inline BOOL CTreeItemT<TBase>::GetText(ATL::CString& strText) const
  4247. {
  4248. ATLASSERT(m_pTreeView != NULL);
  4249. return m_pTreeView->GetItemText(m_hTreeItem, strText);
  4250. }
  4251. #endif // __ATLSTR_H__
  4252. template <class TBase>
  4253. inline BOOL CTreeItemT<TBase>::GetImage(int& nImage, int& nSelectedImage) const
  4254. {
  4255. ATLASSERT(m_pTreeView != NULL);
  4256. return m_pTreeView->GetItemImage(m_hTreeItem,nImage,nSelectedImage);
  4257. }
  4258. template <class TBase>
  4259. inline UINT CTreeItemT<TBase>::GetState(UINT nStateMask) const
  4260. {
  4261. ATLASSERT(m_pTreeView != NULL);
  4262. return m_pTreeView->GetItemState(m_hTreeItem,nStateMask);
  4263. }
  4264. template <class TBase>
  4265. inline DWORD_PTR CTreeItemT<TBase>::GetData() const
  4266. {
  4267. ATLASSERT(m_pTreeView != NULL);
  4268. return m_pTreeView->GetItemData(m_hTreeItem);
  4269. }
  4270. template <class TBase>
  4271. inline BOOL CTreeItemT<TBase>::SetItem(UINT nMask, LPCTSTR lpszItem, int nImage,
  4272. int nSelectedImage, UINT nState, UINT nStateMask, LPARAM lParam)
  4273. {
  4274. ATLASSERT(m_pTreeView != NULL);
  4275. return m_pTreeView->SetItem(m_hTreeItem, nMask, lpszItem, nImage, nSelectedImage, nState, nStateMask, lParam);
  4276. }
  4277. template <class TBase>
  4278. inline BOOL CTreeItemT<TBase>::SetText(LPCTSTR lpszItem)
  4279. {
  4280. ATLASSERT(m_pTreeView != NULL);
  4281. return m_pTreeView->SetItemText(m_hTreeItem,lpszItem);
  4282. }
  4283. template <class TBase>
  4284. inline BOOL CTreeItemT<TBase>::SetImage(int nImage, int nSelectedImage)
  4285. {
  4286. ATLASSERT(m_pTreeView != NULL);
  4287. return m_pTreeView->SetItemImage(m_hTreeItem,nImage,nSelectedImage);
  4288. }
  4289. template <class TBase>
  4290. inline BOOL CTreeItemT<TBase>::SetState(UINT nState, UINT nStateMask)
  4291. {
  4292. ATLASSERT(m_pTreeView != NULL);
  4293. return m_pTreeView->SetItemState(m_hTreeItem,nState,nStateMask);
  4294. }
  4295. template <class TBase>
  4296. inline BOOL CTreeItemT<TBase>::SetData(DWORD_PTR dwData)
  4297. {
  4298. ATLASSERT(m_pTreeView != NULL);
  4299. return m_pTreeView->SetItemData(m_hTreeItem,dwData);
  4300. }
  4301. template <class TBase>
  4302. inline BOOL CTreeItemT<TBase>::HasChildren() const
  4303. {
  4304. ATLASSERT(m_pTreeView != NULL);
  4305. return m_pTreeView->ItemHasChildren(m_hTreeItem);
  4306. }
  4307. template <class TBase>
  4308. inline BOOL CTreeItemT<TBase>::Delete()
  4309. {
  4310. ATLASSERT(m_pTreeView != NULL);
  4311. return m_pTreeView->DeleteItem(m_hTreeItem);
  4312. }
  4313. template <class TBase>
  4314. inline BOOL CTreeItemT<TBase>::Expand(UINT nCode /*= TVE_EXPAND*/)
  4315. {
  4316. ATLASSERT(m_pTreeView != NULL);
  4317. return m_pTreeView->Expand(m_hTreeItem,nCode);
  4318. }
  4319. template <class TBase>
  4320. inline BOOL CTreeItemT<TBase>::Select(UINT nCode)
  4321. {
  4322. ATLASSERT(m_pTreeView != NULL);
  4323. return m_pTreeView->Select(m_hTreeItem,nCode);
  4324. }
  4325. template <class TBase>
  4326. inline BOOL CTreeItemT<TBase>::Select()
  4327. {
  4328. ATLASSERT(m_pTreeView != NULL);
  4329. return m_pTreeView->SelectItem(m_hTreeItem);
  4330. }
  4331. template <class TBase>
  4332. inline BOOL CTreeItemT<TBase>::SelectDropTarget()
  4333. {
  4334. ATLASSERT(m_pTreeView != NULL);
  4335. return m_pTreeView->SelectDropTarget(m_hTreeItem);
  4336. }
  4337. template <class TBase>
  4338. inline BOOL CTreeItemT<TBase>::SelectSetFirstVisible()
  4339. {
  4340. ATLASSERT(m_pTreeView != NULL);
  4341. return m_pTreeView->SelectSetFirstVisible(m_hTreeItem);
  4342. }
  4343. template <class TBase>
  4344. inline HWND CTreeItemT<TBase>::EditLabel()
  4345. {
  4346. ATLASSERT(m_pTreeView != NULL);
  4347. return m_pTreeView->EditLabel(m_hTreeItem);
  4348. }
  4349. template <class TBase>
  4350. inline HIMAGELIST CTreeItemT<TBase>::CreateDragImage()
  4351. {
  4352. ATLASSERT(m_pTreeView != NULL);
  4353. return m_pTreeView->CreateDragImage(m_hTreeItem);
  4354. }
  4355. template <class TBase>
  4356. inline BOOL CTreeItemT<TBase>::SortChildren(BOOL bRecurse /*= FALSE*/)
  4357. {
  4358. ATLASSERT(m_pTreeView != NULL);
  4359. return m_pTreeView->SortChildren(m_hTreeItem, bRecurse);
  4360. }
  4361. template <class TBase>
  4362. inline BOOL CTreeItemT<TBase>::EnsureVisible()
  4363. {
  4364. ATLASSERT(m_pTreeView != NULL);
  4365. return m_pTreeView->EnsureVisible(m_hTreeItem);
  4366. }
  4367. template <class TBase>
  4368. inline CTreeItemT<TBase> CTreeItemT<TBase>::_Insert(LPCTSTR lpstrItem, int nImageIndex, HTREEITEM hItemAfter)
  4369. {
  4370. ATLASSERT(m_pTreeView != NULL);
  4371. TVINSERTSTRUCT ins = {};
  4372. ins.hParent = m_hTreeItem;
  4373. ins.hInsertAfter = hItemAfter;
  4374. ins.item.mask = TVIF_TEXT;
  4375. ins.item.pszText = (LPTSTR)lpstrItem;
  4376. if(nImageIndex != -1)
  4377. {
  4378. ins.item.mask |= TVIF_IMAGE | TVIF_SELECTEDIMAGE;
  4379. ins.item.iImage = nImageIndex;
  4380. ins.item.iSelectedImage = nImageIndex;
  4381. }
  4382. return CTreeItemT<TBase>(m_pTreeView->InsertItem(&ins), m_pTreeView);
  4383. }
  4384. template <class TBase>
  4385. inline int CTreeItemT<TBase>::GetImageIndex() const
  4386. {
  4387. ATLASSERT(m_pTreeView != NULL);
  4388. TVITEM item = {};
  4389. item.mask = TVIF_HANDLE | TVIF_IMAGE;
  4390. item.hItem = m_hTreeItem;
  4391. m_pTreeView->GetItem(&item);
  4392. return item.iImage;
  4393. }
  4394. template <class TBase>
  4395. inline BOOL CTreeItemT<TBase>::SetInsertMark(BOOL bAfter)
  4396. {
  4397. ATLASSERT(m_pTreeView != NULL);
  4398. return m_pTreeView->SetInsertMark(m_hTreeItem, bAfter);
  4399. }
  4400. template <class TBase>
  4401. inline UINT CTreeItemT<TBase>::MapHTREEITEMToAccID() const
  4402. {
  4403. ATLASSERT(m_pTreeView != NULL);
  4404. return m_pTreeView->MapHTREEITEMToAccID(m_hTreeItem);
  4405. }
  4406. #if (_WIN32_WINNT >= 0x0600)
  4407. template <class TBase>
  4408. inline void CTreeItemT<TBase>::ShowInfoTip()
  4409. {
  4410. ATLASSERT(m_pTreeView != NULL);
  4411. m_pTreeView->ShowInfoTip(m_hTreeItem);
  4412. }
  4413. template <class TBase>
  4414. inline BOOL CTreeItemT<TBase>::GetPartRect(TVITEMPART partID, LPRECT lpRect) const
  4415. {
  4416. ATLASSERT(m_pTreeView != NULL);
  4417. return m_pTreeView->GetItemPartRect(m_hTreeItem, partID, lpRect);
  4418. }
  4419. #endif // (_WIN32_WINNT >= 0x0600)
  4420. ///////////////////////////////////////////////////////////////////////////////
  4421. // CToolBarCtrl
  4422. template <class TBase>
  4423. class CToolBarCtrlT : public TBase
  4424. {
  4425. public:
  4426. // Construction
  4427. CToolBarCtrlT(HWND hWnd = NULL) : TBase(hWnd)
  4428. { }
  4429. CToolBarCtrlT< TBase >& operator =(HWND hWnd)
  4430. {
  4431. this->m_hWnd = hWnd;
  4432. return *this;
  4433. }
  4434. HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  4435. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  4436. ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  4437. {
  4438. return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  4439. }
  4440. // Attributes
  4441. static LPCTSTR GetWndClassName()
  4442. {
  4443. return TOOLBARCLASSNAME;
  4444. }
  4445. BOOL IsButtonEnabled(int nID) const
  4446. {
  4447. ATLASSERT(::IsWindow(this->m_hWnd));
  4448. return (BOOL)::SendMessage(this->m_hWnd, TB_ISBUTTONENABLED, nID, 0L);
  4449. }
  4450. BOOL IsButtonChecked(int nID) const
  4451. {
  4452. ATLASSERT(::IsWindow(this->m_hWnd));
  4453. return (BOOL)::SendMessage(this->m_hWnd, TB_ISBUTTONCHECKED, nID, 0L);
  4454. }
  4455. BOOL IsButtonPressed(int nID) const
  4456. {
  4457. ATLASSERT(::IsWindow(this->m_hWnd));
  4458. return (BOOL)::SendMessage(this->m_hWnd, TB_ISBUTTONPRESSED, nID, 0L);
  4459. }
  4460. BOOL IsButtonHidden(int nID) const
  4461. {
  4462. ATLASSERT(::IsWindow(this->m_hWnd));
  4463. return(BOOL) ::SendMessage(this->m_hWnd, TB_ISBUTTONHIDDEN, nID, 0L);
  4464. }
  4465. BOOL IsButtonIndeterminate(int nID) const
  4466. {
  4467. ATLASSERT(::IsWindow(this->m_hWnd));
  4468. return (BOOL)::SendMessage(this->m_hWnd, TB_ISBUTTONINDETERMINATE, nID, 0L);
  4469. }
  4470. int GetState(int nID) const
  4471. {
  4472. ATLASSERT(::IsWindow(this->m_hWnd));
  4473. return (int)::SendMessage(this->m_hWnd, TB_GETSTATE, nID, 0L);
  4474. }
  4475. BOOL SetState(int nID, UINT nState)
  4476. {
  4477. ATLASSERT(::IsWindow(this->m_hWnd));
  4478. return (BOOL)::SendMessage(this->m_hWnd, TB_SETSTATE, nID, MAKELPARAM(nState, 0));
  4479. }
  4480. BOOL GetButton(int nIndex, LPTBBUTTON lpButton) const
  4481. {
  4482. ATLASSERT(::IsWindow(this->m_hWnd));
  4483. return (BOOL)::SendMessage(this->m_hWnd, TB_GETBUTTON, nIndex, (LPARAM)lpButton);
  4484. }
  4485. int GetButtonCount() const
  4486. {
  4487. ATLASSERT(::IsWindow(this->m_hWnd));
  4488. return (int)::SendMessage(this->m_hWnd, TB_BUTTONCOUNT, 0, 0L);
  4489. }
  4490. BOOL GetItemRect(int nIndex, LPRECT lpRect) const
  4491. {
  4492. ATLASSERT(::IsWindow(this->m_hWnd));
  4493. return (BOOL)::SendMessage(this->m_hWnd, TB_GETITEMRECT, nIndex, (LPARAM)lpRect);
  4494. }
  4495. void SetButtonStructSize(int nSize = sizeof(TBBUTTON))
  4496. {
  4497. ATLASSERT(::IsWindow(this->m_hWnd));
  4498. ::SendMessage(this->m_hWnd, TB_BUTTONSTRUCTSIZE, nSize, 0L);
  4499. }
  4500. BOOL SetButtonSize(SIZE size)
  4501. {
  4502. ATLASSERT(::IsWindow(this->m_hWnd));
  4503. return (BOOL)::SendMessage(this->m_hWnd, TB_SETBUTTONSIZE, 0, MAKELPARAM(size.cx, size.cy));
  4504. }
  4505. BOOL SetButtonSize(int cx, int cy)
  4506. {
  4507. ATLASSERT(::IsWindow(this->m_hWnd));
  4508. return (BOOL)::SendMessage(this->m_hWnd, TB_SETBUTTONSIZE, 0, MAKELPARAM(cx, cy));
  4509. }
  4510. BOOL SetBitmapSize(SIZE size)
  4511. {
  4512. ATLASSERT(::IsWindow(this->m_hWnd));
  4513. return (BOOL)::SendMessage(this->m_hWnd, TB_SETBITMAPSIZE, 0, MAKELPARAM(size.cx, size.cy));
  4514. }
  4515. BOOL SetBitmapSize(int cx, int cy)
  4516. {
  4517. ATLASSERT(::IsWindow(this->m_hWnd));
  4518. return (BOOL)::SendMessage(this->m_hWnd, TB_SETBITMAPSIZE, 0, MAKELPARAM(cx, cy));
  4519. }
  4520. CToolTipCtrl GetToolTips() const
  4521. {
  4522. ATLASSERT(::IsWindow(this->m_hWnd));
  4523. return CToolTipCtrl((HWND)::SendMessage(this->m_hWnd, TB_GETTOOLTIPS, 0, 0L));
  4524. }
  4525. void SetToolTips(HWND hWndToolTip)
  4526. {
  4527. ATLASSERT(::IsWindow(this->m_hWnd));
  4528. ::SendMessage(this->m_hWnd, TB_SETTOOLTIPS, (WPARAM)hWndToolTip, 0L);
  4529. }
  4530. void SetNotifyWnd(HWND hWnd)
  4531. {
  4532. ATLASSERT(::IsWindow(this->m_hWnd));
  4533. ::SendMessage(this->m_hWnd, TB_SETPARENT, (WPARAM)hWnd, 0L);
  4534. }
  4535. int GetRows() const
  4536. {
  4537. ATLASSERT(::IsWindow(this->m_hWnd));
  4538. return (int)::SendMessage(this->m_hWnd, TB_GETROWS, 0, 0L);
  4539. }
  4540. void SetRows(int nRows, BOOL bLarger, LPRECT lpRect)
  4541. {
  4542. ATLASSERT(::IsWindow(this->m_hWnd));
  4543. ::SendMessage(this->m_hWnd, TB_SETROWS, MAKELPARAM(nRows, bLarger), (LPARAM)lpRect);
  4544. }
  4545. BOOL SetCmdID(int nIndex, UINT nID)
  4546. {
  4547. ATLASSERT(::IsWindow(this->m_hWnd));
  4548. return (BOOL)::SendMessage(this->m_hWnd, TB_SETCMDID, nIndex, nID);
  4549. }
  4550. DWORD GetBitmapFlags() const
  4551. {
  4552. ATLASSERT(::IsWindow(this->m_hWnd));
  4553. return (DWORD)::SendMessage(this->m_hWnd, TB_GETBITMAPFLAGS, 0, 0L);
  4554. }
  4555. int GetBitmap(int nID) const
  4556. {
  4557. ATLASSERT(::IsWindow(this->m_hWnd));
  4558. return (int)::SendMessage(this->m_hWnd, TB_GETBITMAP, nID, 0L);
  4559. }
  4560. int GetButtonText(int nID, LPTSTR lpstrText) const
  4561. {
  4562. ATLASSERT(::IsWindow(this->m_hWnd));
  4563. return (int)::SendMessage(this->m_hWnd, TB_GETBUTTONTEXT, nID, (LPARAM)lpstrText);
  4564. }
  4565. // nIndex - IE5 or higher only
  4566. CImageList GetImageList(int nIndex = 0) const
  4567. {
  4568. ATLASSERT(::IsWindow(this->m_hWnd));
  4569. return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, TB_GETIMAGELIST, nIndex, 0L));
  4570. }
  4571. // nIndex - IE5 or higher only
  4572. CImageList SetImageList(HIMAGELIST hImageList, int nIndex = 0)
  4573. {
  4574. ATLASSERT(::IsWindow(this->m_hWnd));
  4575. return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, TB_SETIMAGELIST, nIndex, (LPARAM)hImageList));
  4576. }
  4577. // nIndex - IE5 or higher only
  4578. CImageList GetDisabledImageList(int nIndex = 0) const
  4579. {
  4580. ATLASSERT(::IsWindow(this->m_hWnd));
  4581. return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, TB_GETDISABLEDIMAGELIST, nIndex, 0L));
  4582. }
  4583. // nIndex - IE5 or higher only
  4584. CImageList SetDisabledImageList(HIMAGELIST hImageList, int nIndex = 0)
  4585. {
  4586. ATLASSERT(::IsWindow(this->m_hWnd));
  4587. return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, TB_SETDISABLEDIMAGELIST, nIndex, (LPARAM)hImageList));
  4588. }
  4589. // nIndex - IE5 or higher only
  4590. CImageList GetHotImageList(int nIndex = 0) const
  4591. {
  4592. ATLASSERT(::IsWindow(this->m_hWnd));
  4593. return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, TB_GETHOTIMAGELIST, nIndex, 0L));
  4594. }
  4595. // nIndex - IE5 or higher only
  4596. CImageList SetHotImageList(HIMAGELIST hImageList, int nIndex = 0)
  4597. {
  4598. ATLASSERT(::IsWindow(this->m_hWnd));
  4599. return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, TB_SETHOTIMAGELIST, nIndex, (LPARAM)hImageList));
  4600. }
  4601. DWORD GetStyle() const
  4602. {
  4603. ATLASSERT(::IsWindow(this->m_hWnd));
  4604. return (DWORD)::SendMessage(this->m_hWnd, TB_GETSTYLE, 0, 0L);
  4605. }
  4606. void SetStyle(DWORD dwStyle)
  4607. {
  4608. ATLASSERT(::IsWindow(this->m_hWnd));
  4609. ::SendMessage(this->m_hWnd, TB_SETSTYLE, 0, dwStyle);
  4610. }
  4611. DWORD GetButtonSize() const
  4612. {
  4613. ATLASSERT(::IsWindow(this->m_hWnd));
  4614. return (DWORD)::SendMessage(this->m_hWnd, TB_GETBUTTONSIZE, 0, 0L);
  4615. }
  4616. void GetButtonSize(SIZE& size) const
  4617. {
  4618. ATLASSERT(::IsWindow(this->m_hWnd));
  4619. DWORD dwRet = (DWORD)::SendMessage(this->m_hWnd, TB_GETBUTTONSIZE, 0, 0L);
  4620. size.cx = LOWORD(dwRet);
  4621. size.cy = HIWORD(dwRet);
  4622. }
  4623. BOOL GetRect(int nID, LPRECT lpRect) const
  4624. {
  4625. ATLASSERT(::IsWindow(this->m_hWnd));
  4626. return (BOOL)::SendMessage(this->m_hWnd, TB_GETRECT, nID, (LPARAM)lpRect);
  4627. }
  4628. int GetTextRows() const
  4629. {
  4630. ATLASSERT(::IsWindow(this->m_hWnd));
  4631. return (int)::SendMessage(this->m_hWnd, TB_GETTEXTROWS, 0, 0L);
  4632. }
  4633. BOOL SetButtonWidth(int cxMin, int cxMax)
  4634. {
  4635. ATLASSERT(::IsWindow(this->m_hWnd));
  4636. return (BOOL)::SendMessage(this->m_hWnd, TB_SETBUTTONWIDTH, 0, MAKELPARAM(cxMin, cxMax));
  4637. }
  4638. BOOL SetIndent(int nIndent)
  4639. {
  4640. ATLASSERT(::IsWindow(this->m_hWnd));
  4641. return (BOOL)::SendMessage(this->m_hWnd, TB_SETINDENT, nIndent, 0L);
  4642. }
  4643. BOOL SetMaxTextRows(int nMaxTextRows)
  4644. {
  4645. ATLASSERT(::IsWindow(this->m_hWnd));
  4646. return (BOOL)::SendMessage(this->m_hWnd, TB_SETMAXTEXTROWS, nMaxTextRows, 0L);
  4647. }
  4648. BOOL GetAnchorHighlight() const
  4649. {
  4650. ATLASSERT(::IsWindow(this->m_hWnd));
  4651. return (BOOL)::SendMessage(this->m_hWnd, TB_GETANCHORHIGHLIGHT, 0, 0L);
  4652. }
  4653. BOOL SetAnchorHighlight(BOOL bEnable = TRUE)
  4654. {
  4655. ATLASSERT(::IsWindow(this->m_hWnd));
  4656. return (BOOL)::SendMessage(this->m_hWnd, TB_SETANCHORHIGHLIGHT, bEnable, 0L);
  4657. }
  4658. int GetButtonInfo(int nID, LPTBBUTTONINFO lptbbi) const
  4659. {
  4660. ATLASSERT(::IsWindow(this->m_hWnd));
  4661. return (int)::SendMessage(this->m_hWnd, TB_GETBUTTONINFO, nID, (LPARAM)lptbbi);
  4662. }
  4663. BOOL SetButtonInfo(int nID, LPTBBUTTONINFO lptbbi)
  4664. {
  4665. ATLASSERT(::IsWindow(this->m_hWnd));
  4666. return (BOOL)::SendMessage(this->m_hWnd, TB_SETBUTTONINFO, nID, (LPARAM)lptbbi);
  4667. }
  4668. BOOL SetButtonInfo(int nID, DWORD dwMask, BYTE Style, BYTE State, LPCTSTR lpszItem,
  4669. int iImage, WORD cx, int iCommand, DWORD_PTR lParam)
  4670. {
  4671. ATLASSERT(::IsWindow(this->m_hWnd));
  4672. TBBUTTONINFO tbbi = {};
  4673. tbbi.cbSize = sizeof(TBBUTTONINFO);
  4674. tbbi.dwMask = dwMask;
  4675. tbbi.idCommand = iCommand;
  4676. tbbi.iImage = iImage;
  4677. tbbi.fsState = State;
  4678. tbbi.fsStyle = Style;
  4679. tbbi.cx = cx;
  4680. tbbi.pszText = (LPTSTR) lpszItem;
  4681. tbbi.lParam = lParam;
  4682. return (BOOL)::SendMessage(this->m_hWnd, TB_SETBUTTONINFO, nID, (LPARAM)&tbbi);
  4683. }
  4684. int GetHotItem() const
  4685. {
  4686. ATLASSERT(::IsWindow(this->m_hWnd));
  4687. return (int)::SendMessage(this->m_hWnd, TB_GETHOTITEM, 0, 0L);
  4688. }
  4689. int SetHotItem(int nItem)
  4690. {
  4691. ATLASSERT(::IsWindow(this->m_hWnd));
  4692. return (int)::SendMessage(this->m_hWnd, TB_SETHOTITEM, nItem, 0L);
  4693. }
  4694. BOOL IsButtonHighlighted(int nButtonID) const
  4695. {
  4696. ATLASSERT(::IsWindow(this->m_hWnd));
  4697. return (BOOL)::SendMessage(this->m_hWnd, TB_ISBUTTONHIGHLIGHTED, nButtonID, 0L);
  4698. }
  4699. DWORD SetDrawTextFlags(DWORD dwMask, DWORD dwFlags)
  4700. {
  4701. ATLASSERT(::IsWindow(this->m_hWnd));
  4702. return (DWORD)::SendMessage(this->m_hWnd, TB_SETDRAWTEXTFLAGS, dwMask, dwFlags);
  4703. }
  4704. BOOL GetColorScheme(LPCOLORSCHEME lpcs) const
  4705. {
  4706. ATLASSERT(::IsWindow(this->m_hWnd));
  4707. return (BOOL)::SendMessage(this->m_hWnd, TB_GETCOLORSCHEME, 0, (LPARAM)lpcs);
  4708. }
  4709. void SetColorScheme(LPCOLORSCHEME lpcs)
  4710. {
  4711. ATLASSERT(::IsWindow(this->m_hWnd));
  4712. ::SendMessage(this->m_hWnd, TB_SETCOLORSCHEME, 0, (LPARAM)lpcs);
  4713. }
  4714. DWORD GetExtendedStyle() const
  4715. {
  4716. ATLASSERT(::IsWindow(this->m_hWnd));
  4717. return (DWORD)::SendMessage(this->m_hWnd, TB_GETEXTENDEDSTYLE, 0, 0L);
  4718. }
  4719. DWORD SetExtendedStyle(DWORD dwStyle)
  4720. {
  4721. ATLASSERT(::IsWindow(this->m_hWnd));
  4722. return (DWORD)::SendMessage(this->m_hWnd, TB_SETEXTENDEDSTYLE, 0, dwStyle);
  4723. }
  4724. void GetInsertMark(LPTBINSERTMARK lptbim) const
  4725. {
  4726. ATLASSERT(::IsWindow(this->m_hWnd));
  4727. ::SendMessage(this->m_hWnd, TB_GETINSERTMARK, 0, (LPARAM)lptbim);
  4728. }
  4729. void SetInsertMark(LPTBINSERTMARK lptbim)
  4730. {
  4731. ATLASSERT(::IsWindow(this->m_hWnd));
  4732. ::SendMessage(this->m_hWnd, TB_SETINSERTMARK, 0, (LPARAM)lptbim);
  4733. }
  4734. COLORREF GetInsertMarkColor() const
  4735. {
  4736. ATLASSERT(::IsWindow(this->m_hWnd));
  4737. return (COLORREF)::SendMessage(this->m_hWnd, TB_GETINSERTMARKCOLOR, 0, 0L);
  4738. }
  4739. COLORREF SetInsertMarkColor(COLORREF clr)
  4740. {
  4741. ATLASSERT(::IsWindow(this->m_hWnd));
  4742. return (COLORREF)::SendMessage(this->m_hWnd, TB_SETINSERTMARKCOLOR, 0, (LPARAM)clr);
  4743. }
  4744. BOOL GetMaxSize(LPSIZE lpSize) const
  4745. {
  4746. ATLASSERT(::IsWindow(this->m_hWnd));
  4747. return (BOOL)::SendMessage(this->m_hWnd, TB_GETMAXSIZE, 0, (LPARAM)lpSize);
  4748. }
  4749. void GetPadding(LPSIZE lpSizePadding) const
  4750. {
  4751. ATLASSERT(::IsWindow(this->m_hWnd));
  4752. ATLASSERT(lpSizePadding != NULL);
  4753. DWORD dwRet = (DWORD)::SendMessage(this->m_hWnd, TB_GETPADDING, 0, 0L);
  4754. lpSizePadding->cx = GET_X_LPARAM(dwRet);
  4755. lpSizePadding->cy = GET_Y_LPARAM(dwRet);
  4756. }
  4757. void SetPadding(int cx, int cy, LPSIZE lpSizePadding = NULL)
  4758. {
  4759. ATLASSERT(::IsWindow(this->m_hWnd));
  4760. DWORD dwRet = (DWORD)::SendMessage(this->m_hWnd, TB_SETPADDING, 0, MAKELPARAM(cx, cy));
  4761. if(lpSizePadding != NULL)
  4762. {
  4763. lpSizePadding->cx = GET_X_LPARAM(dwRet);
  4764. lpSizePadding->cy = GET_Y_LPARAM(dwRet);
  4765. }
  4766. }
  4767. BOOL GetUnicodeFormat() const
  4768. {
  4769. ATLASSERT(::IsWindow(this->m_hWnd));
  4770. return (BOOL)::SendMessage(this->m_hWnd, TB_GETUNICODEFORMAT, 0, 0L);
  4771. }
  4772. BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
  4773. {
  4774. ATLASSERT(::IsWindow(this->m_hWnd));
  4775. return (BOOL)::SendMessage(this->m_hWnd, TB_SETUNICODEFORMAT, bUnicode, 0L);
  4776. }
  4777. int GetString(int nString, LPTSTR lpstrString, int cchMaxLen) const
  4778. {
  4779. ATLASSERT(::IsWindow(this->m_hWnd));
  4780. return (int)::SendMessage(this->m_hWnd, TB_GETSTRING, MAKEWPARAM(cchMaxLen, nString), (LPARAM)lpstrString);
  4781. }
  4782. int GetStringBSTR(int nString, BSTR& bstrString) const
  4783. {
  4784. USES_CONVERSION;
  4785. ATLASSERT(::IsWindow(this->m_hWnd));
  4786. ATLASSERT(bstrString == NULL);
  4787. int nLength = (int)(short)LOWORD(::SendMessage(this->m_hWnd, TB_GETSTRING, MAKEWPARAM(0, nString), NULL));
  4788. if(nLength != -1)
  4789. {
  4790. ATL::CTempBuffer<TCHAR, _WTL_STACK_ALLOC_THRESHOLD> buff;
  4791. LPTSTR lpstrText = buff.Allocate(nLength + 1);
  4792. if(lpstrText != NULL)
  4793. {
  4794. nLength = (int)::SendMessage(this->m_hWnd, TB_GETSTRING, MAKEWPARAM(nLength + 1, nString), (LPARAM)lpstrText);
  4795. if(nLength != -1)
  4796. bstrString = ::SysAllocString(T2OLE(lpstrText));
  4797. }
  4798. else
  4799. {
  4800. nLength = -1;
  4801. }
  4802. }
  4803. return nLength;
  4804. }
  4805. #ifdef __ATLSTR_H__
  4806. int GetString(int nString, ATL::CString& str) const
  4807. {
  4808. ATLASSERT(::IsWindow(this->m_hWnd));
  4809. int nLength = (int)(short)LOWORD(::SendMessage(this->m_hWnd, TB_GETSTRING, MAKEWPARAM(0, nString), NULL));
  4810. if(nLength != -1)
  4811. {
  4812. LPTSTR lpstr = str.GetBufferSetLength(nLength + 1);
  4813. if(lpstr != NULL)
  4814. nLength = (int)::SendMessage(this->m_hWnd, TB_GETSTRING, MAKEWPARAM(nLength + 1, nString), (LPARAM)lpstr);
  4815. else
  4816. nLength = -1;
  4817. str.ReleaseBuffer();
  4818. }
  4819. return nLength;
  4820. }
  4821. #endif // __ATLSTR_H__
  4822. void GetMetrics(LPTBMETRICS lptbm) const
  4823. {
  4824. ATLASSERT(::IsWindow(this->m_hWnd));
  4825. ::SendMessage(this->m_hWnd, TB_GETMETRICS, 0, (LPARAM)lptbm);
  4826. }
  4827. void SetMetrics(LPTBMETRICS lptbm)
  4828. {
  4829. ATLASSERT(::IsWindow(this->m_hWnd));
  4830. ::SendMessage(this->m_hWnd, TB_SETMETRICS, 0, (LPARAM)lptbm);
  4831. }
  4832. void SetWindowTheme(LPCWSTR lpstrTheme)
  4833. {
  4834. ATLASSERT(::IsWindow(this->m_hWnd));
  4835. ::SendMessage(this->m_hWnd, TB_SETWINDOWTHEME, 0, (LPARAM)lpstrTheme);
  4836. }
  4837. #if (_WIN32_WINNT >= 0x0600)
  4838. CImageList GetPressedImageList(int nIndex = 0) const
  4839. {
  4840. ATLASSERT(::IsWindow(this->m_hWnd));
  4841. return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, TB_GETPRESSEDIMAGELIST, nIndex, 0L));
  4842. }
  4843. CImageList SetPressedImageList(HIMAGELIST hImageList, int nIndex = 0)
  4844. {
  4845. ATLASSERT(::IsWindow(this->m_hWnd));
  4846. return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, TB_SETPRESSEDIMAGELIST, nIndex, (LPARAM)hImageList));
  4847. }
  4848. void GetItemDropDownRect(int nIndex, LPRECT lpRect) const
  4849. {
  4850. #ifndef TB_GETITEMDROPDOWNRECT
  4851. const int TB_GETITEMDROPDOWNRECT = WM_USER + 103;
  4852. #endif
  4853. ATLASSERT(::IsWindow(this->m_hWnd));
  4854. BOOL bRet = (BOOL)::SendMessage(this->m_hWnd, TB_GETITEMDROPDOWNRECT, nIndex, (LPARAM)lpRect);
  4855. (void)bRet; // avoid level 4 warning
  4856. ATLASSERT(bRet != FALSE);
  4857. }
  4858. #endif // (_WIN32_WINNT >= 0x0600)
  4859. // Operations
  4860. BOOL EnableButton(int nID, BOOL bEnable = TRUE)
  4861. {
  4862. ATLASSERT(::IsWindow(this->m_hWnd));
  4863. return (BOOL)::SendMessage(this->m_hWnd, TB_ENABLEBUTTON, nID, MAKELPARAM(bEnable, 0));
  4864. }
  4865. BOOL CheckButton(int nID, BOOL bCheck = TRUE)
  4866. {
  4867. ATLASSERT(::IsWindow(this->m_hWnd));
  4868. return (BOOL)::SendMessage(this->m_hWnd, TB_CHECKBUTTON, nID, MAKELPARAM(bCheck, 0));
  4869. }
  4870. BOOL PressButton(int nID, BOOL bPress = TRUE)
  4871. {
  4872. ATLASSERT(::IsWindow(this->m_hWnd));
  4873. return (BOOL)::SendMessage(this->m_hWnd, TB_PRESSBUTTON, nID, MAKELPARAM(bPress, 0));
  4874. }
  4875. BOOL HideButton(int nID, BOOL bHide = TRUE)
  4876. {
  4877. ATLASSERT(::IsWindow(this->m_hWnd));
  4878. return (BOOL)::SendMessage(this->m_hWnd, TB_HIDEBUTTON, nID, MAKELPARAM(bHide, 0));
  4879. }
  4880. BOOL Indeterminate(int nID, BOOL bIndeterminate = TRUE)
  4881. {
  4882. ATLASSERT(::IsWindow(this->m_hWnd));
  4883. return (BOOL)::SendMessage(this->m_hWnd, TB_INDETERMINATE, nID, MAKELPARAM(bIndeterminate, 0));
  4884. }
  4885. int AddBitmap(int nNumButtons, UINT nBitmapID)
  4886. {
  4887. ATLASSERT(::IsWindow(this->m_hWnd));
  4888. TBADDBITMAP tbab = {};
  4889. tbab.hInst = ModuleHelper::GetResourceInstance();
  4890. ATLASSERT(tbab.hInst != NULL);
  4891. tbab.nID = nBitmapID;
  4892. return (int)::SendMessage(this->m_hWnd, TB_ADDBITMAP, (WPARAM)nNumButtons, (LPARAM)&tbab);
  4893. }
  4894. int AddBitmap(int nNumButtons, HBITMAP hBitmap)
  4895. {
  4896. ATLASSERT(::IsWindow(this->m_hWnd));
  4897. TBADDBITMAP tbab = {};
  4898. tbab.hInst = NULL;
  4899. tbab.nID = (UINT_PTR)hBitmap;
  4900. return (int)::SendMessage(this->m_hWnd, TB_ADDBITMAP, (WPARAM)nNumButtons, (LPARAM)&tbab);
  4901. }
  4902. BOOL AddButtons(int nNumButtons, LPCTBBUTTON lpButtons)
  4903. {
  4904. ATLASSERT(::IsWindow(this->m_hWnd));
  4905. return (BOOL)::SendMessage(this->m_hWnd, TB_ADDBUTTONS, nNumButtons, (LPARAM)lpButtons);
  4906. }
  4907. BOOL InsertButton(int nIndex, LPCTBBUTTON lpButton)
  4908. {
  4909. ATLASSERT(::IsWindow(this->m_hWnd));
  4910. return (BOOL)::SendMessage(this->m_hWnd, TB_INSERTBUTTON, nIndex, (LPARAM)lpButton);
  4911. }
  4912. BOOL InsertButton(int nIndex, int iCommand, BYTE Style, BYTE State, int iBitmap,
  4913. INT_PTR iString, DWORD_PTR lParam)
  4914. {
  4915. ATLASSERT(::IsWindow(this->m_hWnd));
  4916. TBBUTTON tbb = {};
  4917. tbb.fsStyle = Style;
  4918. tbb.fsState = State;
  4919. tbb.idCommand = iCommand;
  4920. tbb.iBitmap = iBitmap;
  4921. tbb.iString = iString;
  4922. tbb.dwData = lParam;
  4923. return (BOOL)::SendMessage(this->m_hWnd, TB_INSERTBUTTON, nIndex, (LPARAM)&tbb);
  4924. }
  4925. BOOL InsertButton(int nIndex, int iCommand, BYTE Style, BYTE State, int iBitmap,
  4926. LPCTSTR lpszItem, DWORD_PTR lParam)
  4927. {
  4928. return InsertButton(nIndex, iCommand, Style, State, iBitmap, (INT_PTR)lpszItem, lParam);
  4929. }
  4930. BOOL AddButton(LPTBBUTTON lpButton)
  4931. {
  4932. return InsertButton(-1, lpButton);
  4933. }
  4934. BOOL AddButton(int iCommand, BYTE Style, BYTE State, int iBitmap, INT_PTR iString, DWORD_PTR lParam)
  4935. {
  4936. return InsertButton(-1, iCommand, Style, State, iBitmap, iString, lParam);
  4937. }
  4938. BOOL AddButton(int iCommand, BYTE Style, BYTE State, int iBitmap, LPCTSTR lpszItem, DWORD_PTR lParam)
  4939. {
  4940. return InsertButton(-1, iCommand, Style, State, iBitmap, lpszItem, lParam);
  4941. }
  4942. BOOL DeleteButton(int nIndex)
  4943. {
  4944. ATLASSERT(::IsWindow(this->m_hWnd));
  4945. return (BOOL)::SendMessage(this->m_hWnd, TB_DELETEBUTTON, nIndex, 0L);
  4946. }
  4947. BOOL InsertSeparator(int nIndex, int cxWidth = 8)
  4948. {
  4949. return InsertButton(nIndex, 0, BTNS_SEP, 0, cxWidth, (INT_PTR)0, 0);
  4950. }
  4951. BOOL AddSeparator(int cxWidth = 8)
  4952. {
  4953. return AddButton(0, BTNS_SEP, 0, cxWidth, (INT_PTR)0, 0);
  4954. }
  4955. int CommandToIndex(UINT nID) const
  4956. {
  4957. ATLASSERT(::IsWindow(this->m_hWnd));
  4958. return (int)::SendMessage(this->m_hWnd, TB_COMMANDTOINDEX, nID, 0L);
  4959. }
  4960. void SaveState(HKEY hKeyRoot, LPCTSTR lpszSubKey, LPCTSTR lpszValueName)
  4961. {
  4962. ATLASSERT(::IsWindow(this->m_hWnd));
  4963. TBSAVEPARAMS tbs = {};
  4964. tbs.hkr = hKeyRoot;
  4965. tbs.pszSubKey = lpszSubKey;
  4966. tbs.pszValueName = lpszValueName;
  4967. ::SendMessage(this->m_hWnd, TB_SAVERESTORE, (WPARAM)TRUE, (LPARAM)&tbs);
  4968. }
  4969. void RestoreState(HKEY hKeyRoot, LPCTSTR lpszSubKey, LPCTSTR lpszValueName)
  4970. {
  4971. ATLASSERT(::IsWindow(this->m_hWnd));
  4972. TBSAVEPARAMS tbs = {};
  4973. tbs.hkr = hKeyRoot;
  4974. tbs.pszSubKey = lpszSubKey;
  4975. tbs.pszValueName = lpszValueName;
  4976. ::SendMessage(this->m_hWnd, TB_SAVERESTORE, (WPARAM)FALSE, (LPARAM)&tbs);
  4977. }
  4978. void Customize()
  4979. {
  4980. ATLASSERT(::IsWindow(this->m_hWnd));
  4981. ::SendMessage(this->m_hWnd, TB_CUSTOMIZE, 0, 0L);
  4982. }
  4983. int AddString(UINT nStringID)
  4984. {
  4985. ATLASSERT(::IsWindow(this->m_hWnd));
  4986. return (int)::SendMessage(this->m_hWnd, TB_ADDSTRING, (WPARAM)ModuleHelper::GetResourceInstance(), (LPARAM)nStringID);
  4987. }
  4988. int AddStrings(LPCTSTR lpszStrings)
  4989. {
  4990. ATLASSERT(::IsWindow(this->m_hWnd));
  4991. return (int)::SendMessage(this->m_hWnd, TB_ADDSTRING, 0, (LPARAM)lpszStrings);
  4992. }
  4993. void AutoSize()
  4994. {
  4995. ATLASSERT(::IsWindow(this->m_hWnd));
  4996. ::SendMessage(this->m_hWnd, TB_AUTOSIZE, 0, 0L);
  4997. }
  4998. BOOL ChangeBitmap(int nID, int nBitmap)
  4999. {
  5000. ATLASSERT(::IsWindow(this->m_hWnd));
  5001. return (BOOL)::SendMessage(this->m_hWnd, TB_CHANGEBITMAP, nID, MAKELPARAM(nBitmap, 0));
  5002. }
  5003. int LoadImages(int nBitmapID)
  5004. {
  5005. ATLASSERT(::IsWindow(this->m_hWnd));
  5006. return (int)::SendMessage(this->m_hWnd, TB_LOADIMAGES, nBitmapID, (LPARAM)ModuleHelper::GetResourceInstance());
  5007. }
  5008. int LoadStdImages(int nBitmapID)
  5009. {
  5010. ATLASSERT(::IsWindow(this->m_hWnd));
  5011. return (int)::SendMessage(this->m_hWnd, TB_LOADIMAGES, nBitmapID, (LPARAM)HINST_COMMCTRL);
  5012. }
  5013. BOOL ReplaceBitmap(LPTBREPLACEBITMAP ptbrb)
  5014. {
  5015. ATLASSERT(::IsWindow(this->m_hWnd));
  5016. return (BOOL)::SendMessage(this->m_hWnd, TB_REPLACEBITMAP, 0, (LPARAM)ptbrb);
  5017. }
  5018. int HitTest(LPPOINT lpPoint) const
  5019. {
  5020. ATLASSERT(::IsWindow(this->m_hWnd));
  5021. return (int)::SendMessage(this->m_hWnd, TB_HITTEST, 0, (LPARAM)lpPoint);
  5022. }
  5023. BOOL InsertMarkHitTest(LPPOINT lpPoint, LPTBINSERTMARK lptbim) const
  5024. {
  5025. ATLASSERT(::IsWindow(this->m_hWnd));
  5026. return (BOOL)::SendMessage(this->m_hWnd, TB_INSERTMARKHITTEST, (WPARAM)lpPoint, (LPARAM)lptbim);
  5027. }
  5028. BOOL InsertMarkHitTest(int x, int y, LPTBINSERTMARK lptbim) const
  5029. {
  5030. ATLASSERT(::IsWindow(this->m_hWnd));
  5031. POINT pt = { x, y };
  5032. return (BOOL)::SendMessage(this->m_hWnd, TB_INSERTMARKHITTEST, (WPARAM)&pt, (LPARAM)lptbim);
  5033. }
  5034. BOOL MapAccelerator(TCHAR chAccel, int& nID) const
  5035. {
  5036. ATLASSERT(::IsWindow(this->m_hWnd));
  5037. return (BOOL)::SendMessage(this->m_hWnd, TB_MAPACCELERATOR, (WPARAM)chAccel, (LPARAM)&nID);
  5038. }
  5039. BOOL MarkButton(int nID, BOOL bHighlight = TRUE)
  5040. {
  5041. ATLASSERT(::IsWindow(this->m_hWnd));
  5042. return (BOOL)::SendMessage(this->m_hWnd, TB_MARKBUTTON, nID, MAKELPARAM(bHighlight, 0));
  5043. }
  5044. BOOL MoveButton(int nOldPos, int nNewPos)
  5045. {
  5046. ATLASSERT(::IsWindow(this->m_hWnd));
  5047. return (BOOL)::SendMessage(this->m_hWnd, TB_MOVEBUTTON, nOldPos, nNewPos);
  5048. }
  5049. HRESULT GetObject(REFIID iid, LPVOID* ppvObject)
  5050. {
  5051. ATLASSERT(::IsWindow(this->m_hWnd));
  5052. return (HRESULT)::SendMessage(this->m_hWnd, TB_GETOBJECT, (WPARAM)&iid, (LPARAM)ppvObject);
  5053. }
  5054. };
  5055. typedef CToolBarCtrlT<ATL::CWindow> CToolBarCtrl;
  5056. ///////////////////////////////////////////////////////////////////////////////
  5057. // CStatusBarCtrl
  5058. template <class TBase>
  5059. class CStatusBarCtrlT : public TBase
  5060. {
  5061. public:
  5062. // Constructors
  5063. CStatusBarCtrlT(HWND hWnd = NULL) : TBase(hWnd)
  5064. { }
  5065. CStatusBarCtrlT< TBase >& operator =(HWND hWnd)
  5066. {
  5067. this->m_hWnd = hWnd;
  5068. return *this;
  5069. }
  5070. HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  5071. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  5072. ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  5073. {
  5074. return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  5075. }
  5076. // Methods
  5077. static LPCTSTR GetWndClassName()
  5078. {
  5079. return STATUSCLASSNAME;
  5080. }
  5081. int GetParts(int nParts, int* pParts) const
  5082. {
  5083. ATLASSERT(::IsWindow(this->m_hWnd));
  5084. return (int)::SendMessage(this->m_hWnd, SB_GETPARTS, nParts, (LPARAM)pParts);
  5085. }
  5086. BOOL SetParts(int nParts, int* pWidths)
  5087. {
  5088. ATLASSERT(::IsWindow(this->m_hWnd));
  5089. return (BOOL)::SendMessage(this->m_hWnd, SB_SETPARTS, nParts, (LPARAM)pWidths);
  5090. }
  5091. int GetTextLength(int nPane, int* pType = NULL) const
  5092. {
  5093. ATLASSERT(::IsWindow(this->m_hWnd));
  5094. ATLASSERT(nPane < 256);
  5095. DWORD dwRet = (DWORD)::SendMessage(this->m_hWnd, SB_GETTEXTLENGTH, (WPARAM)nPane, 0L);
  5096. if (pType != NULL)
  5097. *pType = (int)(short)HIWORD(dwRet);
  5098. return (int)(short)LOWORD(dwRet);
  5099. }
  5100. int GetText(int nPane, LPTSTR lpszText, int* pType = NULL) const
  5101. {
  5102. ATLASSERT(::IsWindow(this->m_hWnd));
  5103. ATLASSERT(nPane < 256);
  5104. DWORD dwRet = (DWORD)::SendMessage(this->m_hWnd, SB_GETTEXT, (WPARAM)nPane, (LPARAM)lpszText);
  5105. if(pType != NULL)
  5106. *pType = (int)(short)HIWORD(dwRet);
  5107. return (int)(short)LOWORD(dwRet);
  5108. }
  5109. BOOL GetTextBSTR(int nPane, BSTR& bstrText, int* pType = NULL) const
  5110. {
  5111. USES_CONVERSION;
  5112. ATLASSERT(::IsWindow(this->m_hWnd));
  5113. ATLASSERT(nPane < 256);
  5114. ATLASSERT(bstrText == NULL);
  5115. int nLength = (int)(short)LOWORD(::SendMessage(this->m_hWnd, SB_GETTEXTLENGTH, (WPARAM)nPane, 0L));
  5116. if(nLength == 0)
  5117. return FALSE;
  5118. ATL::CTempBuffer<TCHAR, _WTL_STACK_ALLOC_THRESHOLD> buff;
  5119. LPTSTR lpstrText = buff.Allocate(nLength + 1);
  5120. if(lpstrText == NULL)
  5121. return FALSE;
  5122. if(!GetText(nPane, lpstrText, pType))
  5123. return FALSE;
  5124. bstrText = ::SysAllocString(T2OLE(lpstrText));
  5125. return (bstrText != NULL) ? TRUE : FALSE;
  5126. }
  5127. #ifdef __ATLSTR_H__
  5128. int GetText(int nPane, ATL::CString& strText, int* pType = NULL) const
  5129. {
  5130. ATLASSERT(::IsWindow(this->m_hWnd));
  5131. ATLASSERT(nPane < 256);
  5132. int nLength = (int)(short)LOWORD(::SendMessage(this->m_hWnd, SB_GETTEXTLENGTH, (WPARAM)nPane, 0L));
  5133. if(nLength == 0)
  5134. return 0;
  5135. LPTSTR lpstr = strText.GetBufferSetLength(nLength);
  5136. if(lpstr == NULL)
  5137. return 0;
  5138. return GetText(nPane, lpstr, pType);
  5139. }
  5140. #endif // __ATLSTR_H__
  5141. BOOL SetText(int nPane, LPCTSTR lpszText, int nType = 0)
  5142. {
  5143. ATLASSERT(::IsWindow(this->m_hWnd));
  5144. ATLASSERT(nPane < 256);
  5145. return (BOOL)::SendMessage(this->m_hWnd, SB_SETTEXT, (nPane | nType), (LPARAM)lpszText);
  5146. }
  5147. BOOL GetRect(int nPane, LPRECT lpRect) const
  5148. {
  5149. ATLASSERT(::IsWindow(this->m_hWnd));
  5150. ATLASSERT(nPane < 256);
  5151. return (BOOL)::SendMessage(this->m_hWnd, SB_GETRECT, nPane, (LPARAM)lpRect);
  5152. }
  5153. BOOL GetBorders(int* pBorders) const
  5154. {
  5155. ATLASSERT(::IsWindow(this->m_hWnd));
  5156. return (BOOL)::SendMessage(this->m_hWnd, SB_GETBORDERS, 0, (LPARAM)pBorders);
  5157. }
  5158. BOOL GetBorders(int& nHorz, int& nVert, int& nSpacing) const
  5159. {
  5160. ATLASSERT(::IsWindow(this->m_hWnd));
  5161. int borders[3] = {};
  5162. BOOL bResult = (BOOL)::SendMessage(this->m_hWnd, SB_GETBORDERS, 0, (LPARAM)&borders);
  5163. if(bResult)
  5164. {
  5165. nHorz = borders[0];
  5166. nVert = borders[1];
  5167. nSpacing = borders[2];
  5168. }
  5169. return bResult;
  5170. }
  5171. void SetMinHeight(int nMin)
  5172. {
  5173. ATLASSERT(::IsWindow(this->m_hWnd));
  5174. ::SendMessage(this->m_hWnd, SB_SETMINHEIGHT, nMin, 0L);
  5175. }
  5176. BOOL SetSimple(BOOL bSimple = TRUE)
  5177. {
  5178. ATLASSERT(::IsWindow(this->m_hWnd));
  5179. return (BOOL)::SendMessage(this->m_hWnd, SB_SIMPLE, bSimple, 0L);
  5180. }
  5181. BOOL IsSimple() const
  5182. {
  5183. ATLASSERT(::IsWindow(this->m_hWnd));
  5184. return (BOOL)::SendMessage(this->m_hWnd, SB_ISSIMPLE, 0, 0L);
  5185. }
  5186. BOOL GetUnicodeFormat() const
  5187. {
  5188. ATLASSERT(::IsWindow(this->m_hWnd));
  5189. return (BOOL)::SendMessage(this->m_hWnd, SB_GETUNICODEFORMAT, 0, 0L);
  5190. }
  5191. BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
  5192. {
  5193. ATLASSERT(::IsWindow(this->m_hWnd));
  5194. return (BOOL)::SendMessage(this->m_hWnd, SB_SETUNICODEFORMAT, bUnicode, 0L);
  5195. }
  5196. void GetTipText(int nPane, LPTSTR lpstrText, int nSize) const
  5197. {
  5198. ATLASSERT(::IsWindow(this->m_hWnd));
  5199. ATLASSERT(nPane < 256);
  5200. ::SendMessage(this->m_hWnd, SB_GETTIPTEXT, MAKEWPARAM(nPane, nSize), (LPARAM)lpstrText);
  5201. }
  5202. void SetTipText(int nPane, LPCTSTR lpstrText)
  5203. {
  5204. ATLASSERT(::IsWindow(this->m_hWnd));
  5205. ATLASSERT(nPane < 256);
  5206. ::SendMessage(this->m_hWnd, SB_SETTIPTEXT, nPane, (LPARAM)lpstrText);
  5207. }
  5208. COLORREF SetBkColor(COLORREF clrBk)
  5209. {
  5210. ATLASSERT(::IsWindow(this->m_hWnd));
  5211. return (COLORREF)::SendMessage(this->m_hWnd, SB_SETBKCOLOR, 0, (LPARAM)clrBk);
  5212. }
  5213. HICON GetIcon(int nPane) const
  5214. {
  5215. ATLASSERT(::IsWindow(this->m_hWnd));
  5216. ATLASSERT(nPane < 256);
  5217. return (HICON)::SendMessage(this->m_hWnd, SB_GETICON, nPane, 0L);
  5218. }
  5219. BOOL SetIcon(int nPane, HICON hIcon)
  5220. {
  5221. ATLASSERT(::IsWindow(this->m_hWnd));
  5222. ATLASSERT(nPane < 256);
  5223. return (BOOL)::SendMessage(this->m_hWnd, SB_SETICON, nPane, (LPARAM)hIcon);
  5224. }
  5225. };
  5226. typedef CStatusBarCtrlT<ATL::CWindow> CStatusBarCtrl;
  5227. ///////////////////////////////////////////////////////////////////////////////
  5228. // CTabCtrl
  5229. template <class TBase>
  5230. class CTabCtrlT : public TBase
  5231. {
  5232. public:
  5233. // Constructors
  5234. CTabCtrlT(HWND hWnd = NULL) : TBase(hWnd)
  5235. { }
  5236. CTabCtrlT< TBase >& operator =(HWND hWnd)
  5237. {
  5238. this->m_hWnd = hWnd;
  5239. return *this;
  5240. }
  5241. HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  5242. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  5243. ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  5244. {
  5245. return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  5246. }
  5247. // Attributes
  5248. static LPCTSTR GetWndClassName()
  5249. {
  5250. return WC_TABCONTROL;
  5251. }
  5252. CImageList GetImageList() const
  5253. {
  5254. ATLASSERT(::IsWindow(this->m_hWnd));
  5255. return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, TCM_GETIMAGELIST, 0, 0L));
  5256. }
  5257. CImageList SetImageList(HIMAGELIST hImageList)
  5258. {
  5259. ATLASSERT(::IsWindow(this->m_hWnd));
  5260. return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, TCM_SETIMAGELIST, 0, (LPARAM)hImageList));
  5261. }
  5262. int GetItemCount() const
  5263. {
  5264. ATLASSERT(::IsWindow(this->m_hWnd));
  5265. return (int)::SendMessage(this->m_hWnd, TCM_GETITEMCOUNT, 0, 0L);
  5266. }
  5267. BOOL GetItem(int nItem, LPTCITEM pTabCtrlItem) const
  5268. {
  5269. ATLASSERT(::IsWindow(this->m_hWnd));
  5270. return (BOOL)::SendMessage(this->m_hWnd, TCM_GETITEM, nItem, (LPARAM)pTabCtrlItem);
  5271. }
  5272. BOOL SetItem(int nItem, LPTCITEM pTabCtrlItem)
  5273. {
  5274. ATLASSERT(::IsWindow(this->m_hWnd));
  5275. return (BOOL)::SendMessage(this->m_hWnd, TCM_SETITEM, nItem, (LPARAM)pTabCtrlItem);
  5276. }
  5277. int SetItem(int nItem, UINT mask, LPCTSTR lpszItem, DWORD dwState, DWORD dwStateMask, int iImage, LPARAM lParam)
  5278. {
  5279. ATLASSERT(::IsWindow(this->m_hWnd));
  5280. TCITEM tci = {};
  5281. tci.mask = mask;
  5282. tci.pszText = (LPTSTR) lpszItem;
  5283. tci.dwState = dwState;
  5284. tci.dwStateMask = dwStateMask;
  5285. tci.iImage = iImage;
  5286. tci.lParam = lParam;
  5287. return (int)::SendMessage(this->m_hWnd, TCM_SETITEM, nItem, (LPARAM)&tci);
  5288. }
  5289. BOOL GetItemRect(int nItem, LPRECT lpRect) const
  5290. {
  5291. ATLASSERT(::IsWindow(this->m_hWnd));
  5292. return (BOOL)::SendMessage(this->m_hWnd, TCM_GETITEMRECT, nItem, (LPARAM)lpRect);
  5293. }
  5294. int GetCurSel() const
  5295. {
  5296. ATLASSERT(::IsWindow(this->m_hWnd));
  5297. return (int)::SendMessage(this->m_hWnd, TCM_GETCURSEL, 0, 0L);
  5298. }
  5299. int SetCurSel(int nItem)
  5300. {
  5301. ATLASSERT(::IsWindow(this->m_hWnd));
  5302. return (int)::SendMessage(this->m_hWnd, TCM_SETCURSEL, nItem, 0L);
  5303. }
  5304. SIZE SetItemSize(SIZE size)
  5305. {
  5306. ATLASSERT(::IsWindow(this->m_hWnd));
  5307. DWORD dwSize = (DWORD)::SendMessage(this->m_hWnd, TCM_SETITEMSIZE, 0, MAKELPARAM(size.cx, size.cy));
  5308. SIZE sizeRet = { GET_X_LPARAM(dwSize), GET_Y_LPARAM(dwSize) };
  5309. return sizeRet;
  5310. }
  5311. void SetItemSize(int cx, int cy)
  5312. {
  5313. ATLASSERT(::IsWindow(this->m_hWnd));
  5314. ::SendMessage(this->m_hWnd, TCM_SETITEMSIZE, 0, MAKELPARAM(cx, cy));
  5315. }
  5316. void SetPadding(SIZE size)
  5317. {
  5318. ATLASSERT(::IsWindow(this->m_hWnd));
  5319. ::SendMessage(this->m_hWnd, TCM_SETPADDING, 0, MAKELPARAM(size.cx, size.cy));
  5320. }
  5321. int GetRowCount() const
  5322. {
  5323. ATLASSERT(::IsWindow(this->m_hWnd));
  5324. return (int)::SendMessage(this->m_hWnd, TCM_GETROWCOUNT, 0, 0L);
  5325. }
  5326. CToolTipCtrl GetToolTips() const
  5327. {
  5328. ATLASSERT(::IsWindow(this->m_hWnd));
  5329. return CToolTipCtrl((HWND)::SendMessage(this->m_hWnd, TCM_GETTOOLTIPS, 0, 0L));
  5330. }
  5331. // this method is deprecated, please use GetToolTips
  5332. CToolTipCtrl GetTooltips() const { return GetToolTips(); }
  5333. void SetToolTips(HWND hWndToolTip)
  5334. {
  5335. ATLASSERT(::IsWindow(this->m_hWnd));
  5336. ::SendMessage(this->m_hWnd, TCM_SETTOOLTIPS, (WPARAM)hWndToolTip, 0L);
  5337. }
  5338. // this method is deprecated, please use SetToolTips
  5339. void SetTooltips(HWND hWndToolTip) { SetToolTips(hWndToolTip); }
  5340. int GetCurFocus() const
  5341. {
  5342. ATLASSERT(::IsWindow(this->m_hWnd));
  5343. return (int)::SendMessage(this->m_hWnd, TCM_GETCURFOCUS, 0, 0L);
  5344. }
  5345. void SetCurFocus(int nItem)
  5346. {
  5347. ATLASSERT(::IsWindow(this->m_hWnd));
  5348. ::SendMessage(this->m_hWnd, TCM_SETCURFOCUS, nItem, 0L);
  5349. }
  5350. BOOL SetItemExtra(int cbExtra)
  5351. {
  5352. ATLASSERT(::IsWindow(this->m_hWnd));
  5353. ATLASSERT(GetItemCount() == 0); // must be empty
  5354. return (BOOL)::SendMessage(this->m_hWnd, TCM_SETITEMEXTRA, cbExtra, 0L);
  5355. }
  5356. int SetMinTabWidth(int nWidth = -1)
  5357. {
  5358. ATLASSERT(::IsWindow(this->m_hWnd));
  5359. return (int)::SendMessage(this->m_hWnd, TCM_SETMINTABWIDTH, 0, nWidth);
  5360. }
  5361. DWORD GetExtendedStyle() const
  5362. {
  5363. ATLASSERT(::IsWindow(this->m_hWnd));
  5364. return (DWORD)::SendMessage(this->m_hWnd, TCM_GETEXTENDEDSTYLE, 0, 0L);
  5365. }
  5366. DWORD SetExtendedStyle(DWORD dwExMask, DWORD dwExStyle)
  5367. {
  5368. ATLASSERT(::IsWindow(this->m_hWnd));
  5369. return (DWORD)::SendMessage(this->m_hWnd, TCM_SETEXTENDEDSTYLE, dwExMask, dwExStyle);
  5370. }
  5371. BOOL GetUnicodeFormat() const
  5372. {
  5373. ATLASSERT(::IsWindow(this->m_hWnd));
  5374. return (BOOL)::SendMessage(this->m_hWnd, TCM_GETUNICODEFORMAT, 0, 0L);
  5375. }
  5376. BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
  5377. {
  5378. ATLASSERT(::IsWindow(this->m_hWnd));
  5379. return (BOOL)::SendMessage(this->m_hWnd, TCM_SETUNICODEFORMAT, bUnicode, 0L);
  5380. }
  5381. // Operations
  5382. int InsertItem(int nItem, LPTCITEM pTabCtrlItem)
  5383. {
  5384. ATLASSERT(::IsWindow(this->m_hWnd));
  5385. return (int)::SendMessage(this->m_hWnd, TCM_INSERTITEM, nItem, (LPARAM)pTabCtrlItem);
  5386. }
  5387. int InsertItem(int nItem, UINT mask, LPCTSTR lpszItem, int iImage, LPARAM lParam)
  5388. {
  5389. ATLASSERT(::IsWindow(this->m_hWnd));
  5390. TCITEM tci = {};
  5391. tci.mask = mask;
  5392. tci.pszText = (LPTSTR) lpszItem;
  5393. tci.iImage = iImage;
  5394. tci.lParam = lParam;
  5395. return (int)::SendMessage(this->m_hWnd, TCM_INSERTITEM, nItem, (LPARAM)&tci);
  5396. }
  5397. int InsertItem(int nItem, LPCTSTR lpszItem)
  5398. {
  5399. ATLASSERT(::IsWindow(this->m_hWnd));
  5400. TCITEM tci = {};
  5401. tci.mask = TCIF_TEXT;
  5402. tci.pszText = (LPTSTR) lpszItem;
  5403. return (int)::SendMessage(this->m_hWnd, TCM_INSERTITEM, nItem, (LPARAM)&tci);
  5404. }
  5405. int AddItem(LPTCITEM pTabCtrlItem)
  5406. {
  5407. return InsertItem(GetItemCount(), pTabCtrlItem);
  5408. }
  5409. int AddItem(UINT mask, LPCTSTR lpszItem, int iImage, LPARAM lParam)
  5410. {
  5411. return InsertItem(GetItemCount(), mask, lpszItem, iImage, lParam);
  5412. }
  5413. int AddItem(LPCTSTR lpszItem)
  5414. {
  5415. return InsertItem(GetItemCount(), lpszItem);
  5416. }
  5417. BOOL DeleteItem(int nItem)
  5418. {
  5419. ATLASSERT(::IsWindow(this->m_hWnd));
  5420. return (BOOL)::SendMessage(this->m_hWnd, TCM_DELETEITEM, nItem, 0L);
  5421. }
  5422. BOOL DeleteAllItems()
  5423. {
  5424. ATLASSERT(::IsWindow(this->m_hWnd));
  5425. return (BOOL)::SendMessage(this->m_hWnd, TCM_DELETEALLITEMS, 0, 0L);
  5426. }
  5427. void AdjustRect(BOOL bLarger, LPRECT lpRect)
  5428. {
  5429. ATLASSERT(::IsWindow(this->m_hWnd));
  5430. ::SendMessage(this->m_hWnd, TCM_ADJUSTRECT, bLarger, (LPARAM)lpRect);
  5431. }
  5432. void RemoveImage(int nImage)
  5433. {
  5434. ATLASSERT(::IsWindow(this->m_hWnd));
  5435. ::SendMessage(this->m_hWnd, TCM_REMOVEIMAGE, nImage, 0L);
  5436. }
  5437. int HitTest(TC_HITTESTINFO* pHitTestInfo) const
  5438. {
  5439. ATLASSERT(::IsWindow(this->m_hWnd));
  5440. return (int)::SendMessage(this->m_hWnd, TCM_HITTEST, 0, (LPARAM)pHitTestInfo);
  5441. }
  5442. void DeselectAll(BOOL bExcludeFocus = TRUE)
  5443. {
  5444. ATLASSERT(::IsWindow(this->m_hWnd));
  5445. ::SendMessage(this->m_hWnd, TCM_DESELECTALL, bExcludeFocus, 0L);
  5446. }
  5447. BOOL HighlightItem(int nIndex, BOOL bHighlight = TRUE)
  5448. {
  5449. ATLASSERT(::IsWindow(this->m_hWnd));
  5450. return (BOOL)::SendMessage(this->m_hWnd, TCM_HIGHLIGHTITEM, nIndex, MAKELPARAM(bHighlight, 0));
  5451. }
  5452. };
  5453. typedef CTabCtrlT<ATL::CWindow> CTabCtrl;
  5454. ///////////////////////////////////////////////////////////////////////////////
  5455. // CTrackBarCtrl
  5456. template <class TBase>
  5457. class CTrackBarCtrlT : public TBase
  5458. {
  5459. public:
  5460. // Constructors
  5461. CTrackBarCtrlT(HWND hWnd = NULL) : TBase(hWnd)
  5462. { }
  5463. CTrackBarCtrlT< TBase >& operator =(HWND hWnd)
  5464. {
  5465. this->m_hWnd = hWnd;
  5466. return *this;
  5467. }
  5468. HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  5469. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  5470. ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  5471. {
  5472. return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  5473. }
  5474. // Attributes
  5475. static LPCTSTR GetWndClassName()
  5476. {
  5477. return TRACKBAR_CLASS;
  5478. }
  5479. int GetLineSize() const
  5480. {
  5481. ATLASSERT(::IsWindow(this->m_hWnd));
  5482. return (int)::SendMessage(this->m_hWnd, TBM_GETLINESIZE, 0, 0L);
  5483. }
  5484. int SetLineSize(int nSize)
  5485. {
  5486. ATLASSERT(::IsWindow(this->m_hWnd));
  5487. return (int)::SendMessage(this->m_hWnd, TBM_SETLINESIZE, 0, nSize);
  5488. }
  5489. int GetPageSize() const
  5490. {
  5491. ATLASSERT(::IsWindow(this->m_hWnd));
  5492. return (int)::SendMessage(this->m_hWnd, TBM_GETPAGESIZE, 0, 0L);
  5493. }
  5494. int SetPageSize(int nSize)
  5495. {
  5496. ATLASSERT(::IsWindow(this->m_hWnd));
  5497. return (int)::SendMessage(this->m_hWnd, TBM_SETPAGESIZE, 0, nSize);
  5498. }
  5499. int GetRangeMin() const
  5500. {
  5501. ATLASSERT(::IsWindow(this->m_hWnd));
  5502. return (int)::SendMessage(this->m_hWnd, TBM_GETRANGEMIN, 0, 0L);
  5503. }
  5504. void SetRangeMin(int nMin, BOOL bRedraw = FALSE)
  5505. {
  5506. ATLASSERT(::IsWindow(this->m_hWnd));
  5507. ::SendMessage(this->m_hWnd, TBM_SETRANGEMIN, bRedraw, nMin);
  5508. }
  5509. int GetRangeMax() const
  5510. {
  5511. ATLASSERT(::IsWindow(this->m_hWnd));
  5512. return (int)::SendMessage(this->m_hWnd, TBM_GETRANGEMAX, 0, 0L);
  5513. }
  5514. void SetRangeMax(int nMax, BOOL bRedraw = FALSE)
  5515. {
  5516. ATLASSERT(::IsWindow(this->m_hWnd));
  5517. ::SendMessage(this->m_hWnd, TBM_SETRANGEMAX, bRedraw, nMax);
  5518. }
  5519. void GetRange(int& nMin, int& nMax) const
  5520. {
  5521. nMin = GetRangeMin();
  5522. nMax = GetRangeMax();
  5523. }
  5524. void SetRange(int nMin, int nMax, BOOL bRedraw = TRUE)
  5525. {
  5526. ATLASSERT(::IsWindow(this->m_hWnd));
  5527. ::SendMessage(this->m_hWnd, TBM_SETRANGE, bRedraw, MAKELPARAM(nMin, nMax));
  5528. }
  5529. int GetSelStart() const
  5530. {
  5531. ATLASSERT(::IsWindow(this->m_hWnd));
  5532. return (int)::SendMessage(this->m_hWnd, TBM_GETSELSTART, 0, 0L);
  5533. }
  5534. void SetSelStart(int nMin, BOOL bRedraw = FALSE)
  5535. {
  5536. ATLASSERT(::IsWindow(this->m_hWnd));
  5537. ::SendMessage(this->m_hWnd, TBM_SETSELSTART, bRedraw, (LPARAM)nMin);
  5538. }
  5539. int GetSelEnd() const
  5540. {
  5541. ATLASSERT(::IsWindow(this->m_hWnd));
  5542. return (int)::SendMessage(this->m_hWnd, TBM_GETSELEND, 0, 0L);
  5543. }
  5544. void SetSelEnd(int nMax, BOOL bRedraw = FALSE)
  5545. {
  5546. ATLASSERT(::IsWindow(this->m_hWnd));
  5547. ::SendMessage(this->m_hWnd, TBM_SETSELEND, bRedraw, (LPARAM)nMax);
  5548. }
  5549. void GetSelection(int& nMin, int& nMax) const
  5550. {
  5551. nMin = GetSelStart();
  5552. nMax = GetSelEnd();
  5553. }
  5554. void SetSelection(int nMin, int nMax, BOOL bRedraw = TRUE)
  5555. {
  5556. SetSelStart(nMin, FALSE);
  5557. SetSelEnd(nMax, bRedraw);
  5558. }
  5559. void GetChannelRect(LPRECT lprc) const
  5560. {
  5561. ATLASSERT(::IsWindow(this->m_hWnd));
  5562. ::SendMessage(this->m_hWnd, TBM_GETCHANNELRECT, 0, (LPARAM)lprc);
  5563. }
  5564. void GetThumbRect(LPRECT lprc) const
  5565. {
  5566. ATLASSERT(::IsWindow(this->m_hWnd));
  5567. ::SendMessage(this->m_hWnd, TBM_GETTHUMBRECT, 0, (LPARAM)lprc);
  5568. }
  5569. int GetPos() const
  5570. {
  5571. ATLASSERT(::IsWindow(this->m_hWnd));
  5572. return (int)::SendMessage(this->m_hWnd, TBM_GETPOS, 0, 0L);
  5573. }
  5574. void SetPos(int nPos)
  5575. {
  5576. ATLASSERT(::IsWindow(this->m_hWnd));
  5577. ::SendMessage(this->m_hWnd, TBM_SETPOS, TRUE, nPos);
  5578. }
  5579. UINT GetNumTics() const
  5580. {
  5581. ATLASSERT(::IsWindow(this->m_hWnd));
  5582. return (UINT)::SendMessage(this->m_hWnd, TBM_GETNUMTICS, 0, 0L);
  5583. }
  5584. DWORD* GetTicArray() const
  5585. {
  5586. ATLASSERT(::IsWindow(this->m_hWnd));
  5587. return (DWORD*)::SendMessage(this->m_hWnd, TBM_GETPTICS, 0, 0L);
  5588. }
  5589. int GetTic(int nTic) const
  5590. {
  5591. ATLASSERT(::IsWindow(this->m_hWnd));
  5592. return (int)::SendMessage(this->m_hWnd, TBM_GETTIC, nTic, 0L);
  5593. }
  5594. BOOL SetTic(int nTic)
  5595. {
  5596. ATLASSERT(::IsWindow(this->m_hWnd));
  5597. return (BOOL)::SendMessage(this->m_hWnd, TBM_SETTIC, 0, nTic);
  5598. }
  5599. int GetTicPos(int nTic) const
  5600. {
  5601. ATLASSERT(::IsWindow(this->m_hWnd));
  5602. return (int)::SendMessage(this->m_hWnd, TBM_GETTICPOS, nTic, 0L);
  5603. }
  5604. void SetTicFreq(int nFreq)
  5605. {
  5606. ATLASSERT(::IsWindow(this->m_hWnd));
  5607. ::SendMessage(this->m_hWnd, TBM_SETTICFREQ, nFreq, 0L);
  5608. }
  5609. int GetThumbLength() const
  5610. {
  5611. ATLASSERT(::IsWindow(this->m_hWnd));
  5612. return (int)::SendMessage(this->m_hWnd, TBM_GETTHUMBLENGTH, 0, 0L);
  5613. }
  5614. void SetThumbLength(int nLength)
  5615. {
  5616. ATLASSERT(::IsWindow(this->m_hWnd));
  5617. ::SendMessage(this->m_hWnd, TBM_SETTHUMBLENGTH, nLength, 0L);
  5618. }
  5619. void SetSel(int nStart, int nEnd, BOOL bRedraw = TRUE)
  5620. {
  5621. ATLASSERT(::IsWindow(this->m_hWnd));
  5622. ATLASSERT((this->GetStyle() & TBS_ENABLESELRANGE) != 0);
  5623. ::SendMessage(this->m_hWnd, TBM_SETSEL, bRedraw, MAKELPARAM(nStart, nEnd));
  5624. }
  5625. ATL::CWindow GetBuddy(BOOL bLeft = TRUE) const
  5626. {
  5627. ATLASSERT(::IsWindow(this->m_hWnd));
  5628. return ATL::CWindow((HWND)::SendMessage(this->m_hWnd, TBM_GETBUDDY, bLeft, 0L));
  5629. }
  5630. ATL::CWindow SetBuddy(HWND hWndBuddy, BOOL bLeft = TRUE)
  5631. {
  5632. ATLASSERT(::IsWindow(this->m_hWnd));
  5633. return ATL::CWindow((HWND)::SendMessage(this->m_hWnd, TBM_SETBUDDY, bLeft, (LPARAM)hWndBuddy));
  5634. }
  5635. CToolTipCtrl GetToolTips() const
  5636. {
  5637. ATLASSERT(::IsWindow(this->m_hWnd));
  5638. return CToolTipCtrl((HWND)::SendMessage(this->m_hWnd, TBM_GETTOOLTIPS, 0, 0L));
  5639. }
  5640. void SetToolTips(HWND hWndTT)
  5641. {
  5642. ATLASSERT(::IsWindow(this->m_hWnd));
  5643. ::SendMessage(this->m_hWnd, TBM_SETTOOLTIPS, (WPARAM)hWndTT, 0L);
  5644. }
  5645. int SetTipSide(int nSide)
  5646. {
  5647. ATLASSERT(::IsWindow(this->m_hWnd));
  5648. return (int)::SendMessage(this->m_hWnd, TBM_SETTIPSIDE, nSide, 0L);
  5649. }
  5650. BOOL GetUnicodeFormat() const
  5651. {
  5652. ATLASSERT(::IsWindow(this->m_hWnd));
  5653. return (BOOL)::SendMessage(this->m_hWnd, TBM_GETUNICODEFORMAT, 0, 0L);
  5654. }
  5655. BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
  5656. {
  5657. ATLASSERT(::IsWindow(this->m_hWnd));
  5658. return (BOOL)::SendMessage(this->m_hWnd, TBM_SETUNICODEFORMAT, bUnicode, 0L);
  5659. }
  5660. // Operations
  5661. void ClearSel(BOOL bRedraw = FALSE)
  5662. {
  5663. ATLASSERT(::IsWindow(this->m_hWnd));
  5664. ::SendMessage(this->m_hWnd, TBM_CLEARSEL, bRedraw, 0L);
  5665. }
  5666. void VerifyPos()
  5667. {
  5668. ATLASSERT(::IsWindow(this->m_hWnd));
  5669. ::SendMessage(this->m_hWnd, TBM_SETPOS, FALSE, 0L);
  5670. }
  5671. void ClearTics(BOOL bRedraw = FALSE)
  5672. {
  5673. ATLASSERT(::IsWindow(this->m_hWnd));
  5674. ::SendMessage(this->m_hWnd, TBM_CLEARTICS, bRedraw, 0L);
  5675. }
  5676. };
  5677. typedef CTrackBarCtrlT<ATL::CWindow> CTrackBarCtrl;
  5678. ///////////////////////////////////////////////////////////////////////////////
  5679. // CUpDownCtrl
  5680. template <class TBase>
  5681. class CUpDownCtrlT : public TBase
  5682. {
  5683. public:
  5684. // Constructors
  5685. CUpDownCtrlT(HWND hWnd = NULL) : TBase(hWnd)
  5686. { }
  5687. CUpDownCtrlT< TBase >& operator =(HWND hWnd)
  5688. {
  5689. this->m_hWnd = hWnd;
  5690. return *this;
  5691. }
  5692. HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  5693. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  5694. ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  5695. {
  5696. return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  5697. }
  5698. // Attributes
  5699. static LPCTSTR GetWndClassName()
  5700. {
  5701. return UPDOWN_CLASS;
  5702. }
  5703. UINT GetAccel(int nAccel, UDACCEL* pAccel) const
  5704. {
  5705. ATLASSERT(::IsWindow(this->m_hWnd));
  5706. return (UINT)LOWORD(::SendMessage(this->m_hWnd, UDM_GETACCEL, nAccel, (LPARAM)pAccel));
  5707. }
  5708. BOOL SetAccel(int nAccel, UDACCEL* pAccel)
  5709. {
  5710. ATLASSERT(::IsWindow(this->m_hWnd));
  5711. return (BOOL)LOWORD(::SendMessage(this->m_hWnd, UDM_SETACCEL, nAccel, (LPARAM)pAccel));
  5712. }
  5713. UINT GetBase() const
  5714. {
  5715. ATLASSERT(::IsWindow(this->m_hWnd));
  5716. return (UINT)LOWORD(::SendMessage(this->m_hWnd, UDM_GETBASE, 0, 0L));
  5717. }
  5718. int SetBase(int nBase)
  5719. {
  5720. ATLASSERT(::IsWindow(this->m_hWnd));
  5721. return (int)::SendMessage(this->m_hWnd, UDM_SETBASE, nBase, 0L);
  5722. }
  5723. ATL::CWindow GetBuddy() const
  5724. {
  5725. ATLASSERT(::IsWindow(this->m_hWnd));
  5726. return ATL::CWindow((HWND)::SendMessage(this->m_hWnd, UDM_GETBUDDY, 0, 0L));
  5727. }
  5728. ATL::CWindow SetBuddy(HWND hWndBuddy)
  5729. {
  5730. ATLASSERT(::IsWindow(this->m_hWnd));
  5731. return ATL::CWindow((HWND)::SendMessage(this->m_hWnd, UDM_SETBUDDY, (WPARAM)hWndBuddy, 0L));
  5732. }
  5733. int GetPos(LPBOOL lpbError = NULL) const
  5734. {
  5735. ATLASSERT(::IsWindow(this->m_hWnd));
  5736. DWORD dwRet = (DWORD)::SendMessage(this->m_hWnd, UDM_GETPOS, 0, 0L);
  5737. // Note: Seems that Windows always sets error to TRUE if
  5738. // UDS_SETBUDDYINT style is not used
  5739. if(lpbError != NULL)
  5740. *lpbError = (HIWORD(dwRet) != 0) ? TRUE : FALSE;
  5741. return (int)(short)LOWORD(dwRet);
  5742. }
  5743. int SetPos(int nPos)
  5744. {
  5745. ATLASSERT(::IsWindow(this->m_hWnd));
  5746. return (int)(short)LOWORD(::SendMessage(this->m_hWnd, UDM_SETPOS, 0, MAKELPARAM(nPos, 0)));
  5747. }
  5748. DWORD GetRange() const
  5749. {
  5750. ATLASSERT(::IsWindow(this->m_hWnd));
  5751. return (DWORD)::SendMessage(this->m_hWnd, UDM_GETRANGE, 0, 0L);
  5752. }
  5753. void GetRange(int& nLower, int& nUpper) const
  5754. {
  5755. ATLASSERT(::IsWindow(this->m_hWnd));
  5756. DWORD dwRet = (DWORD)::SendMessage(this->m_hWnd, UDM_GETRANGE, 0, 0L);
  5757. nLower = (int)(short)HIWORD(dwRet);
  5758. nUpper = (int)(short)LOWORD(dwRet);
  5759. }
  5760. void SetRange(int nLower, int nUpper)
  5761. {
  5762. ATLASSERT(::IsWindow(this->m_hWnd));
  5763. ::SendMessage(this->m_hWnd, UDM_SETRANGE, 0, MAKELPARAM(nUpper, nLower));
  5764. }
  5765. void SetRange32(int nLower, int nUpper)
  5766. {
  5767. ATLASSERT(::IsWindow(this->m_hWnd));
  5768. ::SendMessage(this->m_hWnd, UDM_SETRANGE32, nLower, nUpper);
  5769. }
  5770. void GetRange32(int& nLower, int& nUpper) const
  5771. {
  5772. ATLASSERT(::IsWindow(this->m_hWnd));
  5773. ::SendMessage(this->m_hWnd, UDM_GETRANGE32, (WPARAM)&nLower, (LPARAM)&nUpper);
  5774. }
  5775. BOOL GetUnicodeFormat() const
  5776. {
  5777. ATLASSERT(::IsWindow(this->m_hWnd));
  5778. return (BOOL)::SendMessage(this->m_hWnd, UDM_GETUNICODEFORMAT, 0, 0L);
  5779. }
  5780. BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
  5781. {
  5782. ATLASSERT(::IsWindow(this->m_hWnd));
  5783. return (BOOL)::SendMessage(this->m_hWnd, UDM_SETUNICODEFORMAT, bUnicode, 0L);
  5784. }
  5785. int GetPos32(LPBOOL lpbError = NULL) const
  5786. {
  5787. ATLASSERT(::IsWindow(this->m_hWnd));
  5788. // Note: Seems that Windows always sets error to TRUE if
  5789. // UDS_SETBUDDYINT style is not used
  5790. return (int)::SendMessage(this->m_hWnd, UDM_GETPOS32, 0, (LPARAM)lpbError);
  5791. }
  5792. int SetPos32(int nPos)
  5793. {
  5794. ATLASSERT(::IsWindow(this->m_hWnd));
  5795. return (int)::SendMessage(this->m_hWnd, UDM_SETPOS32, 0, (LPARAM)nPos);
  5796. }
  5797. };
  5798. typedef CUpDownCtrlT<ATL::CWindow> CUpDownCtrl;
  5799. ///////////////////////////////////////////////////////////////////////////////
  5800. // CProgressBarCtrl
  5801. template <class TBase>
  5802. class CProgressBarCtrlT : public TBase
  5803. {
  5804. public:
  5805. // Constructors
  5806. CProgressBarCtrlT(HWND hWnd = NULL) : TBase(hWnd)
  5807. { }
  5808. CProgressBarCtrlT< TBase >& operator =(HWND hWnd)
  5809. {
  5810. this->m_hWnd = hWnd;
  5811. return *this;
  5812. }
  5813. HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  5814. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  5815. ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  5816. {
  5817. return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  5818. }
  5819. // Attributes
  5820. static LPCTSTR GetWndClassName()
  5821. {
  5822. return PROGRESS_CLASS;
  5823. }
  5824. DWORD SetRange(int nLower, int nUpper)
  5825. {
  5826. ATLASSERT(::IsWindow(this->m_hWnd));
  5827. return (DWORD)::SendMessage(this->m_hWnd, PBM_SETRANGE, 0, MAKELPARAM(nLower, nUpper));
  5828. }
  5829. int SetPos(int nPos)
  5830. {
  5831. ATLASSERT(::IsWindow(this->m_hWnd));
  5832. return (int)(short)LOWORD(::SendMessage(this->m_hWnd, PBM_SETPOS, nPos, 0L));
  5833. }
  5834. int OffsetPos(int nPos)
  5835. {
  5836. ATLASSERT(::IsWindow(this->m_hWnd));
  5837. return (int)(short)LOWORD(::SendMessage(this->m_hWnd, PBM_DELTAPOS, nPos, 0L));
  5838. }
  5839. int SetStep(int nStep)
  5840. {
  5841. ATLASSERT(::IsWindow(this->m_hWnd));
  5842. return (int)(short)LOWORD(::SendMessage(this->m_hWnd, PBM_SETSTEP, nStep, 0L));
  5843. }
  5844. UINT GetPos() const
  5845. {
  5846. ATLASSERT(::IsWindow(this->m_hWnd));
  5847. return (UINT)::SendMessage(this->m_hWnd, PBM_GETPOS, 0, 0L);
  5848. }
  5849. void GetRange(PPBRANGE pPBRange) const
  5850. {
  5851. ATLASSERT(::IsWindow(this->m_hWnd));
  5852. ATLASSERT(pPBRange != NULL);
  5853. ::SendMessage(this->m_hWnd, PBM_GETRANGE, TRUE, (LPARAM)pPBRange);
  5854. }
  5855. void GetRange(int& nLower, int& nUpper) const
  5856. {
  5857. ATLASSERT(::IsWindow(this->m_hWnd));
  5858. PBRANGE range = {};
  5859. ::SendMessage(this->m_hWnd, PBM_GETRANGE, TRUE, (LPARAM)&range);
  5860. nLower = range.iLow;
  5861. nUpper = range.iHigh;
  5862. }
  5863. int GetRangeLimit(BOOL bLowLimit) const
  5864. {
  5865. ATLASSERT(::IsWindow(this->m_hWnd));
  5866. return (int)::SendMessage(this->m_hWnd, PBM_GETRANGE, bLowLimit, (LPARAM)NULL);
  5867. }
  5868. DWORD SetRange32(int nMin, int nMax)
  5869. {
  5870. ATLASSERT(::IsWindow(this->m_hWnd));
  5871. return (DWORD)::SendMessage(this->m_hWnd, PBM_SETRANGE32, nMin, nMax);
  5872. }
  5873. COLORREF SetBarColor(COLORREF clr)
  5874. {
  5875. ATLASSERT(::IsWindow(this->m_hWnd));
  5876. return (COLORREF)::SendMessage(this->m_hWnd, PBM_SETBARCOLOR, 0, (LPARAM)clr);
  5877. }
  5878. COLORREF SetBkColor(COLORREF clr)
  5879. {
  5880. ATLASSERT(::IsWindow(this->m_hWnd));
  5881. return (COLORREF)::SendMessage(this->m_hWnd, PBM_SETBKCOLOR, 0, (LPARAM)clr);
  5882. }
  5883. #ifdef PBM_SETMARQUEE
  5884. BOOL SetMarquee(BOOL bMarquee, UINT uUpdateTime = 0U)
  5885. {
  5886. ATLASSERT(::IsWindow(this->m_hWnd));
  5887. return (BOOL)::SendMessage(this->m_hWnd, PBM_SETMARQUEE, (WPARAM)bMarquee, (LPARAM)uUpdateTime);
  5888. }
  5889. #endif
  5890. #if (_WIN32_WINNT >= 0x0600)
  5891. int GetStep() const
  5892. {
  5893. ATLASSERT(::IsWindow(this->m_hWnd));
  5894. return (int)::SendMessage(this->m_hWnd, PBM_GETSTEP, 0, 0L);
  5895. }
  5896. COLORREF GetBkColor() const
  5897. {
  5898. ATLASSERT(::IsWindow(this->m_hWnd));
  5899. return (COLORREF)::SendMessage(this->m_hWnd, PBM_GETBKCOLOR, 0, 0L);
  5900. }
  5901. COLORREF GetBarColor() const
  5902. {
  5903. ATLASSERT(::IsWindow(this->m_hWnd));
  5904. return (COLORREF)::SendMessage(this->m_hWnd, PBM_GETBARCOLOR, 0, 0L);
  5905. }
  5906. int GetState() const
  5907. {
  5908. ATLASSERT(::IsWindow(this->m_hWnd));
  5909. return (int)::SendMessage(this->m_hWnd, PBM_GETSTATE, 0, 0L);
  5910. }
  5911. int SetState(int nState)
  5912. {
  5913. ATLASSERT(::IsWindow(this->m_hWnd));
  5914. return (int)::SendMessage(this->m_hWnd, PBM_SETSTATE, nState, 0L);
  5915. }
  5916. #endif // (_WIN32_WINNT >= 0x0600)
  5917. // Operations
  5918. int StepIt()
  5919. {
  5920. ATLASSERT(::IsWindow(this->m_hWnd));
  5921. return (int)(short)LOWORD(::SendMessage(this->m_hWnd, PBM_STEPIT, 0, 0L));
  5922. }
  5923. };
  5924. typedef CProgressBarCtrlT<ATL::CWindow> CProgressBarCtrl;
  5925. ///////////////////////////////////////////////////////////////////////////////
  5926. // CHotKeyCtrl
  5927. template <class TBase>
  5928. class CHotKeyCtrlT : public TBase
  5929. {
  5930. public:
  5931. // Constructors
  5932. CHotKeyCtrlT(HWND hWnd = NULL) : TBase(hWnd)
  5933. { }
  5934. CHotKeyCtrlT< TBase >& operator =(HWND hWnd)
  5935. {
  5936. this->m_hWnd = hWnd;
  5937. return *this;
  5938. }
  5939. HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  5940. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  5941. ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  5942. {
  5943. return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  5944. }
  5945. // Attributes
  5946. static LPCTSTR GetWndClassName()
  5947. {
  5948. return HOTKEY_CLASS;
  5949. }
  5950. DWORD GetHotKey() const
  5951. {
  5952. ATLASSERT(::IsWindow(this->m_hWnd));
  5953. return (DWORD)::SendMessage(this->m_hWnd, HKM_GETHOTKEY, 0, 0L);
  5954. }
  5955. void GetHotKey(WORD &wVirtualKeyCode, WORD &wModifiers) const
  5956. {
  5957. ATLASSERT(::IsWindow(this->m_hWnd));
  5958. DWORD dw = (DWORD)::SendMessage(this->m_hWnd, HKM_GETHOTKEY, 0, 0L);
  5959. wVirtualKeyCode = LOBYTE(LOWORD(dw));
  5960. wModifiers = HIBYTE(LOWORD(dw));
  5961. }
  5962. void SetHotKey(WORD wVirtualKeyCode, WORD wModifiers)
  5963. {
  5964. ATLASSERT(::IsWindow(this->m_hWnd));
  5965. ::SendMessage(this->m_hWnd, HKM_SETHOTKEY, MAKEWORD(wVirtualKeyCode, wModifiers), 0L);
  5966. }
  5967. void SetRules(WORD wInvalidComb, WORD wModifiers)
  5968. {
  5969. ATLASSERT(::IsWindow(this->m_hWnd));
  5970. ::SendMessage(this->m_hWnd, HKM_SETRULES, wInvalidComb, MAKELPARAM(wModifiers, 0));
  5971. }
  5972. };
  5973. typedef CHotKeyCtrlT<ATL::CWindow> CHotKeyCtrl;
  5974. ///////////////////////////////////////////////////////////////////////////////
  5975. // CAnimateCtrl
  5976. template <class TBase>
  5977. class CAnimateCtrlT : public TBase
  5978. {
  5979. public:
  5980. // Constructors
  5981. CAnimateCtrlT(HWND hWnd = NULL) : TBase(hWnd)
  5982. { }
  5983. CAnimateCtrlT< TBase >& operator =(HWND hWnd)
  5984. {
  5985. this->m_hWnd = hWnd;
  5986. return *this;
  5987. }
  5988. HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  5989. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  5990. ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  5991. {
  5992. return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  5993. }
  5994. // Attributes
  5995. static LPCTSTR GetWndClassName()
  5996. {
  5997. return ANIMATE_CLASS;
  5998. }
  5999. // Operations
  6000. BOOL Open(ATL::_U_STRINGorID FileName)
  6001. {
  6002. ATLASSERT(::IsWindow(this->m_hWnd));
  6003. return (BOOL)::SendMessage(this->m_hWnd, ACM_OPEN, 0, (LPARAM)FileName.m_lpstr);
  6004. }
  6005. BOOL Play(UINT nFrom, UINT nTo, UINT nRep)
  6006. {
  6007. ATLASSERT(::IsWindow(this->m_hWnd));
  6008. return (BOOL)::SendMessage(this->m_hWnd, ACM_PLAY, nRep, MAKELPARAM(nFrom, nTo));
  6009. }
  6010. BOOL Stop()
  6011. {
  6012. ATLASSERT(::IsWindow(this->m_hWnd));
  6013. return (BOOL)::SendMessage(this->m_hWnd, ACM_STOP, 0, 0L);
  6014. }
  6015. BOOL Close()
  6016. {
  6017. ATLASSERT(::IsWindow(this->m_hWnd));
  6018. return (BOOL)::SendMessage(this->m_hWnd, ACM_OPEN, 0, 0L);
  6019. }
  6020. BOOL Seek(UINT nTo)
  6021. {
  6022. ATLASSERT(::IsWindow(this->m_hWnd));
  6023. return (BOOL)::SendMessage(this->m_hWnd, ACM_PLAY, 0, MAKELPARAM(nTo, nTo));
  6024. }
  6025. // Vista only
  6026. BOOL IsPlaying() const
  6027. {
  6028. ATLASSERT(::IsWindow(this->m_hWnd));
  6029. return (BOOL)::SendMessage(this->m_hWnd, ACM_ISPLAYING, 0, 0L);
  6030. }
  6031. };
  6032. typedef CAnimateCtrlT<ATL::CWindow> CAnimateCtrl;
  6033. ///////////////////////////////////////////////////////////////////////////////
  6034. // CRichEditCtrl
  6035. #if !defined(_UNICODE) && (_RICHEDIT_VER >= 0x0500)
  6036. #undef MSFTEDIT_CLASS
  6037. #define MSFTEDIT_CLASS "RICHEDIT50W"
  6038. #endif
  6039. template <class TBase>
  6040. class CRichEditCtrlT : public TBase
  6041. {
  6042. public:
  6043. // Constructors
  6044. CRichEditCtrlT(HWND hWnd = NULL) : TBase(hWnd)
  6045. { }
  6046. CRichEditCtrlT< TBase >& operator =(HWND hWnd)
  6047. {
  6048. this->m_hWnd = hWnd;
  6049. return *this;
  6050. }
  6051. HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  6052. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  6053. ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  6054. {
  6055. return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  6056. }
  6057. // Attributes
  6058. static LPCTSTR GetWndClassName()
  6059. {
  6060. #if (_RICHEDIT_VER >= 0x0500)
  6061. return MSFTEDIT_CLASS;
  6062. #else
  6063. return RICHEDIT_CLASS;
  6064. #endif
  6065. }
  6066. static LPCTSTR GetLibraryName()
  6067. {
  6068. #if (_RICHEDIT_VER >= 0x0500)
  6069. return _T("MSFTEDIT.DLL");
  6070. #else
  6071. return _T("RICHED20.DLL");
  6072. #endif
  6073. }
  6074. int GetLineCount() const
  6075. {
  6076. ATLASSERT(::IsWindow(this->m_hWnd));
  6077. return (int)::SendMessage(this->m_hWnd, EM_GETLINECOUNT, 0, 0L);
  6078. }
  6079. BOOL GetModify() const
  6080. {
  6081. ATLASSERT(::IsWindow(this->m_hWnd));
  6082. return (BOOL)::SendMessage(this->m_hWnd, EM_GETMODIFY, 0, 0L);
  6083. }
  6084. void SetModify(BOOL bModified = TRUE)
  6085. {
  6086. ATLASSERT(::IsWindow(this->m_hWnd));
  6087. ::SendMessage(this->m_hWnd, EM_SETMODIFY, bModified, 0L);
  6088. }
  6089. void GetRect(LPRECT lpRect) const
  6090. {
  6091. ATLASSERT(::IsWindow(this->m_hWnd));
  6092. ::SendMessage(this->m_hWnd, EM_GETRECT, 0, (LPARAM)lpRect);
  6093. }
  6094. DWORD GetOptions() const
  6095. {
  6096. ATLASSERT(::IsWindow(this->m_hWnd));
  6097. return (DWORD)::SendMessage(this->m_hWnd, EM_GETOPTIONS, 0, 0L);
  6098. }
  6099. DWORD SetOptions(WORD wOperation, DWORD dwOptions)
  6100. {
  6101. ATLASSERT(::IsWindow(this->m_hWnd));
  6102. return (DWORD)::SendMessage(this->m_hWnd, EM_SETOPTIONS, wOperation, dwOptions);
  6103. }
  6104. // NOTE: first word in lpszBuffer must contain the size of the buffer!
  6105. int GetLine(int nIndex, LPTSTR lpszBuffer) const
  6106. {
  6107. ATLASSERT(::IsWindow(this->m_hWnd));
  6108. return (int)::SendMessage(this->m_hWnd, EM_GETLINE, nIndex, (LPARAM)lpszBuffer);
  6109. }
  6110. int GetLine(int nIndex, LPTSTR lpszBuffer, int nMaxLength) const
  6111. {
  6112. ATLASSERT(::IsWindow(this->m_hWnd));
  6113. *(LPWORD)lpszBuffer = (WORD)nMaxLength;
  6114. return (int)::SendMessage(this->m_hWnd, EM_GETLINE, nIndex, (LPARAM)lpszBuffer);
  6115. }
  6116. BOOL CanUndo() const
  6117. {
  6118. ATLASSERT(::IsWindow(this->m_hWnd));
  6119. return (BOOL)::SendMessage(this->m_hWnd, EM_CANUNDO, 0, 0L);
  6120. }
  6121. BOOL CanPaste(UINT nFormat = 0) const
  6122. {
  6123. ATLASSERT(::IsWindow(this->m_hWnd));
  6124. return (BOOL)::SendMessage(this->m_hWnd, EM_CANPASTE, nFormat, 0L);
  6125. }
  6126. void GetSel(LONG& nStartChar, LONG& nEndChar) const
  6127. {
  6128. ATLASSERT(::IsWindow(this->m_hWnd));
  6129. CHARRANGE cr = {};
  6130. ::SendMessage(this->m_hWnd, EM_EXGETSEL, 0, (LPARAM)&cr);
  6131. nStartChar = cr.cpMin;
  6132. nEndChar = cr.cpMax;
  6133. }
  6134. void GetSel(CHARRANGE &cr) const
  6135. {
  6136. ATLASSERT(::IsWindow(this->m_hWnd));
  6137. ::SendMessage(this->m_hWnd, EM_EXGETSEL, 0, (LPARAM)&cr);
  6138. }
  6139. int SetSel(LONG nStartChar, LONG nEndChar)
  6140. {
  6141. ATLASSERT(::IsWindow(this->m_hWnd));
  6142. CHARRANGE cr = { nStartChar, nEndChar };
  6143. return (int)::SendMessage(this->m_hWnd, EM_EXSETSEL, 0, (LPARAM)&cr);
  6144. }
  6145. int SetSel(CHARRANGE &cr)
  6146. {
  6147. ATLASSERT(::IsWindow(this->m_hWnd));
  6148. return (int)::SendMessage(this->m_hWnd, EM_EXSETSEL, 0, (LPARAM)&cr);
  6149. }
  6150. int SetSelAll()
  6151. {
  6152. return SetSel(0, -1);
  6153. }
  6154. int SetSelNone()
  6155. {
  6156. return SetSel(-1, 0);
  6157. }
  6158. DWORD GetDefaultCharFormat(CHARFORMAT& cf) const
  6159. {
  6160. ATLASSERT(::IsWindow(this->m_hWnd));
  6161. cf.cbSize = sizeof(CHARFORMAT);
  6162. return (DWORD)::SendMessage(this->m_hWnd, EM_GETCHARFORMAT, 0, (LPARAM)&cf);
  6163. }
  6164. DWORD GetSelectionCharFormat(CHARFORMAT& cf) const
  6165. {
  6166. ATLASSERT(::IsWindow(this->m_hWnd));
  6167. cf.cbSize = sizeof(CHARFORMAT);
  6168. return (DWORD)::SendMessage(this->m_hWnd, EM_GETCHARFORMAT, 1, (LPARAM)&cf);
  6169. }
  6170. DWORD GetEventMask() const
  6171. {
  6172. ATLASSERT(::IsWindow(this->m_hWnd));
  6173. return (DWORD)::SendMessage(this->m_hWnd, EM_GETEVENTMASK, 0, 0L);
  6174. }
  6175. LONG GetLimitText() const
  6176. {
  6177. ATLASSERT(::IsWindow(this->m_hWnd));
  6178. return (LONG)::SendMessage(this->m_hWnd, EM_GETLIMITTEXT, 0, 0L);
  6179. }
  6180. DWORD GetParaFormat(PARAFORMAT& pf) const
  6181. {
  6182. ATLASSERT(::IsWindow(this->m_hWnd));
  6183. pf.cbSize = sizeof(PARAFORMAT);
  6184. return (DWORD)::SendMessage(this->m_hWnd, EM_GETPARAFORMAT, 0, (LPARAM)&pf);
  6185. }
  6186. LONG GetSelText(LPTSTR lpstrBuff) const
  6187. {
  6188. ATLASSERT(::IsWindow(this->m_hWnd));
  6189. return (LONG)::SendMessage(this->m_hWnd, EM_GETSELTEXT, 0, (LPARAM)lpstrBuff);
  6190. }
  6191. BOOL GetSelTextBSTR(BSTR& bstrText) const
  6192. {
  6193. USES_CONVERSION;
  6194. ATLASSERT(::IsWindow(this->m_hWnd));
  6195. ATLASSERT(bstrText == NULL);
  6196. CHARRANGE cr = {};
  6197. ::SendMessage(this->m_hWnd, EM_EXGETSEL, 0, (LPARAM)&cr);
  6198. ATL::CTempBuffer<TCHAR, _WTL_STACK_ALLOC_THRESHOLD> buff;
  6199. LPTSTR lpstrText = buff.Allocate(cr.cpMax - cr.cpMin + 1);
  6200. if(lpstrText == NULL)
  6201. return FALSE;
  6202. if(::SendMessage(this->m_hWnd, EM_GETSELTEXT, 0, (LPARAM)lpstrText) == 0)
  6203. return FALSE;
  6204. bstrText = ::SysAllocString(T2W(lpstrText));
  6205. return (bstrText != NULL) ? TRUE : FALSE;
  6206. }
  6207. #ifdef __ATLSTR_H__
  6208. LONG GetSelText(ATL::CString& strText) const
  6209. {
  6210. ATLASSERT(::IsWindow(this->m_hWnd));
  6211. CHARRANGE cr = {};
  6212. ::SendMessage(this->m_hWnd, EM_EXGETSEL, 0, (LPARAM)&cr);
  6213. LONG lLen = 0;
  6214. LPTSTR lpstrText = strText.GetBufferSetLength(cr.cpMax - cr.cpMin);
  6215. if(lpstrText != NULL)
  6216. {
  6217. lLen = (LONG)::SendMessage(this->m_hWnd, EM_GETSELTEXT, 0, (LPARAM)lpstrText);
  6218. strText.ReleaseBuffer();
  6219. }
  6220. return lLen;
  6221. }
  6222. #endif // __ATLSTR_H__
  6223. WORD GetSelectionType() const
  6224. {
  6225. ATLASSERT(::IsWindow(this->m_hWnd));
  6226. return (WORD)::SendMessage(this->m_hWnd, EM_SELECTIONTYPE, 0, 0L);
  6227. }
  6228. COLORREF SetBackgroundColor(COLORREF cr)
  6229. {
  6230. ATLASSERT(::IsWindow(this->m_hWnd));
  6231. return (COLORREF)::SendMessage(this->m_hWnd, EM_SETBKGNDCOLOR, 0, cr);
  6232. }
  6233. COLORREF SetBackgroundColor() // sets to system background
  6234. {
  6235. ATLASSERT(::IsWindow(this->m_hWnd));
  6236. return (COLORREF)::SendMessage(this->m_hWnd, EM_SETBKGNDCOLOR, 1, 0);
  6237. }
  6238. BOOL SetCharFormat(CHARFORMAT& cf, WORD wFlags)
  6239. {
  6240. ATLASSERT(::IsWindow(this->m_hWnd));
  6241. cf.cbSize = sizeof(CHARFORMAT);
  6242. return (BOOL)::SendMessage(this->m_hWnd, EM_SETCHARFORMAT, (WPARAM)wFlags, (LPARAM)&cf);
  6243. }
  6244. BOOL SetDefaultCharFormat(CHARFORMAT& cf)
  6245. {
  6246. ATLASSERT(::IsWindow(this->m_hWnd));
  6247. cf.cbSize = sizeof(CHARFORMAT);
  6248. return (BOOL)::SendMessage(this->m_hWnd, EM_SETCHARFORMAT, 0, (LPARAM)&cf);
  6249. }
  6250. BOOL SetSelectionCharFormat(CHARFORMAT& cf)
  6251. {
  6252. ATLASSERT(::IsWindow(this->m_hWnd));
  6253. cf.cbSize = sizeof(CHARFORMAT);
  6254. return (BOOL)::SendMessage(this->m_hWnd, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf);
  6255. }
  6256. BOOL SetWordCharFormat(CHARFORMAT& cf)
  6257. {
  6258. ATLASSERT(::IsWindow(this->m_hWnd));
  6259. cf.cbSize = sizeof(CHARFORMAT);
  6260. return (BOOL)::SendMessage(this->m_hWnd, EM_SETCHARFORMAT, SCF_SELECTION | SCF_WORD, (LPARAM)&cf);
  6261. }
  6262. DWORD SetEventMask(DWORD dwEventMask)
  6263. {
  6264. ATLASSERT(::IsWindow(this->m_hWnd));
  6265. return (DWORD)::SendMessage(this->m_hWnd, EM_SETEVENTMASK, 0, dwEventMask);
  6266. }
  6267. BOOL SetParaFormat(PARAFORMAT& pf)
  6268. {
  6269. ATLASSERT(::IsWindow(this->m_hWnd));
  6270. pf.cbSize = sizeof(PARAFORMAT);
  6271. return (BOOL)::SendMessage(this->m_hWnd, EM_SETPARAFORMAT, 0, (LPARAM)&pf);
  6272. }
  6273. BOOL SetTargetDevice(HDC hDC, int cxLineWidth)
  6274. {
  6275. ATLASSERT(::IsWindow(this->m_hWnd));
  6276. return (BOOL)::SendMessage(this->m_hWnd, EM_SETTARGETDEVICE, (WPARAM)hDC, cxLineWidth);
  6277. }
  6278. int GetTextLength() const
  6279. {
  6280. ATLASSERT(::IsWindow(this->m_hWnd));
  6281. return (int)::SendMessage(this->m_hWnd, WM_GETTEXTLENGTH, 0, 0L);
  6282. }
  6283. BOOL SetReadOnly(BOOL bReadOnly = TRUE)
  6284. {
  6285. ATLASSERT(::IsWindow(this->m_hWnd));
  6286. return (BOOL)::SendMessage(this->m_hWnd, EM_SETREADONLY, bReadOnly, 0L);
  6287. }
  6288. int GetFirstVisibleLine() const
  6289. {
  6290. ATLASSERT(::IsWindow(this->m_hWnd));
  6291. return (int)::SendMessage(this->m_hWnd, EM_GETFIRSTVISIBLELINE, 0, 0L);
  6292. }
  6293. int GetTextRange(TEXTRANGE* pTextRange) const
  6294. {
  6295. ATLASSERT(::IsWindow(this->m_hWnd));
  6296. return (int)::SendMessage(this->m_hWnd, EM_GETTEXTRANGE, 0, (LPARAM)pTextRange);
  6297. }
  6298. int GetTextRange(LONG nStartChar, LONG nEndChar, LPTSTR lpstrText) const
  6299. {
  6300. ATLASSERT(::IsWindow(this->m_hWnd));
  6301. TEXTRANGE tr = {};
  6302. tr.chrg.cpMin = nStartChar;
  6303. tr.chrg.cpMax = nEndChar;
  6304. tr.lpstrText = lpstrText;
  6305. return (int)::SendMessage(this->m_hWnd, EM_GETTEXTRANGE, 0, (LPARAM)&tr);
  6306. }
  6307. DWORD GetDefaultCharFormat(CHARFORMAT2& cf) const
  6308. {
  6309. ATLASSERT(::IsWindow(this->m_hWnd));
  6310. cf.cbSize = sizeof(CHARFORMAT2);
  6311. return (DWORD)::SendMessage(this->m_hWnd, EM_GETCHARFORMAT, 0, (LPARAM)&cf);
  6312. }
  6313. BOOL SetCharFormat(CHARFORMAT2& cf, WORD wFlags)
  6314. {
  6315. ATLASSERT(::IsWindow(this->m_hWnd));
  6316. cf.cbSize = sizeof(CHARFORMAT2);
  6317. return (BOOL)::SendMessage(this->m_hWnd, EM_SETCHARFORMAT, (WPARAM)wFlags, (LPARAM)&cf);
  6318. }
  6319. BOOL SetDefaultCharFormat(CHARFORMAT2& cf)
  6320. {
  6321. ATLASSERT(::IsWindow(this->m_hWnd));
  6322. cf.cbSize = sizeof(CHARFORMAT2);
  6323. return (BOOL)::SendMessage(this->m_hWnd, EM_SETCHARFORMAT, 0, (LPARAM)&cf);
  6324. }
  6325. DWORD GetSelectionCharFormat(CHARFORMAT2& cf) const
  6326. {
  6327. ATLASSERT(::IsWindow(this->m_hWnd));
  6328. cf.cbSize = sizeof(CHARFORMAT2);
  6329. return (DWORD)::SendMessage(this->m_hWnd, EM_GETCHARFORMAT, 1, (LPARAM)&cf);
  6330. }
  6331. BOOL SetSelectionCharFormat(CHARFORMAT2& cf)
  6332. {
  6333. ATLASSERT(::IsWindow(this->m_hWnd));
  6334. cf.cbSize = sizeof(CHARFORMAT2);
  6335. return (BOOL)::SendMessage(this->m_hWnd, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf);
  6336. }
  6337. BOOL SetWordCharFormat(CHARFORMAT2& cf)
  6338. {
  6339. ATLASSERT(::IsWindow(this->m_hWnd));
  6340. cf.cbSize = sizeof(CHARFORMAT2);
  6341. return (BOOL)::SendMessage(this->m_hWnd, EM_SETCHARFORMAT, SCF_SELECTION | SCF_WORD, (LPARAM)&cf);
  6342. }
  6343. DWORD GetParaFormat(PARAFORMAT2& pf) const
  6344. {
  6345. ATLASSERT(::IsWindow(this->m_hWnd));
  6346. pf.cbSize = sizeof(PARAFORMAT2);
  6347. return (DWORD)::SendMessage(this->m_hWnd, EM_GETPARAFORMAT, 0, (LPARAM)&pf);
  6348. }
  6349. BOOL SetParaFormat(PARAFORMAT2& pf)
  6350. {
  6351. ATLASSERT(::IsWindow(this->m_hWnd));
  6352. pf.cbSize = sizeof(PARAFORMAT2);
  6353. return (BOOL)::SendMessage(this->m_hWnd, EM_SETPARAFORMAT, 0, (LPARAM)&pf);
  6354. }
  6355. TEXTMODE GetTextMode() const
  6356. {
  6357. ATLASSERT(::IsWindow(this->m_hWnd));
  6358. return (TEXTMODE)::SendMessage(this->m_hWnd, EM_GETTEXTMODE, 0, 0L);
  6359. }
  6360. BOOL SetTextMode(TEXTMODE enumTextMode)
  6361. {
  6362. ATLASSERT(::IsWindow(this->m_hWnd));
  6363. return !(BOOL)::SendMessage(this->m_hWnd, EM_SETTEXTMODE, enumTextMode, 0L);
  6364. }
  6365. UNDONAMEID GetUndoName() const
  6366. {
  6367. ATLASSERT(::IsWindow(this->m_hWnd));
  6368. return (UNDONAMEID)::SendMessage(this->m_hWnd, EM_GETUNDONAME, 0, 0L);
  6369. }
  6370. UNDONAMEID GetRedoName() const
  6371. {
  6372. ATLASSERT(::IsWindow(this->m_hWnd));
  6373. return (UNDONAMEID)::SendMessage(this->m_hWnd, EM_GETREDONAME, 0, 0L);
  6374. }
  6375. BOOL CanRedo() const
  6376. {
  6377. ATLASSERT(::IsWindow(this->m_hWnd));
  6378. return (BOOL)::SendMessage(this->m_hWnd, EM_CANREDO, 0, 0L);
  6379. }
  6380. BOOL GetAutoURLDetect() const
  6381. {
  6382. ATLASSERT(::IsWindow(this->m_hWnd));
  6383. return (BOOL)::SendMessage(this->m_hWnd, EM_GETAUTOURLDETECT, 0, 0L);
  6384. }
  6385. BOOL SetAutoURLDetect(BOOL bAutoDetect = TRUE)
  6386. {
  6387. ATLASSERT(::IsWindow(this->m_hWnd));
  6388. return !(BOOL)::SendMessage(this->m_hWnd, EM_AUTOURLDETECT, bAutoDetect, 0L);
  6389. }
  6390. // this method is deprecated, please use SetAutoURLDetect
  6391. BOOL EnableAutoURLDetect(BOOL bEnable = TRUE) { return SetAutoURLDetect(bEnable); }
  6392. UINT SetUndoLimit(UINT uUndoLimit)
  6393. {
  6394. ATLASSERT(::IsWindow(this->m_hWnd));
  6395. return (UINT)::SendMessage(this->m_hWnd, EM_SETUNDOLIMIT, uUndoLimit, 0L);
  6396. }
  6397. void SetPalette(HPALETTE hPalette)
  6398. {
  6399. ATLASSERT(::IsWindow(this->m_hWnd));
  6400. ::SendMessage(this->m_hWnd, EM_SETPALETTE, (WPARAM)hPalette, 0L);
  6401. }
  6402. int GetTextEx(GETTEXTEX* pGetTextEx, LPTSTR lpstrText) const
  6403. {
  6404. ATLASSERT(::IsWindow(this->m_hWnd));
  6405. return (int)::SendMessage(this->m_hWnd, EM_GETTEXTEX, (WPARAM)pGetTextEx, (LPARAM)lpstrText);
  6406. }
  6407. int GetTextEx(LPTSTR lpstrText, int nTextLen, DWORD dwFlags = GT_DEFAULT, UINT uCodePage = CP_ACP, LPCSTR lpDefaultChar = NULL, LPBOOL lpUsedDefChar = NULL) const
  6408. {
  6409. ATLASSERT(::IsWindow(this->m_hWnd));
  6410. GETTEXTEX gte = {};
  6411. gte.cb = nTextLen * sizeof(TCHAR);
  6412. gte.codepage = uCodePage;
  6413. gte.flags = dwFlags;
  6414. gte.lpDefaultChar = lpDefaultChar;
  6415. gte.lpUsedDefChar = lpUsedDefChar;
  6416. return (int)::SendMessage(this->m_hWnd, EM_GETTEXTEX, (WPARAM)&gte, (LPARAM)lpstrText);
  6417. }
  6418. int GetTextLengthEx(GETTEXTLENGTHEX* pGetTextLengthEx) const
  6419. {
  6420. ATLASSERT(::IsWindow(this->m_hWnd));
  6421. return (int)::SendMessage(this->m_hWnd, EM_GETTEXTLENGTHEX, (WPARAM)pGetTextLengthEx, 0L);
  6422. }
  6423. int GetTextLengthEx(DWORD dwFlags = GTL_DEFAULT, UINT uCodePage = CP_ACP) const
  6424. {
  6425. ATLASSERT(::IsWindow(this->m_hWnd));
  6426. GETTEXTLENGTHEX gtle = {};
  6427. gtle.codepage = uCodePage;
  6428. gtle.flags = dwFlags;
  6429. return (int)::SendMessage(this->m_hWnd, EM_GETTEXTLENGTHEX, (WPARAM)&gtle, 0L);
  6430. }
  6431. EDITWORDBREAKPROC GetWordBreakProc() const
  6432. {
  6433. ATLASSERT(::IsWindow(this->m_hWnd));
  6434. return (EDITWORDBREAKPROC)::SendMessage(this->m_hWnd, EM_GETWORDBREAKPROC, 0, 0L);
  6435. }
  6436. void SetWordBreakProc(EDITWORDBREAKPROC ewbprc)
  6437. {
  6438. ATLASSERT(::IsWindow(this->m_hWnd));
  6439. ::SendMessage(this->m_hWnd, EM_SETWORDBREAKPROC, 0, (LPARAM)ewbprc);
  6440. }
  6441. int SetTextEx(SETTEXTEX* pSetTextEx, LPCTSTR lpstrText)
  6442. {
  6443. ATLASSERT(::IsWindow(this->m_hWnd));
  6444. return (int)::SendMessage(this->m_hWnd, EM_SETTEXTEX, (WPARAM)pSetTextEx, (LPARAM)lpstrText);
  6445. }
  6446. int SetTextEx(LPCTSTR lpstrText, DWORD dwFlags = ST_DEFAULT, UINT uCodePage = CP_ACP)
  6447. {
  6448. ATLASSERT(::IsWindow(this->m_hWnd));
  6449. SETTEXTEX ste = {};
  6450. ste.flags = dwFlags;
  6451. ste.codepage = uCodePage;
  6452. return (int)::SendMessage(this->m_hWnd, EM_SETTEXTEX, (WPARAM)&ste, (LPARAM)lpstrText);
  6453. }
  6454. int GetEditStyle() const
  6455. {
  6456. ATLASSERT(::IsWindow(this->m_hWnd));
  6457. return (int)::SendMessage(this->m_hWnd, EM_GETEDITSTYLE, 0, 0L);
  6458. }
  6459. int SetEditStyle(int nStyle, int nMask = -1)
  6460. {
  6461. ATLASSERT(::IsWindow(this->m_hWnd));
  6462. if(nMask == -1)
  6463. nMask = nStyle; // set everything specified
  6464. return (int)::SendMessage(this->m_hWnd, EM_SETEDITSTYLE, nStyle, nMask);
  6465. }
  6466. BOOL SetFontSize(int nFontSizeDelta)
  6467. {
  6468. ATLASSERT(::IsWindow(this->m_hWnd));
  6469. ATLASSERT((nFontSizeDelta >= -1637) && (nFontSizeDelta <= 1638));
  6470. return (BOOL)::SendMessage(this->m_hWnd, EM_SETFONTSIZE, nFontSizeDelta, 0L);
  6471. }
  6472. void GetScrollPos(LPPOINT lpPoint) const
  6473. {
  6474. ATLASSERT(::IsWindow(this->m_hWnd));
  6475. ATLASSERT(lpPoint != NULL);
  6476. ::SendMessage(this->m_hWnd, EM_GETSCROLLPOS, 0, (LPARAM)lpPoint);
  6477. }
  6478. void SetScrollPos(LPPOINT lpPoint)
  6479. {
  6480. ATLASSERT(::IsWindow(this->m_hWnd));
  6481. ATLASSERT(lpPoint != NULL);
  6482. ::SendMessage(this->m_hWnd, EM_SETSCROLLPOS, 0, (LPARAM)lpPoint);
  6483. }
  6484. BOOL GetZoom(int& nNum, int& nDen) const
  6485. {
  6486. ATLASSERT(::IsWindow(this->m_hWnd));
  6487. return (BOOL)::SendMessage(this->m_hWnd, EM_GETZOOM, (WPARAM)&nNum, (LPARAM)&nDen);
  6488. }
  6489. BOOL SetZoom(int nNum, int nDen)
  6490. {
  6491. ATLASSERT(::IsWindow(this->m_hWnd));
  6492. ATLASSERT((nNum >= 0) && (nNum <= 64));
  6493. ATLASSERT((nDen >= 0) && (nDen <= 64));
  6494. return (BOOL)::SendMessage(this->m_hWnd, EM_SETZOOM, nNum, nDen);
  6495. }
  6496. BOOL SetZoomOff()
  6497. {
  6498. ATLASSERT(::IsWindow(this->m_hWnd));
  6499. return (BOOL)::SendMessage(this->m_hWnd, EM_SETZOOM, 0, 0L);
  6500. }
  6501. void SetMargins(UINT nLeft, UINT nRight, WORD wFlags = EC_LEFTMARGIN | EC_RIGHTMARGIN)
  6502. {
  6503. ATLASSERT(::IsWindow(this->m_hWnd));
  6504. ::SendMessage(this->m_hWnd, EM_SETMARGINS, wFlags, MAKELONG(nLeft, nRight));
  6505. }
  6506. WORD GetTypographyOptions() const
  6507. {
  6508. ATLASSERT(::IsWindow(this->m_hWnd));
  6509. return (WORD)::SendMessage(this->m_hWnd, EM_GETTYPOGRAPHYOPTIONS, 0, 0L);
  6510. }
  6511. BOOL SetTypographyOptions(WORD wOptions, WORD wMask) const
  6512. {
  6513. ATLASSERT(::IsWindow(this->m_hWnd));
  6514. return (BOOL)::SendMessage(this->m_hWnd, EM_SETTYPOGRAPHYOPTIONS, wOptions, wMask);
  6515. }
  6516. // Operations
  6517. void LimitText(LONG nChars = 0)
  6518. {
  6519. ATLASSERT(::IsWindow(this->m_hWnd));
  6520. ::SendMessage(this->m_hWnd, EM_EXLIMITTEXT, 0, nChars);
  6521. }
  6522. int LineFromChar(LONG nIndex) const
  6523. {
  6524. ATLASSERT(::IsWindow(this->m_hWnd));
  6525. return (int)::SendMessage(this->m_hWnd, EM_EXLINEFROMCHAR, 0, nIndex);
  6526. }
  6527. POINT PosFromChar(LONG nChar) const
  6528. {
  6529. ATLASSERT(::IsWindow(this->m_hWnd));
  6530. POINT point = {};
  6531. ::SendMessage(this->m_hWnd, EM_POSFROMCHAR, (WPARAM)&point, nChar);
  6532. return point;
  6533. }
  6534. int CharFromPos(POINT pt) const
  6535. {
  6536. ATLASSERT(::IsWindow(this->m_hWnd));
  6537. POINTL ptl = { pt.x, pt.y };
  6538. return (int)::SendMessage(this->m_hWnd, EM_CHARFROMPOS, 0, (LPARAM)&ptl);
  6539. }
  6540. void EmptyUndoBuffer()
  6541. {
  6542. ATLASSERT(::IsWindow(this->m_hWnd));
  6543. ::SendMessage(this->m_hWnd, EM_EMPTYUNDOBUFFER, 0, 0L);
  6544. }
  6545. int LineIndex(int nLine = -1) const
  6546. {
  6547. ATLASSERT(::IsWindow(this->m_hWnd));
  6548. return (int)::SendMessage(this->m_hWnd, EM_LINEINDEX, nLine, 0L);
  6549. }
  6550. int LineLength(int nLine = -1) const
  6551. {
  6552. ATLASSERT(::IsWindow(this->m_hWnd));
  6553. return (int)::SendMessage(this->m_hWnd, EM_LINELENGTH, nLine, 0L);
  6554. }
  6555. BOOL LineScroll(int nLines)
  6556. {
  6557. ATLASSERT(::IsWindow(this->m_hWnd));
  6558. return (BOOL)::SendMessage(this->m_hWnd, EM_LINESCROLL, 0, nLines);
  6559. }
  6560. void ReplaceSel(LPCTSTR lpszNewText, BOOL bCanUndo = FALSE)
  6561. {
  6562. ATLASSERT(::IsWindow(this->m_hWnd));
  6563. ::SendMessage(this->m_hWnd, EM_REPLACESEL, (WPARAM) bCanUndo, (LPARAM)lpszNewText);
  6564. }
  6565. void SetRect(LPCRECT lpRect)
  6566. {
  6567. ATLASSERT(::IsWindow(this->m_hWnd));
  6568. ::SendMessage(this->m_hWnd, EM_SETRECT, 0, (LPARAM)lpRect);
  6569. }
  6570. BOOL DisplayBand(LPRECT pDisplayRect)
  6571. {
  6572. ATLASSERT(::IsWindow(this->m_hWnd));
  6573. return (BOOL)::SendMessage(this->m_hWnd, EM_DISPLAYBAND, 0, (LPARAM)pDisplayRect);
  6574. }
  6575. LONG FindText(DWORD dwFlags, FINDTEXT& ft) const
  6576. {
  6577. ATLASSERT(::IsWindow(this->m_hWnd));
  6578. #ifdef _UNICODE
  6579. return (LONG)::SendMessage(this->m_hWnd, EM_FINDTEXTW, dwFlags, (LPARAM)&ft);
  6580. #else
  6581. return (LONG)::SendMessage(this->m_hWnd, EM_FINDTEXT, dwFlags, (LPARAM)&ft);
  6582. #endif
  6583. }
  6584. LONG FindText(DWORD dwFlags, FINDTEXTEX& ft) const
  6585. {
  6586. ATLASSERT(::IsWindow(this->m_hWnd));
  6587. #ifdef _UNICODE
  6588. return (LONG)::SendMessage(this->m_hWnd, EM_FINDTEXTEXW, dwFlags, (LPARAM)&ft);
  6589. #else
  6590. return (LONG)::SendMessage(this->m_hWnd, EM_FINDTEXTEX, dwFlags, (LPARAM)&ft);
  6591. #endif
  6592. }
  6593. LONG FormatRange(FORMATRANGE& fr, BOOL bDisplay = TRUE)
  6594. {
  6595. ATLASSERT(::IsWindow(this->m_hWnd));
  6596. return (LONG)::SendMessage(this->m_hWnd, EM_FORMATRANGE, bDisplay, (LPARAM)&fr);
  6597. }
  6598. LONG FormatRange(FORMATRANGE* pFormatRange, BOOL bDisplay = TRUE)
  6599. {
  6600. ATLASSERT(::IsWindow(this->m_hWnd));
  6601. return (LONG)::SendMessage(this->m_hWnd, EM_FORMATRANGE, bDisplay, (LPARAM)pFormatRange);
  6602. }
  6603. void HideSelection(BOOL bHide = TRUE, BOOL bChangeStyle = FALSE)
  6604. {
  6605. ATLASSERT(::IsWindow(this->m_hWnd));
  6606. ::SendMessage(this->m_hWnd, EM_HIDESELECTION, bHide, bChangeStyle);
  6607. }
  6608. void PasteSpecial(UINT uClipFormat, DWORD dwAspect = 0, HMETAFILE hMF = 0)
  6609. {
  6610. ATLASSERT(::IsWindow(this->m_hWnd));
  6611. REPASTESPECIAL reps = { dwAspect, (DWORD_PTR)hMF };
  6612. ::SendMessage(this->m_hWnd, EM_PASTESPECIAL, uClipFormat, (LPARAM)&reps);
  6613. }
  6614. void RequestResize()
  6615. {
  6616. ATLASSERT(::IsWindow(this->m_hWnd));
  6617. ::SendMessage(this->m_hWnd, EM_REQUESTRESIZE, 0, 0L);
  6618. }
  6619. LONG StreamIn(UINT uFormat, EDITSTREAM& es)
  6620. {
  6621. ATLASSERT(::IsWindow(this->m_hWnd));
  6622. return (LONG)::SendMessage(this->m_hWnd, EM_STREAMIN, uFormat, (LPARAM)&es);
  6623. }
  6624. LONG StreamOut(UINT uFormat, EDITSTREAM& es)
  6625. {
  6626. ATLASSERT(::IsWindow(this->m_hWnd));
  6627. return (LONG)::SendMessage(this->m_hWnd, EM_STREAMOUT, uFormat, (LPARAM)&es);
  6628. }
  6629. DWORD FindWordBreak(int nCode, LONG nStartChar)
  6630. {
  6631. ATLASSERT(::IsWindow(this->m_hWnd));
  6632. return (DWORD)::SendMessage(this->m_hWnd, EM_FINDWORDBREAK, nCode, nStartChar);
  6633. }
  6634. // Additional operations
  6635. void ScrollCaret()
  6636. {
  6637. ATLASSERT(::IsWindow(this->m_hWnd));
  6638. ::SendMessage(this->m_hWnd, EM_SCROLLCARET, 0, 0L);
  6639. }
  6640. int InsertText(long nInsertAfterChar, LPCTSTR lpstrText, BOOL bCanUndo = FALSE)
  6641. {
  6642. int nRet = SetSel(nInsertAfterChar, nInsertAfterChar);
  6643. ReplaceSel(lpstrText, bCanUndo);
  6644. return nRet;
  6645. }
  6646. int AppendText(LPCTSTR lpstrText, BOOL bCanUndo = FALSE)
  6647. {
  6648. return InsertText(this->GetWindowTextLength(), lpstrText, bCanUndo);
  6649. }
  6650. // Clipboard operations
  6651. BOOL Undo()
  6652. {
  6653. ATLASSERT(::IsWindow(this->m_hWnd));
  6654. return (BOOL)::SendMessage(this->m_hWnd, EM_UNDO, 0, 0L);
  6655. }
  6656. void Clear()
  6657. {
  6658. ATLASSERT(::IsWindow(this->m_hWnd));
  6659. ::SendMessage(this->m_hWnd, WM_CLEAR, 0, 0L);
  6660. }
  6661. void Copy()
  6662. {
  6663. ATLASSERT(::IsWindow(this->m_hWnd));
  6664. ::SendMessage(this->m_hWnd, WM_COPY, 0, 0L);
  6665. }
  6666. void Cut()
  6667. {
  6668. ATLASSERT(::IsWindow(this->m_hWnd));
  6669. ::SendMessage(this->m_hWnd, WM_CUT, 0, 0L);
  6670. }
  6671. void Paste()
  6672. {
  6673. ATLASSERT(::IsWindow(this->m_hWnd));
  6674. ::SendMessage(this->m_hWnd, WM_PASTE, 0, 0L);
  6675. }
  6676. // OLE support
  6677. IRichEditOle* GetOleInterface() const
  6678. {
  6679. ATLASSERT(::IsWindow(this->m_hWnd));
  6680. IRichEditOle *pRichEditOle = NULL;
  6681. ::SendMessage(this->m_hWnd, EM_GETOLEINTERFACE, 0, (LPARAM)&pRichEditOle);
  6682. return pRichEditOle;
  6683. }
  6684. BOOL SetOleCallback(IRichEditOleCallback* pCallback)
  6685. {
  6686. ATLASSERT(::IsWindow(this->m_hWnd));
  6687. return (BOOL)::SendMessage(this->m_hWnd, EM_SETOLECALLBACK, 0, (LPARAM)pCallback);
  6688. }
  6689. BOOL Redo()
  6690. {
  6691. ATLASSERT(::IsWindow(this->m_hWnd));
  6692. return (BOOL)::SendMessage(this->m_hWnd, EM_REDO, 0, 0L);
  6693. }
  6694. void StopGroupTyping()
  6695. {
  6696. ATLASSERT(::IsWindow(this->m_hWnd));
  6697. ::SendMessage(this->m_hWnd, EM_STOPGROUPTYPING, 0, 0L);
  6698. }
  6699. void ShowScrollBar(int nBarType, BOOL bVisible = TRUE)
  6700. {
  6701. ATLASSERT(::IsWindow(this->m_hWnd));
  6702. ::SendMessage(this->m_hWnd, EM_SHOWSCROLLBAR, nBarType, bVisible);
  6703. }
  6704. BOOL SetTabStops(int nTabStops, LPINT rgTabStops)
  6705. {
  6706. ATLASSERT(::IsWindow(this->m_hWnd));
  6707. return (BOOL)::SendMessage(this->m_hWnd, EM_SETTABSTOPS, nTabStops, (LPARAM)rgTabStops);
  6708. }
  6709. BOOL SetTabStops()
  6710. {
  6711. ATLASSERT(::IsWindow(this->m_hWnd));
  6712. return (BOOL)::SendMessage(this->m_hWnd, EM_SETTABSTOPS, 0, 0L);
  6713. }
  6714. BOOL SetTabStops(const int& cxEachStop) // takes an 'int'
  6715. {
  6716. ATLASSERT(::IsWindow(this->m_hWnd));
  6717. return (BOOL)::SendMessage(this->m_hWnd, EM_SETTABSTOPS, 1, (LPARAM)(LPINT)&cxEachStop);
  6718. }
  6719. #if (_RICHEDIT_VER >= 0x0800)
  6720. AutoCorrectProc GetAutoCorrectProc() const
  6721. {
  6722. ATLASSERT(::IsWindow(this->m_hWnd));
  6723. return (AutoCorrectProc)::SendMessage(this->m_hWnd, EM_GETAUTOCORRECTPROC, 0, 0L);
  6724. }
  6725. BOOL SetAutoCorrectProc(AutoCorrectProc pfn)
  6726. {
  6727. ATLASSERT(::IsWindow(this->m_hWnd));
  6728. return (BOOL)::SendMessage(this->m_hWnd, EM_SETAUTOCORRECTPROC, (WPARAM)pfn, 0L);
  6729. }
  6730. BOOL CallAutoCorrectProc(WCHAR ch)
  6731. {
  6732. ATLASSERT(::IsWindow(this->m_hWnd));
  6733. return (BOOL)::SendMessage(this->m_hWnd, EM_CALLAUTOCORRECTPROC, (WPARAM)ch, 0L);
  6734. }
  6735. DWORD GetEditStyleEx() const
  6736. {
  6737. ATLASSERT(::IsWindow(this->m_hWnd));
  6738. return (DWORD)::SendMessage(this->m_hWnd, EM_GETEDITSTYLEEX, 0, 0L);
  6739. }
  6740. DWORD SetEditStyleEx(DWORD dwStyleEx, DWORD dwMask)
  6741. {
  6742. ATLASSERT(::IsWindow(this->m_hWnd));
  6743. return (DWORD)::SendMessage(this->m_hWnd, EM_SETEDITSTYLEEX, dwStyleEx, dwMask);
  6744. }
  6745. DWORD GetStoryType(int nStoryIndex) const
  6746. {
  6747. ATLASSERT(::IsWindow(this->m_hWnd));
  6748. return (DWORD)::SendMessage(this->m_hWnd, EM_GETSTORYTYPE, nStoryIndex, 0L);
  6749. }
  6750. DWORD SetStoryType(int nStoryIndex, DWORD dwStoryType)
  6751. {
  6752. ATLASSERT(::IsWindow(this->m_hWnd));
  6753. return (DWORD)::SendMessage(this->m_hWnd, EM_SETSTORYTYPE, nStoryIndex, dwStoryType);
  6754. }
  6755. DWORD GetEllipsisMode() const
  6756. {
  6757. ATLASSERT(::IsWindow(this->m_hWnd));
  6758. DWORD dwMode = 0;
  6759. BOOL bRet = (BOOL)::SendMessage(this->m_hWnd, EM_GETELLIPSISMODE, 0, (LPARAM)&dwMode);
  6760. (void)bRet; // avoid level 4 warning
  6761. ATLASSERT(bRet != FALSE);
  6762. return dwMode;
  6763. }
  6764. BOOL SetEllipsisMode(DWORD dwEllipsisMode)
  6765. {
  6766. ATLASSERT(::IsWindow(this->m_hWnd));
  6767. return (BOOL)::SendMessage(this->m_hWnd, EM_SETELLIPSISMODE, 0, dwEllipsisMode);
  6768. }
  6769. BOOL GetEllipsisState() const
  6770. {
  6771. ATLASSERT(::IsWindow(this->m_hWnd));
  6772. return (BOOL)::SendMessage(this->m_hWnd, EM_GETELLIPSISSTATE, 0, 0L);
  6773. }
  6774. BOOL GetTouchOptions(int nTouchOptions) const
  6775. {
  6776. ATLASSERT(::IsWindow(this->m_hWnd));
  6777. return (BOOL)::SendMessage(this->m_hWnd, EM_GETTOUCHOPTIONS, nTouchOptions, 0L);
  6778. }
  6779. void SetTouchOptions(int nTouchOptions, BOOL bEnable)
  6780. {
  6781. ATLASSERT(::IsWindow(this->m_hWnd));
  6782. ::SendMessage(this->m_hWnd, EM_SETTOUCHOPTIONS, nTouchOptions, bEnable);
  6783. }
  6784. HRESULT InsertTable(TABLEROWPARMS* pRowParams, TABLECELLPARMS* pCellParams)
  6785. {
  6786. ATLASSERT(::IsWindow(this->m_hWnd));
  6787. return (HRESULT)::SendMessage(this->m_hWnd, EM_INSERTTABLE, (WPARAM)pRowParams, (LPARAM)pCellParams);
  6788. }
  6789. HRESULT GetTableParams(TABLEROWPARMS* pRowParams, TABLECELLPARMS* pCellParams) const
  6790. {
  6791. ATLASSERT(::IsWindow(this->m_hWnd));
  6792. return (HRESULT)::SendMessage(this->m_hWnd, EM_GETTABLEPARMS, (WPARAM)pRowParams, (LPARAM)pCellParams);
  6793. }
  6794. HRESULT SetTableParams(TABLEROWPARMS* pRowParams, TABLECELLPARMS* pCellParams)
  6795. {
  6796. ATLASSERT(::IsWindow(this->m_hWnd));
  6797. return (HRESULT)::SendMessage(this->m_hWnd, EM_SETTABLEPARMS, (WPARAM)pRowParams, (LPARAM)pCellParams);
  6798. }
  6799. HRESULT InsertImage(RICHEDIT_IMAGE_PARAMETERS* pParams)
  6800. {
  6801. ATLASSERT(::IsWindow(this->m_hWnd));
  6802. return (HRESULT)::SendMessage(this->m_hWnd, EM_INSERTIMAGE, 0, (LPARAM)pParams);
  6803. }
  6804. BOOL SetUiaName(LPCTSTR lpstrName)
  6805. {
  6806. ATLASSERT(::IsWindow(this->m_hWnd));
  6807. return (BOOL)::SendMessage(this->m_hWnd, EM_SETUIANAME, 0, (LPARAM)lpstrName);
  6808. }
  6809. #endif // (_RICHEDIT_VER >= 0x0800)
  6810. };
  6811. typedef CRichEditCtrlT<ATL::CWindow> CRichEditCtrl;
  6812. ///////////////////////////////////////////////////////////////////////////////
  6813. // CRichEditCommands - message handlers for standard EDIT commands
  6814. // Chain to CRichEditCommands message map. Your class must also derive from CRichEditCtrl.
  6815. // Example:
  6816. // class CMyRichEdit : public CWindowImpl<CMyRichEdit, CRichEditCtrl>,
  6817. // public CRichEditCommands<CMyRichEdit>
  6818. // {
  6819. // public:
  6820. // BEGIN_MSG_MAP(CMyRichEdit)
  6821. // // your handlers...
  6822. // CHAIN_MSG_MAP_ALT(CRichEditCommands<CMyRichEdit>, 1)
  6823. // END_MSG_MAP()
  6824. // // other stuff...
  6825. // };
  6826. template <class T>
  6827. class CRichEditCommands : public CEditCommands< T >
  6828. {
  6829. public:
  6830. BEGIN_MSG_MAP(CRichEditCommands< T >)
  6831. ALT_MSG_MAP(1)
  6832. COMMAND_ID_HANDLER(ID_EDIT_CLEAR, CEditCommands< T >::OnEditClear)
  6833. COMMAND_ID_HANDLER(ID_EDIT_CLEAR_ALL, CEditCommands< T >::OnEditClearAll)
  6834. COMMAND_ID_HANDLER(ID_EDIT_COPY, CEditCommands< T >::OnEditCopy)
  6835. COMMAND_ID_HANDLER(ID_EDIT_CUT, CEditCommands< T >::OnEditCut)
  6836. COMMAND_ID_HANDLER(ID_EDIT_PASTE, CEditCommands< T >::OnEditPaste)
  6837. COMMAND_ID_HANDLER(ID_EDIT_SELECT_ALL, CEditCommands< T >::OnEditSelectAll)
  6838. COMMAND_ID_HANDLER(ID_EDIT_UNDO, CEditCommands< T >::OnEditUndo)
  6839. COMMAND_ID_HANDLER(ID_EDIT_REDO, OnEditRedo)
  6840. END_MSG_MAP()
  6841. LRESULT OnEditRedo(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  6842. {
  6843. T* pT = static_cast<T*>(this);
  6844. pT->Redo();
  6845. return 0;
  6846. }
  6847. // State (update UI) helpers
  6848. BOOL CanCut() const
  6849. { return HasSelection(); }
  6850. BOOL CanCopy() const
  6851. { return HasSelection(); }
  6852. BOOL CanClear() const
  6853. { return HasSelection(); }
  6854. // Implementation
  6855. BOOL HasSelection() const
  6856. {
  6857. const T* pT = static_cast<const T*>(this);
  6858. return (pT->GetSelectionType() != SEL_EMPTY);
  6859. }
  6860. };
  6861. ///////////////////////////////////////////////////////////////////////////////
  6862. // CDragListBox
  6863. template <class TBase>
  6864. class CDragListBoxT : public CListBoxT< TBase >
  6865. {
  6866. public:
  6867. // Constructors
  6868. CDragListBoxT(HWND hWnd = NULL) : CListBoxT< TBase >(hWnd)
  6869. { }
  6870. CDragListBoxT< TBase >& operator =(HWND hWnd)
  6871. {
  6872. this->m_hWnd = hWnd;
  6873. return *this;
  6874. }
  6875. HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  6876. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  6877. ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  6878. {
  6879. HWND hWnd = TBase::Create(TBase::GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  6880. if(hWnd != NULL)
  6881. MakeDragList();
  6882. return hWnd;
  6883. }
  6884. // Operations
  6885. BOOL MakeDragList()
  6886. {
  6887. ATLASSERT(::IsWindow(this->m_hWnd));
  6888. ATLASSERT((this->GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) == 0);
  6889. return ::MakeDragList(this->m_hWnd);
  6890. }
  6891. int LBItemFromPt(POINT pt, BOOL bAutoScroll = TRUE)
  6892. {
  6893. ATLASSERT(::IsWindow(this->m_hWnd));
  6894. return ::LBItemFromPt(this->m_hWnd, pt, bAutoScroll);
  6895. }
  6896. void DrawInsert(int nItem)
  6897. {
  6898. ATLASSERT(::IsWindow(this->m_hWnd));
  6899. ::DrawInsert(this->GetParent(), this->m_hWnd, nItem);
  6900. }
  6901. static UINT GetDragListMessage()
  6902. {
  6903. static UINT uDragListMessage = 0;
  6904. if(uDragListMessage == 0)
  6905. {
  6906. CStaticDataInitCriticalSectionLock lock;
  6907. if(FAILED(lock.Lock()))
  6908. {
  6909. ATLTRACE2(atlTraceUI, 0, _T("ERROR : Unable to lock critical section in CDragListBox::GetDragListMessage.\n"));
  6910. ATLASSERT(FALSE);
  6911. return 0;
  6912. }
  6913. if(uDragListMessage == 0)
  6914. uDragListMessage = ::RegisterWindowMessage(DRAGLISTMSGSTRING);
  6915. lock.Unlock();
  6916. }
  6917. ATLASSERT(uDragListMessage != 0);
  6918. return uDragListMessage;
  6919. }
  6920. };
  6921. typedef CDragListBoxT<ATL::CWindow> CDragListBox;
  6922. template <class T>
  6923. class CDragListNotifyImpl
  6924. {
  6925. public:
  6926. BEGIN_MSG_MAP(CDragListNotifyImpl< T >)
  6927. MESSAGE_HANDLER(CDragListBox::GetDragListMessage(), OnDragListNotify)
  6928. END_MSG_MAP()
  6929. LRESULT OnDragListNotify(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  6930. {
  6931. (void)uMsg; // avoid level 4 warning
  6932. ATLASSERT(uMsg == CDragListBox::GetDragListMessage());
  6933. T* pT = static_cast<T*>(this);
  6934. LPDRAGLISTINFO lpDragListInfo = (LPDRAGLISTINFO)lParam;
  6935. LRESULT lRet = 0;
  6936. switch(lpDragListInfo->uNotification)
  6937. {
  6938. case DL_BEGINDRAG:
  6939. lRet = (LPARAM)pT->OnBeginDrag((int)wParam, lpDragListInfo->hWnd, lpDragListInfo->ptCursor);
  6940. break;
  6941. case DL_CANCELDRAG:
  6942. pT->OnCancelDrag((int)wParam, lpDragListInfo->hWnd, lpDragListInfo->ptCursor);
  6943. break;
  6944. case DL_DRAGGING:
  6945. lRet = (LPARAM)pT->OnDragging((int)wParam, lpDragListInfo->hWnd, lpDragListInfo->ptCursor);
  6946. break;
  6947. case DL_DROPPED:
  6948. pT->OnDropped((int)wParam, lpDragListInfo->hWnd, lpDragListInfo->ptCursor);
  6949. break;
  6950. default:
  6951. ATLTRACE2(atlTraceUI, 0, _T("Unknown DragListBox notification\n"));
  6952. bHandled = FALSE; // don't handle it
  6953. break;
  6954. }
  6955. return lRet;
  6956. }
  6957. // Overrideables
  6958. BOOL OnBeginDrag(int /*nCtlID*/, HWND /*hWndDragList*/, POINT /*ptCursor*/)
  6959. {
  6960. return TRUE; // allow dragging
  6961. }
  6962. void OnCancelDrag(int /*nCtlID*/, HWND /*hWndDragList*/, POINT /*ptCursor*/)
  6963. {
  6964. // nothing to do
  6965. }
  6966. int OnDragging(int /*nCtlID*/, HWND /*hWndDragList*/, POINT /*ptCursor*/)
  6967. {
  6968. return 0; // don't change cursor
  6969. }
  6970. void OnDropped(int /*nCtlID*/, HWND /*hWndDragList*/, POINT /*ptCursor*/)
  6971. {
  6972. // nothing to do
  6973. }
  6974. };
  6975. ///////////////////////////////////////////////////////////////////////////////
  6976. // CReBarCtrl
  6977. template <class TBase>
  6978. class CReBarCtrlT : public TBase
  6979. {
  6980. public:
  6981. // Constructors
  6982. CReBarCtrlT(HWND hWnd = NULL) : TBase(hWnd)
  6983. { }
  6984. CReBarCtrlT< TBase >& operator =(HWND hWnd)
  6985. {
  6986. this->m_hWnd = hWnd;
  6987. return *this;
  6988. }
  6989. HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  6990. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  6991. ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  6992. {
  6993. return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  6994. }
  6995. // Attributes
  6996. static LPCTSTR GetWndClassName()
  6997. {
  6998. return REBARCLASSNAME;
  6999. }
  7000. UINT GetBandCount() const
  7001. {
  7002. ATLASSERT(::IsWindow(this->m_hWnd));
  7003. return (UINT)::SendMessage(this->m_hWnd, RB_GETBANDCOUNT, 0, 0L);
  7004. }
  7005. BOOL GetBandInfo(int nBand, LPREBARBANDINFO lprbbi) const
  7006. {
  7007. ATLASSERT(::IsWindow(this->m_hWnd));
  7008. return (BOOL)::SendMessage(this->m_hWnd, RB_GETBANDINFO, nBand, (LPARAM)lprbbi);
  7009. }
  7010. BOOL SetBandInfo(int nBand, LPREBARBANDINFO lprbbi)
  7011. {
  7012. ATLASSERT(::IsWindow(this->m_hWnd));
  7013. return (BOOL)::SendMessage(this->m_hWnd, RB_SETBANDINFO, nBand, (LPARAM)lprbbi);
  7014. }
  7015. BOOL GetBarInfo(LPREBARINFO lprbi) const
  7016. {
  7017. ATLASSERT(::IsWindow(this->m_hWnd));
  7018. return (BOOL)::SendMessage(this->m_hWnd, RB_GETBARINFO, 0, (LPARAM)lprbi);
  7019. }
  7020. BOOL SetBarInfo(LPREBARINFO lprbi)
  7021. {
  7022. ATLASSERT(::IsWindow(this->m_hWnd));
  7023. return (BOOL)::SendMessage(this->m_hWnd, RB_SETBARINFO, 0, (LPARAM)lprbi);
  7024. }
  7025. CImageList GetImageList() const
  7026. {
  7027. ATLASSERT(::IsWindow(this->m_hWnd));
  7028. REBARINFO rbi = {};
  7029. rbi.cbSize = sizeof(REBARINFO);
  7030. rbi.fMask = RBIM_IMAGELIST;
  7031. BOOL bRet = (BOOL)::SendMessage(this->m_hWnd, RB_GETBARINFO, 0, (LPARAM)&rbi);
  7032. return CImageList((bRet != FALSE) ? rbi.himl : NULL);
  7033. }
  7034. BOOL SetImageList(HIMAGELIST hImageList)
  7035. {
  7036. ATLASSERT(::IsWindow(this->m_hWnd));
  7037. REBARINFO rbi = {};
  7038. rbi.cbSize = sizeof(REBARINFO);
  7039. rbi.fMask = RBIM_IMAGELIST;
  7040. rbi.himl = hImageList;
  7041. return (BOOL)::SendMessage(this->m_hWnd, RB_SETBARINFO, 0, (LPARAM)&rbi);
  7042. }
  7043. UINT GetRowCount() const
  7044. {
  7045. ATLASSERT(::IsWindow(this->m_hWnd));
  7046. return (UINT)::SendMessage(this->m_hWnd, RB_GETROWCOUNT, 0, 0L);
  7047. }
  7048. UINT GetRowHeight(int nBand) const
  7049. {
  7050. ATLASSERT(::IsWindow(this->m_hWnd));
  7051. return (UINT)::SendMessage(this->m_hWnd, RB_GETROWHEIGHT, nBand, 0L);
  7052. }
  7053. COLORREF GetTextColor() const
  7054. {
  7055. ATLASSERT(::IsWindow(this->m_hWnd));
  7056. return (COLORREF)::SendMessage(this->m_hWnd, RB_GETTEXTCOLOR, 0, 0L);
  7057. }
  7058. COLORREF SetTextColor(COLORREF clr)
  7059. {
  7060. ATLASSERT(::IsWindow(this->m_hWnd));
  7061. return (COLORREF)::SendMessage(this->m_hWnd, RB_SETTEXTCOLOR, 0, (LPARAM)clr);
  7062. }
  7063. COLORREF GetBkColor() const
  7064. {
  7065. ATLASSERT(::IsWindow(this->m_hWnd));
  7066. return (COLORREF)::SendMessage(this->m_hWnd, RB_GETBKCOLOR, 0, 0L);
  7067. }
  7068. COLORREF SetBkColor(COLORREF clr)
  7069. {
  7070. ATLASSERT(::IsWindow(this->m_hWnd));
  7071. return (COLORREF)::SendMessage(this->m_hWnd, RB_SETBKCOLOR, 0, (LPARAM)clr);
  7072. }
  7073. UINT GetBarHeight() const
  7074. {
  7075. ATLASSERT(::IsWindow(this->m_hWnd));
  7076. return (UINT)::SendMessage(this->m_hWnd, RB_GETBARHEIGHT, 0, 0L);
  7077. }
  7078. BOOL GetRect(int nBand, LPRECT lpRect) const
  7079. {
  7080. ATLASSERT(::IsWindow(this->m_hWnd));
  7081. return (BOOL)::SendMessage(this->m_hWnd, RB_GETRECT, nBand, (LPARAM)lpRect);
  7082. }
  7083. CToolTipCtrl GetToolTips() const
  7084. {
  7085. ATLASSERT(::IsWindow(this->m_hWnd));
  7086. return CToolTipCtrl((HWND)::SendMessage(this->m_hWnd, RB_GETTOOLTIPS, 0, 0L));
  7087. }
  7088. void SetToolTips(HWND hwndToolTip)
  7089. {
  7090. ATLASSERT(::IsWindow(this->m_hWnd));
  7091. ::SendMessage(this->m_hWnd, RB_SETTOOLTIPS, (WPARAM)hwndToolTip, 0L);
  7092. }
  7093. void GetBandBorders(int nBand, LPRECT lpRect) const
  7094. {
  7095. ATLASSERT(::IsWindow(this->m_hWnd));
  7096. ATLASSERT(lpRect != NULL);
  7097. ::SendMessage(this->m_hWnd, RB_GETBANDBORDERS, nBand, (LPARAM)lpRect);
  7098. }
  7099. BOOL GetColorScheme(LPCOLORSCHEME lpColorScheme) const
  7100. {
  7101. ATLASSERT(::IsWindow(this->m_hWnd));
  7102. ATLASSERT(lpColorScheme != NULL);
  7103. return (BOOL)::SendMessage(this->m_hWnd, RB_GETCOLORSCHEME, 0, (LPARAM)lpColorScheme);
  7104. }
  7105. void SetColorScheme(LPCOLORSCHEME lpColorScheme)
  7106. {
  7107. ATLASSERT(::IsWindow(this->m_hWnd));
  7108. ATLASSERT(lpColorScheme != NULL);
  7109. ::SendMessage(this->m_hWnd, RB_SETCOLORSCHEME, 0, (LPARAM)lpColorScheme);
  7110. }
  7111. HPALETTE GetPalette() const
  7112. {
  7113. ATLASSERT(::IsWindow(this->m_hWnd));
  7114. return (HPALETTE)::SendMessage(this->m_hWnd, RB_GETPALETTE, 0, 0L);
  7115. }
  7116. HPALETTE SetPalette(HPALETTE hPalette)
  7117. {
  7118. ATLASSERT(::IsWindow(this->m_hWnd));
  7119. return (HPALETTE)::SendMessage(this->m_hWnd, RB_SETPALETTE, 0, (LPARAM)hPalette);
  7120. }
  7121. BOOL GetUnicodeFormat() const
  7122. {
  7123. ATLASSERT(::IsWindow(this->m_hWnd));
  7124. return (BOOL)::SendMessage(this->m_hWnd, RB_GETUNICODEFORMAT, 0, 0L);
  7125. }
  7126. BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
  7127. {
  7128. ATLASSERT(::IsWindow(this->m_hWnd));
  7129. return (BOOL)::SendMessage(this->m_hWnd, RB_SETUNICODEFORMAT, bUnicode, 0L);
  7130. }
  7131. // requires uxtheme.h to be included to use MARGINS struct
  7132. #ifndef _UXTHEME_H_
  7133. typedef struct _MARGINS* PMARGINS;
  7134. #endif // !_UXTHEME_H_
  7135. void GetBandMargins(PMARGINS pMargins) const
  7136. {
  7137. ATLASSERT(::IsWindow(this->m_hWnd));
  7138. ::SendMessage(this->m_hWnd, RB_GETBANDMARGINS, 0, (LPARAM)pMargins);
  7139. }
  7140. void SetWindowTheme(LPCWSTR lpstrTheme)
  7141. {
  7142. ATLASSERT(::IsWindow(this->m_hWnd));
  7143. ::SendMessage(this->m_hWnd, RB_SETWINDOWTHEME, 0, (LPARAM)lpstrTheme);
  7144. }
  7145. DWORD GetExtendedStyle() const
  7146. {
  7147. ATLASSERT(::IsWindow(this->m_hWnd));
  7148. return (DWORD)::SendMessage(this->m_hWnd, RB_GETEXTENDEDSTYLE, 0, 0L);
  7149. }
  7150. DWORD SetExtendedStyle(DWORD dwStyle, DWORD dwMask)
  7151. {
  7152. ATLASSERT(::IsWindow(this->m_hWnd));
  7153. return (DWORD)::SendMessage(this->m_hWnd, RB_SETEXTENDEDSTYLE, dwMask, dwStyle);
  7154. }
  7155. // Operations
  7156. BOOL InsertBand(int nBand, LPREBARBANDINFO lprbbi)
  7157. {
  7158. ATLASSERT(::IsWindow(this->m_hWnd));
  7159. return (BOOL)::SendMessage(this->m_hWnd, RB_INSERTBAND, nBand, (LPARAM)lprbbi);
  7160. }
  7161. BOOL AddBand(LPREBARBANDINFO lprbbi)
  7162. {
  7163. return InsertBand(-1, lprbbi);
  7164. }
  7165. BOOL DeleteBand(int nBand)
  7166. {
  7167. ATLASSERT(::IsWindow(this->m_hWnd));
  7168. return (BOOL)::SendMessage(this->m_hWnd, RB_DELETEBAND, nBand, 0L);
  7169. }
  7170. ATL::CWindow SetNotifyWnd(HWND hWnd)
  7171. {
  7172. ATLASSERT(::IsWindow(this->m_hWnd));
  7173. return ATL::CWindow((HWND)::SendMessage(this->m_hWnd, RB_SETPARENT, (WPARAM)hWnd, 0L));
  7174. }
  7175. void BeginDrag(int nBand, DWORD dwPos)
  7176. {
  7177. ATLASSERT(::IsWindow(this->m_hWnd));
  7178. ::SendMessage(this->m_hWnd, RB_BEGINDRAG, nBand, dwPos);
  7179. }
  7180. void BeginDrag(int nBand, int xPos, int yPos)
  7181. {
  7182. ATLASSERT(::IsWindow(this->m_hWnd));
  7183. ::SendMessage(this->m_hWnd, RB_BEGINDRAG, nBand, MAKELPARAM(xPos, yPos));
  7184. }
  7185. void EndDrag()
  7186. {
  7187. ATLASSERT(::IsWindow(this->m_hWnd));
  7188. ::SendMessage(this->m_hWnd, RB_ENDDRAG, 0, 0L);
  7189. }
  7190. void DragMove(DWORD dwPos)
  7191. {
  7192. ATLASSERT(::IsWindow(this->m_hWnd));
  7193. ::SendMessage(this->m_hWnd, RB_DRAGMOVE, 0, dwPos);
  7194. }
  7195. void DragMove(int xPos, int yPos)
  7196. {
  7197. ATLASSERT(::IsWindow(this->m_hWnd));
  7198. ::SendMessage(this->m_hWnd, RB_DRAGMOVE, 0, MAKELPARAM(xPos, yPos));
  7199. }
  7200. void GetDropTarget(IDropTarget** ppDropTarget) const
  7201. {
  7202. ATLASSERT(::IsWindow(this->m_hWnd));
  7203. ::SendMessage(this->m_hWnd, RB_GETDROPTARGET, 0, (LPARAM)ppDropTarget);
  7204. }
  7205. void MaximizeBand(int nBand, BOOL bIdeal = FALSE)
  7206. {
  7207. ATLASSERT(::IsWindow(this->m_hWnd));
  7208. ::SendMessage(this->m_hWnd, RB_MAXIMIZEBAND, nBand, bIdeal);
  7209. }
  7210. void MinimizeBand(int nBand)
  7211. {
  7212. ATLASSERT(::IsWindow(this->m_hWnd));
  7213. ::SendMessage(this->m_hWnd, RB_MINIMIZEBAND, nBand, 0L);
  7214. }
  7215. BOOL SizeToRect(LPRECT lpRect)
  7216. {
  7217. ATLASSERT(::IsWindow(this->m_hWnd));
  7218. return (BOOL)::SendMessage(this->m_hWnd, RB_SIZETORECT, 0, (LPARAM)lpRect);
  7219. }
  7220. int IdToIndex(UINT uBandID) const
  7221. {
  7222. ATLASSERT(::IsWindow(this->m_hWnd));
  7223. return (int)::SendMessage(this->m_hWnd, RB_IDTOINDEX, uBandID, 0L);
  7224. }
  7225. int HitTest(LPRBHITTESTINFO lprbht) const
  7226. {
  7227. ATLASSERT(::IsWindow(this->m_hWnd));
  7228. return (int)::SendMessage(this->m_hWnd, RB_HITTEST, 0, (LPARAM)lprbht);
  7229. }
  7230. BOOL ShowBand(int nBand, BOOL bShow)
  7231. {
  7232. ATLASSERT(::IsWindow(this->m_hWnd));
  7233. return (BOOL)::SendMessage(this->m_hWnd, RB_SHOWBAND, nBand, bShow);
  7234. }
  7235. BOOL MoveBand(int nBand, int nNewPos)
  7236. {
  7237. ATLASSERT(::IsWindow(this->m_hWnd));
  7238. ATLASSERT((nNewPos >= 0) && (nNewPos <= ((int)GetBandCount() - 1)));
  7239. return (BOOL)::SendMessage(this->m_hWnd, RB_MOVEBAND, nBand, nNewPos);
  7240. }
  7241. void PushChevron(int nBand, LPARAM lAppValue)
  7242. {
  7243. ATLASSERT(::IsWindow(this->m_hWnd));
  7244. ::SendMessage(this->m_hWnd, RB_PUSHCHEVRON, nBand, lAppValue);
  7245. }
  7246. // Extra operations
  7247. void LockBands(bool bLock)
  7248. {
  7249. int nBandCount = GetBandCount();
  7250. for(int i =0; i < nBandCount; i++)
  7251. {
  7252. REBARBANDINFO rbbi = { RunTimeHelper::SizeOf_REBARBANDINFO() };
  7253. rbbi.fMask = RBBIM_STYLE;
  7254. BOOL bRet = GetBandInfo(i, &rbbi);
  7255. ATLASSERT(bRet);
  7256. if((rbbi.fStyle & RBBS_GRIPPERALWAYS) == 0)
  7257. {
  7258. rbbi.fStyle |= RBBS_GRIPPERALWAYS;
  7259. bRet = SetBandInfo(i, &rbbi);
  7260. ATLASSERT(bRet);
  7261. rbbi.fStyle &= ~RBBS_GRIPPERALWAYS;
  7262. }
  7263. if(bLock)
  7264. rbbi.fStyle |= RBBS_NOGRIPPER;
  7265. else
  7266. rbbi.fStyle &= ~RBBS_NOGRIPPER;
  7267. bRet = SetBandInfo(i, &rbbi);
  7268. ATLASSERT(bRet);
  7269. }
  7270. }
  7271. #if (_WIN32_WINNT >= 0x0600)
  7272. BOOL SetBandWidth(int nBand, int cxWidth)
  7273. {
  7274. ATLASSERT(::IsWindow(this->m_hWnd));
  7275. return (BOOL)::SendMessage(this->m_hWnd, RB_SETBANDWIDTH, nBand, cxWidth);
  7276. }
  7277. #endif // (_WIN32_WINNT >= 0x0600)
  7278. };
  7279. typedef CReBarCtrlT<ATL::CWindow> CReBarCtrl;
  7280. ///////////////////////////////////////////////////////////////////////////////
  7281. // CComboBoxEx
  7282. template <class TBase>
  7283. class CComboBoxExT : public CComboBoxT< TBase >
  7284. {
  7285. public:
  7286. // Constructors
  7287. CComboBoxExT(HWND hWnd = NULL) : CComboBoxT< TBase >(hWnd)
  7288. { }
  7289. CComboBoxExT< TBase >& operator =(HWND hWnd)
  7290. {
  7291. this->m_hWnd = hWnd;
  7292. return *this;
  7293. }
  7294. HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  7295. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  7296. ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  7297. {
  7298. return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  7299. }
  7300. // Attributes
  7301. static LPCTSTR GetWndClassName()
  7302. {
  7303. return WC_COMBOBOXEX;
  7304. }
  7305. CImageList GetImageList() const
  7306. {
  7307. ATLASSERT(::IsWindow(this->m_hWnd));
  7308. return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, CBEM_GETIMAGELIST, 0, 0L));
  7309. }
  7310. CImageList SetImageList(HIMAGELIST hImageList)
  7311. {
  7312. ATLASSERT(::IsWindow(this->m_hWnd));
  7313. return CImageList((HIMAGELIST)::SendMessage(this->m_hWnd, CBEM_SETIMAGELIST, 0, (LPARAM)hImageList));
  7314. }
  7315. DWORD GetExtendedStyle() const
  7316. {
  7317. ATLASSERT(::IsWindow(this->m_hWnd));
  7318. return (DWORD)::SendMessage(this->m_hWnd, CBEM_GETEXTENDEDSTYLE, 0, 0L);
  7319. }
  7320. DWORD SetExtendedStyle(DWORD dwExMask, DWORD dwExStyle)
  7321. {
  7322. ATLASSERT(::IsWindow(this->m_hWnd));
  7323. return (DWORD)::SendMessage(this->m_hWnd, CBEM_SETEXTENDEDSTYLE, dwExMask, dwExStyle);
  7324. }
  7325. BOOL GetUnicodeFormat() const
  7326. {
  7327. ATLASSERT(::IsWindow(this->m_hWnd));
  7328. return (BOOL)::SendMessage(this->m_hWnd, CBEM_GETUNICODEFORMAT, 0, 0L);
  7329. }
  7330. BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
  7331. {
  7332. ATLASSERT(::IsWindow(this->m_hWnd));
  7333. return (BOOL)::SendMessage(this->m_hWnd, CBEM_SETUNICODEFORMAT, bUnicode, 0L);
  7334. }
  7335. void SetWindowTheme(LPCWSTR lpstrTheme)
  7336. {
  7337. ATLASSERT(::IsWindow(this->m_hWnd));
  7338. ::SendMessage(this->m_hWnd, CBEM_SETWINDOWTHEME, 0, (LPARAM)lpstrTheme);
  7339. }
  7340. // Operations
  7341. int InsertItem(const COMBOBOXEXITEM* lpcCBItem)
  7342. {
  7343. ATLASSERT(::IsWindow(this->m_hWnd));
  7344. return (int)::SendMessage(this->m_hWnd, CBEM_INSERTITEM, 0, (LPARAM)lpcCBItem);
  7345. }
  7346. int InsertItem(UINT nMask, int nIndex, LPCTSTR lpszItem, int nImage, int nSelImage,
  7347. int iIndent, int iOverlay, LPARAM lParam)
  7348. {
  7349. ATLASSERT(::IsWindow(this->m_hWnd));
  7350. COMBOBOXEXITEM cbex = {};
  7351. cbex.mask = nMask;
  7352. cbex.iItem = nIndex;
  7353. cbex.pszText = (LPTSTR) lpszItem;
  7354. cbex.iImage = nImage;
  7355. cbex.iSelectedImage = nSelImage;
  7356. cbex.iIndent = iIndent;
  7357. cbex.iOverlay = iOverlay;
  7358. cbex.lParam = lParam;
  7359. return (int)::SendMessage(this->m_hWnd, CBEM_INSERTITEM, 0, (LPARAM)&cbex);
  7360. }
  7361. int InsertItem(int nIndex, LPCTSTR lpszItem, int nImage, int nSelImage, int iIndent, LPARAM lParam = 0)
  7362. {
  7363. ATLASSERT(::IsWindow(this->m_hWnd));
  7364. COMBOBOXEXITEM cbex = {};
  7365. cbex.mask = CBEIF_TEXT | CBEIF_IMAGE | CBEIF_SELECTEDIMAGE | CBEIF_INDENT | CBEIF_LPARAM;
  7366. cbex.iItem = nIndex;
  7367. cbex.pszText = (LPTSTR) lpszItem;
  7368. cbex.iImage = nImage;
  7369. cbex.iSelectedImage = nSelImage;
  7370. cbex.iIndent = iIndent;
  7371. cbex.lParam = lParam;
  7372. return (int)::SendMessage(this->m_hWnd, CBEM_INSERTITEM, 0, (LPARAM)&cbex);
  7373. }
  7374. int AddItem(UINT nMask, LPCTSTR lpszItem, int nImage, int nSelImage, int iIndent, int iOverlay, LPARAM lParam)
  7375. {
  7376. return InsertItem(nMask, -1, lpszItem, nImage, nSelImage, iIndent, iOverlay, lParam);
  7377. }
  7378. int AddItem(LPCTSTR lpszItem, int nImage, int nSelImage, int iIndent, LPARAM lParam = 0)
  7379. {
  7380. return InsertItem(-1, lpszItem, nImage, nSelImage, iIndent, lParam);
  7381. }
  7382. int DeleteItem(int nIndex)
  7383. {
  7384. ATLASSERT(::IsWindow(this->m_hWnd));
  7385. return (int)::SendMessage(this->m_hWnd, CBEM_DELETEITEM, nIndex, 0L);
  7386. }
  7387. BOOL GetItem(PCOMBOBOXEXITEM pCBItem) const
  7388. {
  7389. ATLASSERT(::IsWindow(this->m_hWnd));
  7390. return (BOOL)::SendMessage(this->m_hWnd, CBEM_GETITEM, 0, (LPARAM)pCBItem);
  7391. }
  7392. BOOL SetItem(const COMBOBOXEXITEM* lpcCBItem)
  7393. {
  7394. ATLASSERT(::IsWindow(this->m_hWnd));
  7395. return (BOOL)::SendMessage(this->m_hWnd, CBEM_SETITEM, 0, (LPARAM)lpcCBItem);
  7396. }
  7397. int SetItem(int nIndex, UINT nMask, LPCTSTR lpszItem, int nImage, int nSelImage,
  7398. int iIndent, int iOverlay, LPARAM lParam)
  7399. {
  7400. ATLASSERT(::IsWindow(this->m_hWnd));
  7401. COMBOBOXEXITEM cbex = {};
  7402. cbex.mask = nMask;
  7403. cbex.iItem = nIndex;
  7404. cbex.pszText = (LPTSTR) lpszItem;
  7405. cbex.iImage = nImage;
  7406. cbex.iSelectedImage = nSelImage;
  7407. cbex.iIndent = iIndent;
  7408. cbex.iOverlay = iOverlay;
  7409. cbex.lParam = lParam;
  7410. return (int)::SendMessage(this->m_hWnd, CBEM_SETITEM, 0, (LPARAM)&cbex);
  7411. }
  7412. BOOL GetItemText(int nIndex, LPTSTR lpszItem, int nLen) const
  7413. {
  7414. ATLASSERT(::IsWindow(this->m_hWnd));
  7415. ATLASSERT(lpszItem != NULL);
  7416. COMBOBOXEXITEM cbex = {};
  7417. cbex.mask = CBEIF_TEXT;
  7418. cbex.iItem = nIndex;
  7419. cbex.pszText = lpszItem;
  7420. cbex.cchTextMax = nLen;
  7421. return (BOOL)::SendMessage(this->m_hWnd, CBEM_GETITEM, 0, (LPARAM)&cbex);
  7422. }
  7423. BOOL GetItemText(int nIndex, BSTR& bstrText) const
  7424. {
  7425. USES_CONVERSION;
  7426. ATLASSERT(::IsWindow(this->m_hWnd));
  7427. ATLASSERT(bstrText == NULL);
  7428. COMBOBOXEXITEM cbex = {};
  7429. cbex.mask = CBEIF_TEXT;
  7430. cbex.iItem = nIndex;
  7431. LPTSTR lpstrText = NULL;
  7432. BOOL bRet = FALSE;
  7433. for(int nLen = 256; ; nLen *= 2)
  7434. {
  7435. ATLTRY(lpstrText = new TCHAR[nLen]);
  7436. if(lpstrText == NULL)
  7437. break;
  7438. lpstrText[0] = NULL;
  7439. cbex.pszText = lpstrText;
  7440. cbex.cchTextMax = nLen;
  7441. bRet = (BOOL)::SendMessage(this->m_hWnd, CBEM_GETITEM, 0, (LPARAM)&cbex);
  7442. if(!bRet || (lstrlen(cbex.pszText) < (nLen - 1)))
  7443. break;
  7444. delete [] lpstrText;
  7445. lpstrText = NULL;
  7446. }
  7447. if(lpstrText != NULL)
  7448. {
  7449. if(bRet)
  7450. bstrText = ::SysAllocString(T2OLE(lpstrText));
  7451. delete [] lpstrText;
  7452. }
  7453. return (bstrText != NULL) ? TRUE : FALSE;
  7454. }
  7455. #ifdef __ATLSTR_H__
  7456. BOOL GetItemText(int nIndex, ATL::CString& strText) const
  7457. {
  7458. ATLASSERT(::IsWindow(this->m_hWnd));
  7459. COMBOBOXEXITEM cbex = {};
  7460. cbex.mask = CBEIF_TEXT;
  7461. cbex.iItem = nIndex;
  7462. strText.Empty();
  7463. BOOL bRet = FALSE;
  7464. for(int nLen = 256; ; nLen *= 2)
  7465. {
  7466. cbex.pszText = strText.GetBufferSetLength(nLen);
  7467. if(cbex.pszText == NULL)
  7468. {
  7469. bRet = FALSE;
  7470. break;
  7471. }
  7472. cbex.cchTextMax = nLen;
  7473. bRet = (BOOL)::SendMessage(this->m_hWnd, CBEM_GETITEM, 0, (LPARAM)&cbex);
  7474. if(!bRet || (lstrlen(cbex.pszText) < (nLen - 1)))
  7475. break;
  7476. }
  7477. strText.ReleaseBuffer();
  7478. return bRet;
  7479. }
  7480. #endif // __ATLSTR_H__
  7481. BOOL SetItemText(int nIndex, LPCTSTR lpszItem)
  7482. {
  7483. ATLASSERT(::IsWindow(this->m_hWnd));
  7484. return SetItem(nIndex, CBEIF_TEXT, lpszItem, 0, 0, 0, 0, 0);
  7485. }
  7486. CComboBox GetComboCtrl() const
  7487. {
  7488. ATLASSERT(::IsWindow(this->m_hWnd));
  7489. return CComboBox((HWND)::SendMessage(this->m_hWnd, CBEM_GETCOMBOCONTROL, 0, 0L));
  7490. }
  7491. CEdit GetEditCtrl() const
  7492. {
  7493. ATLASSERT(::IsWindow(this->m_hWnd));
  7494. return CEdit((HWND)::SendMessage(this->m_hWnd, CBEM_GETEDITCONTROL, 0, 0L));
  7495. }
  7496. BOOL HasEditChanged() const
  7497. {
  7498. ATLASSERT(::IsWindow(this->m_hWnd));
  7499. return (BOOL)::SendMessage(this->m_hWnd, CBEM_HASEDITCHANGED, 0, 0L);
  7500. }
  7501. // Non-functional
  7502. int AddString(LPCTSTR /*lpszItem*/)
  7503. {
  7504. ATLASSERT(FALSE); // Not available in CComboBoxEx; use InsertItem
  7505. return 0;
  7506. }
  7507. int InsertString(int /*nIndex*/, LPCTSTR /*lpszString*/)
  7508. {
  7509. ATLASSERT(FALSE); // Not available in CComboBoxEx; use InsertItem
  7510. return 0;
  7511. }
  7512. int Dir(UINT /*attr*/, LPCTSTR /*lpszWildCard*/)
  7513. {
  7514. ATLASSERT(FALSE); // Not available in CComboBoxEx
  7515. return 0;
  7516. }
  7517. int FindString(int /*nStartAfter*/, LPCTSTR /*lpszString*/) const
  7518. {
  7519. ATLASSERT(FALSE); // Not available in CComboBoxEx; try FindStringExact
  7520. return 0;
  7521. }
  7522. };
  7523. typedef CComboBoxExT<ATL::CWindow> CComboBoxEx;
  7524. ///////////////////////////////////////////////////////////////////////////////
  7525. // CMonthCalendarCtrl
  7526. template <class TBase>
  7527. class CMonthCalendarCtrlT : public TBase
  7528. {
  7529. public:
  7530. // Constructors
  7531. CMonthCalendarCtrlT(HWND hWnd = NULL) : TBase(hWnd)
  7532. { }
  7533. CMonthCalendarCtrlT< TBase >& operator =(HWND hWnd)
  7534. {
  7535. this->m_hWnd = hWnd;
  7536. return *this;
  7537. }
  7538. HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  7539. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  7540. ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  7541. {
  7542. return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  7543. }
  7544. // Attributes
  7545. static LPCTSTR GetWndClassName()
  7546. {
  7547. return MONTHCAL_CLASS;
  7548. }
  7549. COLORREF GetColor(int nColorType) const
  7550. {
  7551. ATLASSERT(::IsWindow(this->m_hWnd));
  7552. return (COLORREF)::SendMessage(this->m_hWnd, MCM_GETCOLOR, nColorType, 0L);
  7553. }
  7554. COLORREF SetColor(int nColorType, COLORREF clr)
  7555. {
  7556. ATLASSERT(::IsWindow(this->m_hWnd));
  7557. return (COLORREF)::SendMessage(this->m_hWnd, MCM_SETCOLOR, nColorType, clr);
  7558. }
  7559. BOOL GetCurSel(LPSYSTEMTIME lpSysTime) const
  7560. {
  7561. ATLASSERT(::IsWindow(this->m_hWnd));
  7562. return (BOOL)::SendMessage(this->m_hWnd, MCM_GETCURSEL, 0, (LPARAM)lpSysTime);
  7563. }
  7564. BOOL SetCurSel(LPSYSTEMTIME lpSysTime)
  7565. {
  7566. ATLASSERT(::IsWindow(this->m_hWnd));
  7567. return (BOOL)::SendMessage(this->m_hWnd, MCM_SETCURSEL, 0, (LPARAM)lpSysTime);
  7568. }
  7569. int GetFirstDayOfWeek(BOOL* pbLocaleVal = NULL) const
  7570. {
  7571. ATLASSERT(::IsWindow(this->m_hWnd));
  7572. DWORD dwRet = (DWORD)::SendMessage(this->m_hWnd, MCM_GETFIRSTDAYOFWEEK, 0, 0L);
  7573. if(pbLocaleVal != NULL)
  7574. *pbLocaleVal = (BOOL)HIWORD(dwRet);
  7575. return (int)(short)LOWORD(dwRet);
  7576. }
  7577. int SetFirstDayOfWeek(int nDay, BOOL* pbLocaleVal = NULL)
  7578. {
  7579. ATLASSERT(::IsWindow(this->m_hWnd));
  7580. DWORD dwRet = (DWORD)::SendMessage(this->m_hWnd, MCM_SETFIRSTDAYOFWEEK, 0, nDay);
  7581. if(pbLocaleVal != NULL)
  7582. *pbLocaleVal = (BOOL)HIWORD(dwRet);
  7583. return (int)(short)LOWORD(dwRet);
  7584. }
  7585. int GetMaxSelCount() const
  7586. {
  7587. ATLASSERT(::IsWindow(this->m_hWnd));
  7588. return (int)::SendMessage(this->m_hWnd, MCM_GETMAXSELCOUNT, 0, 0L);
  7589. }
  7590. BOOL SetMaxSelCount(int nMax)
  7591. {
  7592. ATLASSERT(::IsWindow(this->m_hWnd));
  7593. return (BOOL)::SendMessage(this->m_hWnd, MCM_SETMAXSELCOUNT, nMax, 0L);
  7594. }
  7595. int GetMonthDelta() const
  7596. {
  7597. ATLASSERT(::IsWindow(this->m_hWnd));
  7598. return (int)::SendMessage(this->m_hWnd, MCM_GETMONTHDELTA, 0, 0L);
  7599. }
  7600. int SetMonthDelta(int nDelta)
  7601. {
  7602. ATLASSERT(::IsWindow(this->m_hWnd));
  7603. return (int)::SendMessage(this->m_hWnd, MCM_SETMONTHDELTA, nDelta, 0L);
  7604. }
  7605. DWORD GetRange(LPSYSTEMTIME lprgSysTimeArray) const
  7606. {
  7607. ATLASSERT(::IsWindow(this->m_hWnd));
  7608. return (DWORD)::SendMessage(this->m_hWnd, MCM_GETRANGE, 0, (LPARAM)lprgSysTimeArray);
  7609. }
  7610. BOOL SetRange(DWORD dwFlags, LPSYSTEMTIME lprgSysTimeArray)
  7611. {
  7612. ATLASSERT(::IsWindow(this->m_hWnd));
  7613. return (BOOL)::SendMessage(this->m_hWnd, MCM_SETRANGE, dwFlags, (LPARAM)lprgSysTimeArray);
  7614. }
  7615. BOOL GetSelRange(LPSYSTEMTIME lprgSysTimeArray) const
  7616. {
  7617. ATLASSERT(::IsWindow(this->m_hWnd));
  7618. return (BOOL)::SendMessage(this->m_hWnd, MCM_GETSELRANGE, 0, (LPARAM)lprgSysTimeArray);
  7619. }
  7620. BOOL SetSelRange(LPSYSTEMTIME lprgSysTimeArray)
  7621. {
  7622. ATLASSERT(::IsWindow(this->m_hWnd));
  7623. return (BOOL)::SendMessage(this->m_hWnd, MCM_SETSELRANGE, 0, (LPARAM)lprgSysTimeArray);
  7624. }
  7625. BOOL GetToday(LPSYSTEMTIME lpSysTime) const
  7626. {
  7627. ATLASSERT(::IsWindow(this->m_hWnd));
  7628. return (BOOL)::SendMessage(this->m_hWnd, MCM_GETTODAY, 0, (LPARAM)lpSysTime);
  7629. }
  7630. void SetToday(LPSYSTEMTIME lpSysTime)
  7631. {
  7632. ATLASSERT(::IsWindow(this->m_hWnd));
  7633. ::SendMessage(this->m_hWnd, MCM_SETTODAY, 0, (LPARAM)lpSysTime);
  7634. }
  7635. BOOL GetMinReqRect(LPRECT lpRectInfo) const
  7636. {
  7637. ATLASSERT(::IsWindow(this->m_hWnd));
  7638. return (BOOL)::SendMessage(this->m_hWnd, MCM_GETMINREQRECT, 0, (LPARAM)lpRectInfo);
  7639. }
  7640. int GetMaxTodayWidth() const
  7641. {
  7642. ATLASSERT(::IsWindow(this->m_hWnd));
  7643. return (int)::SendMessage(this->m_hWnd, MCM_GETMAXTODAYWIDTH, 0, 0L);
  7644. }
  7645. BOOL GetUnicodeFormat() const
  7646. {
  7647. ATLASSERT(::IsWindow(this->m_hWnd));
  7648. return (BOOL)::SendMessage(this->m_hWnd, MCM_GETUNICODEFORMAT, 0, 0L);
  7649. }
  7650. BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
  7651. {
  7652. ATLASSERT(::IsWindow(this->m_hWnd));
  7653. return (BOOL)::SendMessage(this->m_hWnd, MCM_SETUNICODEFORMAT, bUnicode, 0L);
  7654. }
  7655. #if defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN)
  7656. DWORD GetCurrentView() const
  7657. {
  7658. ATLASSERT(::IsWindow(this->m_hWnd));
  7659. return (DWORD)::SendMessage(this->m_hWnd, MCM_GETCURRENTVIEW, 0, 0L);
  7660. }
  7661. BOOL SetCurrentView(DWORD dwView)
  7662. {
  7663. ATLASSERT(::IsWindow(this->m_hWnd));
  7664. return (BOOL)::SendMessage(this->m_hWnd, MCM_SETCURRENTVIEW, 0, dwView);
  7665. }
  7666. DWORD GetCalendarCount() const
  7667. {
  7668. ATLASSERT(::IsWindow(this->m_hWnd));
  7669. return (DWORD)::SendMessage(this->m_hWnd, MCM_GETCALENDARCOUNT, 0, 0L);
  7670. }
  7671. BOOL GetCalendarGridInfo(PMCGRIDINFO pGridInfo) const
  7672. {
  7673. ATLASSERT(::IsWindow(this->m_hWnd));
  7674. return (BOOL)::SendMessage(this->m_hWnd, MCM_GETCALENDARGRIDINFO, 0, (LPARAM)pGridInfo);
  7675. }
  7676. CALID GetCALID() const
  7677. {
  7678. ATLASSERT(::IsWindow(this->m_hWnd));
  7679. return (CALID)::SendMessage(this->m_hWnd, MCM_GETCALID, 0, 0L);
  7680. }
  7681. void SetCALID(CALID calid)
  7682. {
  7683. ATLASSERT(::IsWindow(this->m_hWnd));
  7684. ::SendMessage(this->m_hWnd, MCM_SETCALID, (LPARAM)calid, 0L);
  7685. }
  7686. int GetCalendarBorder() const
  7687. {
  7688. ATLASSERT(::IsWindow(this->m_hWnd));
  7689. return (int)::SendMessage(this->m_hWnd, MCM_GETCALENDARBORDER, 0, 0L);
  7690. }
  7691. void SetCalendarBorder(int cxyBorder, BOOL bSet = TRUE)
  7692. {
  7693. ATLASSERT(::IsWindow(this->m_hWnd));
  7694. ::SendMessage(this->m_hWnd, MCM_SETCALENDARBORDER, (WPARAM)bSet, (LPARAM)cxyBorder);
  7695. }
  7696. #endif // defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN)
  7697. // Operations
  7698. int GetMonthRange(DWORD dwFlags, LPSYSTEMTIME lprgSysTimeArray) const
  7699. {
  7700. ATLASSERT(::IsWindow(this->m_hWnd));
  7701. return (int)::SendMessage(this->m_hWnd, MCM_GETMONTHRANGE, dwFlags, (LPARAM)lprgSysTimeArray);
  7702. }
  7703. BOOL SetDayState(int nMonths, LPMONTHDAYSTATE lpDayStateArray)
  7704. {
  7705. ATLASSERT(::IsWindow(this->m_hWnd));
  7706. return (BOOL)::SendMessage(this->m_hWnd, MCM_SETDAYSTATE, nMonths, (LPARAM)lpDayStateArray);
  7707. }
  7708. DWORD HitTest(PMCHITTESTINFO pMCHitTest) const
  7709. {
  7710. ATLASSERT(::IsWindow(this->m_hWnd));
  7711. return (DWORD)::SendMessage(this->m_hWnd, MCM_HITTEST, 0, (LPARAM)pMCHitTest);
  7712. }
  7713. #if defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN)
  7714. void SizeRectToMin(LPRECT lpRect)
  7715. {
  7716. ATLASSERT(::IsWindow(this->m_hWnd));
  7717. ::SendMessage(this->m_hWnd, MCM_SIZERECTTOMIN, 0, (LPARAM)lpRect);
  7718. }
  7719. #endif // defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN)
  7720. };
  7721. typedef CMonthCalendarCtrlT<ATL::CWindow> CMonthCalendarCtrl;
  7722. ///////////////////////////////////////////////////////////////////////////////
  7723. // CDateTimePickerCtrl
  7724. template <class TBase>
  7725. class CDateTimePickerCtrlT : public TBase
  7726. {
  7727. public:
  7728. // Constructors
  7729. CDateTimePickerCtrlT(HWND hWnd = NULL) : TBase(hWnd)
  7730. { }
  7731. CDateTimePickerCtrlT< TBase >& operator =(HWND hWnd)
  7732. {
  7733. this->m_hWnd = hWnd;
  7734. return *this;
  7735. }
  7736. HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  7737. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  7738. ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  7739. {
  7740. return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  7741. }
  7742. // Operations
  7743. static LPCTSTR GetWndClassName()
  7744. {
  7745. return DATETIMEPICK_CLASS;
  7746. }
  7747. BOOL SetFormat(LPCTSTR lpszFormat)
  7748. {
  7749. ATLASSERT(::IsWindow(this->m_hWnd));
  7750. return (BOOL)::SendMessage(this->m_hWnd, DTM_SETFORMAT, 0, (LPARAM)lpszFormat);
  7751. }
  7752. COLORREF GetMonthCalColor(int nColorType) const
  7753. {
  7754. ATLASSERT(::IsWindow(this->m_hWnd));
  7755. return (COLORREF)::SendMessage(this->m_hWnd, DTM_GETMCCOLOR, nColorType, 0L);
  7756. }
  7757. COLORREF SetMonthCalColor(int nColorType, COLORREF clr)
  7758. {
  7759. ATLASSERT(::IsWindow(this->m_hWnd));
  7760. return (COLORREF)::SendMessage(this->m_hWnd, DTM_SETMCCOLOR, nColorType, clr);
  7761. }
  7762. DWORD GetRange(LPSYSTEMTIME lpSysTimeArray) const
  7763. {
  7764. ATLASSERT(::IsWindow(this->m_hWnd));
  7765. return (DWORD)::SendMessage(this->m_hWnd, DTM_GETRANGE, 0, (LPARAM)lpSysTimeArray);
  7766. }
  7767. BOOL SetRange(DWORD dwFlags, LPSYSTEMTIME lpSysTimeArray)
  7768. {
  7769. ATLASSERT(::IsWindow(this->m_hWnd));
  7770. return (BOOL)::SendMessage(this->m_hWnd, DTM_SETRANGE, dwFlags, (LPARAM)lpSysTimeArray);
  7771. }
  7772. DWORD GetSystemTime(LPSYSTEMTIME lpSysTime) const
  7773. {
  7774. ATLASSERT(::IsWindow(this->m_hWnd));
  7775. return (DWORD)::SendMessage(this->m_hWnd, DTM_GETSYSTEMTIME, 0, (LPARAM)lpSysTime);
  7776. }
  7777. BOOL SetSystemTime(DWORD dwFlags, LPSYSTEMTIME lpSysTime)
  7778. {
  7779. ATLASSERT(::IsWindow(this->m_hWnd));
  7780. return (BOOL)::SendMessage(this->m_hWnd, DTM_SETSYSTEMTIME, dwFlags, (LPARAM)lpSysTime);
  7781. }
  7782. CMonthCalendarCtrl GetMonthCal() const
  7783. {
  7784. ATLASSERT(::IsWindow(this->m_hWnd));
  7785. return CMonthCalendarCtrl((HWND)::SendMessage(this->m_hWnd, DTM_GETMONTHCAL, 0, 0L));
  7786. }
  7787. CFontHandle GetMonthCalFont() const
  7788. {
  7789. ATLASSERT(::IsWindow(this->m_hWnd));
  7790. return CFontHandle((HFONT)::SendMessage(this->m_hWnd, DTM_GETMCFONT, 0, 0L));
  7791. }
  7792. void SetMonthCalFont(HFONT hFont, BOOL bRedraw = TRUE)
  7793. {
  7794. ATLASSERT(::IsWindow(this->m_hWnd));
  7795. ::SendMessage(this->m_hWnd, DTM_SETMCFONT, (WPARAM)hFont, MAKELPARAM(bRedraw, 0));
  7796. }
  7797. #if defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN)
  7798. DWORD GetMonthCalStyle() const
  7799. {
  7800. ATLASSERT(::IsWindow(this->m_hWnd));
  7801. return (DWORD)::SendMessage(this->m_hWnd, DTM_GETMCSTYLE, 0, 0L);
  7802. }
  7803. DWORD SetMonthCalStyle(DWORD dwStyle)
  7804. {
  7805. ATLASSERT(::IsWindow(this->m_hWnd));
  7806. return (DWORD)::SendMessage(this->m_hWnd, DTM_SETMCSTYLE, 0, (LPARAM)dwStyle);
  7807. }
  7808. void GetDateTimePickerInfo(LPDATETIMEPICKERINFO lpPickerInfo) const
  7809. {
  7810. ATLASSERT(::IsWindow(this->m_hWnd));
  7811. ::SendMessage(this->m_hWnd, DTM_GETDATETIMEPICKERINFO, 0, (LPARAM)lpPickerInfo);
  7812. }
  7813. BOOL GetIdealSize(LPSIZE lpSize) const
  7814. {
  7815. ATLASSERT(::IsWindow(this->m_hWnd));
  7816. return (BOOL)::SendMessage(this->m_hWnd, DTM_GETIDEALSIZE, 0, (LPARAM)lpSize);
  7817. }
  7818. void CloseMonthCal()
  7819. {
  7820. ATLASSERT(::IsWindow(this->m_hWnd));
  7821. ::SendMessage(this->m_hWnd, DTM_CLOSEMONTHCAL, 0, 0L);
  7822. }
  7823. #endif // defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN)
  7824. };
  7825. typedef CDateTimePickerCtrlT<ATL::CWindow> CDateTimePickerCtrl;
  7826. ///////////////////////////////////////////////////////////////////////////////
  7827. // CFlatScrollBarImpl - support for flat scroll bars
  7828. template <class T>
  7829. class CFlatScrollBarImpl
  7830. {
  7831. public:
  7832. // Initialization
  7833. BOOL FlatSB_Initialize()
  7834. {
  7835. T* pT = static_cast<T*>(this);
  7836. ATLASSERT(::IsWindow(pT->m_hWnd));
  7837. return ::InitializeFlatSB(pT->m_hWnd);
  7838. }
  7839. HRESULT FlatSB_Uninitialize()
  7840. {
  7841. T* pT = static_cast<T*>(this);
  7842. ATLASSERT(::IsWindow(pT->m_hWnd));
  7843. return ::UninitializeFlatSB(pT->m_hWnd);
  7844. }
  7845. // Flat scroll bar properties
  7846. BOOL FlatSB_GetScrollProp(UINT uIndex, LPINT lpnValue) const
  7847. {
  7848. const T* pT = static_cast<const T*>(this);
  7849. ATLASSERT(::IsWindow(pT->m_hWnd));
  7850. return ::FlatSB_GetScrollProp(pT->m_hWnd, uIndex, lpnValue);
  7851. }
  7852. BOOL FlatSB_SetScrollProp(UINT uIndex, int nValue, BOOL bRedraw = TRUE)
  7853. {
  7854. T* pT = static_cast<T*>(this);
  7855. ATLASSERT(::IsWindow(pT->m_hWnd));
  7856. return ::FlatSB_SetScrollProp(pT->m_hWnd, uIndex, nValue, bRedraw);
  7857. }
  7858. // Attributes
  7859. int FlatSB_GetScrollPos(int nBar) const
  7860. {
  7861. const T* pT = static_cast<const T*>(this);
  7862. ATLASSERT(::IsWindow(pT->m_hWnd));
  7863. return ::FlatSB_GetScrollPos(pT->m_hWnd, nBar);
  7864. }
  7865. int FlatSB_SetScrollPos(int nBar, int nPos, BOOL bRedraw = TRUE)
  7866. {
  7867. T* pT = static_cast<T*>(this);
  7868. ATLASSERT(::IsWindow(pT->m_hWnd));
  7869. return ::FlatSB_SetScrollPos(pT->m_hWnd, nBar, nPos, bRedraw);
  7870. }
  7871. BOOL FlatSB_GetScrollRange(int nBar, LPINT lpMinPos, LPINT lpMaxPos) const
  7872. {
  7873. const T* pT = static_cast<const T*>(this);
  7874. ATLASSERT(::IsWindow(pT->m_hWnd));
  7875. return ::FlatSB_GetScrollRange(pT->m_hWnd, nBar, lpMinPos, lpMaxPos);
  7876. }
  7877. BOOL FlatSB_SetScrollRange(int nBar, int nMinPos, int nMaxPos, BOOL bRedraw = TRUE)
  7878. {
  7879. T* pT = static_cast<T*>(this);
  7880. ATLASSERT(::IsWindow(pT->m_hWnd));
  7881. return ::FlatSB_SetScrollRange(pT->m_hWnd, nBar, nMinPos, nMaxPos, bRedraw);
  7882. }
  7883. BOOL FlatSB_GetScrollInfo(int nBar, LPSCROLLINFO lpScrollInfo) const
  7884. {
  7885. const T* pT = static_cast<const T*>(this);
  7886. ATLASSERT(::IsWindow(pT->m_hWnd));
  7887. return ::FlatSB_GetScrollInfo(pT->m_hWnd, nBar, lpScrollInfo);
  7888. }
  7889. int FlatSB_SetScrollInfo(int nBar, LPSCROLLINFO lpScrollInfo, BOOL bRedraw = TRUE)
  7890. {
  7891. T* pT = static_cast<T*>(this);
  7892. ATLASSERT(::IsWindow(pT->m_hWnd));
  7893. return ::FlatSB_SetScrollInfo(pT->m_hWnd, nBar, lpScrollInfo, bRedraw);
  7894. }
  7895. // Operations
  7896. BOOL FlatSB_ShowScrollBar(UINT nBar, BOOL bShow = TRUE)
  7897. {
  7898. T* pT = static_cast<T*>(this);
  7899. ATLASSERT(::IsWindow(pT->m_hWnd));
  7900. return ::FlatSB_ShowScrollBar(pT->m_hWnd, nBar, bShow);
  7901. }
  7902. BOOL FlatSB_EnableScrollBar(UINT uSBFlags, UINT uArrowFlags = ESB_ENABLE_BOTH)
  7903. {
  7904. T* pT = static_cast<T*>(this);
  7905. ATLASSERT(::IsWindow(pT->m_hWnd));
  7906. return ::FlatSB_EnableScrollBar(pT->m_hWnd, uSBFlags, uArrowFlags);
  7907. }
  7908. };
  7909. template <class TBase>
  7910. class CFlatScrollBarT : public TBase, public CFlatScrollBarImpl<CFlatScrollBarT< TBase > >
  7911. {
  7912. public:
  7913. CFlatScrollBarT(HWND hWnd = NULL) : TBase(hWnd)
  7914. { }
  7915. CFlatScrollBarT< TBase >& operator =(HWND hWnd)
  7916. {
  7917. this->m_hWnd = hWnd;
  7918. return *this;
  7919. }
  7920. };
  7921. typedef CFlatScrollBarT<ATL::CWindow> CFlatScrollBar;
  7922. ///////////////////////////////////////////////////////////////////////////////
  7923. // CIPAddressCtrl
  7924. template <class TBase>
  7925. class CIPAddressCtrlT : public TBase
  7926. {
  7927. public:
  7928. // Constructors
  7929. CIPAddressCtrlT(HWND hWnd = NULL) : TBase(hWnd)
  7930. { }
  7931. CIPAddressCtrlT< TBase >& operator =(HWND hWnd)
  7932. {
  7933. this->m_hWnd = hWnd;
  7934. return *this;
  7935. }
  7936. HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  7937. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  7938. ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  7939. {
  7940. return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  7941. }
  7942. // Atteributes
  7943. static LPCTSTR GetWndClassName()
  7944. {
  7945. return WC_IPADDRESS;
  7946. }
  7947. BOOL IsBlank() const
  7948. {
  7949. ATLASSERT(::IsWindow(this->m_hWnd));
  7950. return (BOOL)::SendMessage(this->m_hWnd, IPM_ISBLANK, 0, 0L);
  7951. }
  7952. int GetAddress(LPDWORD lpdwAddress) const
  7953. {
  7954. ATLASSERT(::IsWindow(this->m_hWnd));
  7955. return (int)::SendMessage(this->m_hWnd, IPM_GETADDRESS, 0, (LPARAM)lpdwAddress);
  7956. }
  7957. void SetAddress(DWORD dwAddress)
  7958. {
  7959. ATLASSERT(::IsWindow(this->m_hWnd));
  7960. ::SendMessage(this->m_hWnd, IPM_SETADDRESS, 0, dwAddress);
  7961. }
  7962. void ClearAddress()
  7963. {
  7964. ATLASSERT(::IsWindow(this->m_hWnd));
  7965. ::SendMessage(this->m_hWnd, IPM_CLEARADDRESS, 0, 0L);
  7966. }
  7967. void SetRange(int nField, WORD wRange)
  7968. {
  7969. ATLASSERT(::IsWindow(this->m_hWnd));
  7970. ::SendMessage(this->m_hWnd, IPM_SETRANGE, nField, wRange);
  7971. }
  7972. void SetRange(int nField, BYTE nMin, BYTE nMax)
  7973. {
  7974. ATLASSERT(::IsWindow(this->m_hWnd));
  7975. ::SendMessage(this->m_hWnd, IPM_SETRANGE, nField, MAKEIPRANGE(nMin, nMax));
  7976. }
  7977. void SetFocus(int nField)
  7978. {
  7979. ATLASSERT(::IsWindow(this->m_hWnd));
  7980. ::SendMessage(this->m_hWnd, IPM_SETFOCUS, nField, 0L);
  7981. }
  7982. };
  7983. typedef CIPAddressCtrlT<ATL::CWindow> CIPAddressCtrl;
  7984. ///////////////////////////////////////////////////////////////////////////////
  7985. // CPagerCtrl
  7986. template <class TBase>
  7987. class CPagerCtrlT : public TBase
  7988. {
  7989. public:
  7990. // Constructors
  7991. CPagerCtrlT(HWND hWnd = NULL) : TBase(hWnd)
  7992. { }
  7993. CPagerCtrlT< TBase >& operator =(HWND hWnd)
  7994. {
  7995. this->m_hWnd = hWnd;
  7996. return *this;
  7997. }
  7998. HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  7999. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  8000. ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  8001. {
  8002. return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  8003. }
  8004. // Attributes
  8005. static LPCTSTR GetWndClassName()
  8006. {
  8007. return WC_PAGESCROLLER;
  8008. }
  8009. int GetButtonSize() const
  8010. {
  8011. ATLASSERT(::IsWindow(this->m_hWnd));
  8012. return (int)::SendMessage(this->m_hWnd, PGM_GETBUTTONSIZE, 0, 0L);
  8013. }
  8014. int SetButtonSize(int nButtonSize)
  8015. {
  8016. ATLASSERT(::IsWindow(this->m_hWnd));
  8017. return (int)::SendMessage(this->m_hWnd, PGM_SETBUTTONSIZE, 0, nButtonSize);
  8018. }
  8019. DWORD GetButtonState(int nButton) const
  8020. {
  8021. ATLASSERT(::IsWindow(this->m_hWnd));
  8022. ATLASSERT((nButton == PGB_TOPORLEFT) || (nButton == PGB_BOTTOMORRIGHT));
  8023. return (DWORD)::SendMessage(this->m_hWnd, PGM_GETBUTTONSTATE, 0, nButton);
  8024. }
  8025. COLORREF GetBkColor() const
  8026. {
  8027. ATLASSERT(::IsWindow(this->m_hWnd));
  8028. return (COLORREF)::SendMessage(this->m_hWnd, PGM_GETBKCOLOR, 0, 0L);
  8029. }
  8030. COLORREF SetBkColor(COLORREF clrBk)
  8031. {
  8032. ATLASSERT(::IsWindow(this->m_hWnd));
  8033. return (COLORREF)::SendMessage(this->m_hWnd, PGM_SETBKCOLOR, 0, (LPARAM)clrBk);
  8034. }
  8035. int GetBorder() const
  8036. {
  8037. ATLASSERT(::IsWindow(this->m_hWnd));
  8038. return (int)::SendMessage(this->m_hWnd, PGM_GETBORDER, 0, 0L);
  8039. }
  8040. int SetBorder(int nBorderSize)
  8041. {
  8042. ATLASSERT(::IsWindow(this->m_hWnd));
  8043. return (int)::SendMessage(this->m_hWnd, PGM_SETBORDER, 0, nBorderSize);
  8044. }
  8045. int GetPos() const
  8046. {
  8047. ATLASSERT(::IsWindow(this->m_hWnd));
  8048. return (int)::SendMessage(this->m_hWnd, PGM_GETPOS, 0, 0L);
  8049. }
  8050. int SetPos(int nPos)
  8051. {
  8052. ATLASSERT(::IsWindow(this->m_hWnd));
  8053. return (int)::SendMessage(this->m_hWnd, PGM_SETPOS, 0, nPos);
  8054. }
  8055. // Operations
  8056. void SetChild(HWND hWndChild)
  8057. {
  8058. ATLASSERT(::IsWindow(this->m_hWnd));
  8059. ::SendMessage(this->m_hWnd, PGM_SETCHILD, 0, (LPARAM)hWndChild);
  8060. }
  8061. void ForwardMouse(BOOL bForward = TRUE)
  8062. {
  8063. ATLASSERT(::IsWindow(this->m_hWnd));
  8064. ::SendMessage(this->m_hWnd, PGM_FORWARDMOUSE, bForward, 0L);
  8065. }
  8066. void RecalcSize()
  8067. {
  8068. ATLASSERT(::IsWindow(this->m_hWnd));
  8069. ::SendMessage(this->m_hWnd, PGM_RECALCSIZE, 0, 0L);
  8070. }
  8071. void GetDropTarget(IDropTarget** ppDropTarget)
  8072. {
  8073. ATLASSERT(::IsWindow(this->m_hWnd));
  8074. ATLASSERT(ppDropTarget != NULL);
  8075. ::SendMessage(this->m_hWnd, PGM_GETDROPTARGET, 0, (LPARAM)ppDropTarget);
  8076. }
  8077. };
  8078. typedef CPagerCtrlT<ATL::CWindow> CPagerCtrl;
  8079. ///////////////////////////////////////////////////////////////////////////////
  8080. // CLinkCtrl - Windows SYSLINK control
  8081. template <class TBase>
  8082. class CLinkCtrlT : public TBase
  8083. {
  8084. public:
  8085. // Constructors
  8086. CLinkCtrlT(HWND hWnd = NULL) : TBase(hWnd)
  8087. { }
  8088. CLinkCtrlT< TBase >& operator =(HWND hWnd)
  8089. {
  8090. this->m_hWnd = hWnd;
  8091. return *this;
  8092. }
  8093. HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
  8094. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  8095. ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
  8096. {
  8097. return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
  8098. }
  8099. // Attributes
  8100. static LPCTSTR GetWndClassName()
  8101. {
  8102. #ifdef _UNICODE
  8103. return WC_LINK;
  8104. #else // !_UNICODE
  8105. return "SysLink";
  8106. #endif // !_UNICODE
  8107. }
  8108. int GetIdealHeight(int cxMaxWidth = 0) const
  8109. {
  8110. ATLASSERT(::IsWindow(this->m_hWnd));
  8111. return (int)::SendMessage(this->m_hWnd, LM_GETIDEALHEIGHT, cxMaxWidth, 0L);
  8112. }
  8113. BOOL GetItem(PLITEM pLItem) const
  8114. {
  8115. ATLASSERT(::IsWindow(this->m_hWnd));
  8116. return (BOOL)::SendMessage(this->m_hWnd, LM_GETITEM, 0, (LPARAM)pLItem);
  8117. }
  8118. BOOL SetItem(PLITEM pLItem)
  8119. {
  8120. ATLASSERT(::IsWindow(this->m_hWnd));
  8121. return (BOOL)::SendMessage(this->m_hWnd, LM_SETITEM, 0, (LPARAM)pLItem);
  8122. }
  8123. // Vista only
  8124. int GetIdealSize(SIZE& size, int cxMaxWidth = 0) const
  8125. {
  8126. ATLASSERT(::IsWindow(this->m_hWnd));
  8127. return (int)::SendMessage(this->m_hWnd, LM_GETIDEALSIZE, cxMaxWidth, (LPARAM)&size);
  8128. }
  8129. // Operations
  8130. BOOL HitTest(PLHITTESTINFO pLHitTestInfo) const
  8131. {
  8132. ATLASSERT(::IsWindow(this->m_hWnd));
  8133. return (BOOL)::SendMessage(this->m_hWnd, LM_HITTEST, 0, (LPARAM)pLHitTestInfo);
  8134. }
  8135. };
  8136. typedef CLinkCtrlT<ATL::CWindow> CLinkCtrl;
  8137. ///////////////////////////////////////////////////////////////////////////////
  8138. // CCustomDraw - MI class for custom-draw support
  8139. template <class T>
  8140. class CCustomDraw
  8141. {
  8142. public:
  8143. // Message map and handlers
  8144. BEGIN_MSG_MAP(CCustomDraw< T >)
  8145. NOTIFY_CODE_HANDLER(NM_CUSTOMDRAW, OnCustomDraw)
  8146. ALT_MSG_MAP(1)
  8147. REFLECTED_NOTIFY_CODE_HANDLER(NM_CUSTOMDRAW, OnCustomDraw)
  8148. END_MSG_MAP()
  8149. // message handler
  8150. LRESULT OnCustomDraw(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
  8151. {
  8152. T* pT = static_cast<T*>(this);
  8153. pT->SetMsgHandled(TRUE);
  8154. LPNMCUSTOMDRAW lpNMCustomDraw = (LPNMCUSTOMDRAW)pnmh;
  8155. DWORD dwRet = 0;
  8156. switch(lpNMCustomDraw->dwDrawStage)
  8157. {
  8158. case CDDS_PREPAINT:
  8159. dwRet = pT->OnPrePaint(idCtrl, lpNMCustomDraw);
  8160. break;
  8161. case CDDS_POSTPAINT:
  8162. dwRet = pT->OnPostPaint(idCtrl, lpNMCustomDraw);
  8163. break;
  8164. case CDDS_PREERASE:
  8165. dwRet = pT->OnPreErase(idCtrl, lpNMCustomDraw);
  8166. break;
  8167. case CDDS_POSTERASE:
  8168. dwRet = pT->OnPostErase(idCtrl, lpNMCustomDraw);
  8169. break;
  8170. case CDDS_ITEMPREPAINT:
  8171. dwRet = pT->OnItemPrePaint(idCtrl, lpNMCustomDraw);
  8172. break;
  8173. case CDDS_ITEMPOSTPAINT:
  8174. dwRet = pT->OnItemPostPaint(idCtrl, lpNMCustomDraw);
  8175. break;
  8176. case CDDS_ITEMPREERASE:
  8177. dwRet = pT->OnItemPreErase(idCtrl, lpNMCustomDraw);
  8178. break;
  8179. case CDDS_ITEMPOSTERASE:
  8180. dwRet = pT->OnItemPostErase(idCtrl, lpNMCustomDraw);
  8181. break;
  8182. case (CDDS_ITEMPREPAINT | CDDS_SUBITEM):
  8183. dwRet = pT->OnSubItemPrePaint(idCtrl, lpNMCustomDraw);
  8184. break;
  8185. default:
  8186. pT->SetMsgHandled(FALSE);
  8187. break;
  8188. }
  8189. bHandled = pT->IsMsgHandled();
  8190. return dwRet;
  8191. }
  8192. // Overrideables
  8193. DWORD OnPrePaint(int /*idCtrl*/, LPNMCUSTOMDRAW /*lpNMCustomDraw*/)
  8194. {
  8195. return CDRF_DODEFAULT;
  8196. }
  8197. DWORD OnPostPaint(int /*idCtrl*/, LPNMCUSTOMDRAW /*lpNMCustomDraw*/)
  8198. {
  8199. return CDRF_DODEFAULT;
  8200. }
  8201. DWORD OnPreErase(int /*idCtrl*/, LPNMCUSTOMDRAW /*lpNMCustomDraw*/)
  8202. {
  8203. return CDRF_DODEFAULT;
  8204. }
  8205. DWORD OnPostErase(int /*idCtrl*/, LPNMCUSTOMDRAW /*lpNMCustomDraw*/)
  8206. {
  8207. return CDRF_DODEFAULT;
  8208. }
  8209. DWORD OnItemPrePaint(int /*idCtrl*/, LPNMCUSTOMDRAW /*lpNMCustomDraw*/)
  8210. {
  8211. return CDRF_DODEFAULT;
  8212. }
  8213. DWORD OnItemPostPaint(int /*idCtrl*/, LPNMCUSTOMDRAW /*lpNMCustomDraw*/)
  8214. {
  8215. return CDRF_DODEFAULT;
  8216. }
  8217. DWORD OnItemPreErase(int /*idCtrl*/, LPNMCUSTOMDRAW /*lpNMCustomDraw*/)
  8218. {
  8219. return CDRF_DODEFAULT;
  8220. }
  8221. DWORD OnItemPostErase(int /*idCtrl*/, LPNMCUSTOMDRAW /*lpNMCustomDraw*/)
  8222. {
  8223. return CDRF_DODEFAULT;
  8224. }
  8225. DWORD OnSubItemPrePaint(int /*idCtrl*/, LPNMCUSTOMDRAW /*lpNMCustomDraw*/)
  8226. {
  8227. return CDRF_DODEFAULT;
  8228. }
  8229. };
  8230. } // namespace WTL
  8231. #endif // __ATLCTRLS_H__