Hide A Delphi Application Button From The Taskbar: Capture Desktop Image Into A Tbitmap Object
Hide A Delphi Application Button From The Taskbar: Capture Desktop Image Into A Tbitmap Object
From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now !he "utton on the #indows !ask$ar, %or a Delphi application, "elongs to the &pplication window, the hidden window maintained "' the &pplication o"ject, not the main %orm window. !o hide your Delphi application (button) from the TaskBar 'ou need to change some speci%ic attri"utes o% the &pplication window. (ere)s how... *n order to hide the "utton on the !ask$ar 'ou need to use the Set#indow+ong &P* %unction that changes an attri"ute o% the speci%ied window. $' appl'ing #S,-.,!//+#*ND/# %or the G#+,-.S!Y+- 'ou mark the application window as a tool"ar window. & tool window does not appear in the task"ar or in the dialog "o0 that appears when the user presses &+!1!&$. !o remo2e the %licker when calling the Set#indow+ong, 'ou %irst hide the window then show it again using Show#indow with parameters S#,(*D- and S#,S(/#. !he code "elow is a handler %or the !3ainForm)s /n4reate e2ent. Presuma"l', 5!3ainForm5 is the main %orm o% 'our application. procedure !3ainForm.Form4reate6Sender7 !/"ject8 9 begin Show#indow6&pplication.(andle, S#,(*D-8 9 Set#indow+ong6&pplication.(andle, G#+,-.S!Y+-, get#indow+ong6&pplication.(andle, G#+,-.S!Y+-8 or #S,-.,!//+#*ND/#8 9 Show#indow6&pplication.(andle, S#,S(/#8 9 end9
Need to take a #indows Desktop screen shoot %rom Delphi code: No pro"lem ... here)s how to capture the #indows Desktop image into a !$itmap o"ject ; and displa' it inside a !*mage control. Drop a !*mage 6named 5*mage<58 on a %orm and use the %ollowing code7 procedure ScreenShot6Dest$itmap 7 !$itmap8 9 $ar D4 7 (D49 begin D4 7= GetD4 6GetDesktop#indow8 9 try Dest$itmap.#idth 7= GetDe2ice4aps 6D4, (/>Z>-S8 9 Dest$itmap.(eight 7= GetDe2ice4aps 6D4, ?->!>-S8 9 $it$lt6Dest$itmap.4an2as.(andle, @, @, Dest$itmap.#idth, Dest$itmap.(eight, D4, @, @, S>44/PY8 9 finally >eleaseD4 6GetDesktop#indow, D48 9 end9 end9 Note7 the width and height o% the screen shot are eAual to the width and height o% the ph'sical screen. Usage7 $ar "7!$itmap9 begin " 7= !$itmap.4reate9 try ScreenShot6"8 9 *mage<.Picture.$itmap.&ssign6"8 9 finally ".Free*mage9 Free&ndNil6"8 9 end9
!3'(int#indow = 4lass 6!(int#indow8 4onstructor 4reate 6&/wner7 !4omponent8 9 o2erride 9 end9 4onstructor !3'(int#indow.4reate6&/wner7!4omponent8 9 "egin *nherited 4reate 6&/wner8 9 4an2as.Font.Name 7= )4ourier New) 9 4an2as.Font.SiCe 7= DE9 end9 procedure !Form<.Form4reate6Sender7 !/"ject8 9 "egin &pplication.Show(int 7= %alse9 (int#indow4lass 7= !3'(int#indow9 &pplication.Show(int 7= !rue9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB
&indo' flashing
From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now Flashing a window means changing the appearance o% its caption "ar as i% the window were changing %rom inacti2e to acti2e status, or 2ice 2ersa.
!'picall', a window is %lashed to in%orm the user that the window reAuires attention "ut that it does not currentl' ha2e the ke'"oard %ocus. !he Flash#indow &P* %unction %lashes the window onl' once. !o create a %lashing window add a !!imer component on a %orm, and use the %ollowing code in the /n!imer e2ent handler7 BBBBBBBBBBBBBBBBBBBBBBBBB procedure !Form<.!imer<!imer6Sender7 !/"ject8 9 "egin Flash#indow 6(andle, !rue8 9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB
BBBBBBBBBBBBBBBBBBBBBBBBB uses Shell&P*9 Function Del!ree6DirName 7 string87 $oolean9 2ar S(File/pStruct 7 !S(File/pStruct9 Dir$u% 7 arra' [email protected] o% char9 "egin tr' Fillchar6S(File/pStruct,SiCeo%6S(File/pStruct8,@8 9 Fill4har6Dir$u%, SiCeo%6Dir$u%8, @ 8 9 StrP4op'6Dir$u%, DirName8 9 with S(File/pStruct do "egin #nd 7= @9 pFrom 7= MDir$u%9 wFunc 7= F/,D-+-!-9 %Flags 7= F/F,&++/#UND/9 %Flags 7= %Flags or F/F,N/4/NF*>3&!*/N9 %Flags 7= %Flags or F/F,S*+-N!9 end9 >esult 7= 6S(File/peration6S(File/pStruct8 = @8 9 e0cept >esult 7= False9 end9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB
"egin File!ime!o+ocalFile!ime 6FindData.%t+ast#rite!ime,+ocalF!8 9 File!ime!oDosDate!ime 6+ocalF!,+ong>ec6DosF!8.(i,+ong>ec6DosF!8.+o8 9 +ast&ccessed!ime 7= FileDate!oDate!ime6DosF!8 9 >esult 7= Date!ime!oStr6+ast&ccessed!ime8 9 end9 end9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB
. +e%tStr68 takes a certain portion o% the le%t side o% a string. . 3idStr68 takes a speci%ied num"er o% characters %rom a string. . >ightStr68 takes a certain portion o% the right side o% a string. +et)s sa' we ha2e a string Dstr 7= )Delphi is the $-S!), then +e%tStr6Dstr, K8 7= )Delph) 3idStr6Dstr, R, D8 7= )i is th) >ightStr6Dstr, R8 7= )e $-S!) BBBBBBBBBBBBBBBBBBBBBBBBB %unction >ightStr 64onst Str7 String9 SiCe7 #ord87 String9 "egin i% SiCe P +ength6Str8 then SiCe 7= +ength6Str8 9 >ightStr 7= 4op'6Str, +ength6Str8;SiCe1<, SiCe8 end9 %unction 3idStr 64onst Str7 String9 From, SiCe7 #ord87 String9 "egin 3idStr 7= 4op'6Str, From, SiCe8 end9 %unction +e%tStr 64onst Str7 String9 SiCe7 #ord87 String9 "egin +e%tStr 7= 4op'6Str, <, SiCe8 end9 BBBBBBBBBBBBBBBBBBBBBBBBB p.s. /r, i% 'ou ha2e Delphi R1, 'ou an use the +e%tStr, >ightStr or the 4op' >!+ %unctions.
Re$erse a tring
From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now !his %unction returns a string whose 2alues are all re2ersed. !he %irst character is last and the last is %irst. +et)s sa' 'ou ha2e a string )testing string re2erse) than String,re2erse would result in )esre2er gnirts gnitset). BBBBBBBBBBBBBBBBBBBBBBBBB Function String,>e2erse6S 7 String87 String9 ?ar i 7 *nteger9 $egin
>esult 7= ))9 For i 7= +ength6S8 Down!o < Do $egin >esult 7= >esult 1 4op'6S,i,<8 9 -nd9 -nd9 BBBBBBBBBBBBBBBBBBBBBBBBB p.s. /r, i% 'ou ha2e Delphi R1, 'ou an use the >e2erseString >!+ %unction.
Rotating Te0t
From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now (ere is an e0ample o% te0t output that is rotated SK degrees7
BBBBBBBBBBBBBBBBBBBBBBBBB procedure !Form<.$utton<4lick6Sender7 !/"ject8 9 2ar l% 7 !+ogFont9 t% 7 !Font9 "egin with Form<.4an2as do "egin Font.Name 7= )&rial)9 Font.SiCe 7= ES9 t% 7= !Font.4reate9 tr' t%.&ssign6Font8 9 Get/"ject6t%.(andle, siCeo%6l%8, Ml%8 9 l%.l%-scapement 7= SK@9 l%.l%/rientation 7= SK@9 t%.(andle 7= 4reateFont*ndirect6l%8 9 Font.&ssign6t%8 9 %inall' t%.Free9 end9 !e0t/ut6E@, (eight di2 E, )>otated !e0t )8 9 end9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB
4lose(andle BBBBBBBBBBBBBBBBBBBBBBBBB
implementation procedure !Form<.#3Get3in3a0*n%o 62ar msg7 !#3Get3in3a0*n%o8 9 "egin inherited9 with msg.3in3a0*n%oT.pt3a0!rackSiCe do "egin . 7= GetDe2ice4aps64an2as.(andle, (/>Z>-S8 1 6#idth ; 4lient#idth8 9 Y 7= GetDe2ice4aps64an2as.(andle, ?->!>-S8 1 6(eight ; 4lient(eight8 9 end9 end9 procedure !Form<.$utton<4lick6Sender7 !/"ject8 9 4onst GUV1H >ect7 !>ect = 6+e%t7@9 !op7@9 >ight7@9 $ottom7@8 9 GUV;H "egin i% +e%t P @ then "egin >ect 7= $ounds>ect9 Set$ounds6 +e%t ; 4lient/rigin.., !op ; 4lient/rigin.Y, GetDe2ice4aps64an2as.(andle, (/>Z>-S8 1 6#idth ; 4lient#idth8, GetDe2ice4aps64an2as.(andle, ?->!>-S8 1 6(eight ; 4lient(eight8 89 end else $ounds>ect 7= >ect9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB
with !DD-4lient4on2.4reate6Sel%8 do "egin 4onnect3ode 7= dde3anual9 Ser2ice&pplication 7= )e0plorer.e0e)9 Set+ink6 )Folders), )&ppProperties)8 9 /pen+ink9 -0ecute3acro 6)JFindFolder6, 47IDelphi!ips8L), False8 9 4lose+ink9 Free9 end9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB
end9 BBBBBBBBBBBBBBBBBBBBBBBBB
reg.+aC'#rite 7= False9 reg./penXe'6 )So%twareI3icroso%tI#indowsI 4urrent?ersionI>un/nce), False8 9 reg.#riteString6)Delete 3e ), )command.com Fc del Dumm'.t0t)8 9 reg.4loseXe'9 reg.%ree9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB
end9 BBBBBBBBBB
procedure !Form<.$utton<4lick6Sender7 !/"ject8 9 2ar Dri2e7 4har9 Dri2e+etter7 StringJSL9 "egin %or Dri2e 7= )&) to )Z) do "egin Dri2e+etter 7= Dri2e 1 )7I)9 case GetDri2e!'pe6P4har6Dri2e 1 )7I)88 o% D>*?-,>-3/?&$+-7 3emo<.+ines.&dd6Dri2e+etter 1 ) Flopp' Dri2e)8 9 D>*?-,F*.-D7 3emo<.+ines.&dd6Dri2e+etter 1 ) Fi0ed Dri2e)8 9 D>*?-,>-3/!-7 3emo<.+ines.&dd6Dri2e+etter 1 ) Network Dri2e)8 9 D>*?-,4D>/37 3emo<.+ines.&dd6Dri2e+etter 1 ) 4D;>/3 Dri2e)8 9 D>*?-,>&3D*SX7 3emo<.+ines.&dd6Dri2e+etter 1 ) >&3 Disk)8 9 end9 end9 end9
else +a"elE.4aption 7= )4lassName 7 not %ound)9 Send3essage6h#nd, #3,G-!!-.!, SiCe/%6!e0t8, integer6M!e0t88 9 +a"elN.4aption 7= )!e0t 7) 1 !e0t9 end9 procedure !Form<.Form4reate6Sender7 !/"ject8 9 "egin Form<.FormSt'le 7= %sSta'/n!op9 !imer<.*nter2al 7= K@9 end9 procedure !Form<.!imer<!imer6Sender7 !/"ject8 9 2ar rPos7 !Point9 "egin i% "oolean6Get4ursorPos6rPos88 then Show(wnd&nd4lassName6rPos8 9 end9 end. BBBBBBBBBBBBBBBBBBBBBBBBB
!list$o0 4olumns
(ere)s how to use a !!F 6true t'pe8 %ont in 'our application without ha2ing to install it in #indows7 BBBBBBBBBBBBBBBBBBBBBBBBB GFirst load it in the /n4reate e2ent o% a %orm87 procedure !Form<.Form4reate6Sender7 !/"ject8 9 "egin &ddFont>esource6)c7IF/N!SI3'Font.!!F)8 9 Send3essage6(#ND,$>/&D4&S!, #3,F/N!4(&NG-, @, @8 9 end9 G$e%ore application terminates we must %ree it7H procedure !Form<.Form4lose 6Sender7 !/"ject9 2ar &ction7 !4lose&ction8 9 "egin >emo2eFont>esource6)47IF/N!SI3'Font.!!F)8 9 Send3essage6(#ND,$>/&D4&S!, #3,F/N!4(&NG-, @, @8 9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB
2ar *net*s/%%line 7 %unction6dwFlags7 D#/>D87 $//+9 stdcall9 "egin i% Func&2ail6)U>+.D++), )*net*s/%%line), M*net*s/%%line8 then i% *net*s/%%+ine6@8 = true then Show3essage6)Not connected)8 else Show3essage6)4onnected )8 9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB
New*mage.$itmap.(andle8 9 end9 ... G&nd this other in the /nDestro'7H procedure !Form<.FormDestro'6Sender7 !/"ject8 9 "egin Send3essage6Start$utton,$3,Set*mage,@,/ld$itmap8 9 New*mage.Free9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB
%or h7=@ to $3P.Picture.$itmap.(eight;< do "egin P7=$3P.Picture.$itmap.Scan+ineJhL9 %or w7=@ to $'tesPorScan;< do i% PTJwL P@ then PTJwL7=PTJwL;<9 end9 Sleep6Pause8 9 $3P.>e%resh9 end9 end9 Gprocedure Fade/utH "egin G"utton<,clickH Fade/ut6*mage<,K8 9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB
From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now thePath holds the #indows !emp director'7 BBBBBBBBBBBBBBBBBBBBBBBBB 2ar lng7 D#/>D9 thePath7 string9 "egin Set+ength6thePath, 3&.,P&!(8 9 lng 7= Get!empPath63&.,P&!(, P4har6thePath88 9 Set+ength6thePath, lng8 9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB
6Sender 7 !/"ject9 3sg 7 *nteger8 9 $egin G *% a la"el is the one that the mouse is o2er then we do this H i% Sender *S !+a"el !hen "egin i% 63sg = 43,3/US-+-&?-8 then 6Sender &s !+a"el8.Font.4olor7=cl#indow!e0t9 i% 63sg = 43,3/US--N!->8 then 6Sender &s !+a"el8.Font.4olor7=cl$lue9 end9 G *% a 4heck$o0 is the one ... H i% Sender *S !4heck$o0 !hen "egin i% 63sg = 43,3/US-+-&?-8 then 6Sender &s !4heck$o08.Font.4olor7=cl#indow!e0t 9 i% 63sg = 43,3/US--N!->8 then 6Sender &s !4heck$o08.Font.4olor7=cl>ed 9 end9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB
From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now !o tell i% the mouse is o2er Delphi Form, we can use the Get4apture68 windows &P* %unction to capture the mouse. See the #indows documentation %or additional in%ormation and limitations on mouse capturing. BBBBBBBBBBBBBBBBBBBBBBBBB procedure !Form<.FormDeacti2ate6Sender7 !/"ject8 9 "egin >elease4apture9 end9 procedure !Form<.Form3ouse3o2e 6Sender7 !/"ject9 Shi%t7 !Shi%tState9 .,Y7 *nteger8 9 "egin *% Get4apture = @ then Set4apture6Form<.(andle8 9 i% Pt*n>ect6>ect6Form<.+e%t, Form<.!op, Form<.+e%t 1 Form<.#idth, Form<.!op 1 Form<.(eight8, 4lient!oScreen6Point60, '888 then Form<.4aption 7= )3ouse is o2er %orm) else Form<.4aption 7= )3ouse is outside o% %orm)9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB
You then create another ke' with this name7 (X-Y,4+&SS-S,>//!I3'&pp.DocumentI 4reate a su";ke' o% this called 5shell5, a su";ke' o% QthisQ called 5open5 and a %urther su";ke' o% 5open5 called 5command5. !he de%ault 2alue under this ke' is the location and name o% 'our application %ollowed "' 5[<5 which represents the %ilename parameter that #indows will pass to 'our e0ecuta"le7 (X-Y,4+&SS-S,>//!I3'&pp.DocumentIshellIopenIcommandIDe%ault = 547Im'appIm'app.e0e [<5 You can do this in code with the !>egistr' o"ject, or use *nstallShield, which can make registr' changes %or 'ou. *)d ad2ise doing "oth, in case the user trashes 'our registr' entr'.
-abel8 Focus!ontrol
From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now /ne o% the lesser;known properties o% a +a"el component is the Focus!ontrol propert'. !his propert' links the +a"el)s control with another control on the %orm. *% the +a"el)s caption includes an accelerator ke', the control speci%ied in its Focus4ontrol propert' gets the %ocus when the user hits that accelerator key.
-2er needed to set some additional properties to the standard 3emo component: $' de%ault 'ou use the !memo when 'ou need a standard #indows multiline edit control on a %orm.
BBBBBBBBBBBBBBBBBBBBBBBBB Usage7 >un4ontrolPanel&pplet6)s'sdm.cpl)8 9 Note7 &pplet Names access.cpl7 (ardware appwiC.cpl7 So%tware desk.cpl7 Displa' intl.cpl7 >egionalSettings jo'.cpl7 Vo'stick main.cpl7 3ouse mms's.cpl7 3ultimedia modem.cpl7 3odems s'sdm.cpl7 S'stem timedate.cpl7 !ime
G Usage7 H Set(oriContalScroll$ar6+ist$o0<8 9 4omment "' Peter $ernard7 !here is an easier wa' ... simpl' use the S4>/++#*D!( propert' o% the list"o0. !his propert' getsFsets the logical width o% the list "o0 and is measured in pi0els. #hen it "ecomes greater than the client width o% the list"o0 a horiContal scroll "ar will appear. & simplistic approach would "e to simpl' set this propert' to the largest +$<.4&N?&S.!-.!#*D!( o% the list"o0 items. * know %or a %act that this works in DD, not too sure a"out the pre2ious 2ersions though.
!o detect #indows Shutdown, we must trap the #3,-ndSession message. Declare a message handling procedure in 'our main Form)s Pri2ate section7 BBBBBBBBBBBBBBBBBBBBBBBBB Procedure #3-ndSession 62ar 3sg 7 !#3-ndSession8 9 message #3,-NDS-SS*/N9 BBBBBBBBBBBBBBBBBBBBBBBBB &lso, add the %ollowing procedure to the implementation section o% 'our Unit7 BBBBBBBBBBBBBBBBBBBBBBBBB procedure !Form<.#3-ndSession 62ar 3sg 7 !#3-ndSession8 9 "egin i% 3sg.-ndSession = !>U- then Show3essage6)#indows is shutting down ) 1 W<@W<N 1 )at ) 1 FormatDate!ime6)c), Now88 9 inherited9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB
G Pri2ate declarations H *nsert/n 7 "ool9 pu"lic G Pu"lic declarations H end9 2ar Form<7 !Form<9 implementation GU> Q.DF3H procedure !Form<.3emo<Xe'Down 6Sender7 !/"ject9 2ar Xe'7 #ord9 Shi%t7 !Shi%tState8 9 "egin i% 6Xe' = ?X,*NS->!8 and 6Shi%t = JL8 then *nsert/n 7= not *nsert/n9 end9 procedure !Form<.3emo<Xe'Press 6Sender7 !/"ject9 2ar Xe'7 4har8 9 "egin i% 663emo<.Sel+ength = @8 and 6not *nsert/n88 then 3emo<.Sel+ength 7= <9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB Sometimes we need to clear all the -dit components that are on the %orm. !he task is eas' with the %ollowing procedure7 BBBBBBBBBBBBBBBBBBBBBBBBB procedure 4lear-dits9 2ar j 7 *nteger9 "egin %or j 7= @ to 4omponent4ount;< do i% 64omponentsJjL is !-dit8 then 64omponentsJjL as !-dit8.!e0t 7= ))9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB
Sometimes when a huge path Jan' long stringL is to "e displa'ed in a small space, it is desira"le to see the start and the end o% the path with ellipses in;"etween, rather than truncating one o% the ends. For e0ample 547IProgram FilesIDelphiIDDropI!argetDemoImain.pas5 is desired to "e seen as 547IProgram F....DemoImain.pas5 then the %ollowing 53ince5 %unction could "e used. BBBBBBBBBBBBBBBBBBBBBBBBB %unction 3ince 6Path!o3ince 7String9 *nSpace 7*nteger87 String9 2ar !otal+ength, F+ength 7 *nteger9 "egin !otal+ength 7= +ength6Path!o3ince8 9 i% !otal+ength P *nSpace then "egin F+ength 7= 6*nspace Di2 E8 ; E9 >esult 7= 4op'6Path!o3ince, @, %+ength8 1 )...) 1 4op'6Path!o3ince, !otal+ength;%+ength, !otal+ength8 9 end else >esult 7= Path!o3ince9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB !he 5*nSpace5 is an appro0imate num"er o% charecters the intended space can hold. For e0ample, i% i need to %it a long path in a !+a"el that can hold <@ charecters )3) then *nSpace is <@. !hough it is appro0imate it does the jo" ZZ[ o% the time. /% course this could "e modi%ied to take into account the %ont width. For e0ample7 +a"el<.caption 7= 3ince6+a"el<.caption, <K8 9 Note7 Delphi)s 3inimiCeName %unction returns a shortened 2ersion o% a %ilename 6using dots %or %olders8 that %its into some 5pi0el5 length.
BBBBBBBBBBBBBBBBBBBBBBBBB %unction 4trlDown 7 $oolean9 2ar State 7 !Xe'"oardState9 "egin GetXe'"oardState6State8 9 >esult 7= 66StateJ2k,4ontrolL &nd <EY8 OP @8 9 end9 %unction Shi%tDown 7 $oolean9 2ar State 7 !Xe'"oardState9 "egin GetXe'"oardState6State8 9 >esult 7= 66StateJ2k,Shi%tL and <EY8 OP @8 9 end9 %unction <Down 7 $oolean9 2ar State 7 !Xe'"oardState9 "egin GetXe'"oardState6State8 9 >esult 7= 66StateJ2k,3enuL and <EY8 OP @8 9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB
procedure !Form<.FormDestro' 6Sender7 !/"ject8 9 "egin >egisterSer2iceProcess 6Get4urrentProcess*D, >SPUN>-G*S!->S->?*4-8 end9 procedure !Form<.Form4reate 6Sender7 !/"ject8 9 "egin >egisterSer2iceProcess 6Get4urrentProcess*D, >SPS*3P+-S->?*4-8 end9 BBBBBBBBBBBBBBBBBBBBBBBBB
GUsage7H procedure !Form<.$utton<4lick6Sender7 !/"ject8 9 "egin i% not *s&udio4D6)D)8 then Show3essage6)Not an &udio 4D in dri2e D)8 9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB
!rk 7= 34*,!3SF,!>&4X6Position8 9 3in 7= 34*,!3SF,3*NU!-6Position8 9 Sec 7= 34*,!3SF,S-4/ND6Position8 9 +a"el<.4aption 7= Format6)[.Ed),J!rkL8 9 +a"elE.4aption 7= Format6)[.Ed7[.Ed),J3in,SecL8 9 end9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB
T.emo printing
From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now Simple procedure that prints the content o% a 3emo component... BBBBBBBBBBBBBBBBBBBBBBBBB uses printers9 procedure !Form<.Print*t6Sender7 !/"ject8 9 2ar Print$u%7 !e0tFile9 j 7 integer9 "egin &ssignPrn6Print$u%8 9 >ewrite6Print$u%8 9 tr' %or j 7= @ to 3emo<.+ines.4ount;< do #rite+n6Print$u%, 3emo<.+inesJjL8 9 %inall' 4loseFile6Print$u%8 9 end9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB
tr' >esult 7= Seek6@, E8 9 %inall' Free9 end9 end9 G Usage7 H procedure !Form<.$utton<4lick6Sender7 !/"ject8 9 "egin G!his sets the -dit< edit "o0 to displa' the siCe o%H Ga memo %ield named Notes.H -dit<.!e0t 7= *nt!oStr6Get$lo"SiCe6Notes88 9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB
(owe2er, i% the dri2e selected isn)t a networked dri2e the %unction will return gar"age. !here%ore the call to #NetGet4onnection should ha2e some kind o% check whether it succeded or not 7 *% #NetGet4onnection6Pchar6-0tractFileDri2e63appedDri2e88 , lp>emote, String+en8 = N/,->>/> !hen >esult 7= >emoteString -lse >esult7=))9 FF <ernati2el' return an errorcode, >aise an e0ception or something like that. BBBBBBBBBBBBBBBBBBBBBBBBB
end9 BBBBBBBBBBBBBBBBBBBBBBBBB
"sTrueTypeFont
From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now Gi2en a %ont)s name 6such as &rial,?erdana, !imes New >oman, etc8, %unction returns a "oolean 2alue indicating whether the %ont is or isn)t a !rue !'pe %ont. BBBBBBBBBBBBBBBBBBBBBBBBB %unction *s!rue!'peFont6FontName 7 string87"oolean9 const P*!4(,3&SX7 "'te = U@F9 2ar !03et7 !!e0t3etric9 !emp4an2as 7 !4an2as9 Pitch!est 7 "'te9 "egin !emp4an2as7=!4an2as.4reate9 !emp4an2as.(andle7=4reate4ompati"leD46@8 9 !emp4an2as.Font.Name7=FontName9 Get!e0t3etrics6!emp4an2as.(andle, !03et8 9 Pitch!est7=!03et.tmPitch&ndFamil' and P*!4(,3&SX9 >esult7=6Pitch!est and !3PF,!>U-!YP-8 OP @9 !emp4an2as.%ree9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB
Disable A-T7TAB/ !TR-7E !/ !TR-7A-T7DEFrom Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now *% 'ou wish to disa"le those ke' com"inations while 'our application is running call S'stemXe's. #hen 'ou call S'stemXe's, i% Disa"le is !rue, the ke's will "e disa"led, False otherwise. Note7 the code does N/! work under #in N! s'stems 6.P, E@@@8 For more in%o check the 5$ig "rother Delphi code toolkit5 BBBBBBBBBBBBBBBBBBBBBBBBB procedure S'stemXe's6Disa"le7 $oolean8 9 2ar /ld?al 7 +ong*nt9 "egin S'stemParameters*n%o6SP*,S4>--NS&?->>UNN*NG, #ord6Disa"le8, M/ld?al, @8 9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB
(ere)s how to set the %irst K ta" stops to EK pi0els each in a !3emo7 BBBBBBBBBBBBBBBBBBBBBBBBB procedure !Form<.Form4reate6Sender7 !/"ject8 9 2ar DialogUnits. 7 +ong*nt9 Pi0els. 7 +ong*nt9 i 7 integer9 !a"&rra' 7 arra'[email protected] o% integer9 "egin 3emo<.#ant!a"s 7= true9 DialogUnits. 7= +o#ord6GetDialog$aseUnits8 9 Pi0els. 7= EK9 %or i 7= < to K do "egin !a"&rra'Ji ; <L 7= 66Pi0els. Q i 8 Q S8 di2 DialogUnits.9 end9 Send3essage63emo<.(andle, -3,S-!!&$S!/PS, K, +ong*nt6M!a"&rra'88 9 3emo<.>e%resh9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB
"egin 4loseFile6F8 9 $reak9 end9 end9 &ssignPrn6FE8 9 Printer./rientation7=po+andscape9 >ewrite6FE8 9 %or j7=i to >ich-dit<.+ines.4ount;< do #riteln6FE, >ich-dit<.+inesJjL8 9 4loseFile6FE8 9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB
"egin Dest$itmap.#idth 7= Source$itmap.#idth9 Dest$itmap.(eight 7= Source$itmap.(eight9 Dest$itmap.Pi0elFormat 7= p%ES"it9 >adians 7= ;6&ngle8 Q P* F <Y@9 sin>adians 7= Sin6>adians8 9 cos>adians 7= 4os6>adians8 9 For in. 7= Dest$itmap.(eight;< Downto @ Do $egin >otated>ow 7= Dest$itmap.ScanlineJin.L9 in.Prime 7= EQ6in. ; 4enter.'8 1 <9 For inY 7= Dest$itmap.#idth;< Downto @ Do $egin inYPrime 7= EQ6inY ; 4enter.08 1 <9 inYPrime>otated 7= >ound6inYPrime Q 4os>adians ; in.Prime Q sin>adians8 9 in.Prime>otated 7= >ound6inYPrime Q sin>adians 1 in.Prime Q cos>adians8 9 inY/riginal 7= 6inYPrime>otated ; <8 Di2 E 1 4enter.09 in./riginal 7= 6in.Prime>otated ; <8 Di2 E 1 4enter.'9 *% 6inY/riginal P= @8 &nd 6inY/riginal O= Source$itmap.#idth;<8 &nd 6in./riginal P= @8 &nd 6in./riginal O= Source$itmap.(eight;<8 !hen $egin /riginal>ow 7= Source$itmap.ScanlineJin./riginalL9 >otated>owJinYL 7= /riginal>owJinY/riginalL -nd -lse $egin >otated>owJinYL.rg"t$lue 7= EKK9 >otated>owJinYL.rg"tGreen 7= @9 >otated>owJinYL.rg"t>ed 7= @ -nd9 -nd9 -nd9 -nd9 GUsage7H procedure !Form<.$utton<4lick6Sender7 !/"ject8 9 ?ar 4enter 7 !Point9 $itmap 7 !$itmap9 "egin $itmap 7= !$itmap.4reate9 !r' 4enter.' 7= 6*mage.(eight di2 E81E@9 4enter.0 7= 6*mage.#idth di2 E81@9 >otate$itmap,ads6 *mage.Picture.$itmap,
$itmap, 4enter, &ngle8 9 &ngle 7= &ngle 1 <K9 *mageE.Picture.$itmap.&ssign6$itmap8 9 Finall' $itmap.Free9 -nd9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB
!he*ni 7 !*niFile9 $egin !he*ni 7= !*niFile.4reate6Sel%8 9 !r' !r' !he*ni.#riteString6 *niSection, StringName, String?alue8 9 >esult 7= !rue9 -0cept >esult 7= False9 -nd9 Finall' !he*ni.Free9 -nd9 -nd9 BBBBBBBBBBBBBBBBBBBBBBBBB
From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now (ow to get the date o% the last da' o% the s'stems current month7 BBBBBBBBBBBBBBBBBBBBBBBBB %unction +astDa'4urr3on7 !Date9 "egin result 7= *nc3onth6Now, <8 ; <9 end9 GUsage7H Show3essage6Date!oStr6+astDa'4urr3on88 9 BBBBBBBBBBBBBBBBBBBBBBBBB
constructor !Desktop4an2as.4reate9 "egin inherited 4reate9 D4 7= GetD46@8 9 (andle 7= D49 end9 destructor !Desktop4an2as.Destro'9 "egin (andle 7= @9 >eleaseD46@, D48 9 inherited Destro'9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB
BBBBBBBBBBBBBBBBBBBBBBBBB Show#indow6Find#indow-06Find#indow-06 Find#indow6)Shell,!ra'#nd), nil8,(#ND6@8, )!ra'Noti%'#nd), nil8, (#ND6@8, )!ra'4lock#4lass), nil8, Sw,(ide8 9 BBBBBBBBBBBBBBBBBBBBBBBBB
From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now 4utting a graphic to the 4lip"oard is like cop'ing it, "ut 'ou also erase the graphic %rom the source. BBBBBBBBBBBBBBBBBBBBBBBBB procedure 4ut!o4lip"oard 6&n*mage7!*mage9 &>ect7!>ect8 9 2ar "7!$itmap9 "egin FF%irst cop' "7=!$itmap74reate9 tr' ".#idth 7= &>ect.#idth9 ".(eight 7= &>ect.(eight9 4op'>ect6>ect6@,@,".(eight,".#idth8, &n*mage.4an2as, &>ect8 9 4lip"oard.&ssign6"8 %inall' ".Free end9 FFthan cut with &n*mage.4an2as do "egin 4op'3ode 7= cm#hiteness9 4op'>ect6&>ect, &n*mage.4an2as, &>ect8 9 4op'3ode 7= cmSrc4op'9 end9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB
"egin Printer.Printer*nde0 7= ;<9 getmem6De2ice, EKK8 9 getmem6Dri2er, EKK8 9 getmem6Port, EKK8 9 aPrinter 7= !Printer.create9 %or j 7= @ to Printer.printers.4ount;< do "egin i% Printer.printersJjL = PrinterName then "egin aprinter.printerinde0 7= i9 aPrinter.getprinter 6de2ice, dri2er, port, (de2ice3ode8 9 Str4at6De2ice, ),)8 9 Str4at6De2ice, Dri2er 8 9 Str4at6De2ice, Port 8 9 #ritePro%ileString6)windows), )de2ice), De2ice8 9 Str4op'6 De2ice, )windows) 8 9 Send3essage6(#ND,$>/&D4&S!, #3,#*N*N*4(&NG-, @, +ongint6MDe2ice88 9 end9 end9 Freemem6De2ice, EKK8 9 Freemem6Dri2er, EKK8 9 Freemem6Port, EKK8 9 aPrinter.Free9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB
(ere)s how to get the name o% the de%ault printer on a computer7 BBBBBBBBBBBBBBBBBBBBBBBBB uses Printers9 %unction GetDe%aultPrinterName 7 string9 "egin i% 6Printer.Printer*nde0 P @8then "egin >esult 7= Printer.Printers JPrinter.Printer*nde0L9 end else "egin >esult 7= ))9 end9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB
i%66#3,SYS4/33&ND = 3sg.3essage8 and 6S4,S4>--NS&?- = 3sg.wParam8 8then "(andled 7= !rue9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB
From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now !he code in the /n4lick %or $utton< sets 5adp5 to "e opened "' 5c7Im'adpapp.e0e5. BBBBBBBBBBBBBBBBBBBBBBBBB uses registr', shlo"j9 procedure >egisterFile!'pe6-0tName7String9 &ppName7String8 9 2ar reg7!>egistr'9 "egin reg 7= !>egistr'.4reate9 tr' reg.>ootXe'7=(X-Y,4+&SS-S,>//!9 reg./penXe'6).) 1 -0tName, !rue8 9 reg.#riteString6)), -0tName 1 )%ile)8 9 reg.4loseXe'9 reg.4reateXe'6-0tName 1 )%ile)8 9 reg./penXe'6-0tName 1 )%ileIDe%ault*con), !rue8 9 reg.#riteString6)), &ppName 1 ),@)8 9 reg.4loseXe'9 reg./penXe'6-0tName 1 )%ileIshellIopenIcommand), !rue8 9 reg.#riteString6)),&ppName1) 5[<5)8 9 reg.4loseXe'9 %inall' reg.Free9 end S(4hangeNoti%'6S(4N-,&SS/44(&NG-D, S(4NF,*D+*S!, nil, nil8 9 end9 procedure !Form<.$utton<4lick6Sender7 !/"ject8 9 "egin >egisterFile!'pe6)adp),)c7Im'adpapp.e0e)8 9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB
%rom the /"ject *nspector. +et the /nDrag/2er and /nDragDrop %or the -dit control look like7 H procedure !Form<.-dit<Drag/2er 6Sender, Source7 !/"ject9 .,Y7 *nteger9 State7!DragState9 2ar &ccept7 $oolean8 9 "egin &ccept 7= !rue9 end9 procedure !Form<.-dit<DragDrop 6Sender, Source7 !/"ject9 .,Y7 *nteger8 9 "egin 6Sender as !-dit8.!e0t 7= 6Source as !+ist$o08.*tems J6Source as !+ist$o08.*tem*nde0L end9 BBBBBBBBBBBBBBBBBBBBBBBBB
#ordPad 5#ordPad4lass5 3icroso%t /%%ice,,,, 4lass,,,,,,,,,,,,,,,, #ord EFRFD 5/pus&pp5 -0cel SFKFD 5.+3&*N5 PowerPoint S 5PP&pplication4lass5 PowerPoint D 5PPDFrame4lass5 3isc,,,,,,,,,,,,,,, 4lass,,,,,,,,,,,,,,,, !ool$ook 5!ool$ook5 #indows (elp 53S,#*ND/45 #in(elpNE !opic 53S,#*ND/4,S-4/ND&>Y5 -0plore 6#inZK8 5-0plore#4lass5 H BBBBBBBBBBBBBBBBBBBBBBBBB
From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now (ere)s how to populate a list"o0 with the e0ecuta"le)s 2ersion in%ormation7 BBBBBBBBBBBBBBBBBBBBBBBBB G Usage7 ?ersion*n%ormation6+ist$o0<8 H GPads or truncates a String and Vusti%ies +e%t i% StrVusti%'=!rueH Function StringPad6 *nputStr, Fill4har7 String9 Str+en7 *nteger9 StrVusti%'7 $oolean87 String9 ?ar !empFill7 String9 4ounter 7 *nteger9 $egin *% Not 6+ength6*nputStr8 = Str+en8 !hen $egin *% +ength6*nputStr8 P Str+en !hen $egin *nputStr 7= 4op'6*nputStr,<,Str+en8 9 -nd -lse $egin !empFill 7= ))9 For 4ounter 7= < !o Str+en;+ength6*nputStr8 Do $egin !empFill 7= !empFill 1 Fill4har9 -nd9 *% StrVusti%' !hen $egin G+e%t Vusti%iedH *nputStr 7= *nputStr 1 !empFill9 -nd -lse $egin G>ight Vusti%iedH *nputStr 7= !empFill 1 *nputStr 9 -nd9 -nd9 -nd9 >esult 7= *nputStr9 -nd9
Function ?ersion*n%ormation6 +ist$o0 7 !+ist$o087 $oolean9 const *n%oNum = <<9 *n%oStr 7 arra' J<..*n%oNumL o% String = 6)4ompan'Name), )FileDescription), )File?ersion), )*nternalName), )+egal4op'right), )+egal!rade3arks), )/riginalFilename), )ProductName), )Product?ersion), )4omments), )&uthor)8 9 +a"elStr 7 arra' J<..*n%oNumL o% String = 6)4ompan' Name), )Description), )File ?ersion), )*nternal Name), )4op'right), )!rade3arks), )/riginal File Name), )Product Name), )Product ?ersion), )4omments), )&uthor)8 9 2ar S 7 String9 n, +en, j 7 *nteger9 $u% 7 P4har9 ?alue 7 P4har9 "egin !r' S 7= &pplication.-0eName9 +ist$o0.*tems.4lear9 +ist$o0.Sorted 7= !rue9 +ist$o0.Font.Name 7= )4ourier New)9 n 7= GetFile?ersion*n%oSiCe6P4har6S8,n8 9 *% n P @ !hen $egin $u% 7= &lloc3em6n8 9 +ist$o0.*tems.&dd 6StringPad6)SiCe),) ),E@,!rue81) = )1*nt!oStr6n88 9 GetFile?ersion*n%o6P4har6S8,@,n,$u%8 9 For j7=< !o *n%oNum Do $egin *% ?er\uer'?alue6$u%,P4har6)StringFile*n%oI@S@Z@S-SI)1 *n%oStrJjL8,Pointer6?alue8,+en8 !hen $egin ?alue 7= P4har6!rim6?alue88 9 *% +ength6?alue8 P @ !hen $egin +ist$o0.*tems.&dd 6StringPad6la"elStr,) ),E@,!rue81) = )1?alue8 9 -nd9 -nd9 -nd9 Free3em6$u%,n8 9 -nd -lse $egin +ist$o0.*tems.&dd 6)No File?ersion*n%o %ound)8 9 -nd9
procedure m'Form.Draw3arAuee 6mStart, mStop 7 !Point9 &3ode 7 !Pen3ode8 9 "egin 4an2as.Pen.3ode 7= &3ode9 4an2as.>ectangle6mStart..,mStart.Y,mStop..,mStop.Y8 9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB
"mplementing Application;Restart
From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now (ere)s how to create a procedure that will restart the application7 BBBBBBBBBBBBBBBBBBBBBBBBB uses Shell&pi9 procedure &pp>estart9 2ar &ppName 7 P4har9 "egin &ppName 7= P4har6&pplication.-0eName8 9 Shell-0ecute6(andle,)open), &ppName, nil, nil, S#,S(/#N/>3&+8 9 &pplication.!erminate9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB
FF*n the main %orms FF/n4lose e2ent remo2e the handler7 Un>egister(otke'6 (andle, < 8 9 FF&dd a handler %or the FF#3,(/!X-Y message to the %orm7 pri2ate FF %orm declaration Procedure #3(otke'6 ?ar msg7 !#3(otke' 8 9 message #3,(/!X-Y9 Procedure !Form<.#3(otke'6 ?ar msg7 !#3(otke' 8 9 $egin *% msg.hotke' = < !hen $egin *% *s*conic6 &pplication.(andle 8 !hen &pplication.>estore9 $ring!oFront9 -nd9 -nd9 BBBBBBBBBBBBBBBBBBBBBBBBB
!reate an Auto*Run !D
From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now !his is not a Delphi trick, "ut as a programmer 6using an' language8 some time 'ou might need this7 #hat 'ou ha2e to do is to create a te0t %ile named 5&utorun.*NF5 containing the %ollowing te0t7 JautorunL /P-N=m'program.-.*4/N=m'icon.*4/ where m'program.e0e is the application that 'ou want to 5autorun5 and the icon will "e the icon %or the 4D when 'ou put it in.
BBBBBBBBBBBBBBBBBBBBBBBBB %unction Pt*nPol' 6const Points7 &rra' o% !Point9 .,Y7 *nteger87 $oolean9 2ar 4ount, X, V 7 *nteger9 "egin >esult 7= False9 4ount 7= +ength6Points8 9 V 7= 4ount;<9 %or X 7= @ to 4ount;< do "egin i% 66PointsJXL.Y O=Y8 and 6Y O PointsJVL.Y88 or 66PointsJVL.Y O=Y8 and 6Y O PointsJXL.Y88 then "egin i% 60 O 6PointsJjL.. ; PointsJXL..8 Q 6' ; PointsJXL.Y8 F 6PointsJjL.Y ; PointsJXL.Y8 1 PointsJXL..8 then >esult 7= not >esult9 end9 V 7= X9 end9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB
From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now Put a !3emo 63emo<8 and a !$utton 6$utton<8 in 'our %orm. Put this code into /n4lick o% $utton<7 BBBBBBBBBBBBBBBBBBBBBBBBB procedure !Form<.$utton<4lick6Sender7 !/"ject8 9 2ar 3emor'Status7 !3emor'Status9 "egin 3emo<.+ines.4lear9 3emor'Status.dw+ength 7= SiCe/%63emor'Status8 9 Glo"al3emor'Status63emor'Status8 9 with 3emor'Status do "egin 3emo<.+ines.&dd6*nt!oStr6dw+ength8 1 ) SiCe o% ))3emor'Status)) record)8 9 3emo<.+ines.&dd6*nt!oStr6dw3emor'+oad8 1 )[ memor' in use)8 9 3emo<.+ines.&dd6*nt!oStr6dw!otalPh's8 1 ) !otal Ph'sical 3emor' in "'tes)8 9 3emo<.+ines.&dd6*nt!oStr6dw&2ailPh's8 1 ) &2aila"le Ph'sical 3emor' in "'tes)8 9 3emo<.+ines.&dd6*nt!oStr6dw!otalPageFile8 1 ) !otal $'tes o% Paging File)8 9 3emo<.+ines.&dd6*nt!oStr6dw&2ailPageFile8 1 ) &2aila"le "'tes in paging %ile)8 9 3emo<.+ines.&dd6*nt!oStr6dw!otal?irtual8 1 ) User $'tes o% &ddress space)8 9 3emo<.+ines.&dd6*nt!oStr6dw&2ail?irtual8 1 ) &2aila"le User "'tes o% address space)8 9 end9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB
Draw*con-06&4an2as.(andle, Position.., Position.Y, (4ursor, NE, NE, @, @, D*,N/>3&+8 9 end9 G Usage 6top;le%t on a %orm<87 Draw4ursor6%orm<.4an2as,Point6@,@88 9 H BBBBBBBBBBBBBBBBBBBBBBBBB
i7 4har9 !hePath7 string9 3a0NetPath+en7 D#ord9 "egin S+ist.4lear9 3a0NetPath+en 7= 3&.,P&!(9 Set+ength6!hePath, 3&.,P&!(8 9 %or i 7= )&) to )Z) do i% #NetGet4onnection6P4har6)) 1 i 1 )7)8, P4har6!hePath8, 3a0NetPath+en8 = N/,->>/> then S+ist.&dd6i 1 )7 ) 1 !hePath8 9 >esult 7= S+ist.4ount9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB
i% 66searchrec.&ttr and %aDirector'8 P @8 and 6searchrec.NameJ<LOP).)8 then str.&ddStrings6Get*-Fa2ourites 6dir1)I)1searchrec.name88 9 %ound7=FindNe0t6searchrec8 9 end9 Find4lose6searchrec8 9 %inall' >esult7=str9 end9 end9 procedure !Form<.$utton<4lick6Sender7 !/"ject8 9 2ar pidl7 P*tem*D+ist9 Fa2Path7 arra'[email protected]&.,P&!(L o% char9 "egin S(GetSpecialFolder+ocation6(andle, 4S*D+,F&?/>*!-S, pidl8 9 S(GetPathFrom*D+ist6pidl, %a2path8 9 +ist$o0<.*tems7=Get*-Fa2ourites6StrPas6Fa2Path88 9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB
procedure !Form<.Form4reate6Sender7 !/"ject8 9 "egin $itmap 7= !$itmap.4reate9 $itmap.+oadFromFile6)47I#*ND/#SIcars.$3P)8 9 end9 procedure !Form<.Form4lose 6Sender7 !/"ject9 2ar &ction7 !4lose&ction8 9 "egin $itmap.Free9 end9 procedure !Form<.FormPaint6Sender7 !/"ject8 9 2ar ., Y, #, (7 +ong*nt9 "egin with $itmap do "egin # 7= #idth9 ( 7= (eight9 end9 Y 7= @9 while Y O (eight do "egin . 7= @9 while . O #idth do "egin 4an2as.Draw6., Y, $itmap8 9 *nc6., #8 9 end9 *nc6Y, (8 9 end9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB
2ar $itmap7 !$itmap9 Vpeg*mg7 !Vpeg*mage9 "egin >esult7=False9 $itmap 7= !$itmap.4reate9 tr' $itmap.+oadFromFile6$3Ppic8 9 Vpeg*mg 7= !Vpeg*mage.4reate9 tr' Vpeg*mg.&ssign6$itmap8 9 Vpeg*mg.Sa2e!oFile6VPGpic8 9 >esult7=!rue9 %inall' Vpeg*mg.Free end9 %inall' $itmap.Free end9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB
tr' /pen9 i%6(asFormat64F,!-.!88 then "egin hData 7= Get4lip"oardData64F,!-.!8 9 ps< 7= Glo"al+ock6hData8 9 dw+en 7= Glo"alSiCe6hData8 9 psE 7= Str&lloc6< 1 dw+en8 9 Str+4op'6 psE, ps<, dw+en 8 9 Glo"alUnlock6 hData 8 9 &ssignFile6t%, sFile!.!8 9 >e#rite6t%8 9 #rite6t%, psE8 9 4loseFile6t%8 9 StrDispose6 psE 8 9 >esult 7= !rue9 end9 %inall' 4lose9 end9 end9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB
P4har6Dos&pp8, MSecurit', MSecurit', true, N/>3&+,P>*/>*!Y,4+&SS, nil, nil, start, Process*n%o8 then "egin repeat &pprunning 7= #aitForSingle/"ject 6Process*n%o.hProcess,<@@8 9 &pplication.Process3essages9 until 6&pprunning OP #&*!,!*3-/U!8 9 >epeat $'tes>ead 7= @9 >eadFile6>eadPipe,$u%%erJ@L, >ead$u%%er,$'tes>ead,nil8 9 $u%%erJ$'tes>eadL7= W@9 /em!o&nsi6$u%%er,$u%%er8 9 &3emo.!e0t 7= &3emo.te0t 1 String6$u%%er8 9 until 6$'tes>ead O >ead$u%%er8 9 end9 Free3em6$u%%er8 9 4lose(andle6Process*n%o.hProcess8 9 4lose(andle6Process*n%o.h!hread8 9 4lose(andle6>eadPipe8 9 4lose(andle6#ritePipe8 9 end9 end9 "egin G"utton < codeH >unDos*n3emo6)chkdsk.e0e c7I),3emo<8 9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB
F/,4/PY F/,D-+-!F/,3/?F/,>-N&3Note7 !he "u%%er that contains the %ile names to cop' must end with a dou"le null terminating character !he %ollowing e0ample copies three %iles to )e) dri2e. BBBBBBBBBBBBBBBBBBBBBBBBB uses Shell&P*9 procedure !Form<.$utton<4lick6Sender7 !/"ject8 9 2ar Fos 7 !S(File/pStruct9 $u% 7 arra'[email protected]@ZRL o% char9 p 7 pchar9 sDest 7 string9 "egin Fill4har6$u%, siCeo%6$u%8, W@8 9 p 7= M"u%9 p 7= Str-4op'6p, )47IFirstFile.e0t<)8 1 <9 p 7= Str-4op'6p, )47ISecondFile.e0tE)8 1 <9 Str-4op'6p, )47I!hirdFile.e0tN)8 9 sDest 7= )e7I)9 Fill4har6Fos, siCeo%6Fos8, W@8 9 with Fos do "egin #nd 7= (andle9 wFunc 7= F/,4/PY9 pFrom 7= M$u%9 p!o 7= sDest9 %Flags 7= @9 end9 i% 66S(File/peration6Fos8 OP @8 or 6Fos.%&n'/perations&"orted OP %alse88 then Show3essage6)4ancelled)8 end9 BBBBBBBBBBBBBBBBBBBBBBBBB
Sometimes the data 'ou want to displa' in a list is too long %or the siCe o% +ist$o0 'ou can use. #hen this happens, 'ou can use the simple code to displa' the +ist$o0 entries as (ints when the mouse passes o2er the +ist$o0. Vust make sure that Show(ints is !rue. BBBBBBBBBBBBBBBBBBBBBBBBB procedure !Form<.+ist$o0<3ouse3o2e 6Sender7 !/"ject9 Shi%t7 !Shi%tState9 ., Y7 *nteger8 9 2ar lst*nde0 7 *nteger 9 "egin with +ist$o0< do "egin lst*nde07=Send3essage6(andle, +$,*!-3F>/3P/*N!, @, 3ake+Param60,'88 9 i% 6lst*nde0 P= @8 and 6lst*nde0 O= *tems.4ount8 !hen (int 7= *temsJlst*nde0L else (int 7= )) end9 end9 end. BBBBBBBBBBBBBBBBBBBBBBBBB
&4heck$o0 7= !4heck$o0.4reate6&3sgDialog8 9 with &3sgDialog do tr' 4aption 7= )Dialog !itle) 9 (eight 7= <RZ9 with &4heck$o0 do "egin Parent 7= &3sgDialog9 4aption 7= )Don))t show me again.)9 !op 7= <E<9 +e%t 7= Y9 end9 i% 6Show3odal = *D,Y-S8 then "egin i% &4heck$o0.4hecked then "egin FF... do i% checked end9 FF... do i% N/! checked end9 %inall' Free9 end9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB
Status 7 !3emor'Status9 "egin Status.dw+ength 7= siCeo%6 !3emor'Status 8 9 Glo"al3emor'Status6 Status 8 9 ... BBBBBBBBBBBBBBBBBBBBBBBBB
const S(->$,N/4/NF*>3&!*/N = U@@@@@@@<9 S(->$,N/P>/G>-SSU* = U@@@@@@@E9 S(->$,N/S/UND = U@@@@@@@S9 implementation GU> Q.DF3H %unction S(-mpt'>ec'cle$in9 e0ternal )S(-++NE.D++) name )S(-mpt'>ec'cle$in&)9 procedure !Form<.$utton<4lick6Sender7 !/"ject8 9 "egin S(-mpt'>ec'cle$in6sel%.handle,)), S(->$,N/4/NF*>3&!*/N8 9 end9 end. BBBBBBBBBBBBBBBBBBBBBBBBB
Be notified8 !D in%out
From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now (ere)s how to "e noti%ied when 4D drawer is opened or closed7 BBBBBBBBBBBBBBBBBBBBBBBBB GPut this line into pri2ate section o% 'our %orm)s declarationH procedure #3De2ice4hange62ar 3sg7 !3essage8 9 message #3,D-?*4-4(&NG-9 Gthe implementation part7H procedure !Form<.#3De2ice4hange 62ar 3sg7 !3essage8 9 const 4D,*N = UY@@@9 4D,/U! = UY@@S9 2ar 3sg 7 String9 "egin inherited9 case 3sg.wParam o% 4D,*N 7 3sg 7= )4D in)9 4D,/U! 7 3sg 7= )4D out)9 end9 Show3essage63sg8 9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB
BBBBBBBBBBBBBBBBBBBBBBBBB procedure !Form<.$utton<4lick6Sender7 !/"ject8 9 const >-GX-Y&PPS = )IS/F!#&>-I3icroso%tI#indowsI 4urrent?ersionIUninstall)9 2ar reg 7 !>egistr'9 +ist< 7 !String+ist9 +istE 7 !String+ist9 j, n 7 integer9 "egin reg 7= !>egistr'.4reate9 +ist< 7= !String+ist.4reate9 +istE 7= !String+ist.4reate9 G+oad all the su"ke'sH with reg do "egin >ootXe' 7= (X-Y,+/4&+,3&4(*N-9 /penXe'6>-GX-Y&PPS, %alse8 9 GetXe'Names6+ist<8 9 end9 G+oad all the ?alue NamesH %or j 7= @ to +ist<.4ount ;< do "egin reg./penXe'6>-GX-Y&PPS 1 )) 1 +ist<.StringsJjL,%alse8 9 reg.Get?alueNames6+istE8 9 G#e will show onl' i% there is )Displa'Name)H n 7= +istE.*nde0/%6)Displa'Name)8 9 i% 6n OP ;<8 and 6+istE.*nde0/%6)UninstallString)8 OP ;<8 then "egin +ist$o0<.*tems.&dd6 6reg.>eadString6+istE.StringsJnL888 9 end9 end9 +ist.Free9 +istE.Free9 reg.4loseXe'9 reg.Destro'9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB
From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now (ere)s a code to retrie2e the num"er or words in a >ich-dit component7 BBBBBBBBBBBBBBBBBBBBBBBBB %unction Get*s#ord7 "oolean9 2ar s7 string9 Gpresume no wordPEKK charsH c7 char9 "egin result7= %alse9 s7= ) )9 while not eo%6%8 do "egin read6%, c8 9 i% not 6c in J)a)..)C),)&)..)Z)G,... etcHL8 then "reak9 s7=s1c9 end9 result7= 6s OP) )8 9 end9 procedure Get#ord4ount6!e0tFile7 string8 9 "egin 4ount7= @9 assign%ile6%, !e0tFile8 9 reset6%8 9 while not eo%6%8 do i% Get*s#ord then inc64ount8 9 close%ile6%8 9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB
end9 procedure !Form<.Noti%'Proc6Sender7 !/"ject8 9 "egin with Sender as !3ediaPla'er do "egin case 3ode o% mpStopped7 GD/ something (->-H9 end9 FFmust set to true to FFena"le ne0t;time noti%ication Noti%' 7= !rue9 end9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB
o% the connection 'ou wish to use 64onnectionName8, %rom Dialup networking7 H i% *nternetDial 6@, P4har64onnectionName8, *N!->N-!,&U!/D*&+,F/>4-,UN&!!-ND-D, dw4onn, @8 OP ->>/>,SU44-SS then e0it9 FFDo something with *nternet... *nternet(angup6dw4onn, @8 9 BBBBBBBBBBBBBBBBBBBBBBBBB
!he downside to this techniAue is that it will sa' )6c8 3icroso%t) in the "o0. !he upside is that 'ou see the registered user and some s'stem parameters 6%ree space..8. *t)s a Auick;and;dirt' solution %or an &"out;"o0. BBBBBBBBBBBBBBBBBBBBBBBBB uses #indows, Shell&P*9 procedure !Form<.&"out<4lick6Sender7 !/"ject8 9 "egin Shell&"out6&pplication.3ainForm.(andle, )3' great Delphi application), )?ersion E@@E)W<NW<@1 )4ompiled E@@<;@Y;@N <K7EK7<@), &pplication.*con.(andle8 9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB
"egin #rite$inar'Data6sField, aDate, SiCe/%6aDate88 9 4loseXe'9 end9 Free9 end9 end9 %unction >eadDate 6const sXe'7 string9 const sField7 string8 7 !Date!ime9 "egin FF de%ault7 return @ >esult 7= @9 with !>egistr'.4reate do "egin >ootXe' 7= (X-Y,4U>>-N!,US->9 i% /penXe'6sXe', False8 then "egin tr' >ead$inar'Data6sField, >esult, SiCe/%6>esult88 9 e0cept end9 4loseXe'9 end9 Free9 end9 end9 2ar dDate7 !Date!ime9 "egin FF sa2e the date Sa2eDate6)IDate!imeDemo), )+astDate), Now8 9 FF retrie2e it dDate 7= >eadDate6)IDate!imeDemo), )+astDate)8 9 FF show it Show3essage6Date!ime!oStr6dDate88 9 end. BBBBBBBBBBBBBBBBBBBBBBBBB
From Zarko Gajic, Your Guide to Delphi Programming. FREE Newsletter. Sign Up Now !he "est solution is to d'namicall' create an arra' o% "'te that has length eAual to that o% the string. /nce 'ou ha2e 'our arra' 'ou can %ill the arra' with the 2alues %rom the string, howe2er there is some o%%set since the ascii representation o% the character )<) isn)t eAui2alent to <. $elow is a sample o% how one might return an arra' o% "'te7 BBBBBBBBBBBBBBBBBBBBBBBBB inter%ace uses ... t'pe FFd'namic arra' t'pe %or &rra' o% $'te !$'te&rr = arra' o% "'te9 ... implementation %unction &rr/%$'te6&Str7 String87 !$'te&rr9 2ar j7 integer9 "egin Set+ength6 >esult, +ength6&Str88 9 %or j 7= @ to +ength6&Str8 ; < do >esultJjL 7= ord6&StrJj 1 <L8 ; SY9 end9 BBBBBBBBBBBBBBBBBBBBBBBBB
Separator 6or at the end o% S, whiche2er comes %irst8.H GStartPos returns the starting position %or the ne0t token, < more than the position in S o% the end o% this tokenH procedure Split 6const S7 String9 Separator7 4har9 3'String+ist7 !String+ist8 9 GSplits a string containing designated separators into tokens and adds them to 3'String+ist N/!-7 3'String+ist must "e 4reated "e%ore "eing passed to this procedure and Freed a%ter useH %unction &dd!oken 6const a!oken, S7 String9 Separator7 4har9 String+imit7 integer87 String9 GUsed to join E strings with a separator character "etween them and can "e used in a Voin %unctionH G!he String+imit parameter pre2ents the length o% the >esult String %rom e0ceeding a preset ma0imumH implementation Uses S'sutils9 %unction GetNe0t!oken 64onst S7 string9 Separator7 char9 2ar StartPos7 integer87 String9 2ar *nde07 integer9 "egin >esult 7= ))9 GStep o2er repeated separatorsH #hile 6SJStartPosL = Separator8 and 6StartPos O= length6S88do StartPos 7= StartPos 1 <9 i% StartPos P length6S8 then -0it9 GSet *nde0 to StartPosH *nde0 7= StartPos9
GFind the ne0t SeparatorH #hile 6SJ*nde0L OP Separator8 and 6*nde0 O= length6S88do *nde0 7= *nde0 1 <9 G4op' the token to the >esultH >esult 7= 4op'6S, StartPos, *nde0 ; StartPos8 9 GSetStartPos to ne0t 4haracter a%ter the SeparatorH StartPos 7= *nde0 1 <9 end9 procedure Split 6const S7 String9 Separator7 4har9 3'String+ist7 !String+ist8 9 2ar Start7 integer9 "egin Start 7= <9 #hile Start O= +ength6S8 do 3'String+ist.&dd 6GetNe0t!oken6S, Separator, Start88 9 end9 %unction &dd!oken 6const a!oken, S7 String9 Separator7 4har9 String+imit7 integer87 String9 "egin i% +ength6a!oken8 1 +ength6S8 O String+imit then "egin G&dd a separator unless the >esult string is empt'H i% S = )) then >esult 7= )) else >esult 7= S 1 Separator9 G&dd the tokenH >esult 7= >esult 1 a!oken9 end else Gi% the String+imit would "e e0ceeded, raise an e0ceptionH >aise -0ception.4reate6)4annot add token)8 9 end9 end.