embarcadero developer network home page - fÆ b6 fÇ...

42
Delphi 2010 䛷᥈ ᥈䜛 䜛䟿 Windows 7 ᪂ᶵ⬟ ᪂ᶵ⬟ ᪂ᶵ⬟ ᪂ᶵ⬟ ᘧ♫䝅䝸䜰䝹䝀䞊䝮䝈 ⥾ᙺ ⣽ᕝ B6Delphi䝔䜽䝙䜹䝹䝉䝑䝅䝵䞁

Upload: others

Post on 26-Mar-2021

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Embarcadero Developer Network Home Page - FÆ B6 FÇ Delphiedn.embarcadero.com/jp/article/images/40256/b6.pdf · 2010. 2. 8. · 4.RAD Studio 2010 FþGeG{GFG5G=GVG8GeGEGuG FÛG FÂGwG

Delphi 2010 Windows 7

B6 Delphi

Page 2: Embarcadero Developer Network Home Page - FÆ B6 FÇ Delphiedn.embarcadero.com/jp/article/images/40256/b6.pdf · 2010. 2. 8. · 4.RAD Studio 2010 FþGeG{GFG5G=GVG8GeGEGuG FÛG FÂGwG

2

• Windows 7

• Windows Vista

• UAC

• Windows 7

• Direct2D

• API

VCL VCL

Win32 API

Page 3: Embarcadero Developer Network Home Page - FÆ B6 FÇ Delphiedn.embarcadero.com/jp/article/images/40256/b6.pdf · 2010. 2. 8. · 4.RAD Studio 2010 FþGeG{GFG5G=GVG8GeGEGuG FÛG FÂGwG

Windows 7

Page 4: Embarcadero Developer Network Home Page - FÆ B6 FÇ Delphiedn.embarcadero.com/jp/article/images/40256/b6.pdf · 2010. 2. 8. · 4.RAD Studio 2010 FþGeG{GFG5G=GVG8GeGEGuG FÛG FÂGwG

4

Windows 7

• Windows 7

• Windows Vista

• Vista 6.0

• 7 6.1

– SysUtils.CheckWin32Version(6, 1); //

• Windows Vista

• Longhorn

• UI Vista

• (DWU)

– DirectX 10.1

– Window

Page 5: Embarcadero Developer Network Home Page - FÆ B6 FÇ Delphiedn.embarcadero.com/jp/article/images/40256/b6.pdf · 2010. 2. 8. · 4.RAD Studio 2010 FþGeG{GFG5G=GVG8GeGEGuG FÛG FÂGwG

Windows 7 Vista

••

• Aero

•• Vista

• Direct API

5

Page 6: Embarcadero Developer Network Home Page - FÆ B6 FÇ Delphiedn.embarcadero.com/jp/article/images/40256/b6.pdf · 2010. 2. 8. · 4.RAD Studio 2010 FþGeG{GFG5G=GVG8GeGEGuG FÛG FÂGwG

Windows Vista

Page 7: Embarcadero Developer Network Home Page - FÆ B6 FÇ Delphiedn.embarcadero.com/jp/article/images/40256/b6.pdf · 2010. 2. 8. · 4.RAD Studio 2010 FþGeG{GFG5G=GVG8GeGEGuG FÛG FÂGwG

• Vista • Xp

• Administrators Administrator

• Vista / 7

• Administrators ≠≠≠≠ Administrator

• UAC • manifest

• UAC

• ShellExecute runas

• UAC

•• http://edn.embarcadero.com/jp/article/images/34159/devcamp04_g4.pdf

UAC

7

Page 8: Embarcadero Developer Network Home Page - FÆ B6 FÇ Delphiedn.embarcadero.com/jp/article/images/40256/b6.pdf · 2010. 2. 8. · 4.RAD Studio 2010 FþGeG{GFG5G=GVG8GeGEGuG FÛG FÂGwG

UAC

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">

<assemblyIdentity

type="win32"

name="CodeGear RAD Studio"

version="14.0.3539.24502"

processorArchitecture="*"/>

<dependency>

<dependentAssembly>

<assemblyIdentity

type="win32"

name="Microsoft.Windows.Common-Controls"

version="6.0.0.0"

publicKeyToken="6595b64144ccf1df"

language="*"

processorArchitecture="*"/>

</dependentAssembly>

</dependency>

8

Delphi 2010 manifest

<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">

<security>

<<<<requestedPrivilegesrequestedPrivilegesrequestedPrivilegesrequestedPrivileges>>>>

<<<<requestedExecutionLevelrequestedExecutionLevelrequestedExecutionLevelrequestedExecutionLevel

level="level="level="level="asInvokerasInvokerasInvokerasInvoker""""

uiAccessuiAccessuiAccessuiAccess="false"/>="false"/>="false"/>="false"/>

</</</</requestedPrivilegesrequestedPrivilegesrequestedPrivilegesrequestedPrivileges>>>>

</security>

</trustInfo>

</assembly>

Page 9: Embarcadero Developer Network Home Page - FÆ B6 FÇ Delphiedn.embarcadero.com/jp/article/images/40256/b6.pdf · 2010. 2. 8. · 4.RAD Studio 2010 FþGeG{GFG5G=GVG8GeGEGuG FÛG FÂGwG

UAC

9

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"><assemblyIdentitytype="win32"name=" "version="1.0.0.0" processorArchitecture="X86"/>

<description> </description>

<dependency><dependentAssembly>

<assemblyIdentitytype="win32"name="Microsoft.Windows.Common-Controls"version="6.0.0.0"publicKeyToken="6595b64144ccf1df"language="*"processorArchitecture="*"/>

</dependentAssembly></dependency>

<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2"><security><requestedPrivileges><requestedExecutionLevel level="requireAdministrator" uiAccess="false" />

</requestedPrivileges></security>

</trustInfo></assembly>

1. manifest

level requireAdministrator

manifest.xml

Page 10: Embarcadero Developer Network Home Page - FÆ B6 FÇ Delphiedn.embarcadero.com/jp/article/images/40256/b6.pdf · 2010. 2. 8. · 4.RAD Studio 2010 FþGeG{GFG5G=GVG8GeGEGuG FÛG FÂGwG

UAC

10

#define CREATEPROCESS_MANIFEST_RESOURCE_ID 1#define RT_MANIFEST 24

CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "manifest.xml"

2.RC manifest.rc

3.RC RES

•%RADStudio%¥5.0¥bin¥brcc32.exe RC

Page 11: Embarcadero Developer Network Home Page - FÆ B6 FÇ Delphiedn.embarcadero.com/jp/article/images/40256/b6.pdf · 2010. 2. 8. · 4.RAD Studio 2010 FþGeG{GFG5G=GVG8GeGEGuG FÛG FÂGwG

UAC

11

4.RAD Studio 2010

5. RES

implementation

{$R *.dfm}{$R manifest.res}

6.

Page 12: Embarcadero Developer Network Home Page - FÆ B6 FÇ Delphiedn.embarcadero.com/jp/article/images/40256/b6.pdf · 2010. 2. 8. · 4.RAD Studio 2010 FþGeG{GFG5G=GVG8GeGEGuG FÛG FÂGwG

• Xp Vista/7

•• SHGetSpecialFolderLocation API

12

Xp Vista / 7

C:¥Documents and Settings C:¥Users

(Roaming )C:¥Documents and Settings¥

¥Application DataC:¥Users¥ ¥AppData¥Roaming

Page 13: Embarcadero Developer Network Home Page - FÆ B6 FÇ Delphiedn.embarcadero.com/jp/article/images/40256/b6.pdf · 2010. 2. 8. · 4.RAD Studio 2010 FþGeG{GFG5G=GVG8GeGEGuG FÛG FÂGwG

SHGetSpecialFolder

usesusesusesuses

ShlObj, ActiveX;

functionfunctionfunctionfunction GetSpecialFolder(constconstconstconst iFolder: DWORD): StringStringStringString;

varvarvarvar

IDL: PItemIDList;

beginbeginbeginbegin

Result := '';

SHGetSpecialFolderLocation(

Application.Handle,

iFolder,

IDL);

trytrytrytry

Result := StringOfChar(#0, MAX_PATH);

ifififif (IDL <> nil) andandandand (SHGetPathFromIDList(IDL, PChar(Result))) thenthenthenthen

Result := Trim(Result);

finallyfinallyfinallyfinally

CoTaskMemFree(IDL);

endendendend;

endendendend;

procedureprocedureprocedureprocedure TForm1.FormCreate(Sender: TObject);

beginbeginbeginbegin

Label1.Caption := GetSpecialFolder(CSIDL_APPDATA);

endendendend;

13

CSIDL_APPDATA

functionfunctionfunctionfunction GetWindowsDir: StringStringStringString

beginbeginbeginbegin

SetLength(Result, MAX_PATH);

Len :=

ExpandEnvironmentStrings(

PChar('%windir%'),

PChar(Result),

Length(Result));

ifififif (Len > 0) thenthenthenthen

Result := Copy(Result, 1, Len)

elseelseelseelse

Result := '';

endendendend;

SHGetSpecialFolder

Page 14: Embarcadero Developer Network Home Page - FÆ B6 FÇ Delphiedn.embarcadero.com/jp/article/images/40256/b6.pdf · 2010. 2. 8. · 4.RAD Studio 2010 FþGeG{GFG5G=GVG8GeGEGuG FÛG FÂGwG

Windows 7

Page 15: Embarcadero Developer Network Home Page - FÆ B6 FÇ Delphiedn.embarcadero.com/jp/article/images/40256/b6.pdf · 2010. 2. 8. · 4.RAD Studio 2010 FþGeG{GFG5G=GVG8GeGEGuG FÛG FÂGwG

15

• Windows 7

Page 16: Embarcadero Developer Network Home Page - FÆ B6 FÇ Delphiedn.embarcadero.com/jp/article/images/40256/b6.pdf · 2010. 2. 8. · 4.RAD Studio 2010 FþGeG{GFG5G=GVG8GeGEGuG FÛG FÂGwG

16

ShlObj.SetCurrentProcessExplicitAppUserModelID(PChar(' '));

SetCurrentProcessExplicitAppUserModelID API

ID

procedureprocedureprocedureprocedure TForm1.FormCreate(Sender: TObject);beginbeginbeginbeginSetCurrentProcessExplicitAppUserModelID('SERIALGAMES.DevCamp.AppID.1');

endendendend;

procedureprocedureprocedureprocedure TForm1.FormCreate(Sender: TObject);beginbeginbeginbeginRandomize;SetCurrentProcessExplicitAppUserModelID(PChar(IntToStr(Random(100))));

endendendend;

Page 17: Embarcadero Developer Network Home Page - FÆ B6 FÇ Delphiedn.embarcadero.com/jp/article/images/40256/b6.pdf · 2010. 2. 8. · 4.RAD Studio 2010 FþGeG{GFG5G=GVG8GeGEGuG FÛG FÂGwG

• AppUserModelID AppID

• CompanyName.ProductName.SubProduct.VersionInformation

• 128 byte

• AppID Windows

• AppUserModelID

• AppID API

17

Page 18: Embarcadero Developer Network Home Page - FÆ B6 FÇ Delphiedn.embarcadero.com/jp/article/images/40256/b6.pdf · 2010. 2. 8. · 4.RAD Studio 2010 FþGeG{GFG5G=GVG8GeGEGuG FÛG FÂGwG

ITaskbarList3

18

Windows 7

ITaskbarList3

※ MSDN

Page 19: Embarcadero Developer Network Home Page - FÆ B6 FÇ Delphiedn.embarcadero.com/jp/article/images/40256/b6.pdf · 2010. 2. 8. · 4.RAD Studio 2010 FþGeG{GFG5G=GVG8GeGEGuG FÛG FÂGwG

19

procedureprocedureprocedureprocedure TfrmTaskbarSample.SetTaskbarButton;varvarvarvarTL: ITaskbarList3;Buttons: array [0.. 1] of TThumbButton;

beginbeginbeginbeginifififif(

Succeeded(CoCreateInstance(CLSID_TaskbarList,nil,CLSCTX_ALL,IID_ITaskbarList3,TL)

))

thenthenthenthen beginbeginbeginbegin// withwithwithwith Buttons[0] dodododo beginbeginbeginbegindwMask := THB_ICON or THB_TOOLTIP or THB_FLAGS;iId := 0;szTip := ' ';dwFlags := THBF_ENABLED;

hIcon := LoadSysIcon(IDI_INFORMATION);endendendend;

// TL.ThumbBarSetImageList(Handle, ImageList1.Handle);

withwithwithwith Buttons[1] dodododo beginbeginbeginbegindwMask := THB_BITMAP or THB_TOOLTIP or THB_FLAGS;iId := 1;szTip := ' ';dwFlags := THBF_ENABLED;

iBitmap := 0;endendendend;

// TL.ThumbBarAddButtons(Handle, Length(Buttons), @Buttons);

endendendend;endendendend;

functionfunctionfunctionfunction TfrmTaskbarSample.LoadSysIcon(constconstconstconst iKind: PChar): HICON;beginbeginbeginbeginResult :=LoadImage(0, iKind, IMAGE_ICON, 0, 0, LR_DEFAULTSIZE or LR_SHARED);

endendendend;

※LoadSysIcon

Page 20: Embarcadero Developer Network Home Page - FÆ B6 FÇ Delphiedn.embarcadero.com/jp/article/images/40256/b6.pdf · 2010. 2. 8. · 4.RAD Studio 2010 FþGeG{GFG5G=GVG8GeGEGuG FÛG FÂGwG

20

procedureprocedureprocedureprocedure TfrmTaskbarSample.WMCommand(var iMsg: TWMCommand);beginbeginbeginbegininheritedinheritedinheritedinherited;

ifififif (iMsg.NotifyCode = THBN_CLICKED) thenthenthenthencasecasecasecase iMsg.ItemID ofofofof0:ShowMessage(' ');

1:ShowMessage('

');endendendend;

endendendend;

Page 21: Embarcadero Developer Network Home Page - FÆ B6 FÇ Delphiedn.embarcadero.com/jp/article/images/40256/b6.pdf · 2010. 2. 8. · 4.RAD Studio 2010 FþGeG{GFG5G=GVG8GeGEGuG FÛG FÂGwG

21

procedureprocedureprocedureprocedure TfrmTaskbarSample.SetOverlayIcon;varvarvarvarTL: ITaskbarList3;

beginbeginbeginbeginifififif(

Succeeded(CoCreateInstance(CLSID_TaskbarList,nil,CLSCTX_ALL,IID_ITaskbarList3,TL)

))

thenthenthenthenTL.SetOverlayIcon(Handle, LoadSysIcon(IDI_ERROR), 'ERROR ');

endendendend;

TL.SetOverlayIcon(Handle, 0, nil);

Page 22: Embarcadero Developer Network Home Page - FÆ B6 FÇ Delphiedn.embarcadero.com/jp/article/images/40256/b6.pdf · 2010. 2. 8. · 4.RAD Studio 2010 FþGeG{GFG5G=GVG8GeGEGuG FÛG FÂGwG

22

procedureprocedureprocedureprocedure TfrmTaskbarSample.InitProgress;beginbeginbeginbeginCoCreateInstance(CLSID_TaskbarList,nilnilnilnil,CLSCTX_ALL,IID_ITaskbarList3,FTaskbarList);

endendendend;

procedureprocedureprocedureprocedure TfrmTaskbarSample.SetProgress(constTfrmTaskbarSample.SetProgress(constTfrmTaskbarSample.SetProgress(constTfrmTaskbarSample.SetProgress(const iCompleted: Integer);beginbeginbeginbeginFTaskbarList.SetProgressState(Handle, TBPF_NORMAL);FTaskbarList.SetProgressValue(Handle, iCompleted, 100);

end;end;end;end;

procedureprocedureprocedureprocedure TfrmTaskbarSample.PauseProgress;beginbeginbeginbeginFTaskbarList.SetProgressState(Handle, TBPF_PAUSED);

endendendend;

procedureprocedureprocedureprocedure TfrmTaskbarSample.ErrorProgress;beginbeginbeginbeginFTaskbarList.SetProgressState(Handle, TBPF_ERROR);

endendendend;

TBPF_NOPROGRESSTBPF_INDETERMINATETBPF_NORMALTBPF_ERRORTBPF_PAUSED

Page 23: Embarcadero Developer Network Home Page - FÆ B6 FÇ Delphiedn.embarcadero.com/jp/article/images/40256/b6.pdf · 2010. 2. 8. · 4.RAD Studio 2010 FþGeG{GFG5G=GVG8GeGEGuG FÛG FÂGwG

23

※ MSDN

Windows 7

Page 24: Embarcadero Developer Network Home Page - FÆ B6 FÇ Delphiedn.embarcadero.com/jp/article/images/40256/b6.pdf · 2010. 2. 8. · 4.RAD Studio 2010 FþGeG{GFG5G=GVG8GeGEGuG FÛG FÂGwG

24

Win32 API

.NET Framework 4.0

VCL ……

MSDN

Page 25: Embarcadero Developer Network Home Page - FÆ B6 FÇ Delphiedn.embarcadero.com/jp/article/images/40256/b6.pdf · 2010. 2. 8. · 4.RAD Studio 2010 FþGeG{GFG5G=GVG8GeGEGuG FÛG FÂGwG

API

API

• InitPropVariantFromString

• InitPropVariantFromBoolean

• PropVariantClear

API

MSDN InitPropVariantFrom* propsys.dll 6.0

Windows 7 propsys.dll 7.0 API

• InitPropVariantFromString

• InitPropVariantFromBoolean

25

Page 26: Embarcadero Developer Network Home Page - FÆ B6 FÇ Delphiedn.embarcadero.com/jp/article/images/40256/b6.pdf · 2010. 2. 8. · 4.RAD Studio 2010 FþGeG{GFG5G=GVG8GeGEGuG FÛG FÂGwG

API

• InitPropVariantFromString InitPropVariantFromStringVector

• InitPropVariantFromBoolean InitPropVariantFromBooleanVector

Vector API

uPropSysForJumplist.pas

26

Page 27: Embarcadero Developer Network Home Page - FÆ B6 FÇ Delphiedn.embarcadero.com/jp/article/images/40256/b6.pdf · 2010. 2. 8. · 4.RAD Studio 2010 FþGeG{GFG5G=GVG8GeGEGuG FÛG FÂGwG

uPropSysForJumpList

27

unitunitunitunit uPropSysForJumpList;

interfaceinterfaceinterfaceinterface

usesusesusesusesWindows, ActiveX;

typetypetypetypePPWideChar = ^PWideChar;PBOOL = ^BOOL;

TInitPropVariantFromStringVector =functionfunctionfunctionfunction(prgsz: PPWideChar;cElems: ULONG;ppropvar: PPropVariant): HRESULT; stdcallstdcallstdcallstdcall;

TInitPropVariantFromString =functionfunctionfunctionfunction(psz: PWideChar;ppropvar: PPropVariant): HRESULT; stdcallstdcallstdcallstdcall;

TInitPropVariantFromBooleanVector =functionfunctionfunctionfunction(prgf: PBOOL;cElems: ULONG;ppropvar: PPropVariant): HRESULT; stdcallstdcallstdcallstdcall;

TInitPropVariantFromBoolean =functionfunctionfunctionfunction(fVal: BOOL;ppropvar: PPropVariant): HRESULT; stdcallstdcallstdcallstdcall;

TPropVariantClear = function(pVarfunction(pVarfunction(pVarfunction(pVar: PPropVariant): HRESULT; stdcallstdcallstdcallstdcall;

InitPropVariantFrom* InitPropVariantFrom*

API

Page 28: Embarcadero Developer Network Home Page - FÆ B6 FÇ Delphiedn.embarcadero.com/jp/article/images/40256/b6.pdf · 2010. 2. 8. · 4.RAD Studio 2010 FþGeG{GFG5G=GVG8GeGEGuG FÛG FÂGwG

uPropSysForJumpList

28

varvarvarvarInitPropVariantFromStringVector: TInitPropVariantFromStringVector = nilnilnilnil;InitPropVariantFromString: TInitPropVariantFromString = nilnilnilnil;InitPropVariantFromBooleanVector: TInitPropVariantFromBooleanVector = nilnilnilnil;InitPropVariantFromBoolean: TInitPropVariantFromBoolean = nilnilnilnil;PropVariantClear: TPropVariantClear = nilnilnilnil;

functionfunctionfunctionfunction PropSysLoaded: Boolean;

implementationimplementationimplementationimplementation

constconstconstconstCPropSysLib = 'propsys.dll';COle32Lib = 'Ole32.dll';

varvarvarvarGPropSysLib: HMODULE = 0;GOle32Lib: HMODULE = 0;

InitPropVariant propsys.dll PropVariantClear ole32.dll

Page 29: Embarcadero Developer Network Home Page - FÆ B6 FÇ Delphiedn.embarcadero.com/jp/article/images/40256/b6.pdf · 2010. 2. 8. · 4.RAD Studio 2010 FþGeG{GFG5G=GVG8GeGEGuG FÛG FÂGwG

uPropSysForJumpList

29

functionfunctionfunctionfunction _InitPropVariantFromString(psz: PWideChar;ppropvar: PPropVariant): HRESULT; stdcallstdcallstdcallstdcall;

beginbeginbeginbeginResult := ERROR_INVALID_FUNCTION;

ifififif (Assigned(InitPropVariantFromStringVector)) thenthenthenthenResult := InitPropVariantFromStringVector(@psz, 1, ppropvar);

endendendend;

functionfunctionfunctionfunction _InitPropVariantFromBoolean(fVal: BOOL;ppropvar: PPropVariant): HRESULT; stdcallstdcallstdcallstdcall;

beginbeginbeginbeginResult := ERROR_INVALID_FUNCTION;

ifififif (Assigned(InitPropVariantFromBooleanVector)) thenthenthenthenResult := InitPropVariantFromBooleanVector(@fVal, 1, ppropvar);

endendendend;

functionfunctionfunctionfunction PropSysLoaded: Boolean;beginbeginbeginbeginResult :=Assigned(InitPropVariantFromString) andandandandAssigned(InitPropVariantFromBoolean) andandandandAssigned(PropVariantClear);

endendendend;

InitPropVariantFrom*

Page 30: Embarcadero Developer Network Home Page - FÆ B6 FÇ Delphiedn.embarcadero.com/jp/article/images/40256/b6.pdf · 2010. 2. 8. · 4.RAD Studio 2010 FþGeG{GFG5G=GVG8GeGEGuG FÛG FÂGwG

uPropSysForJumpList

30

procedureprocedureprocedureprocedure LoadPropSys;beginbeginbeginbeginGPropSysLib := LoadLibrary(CPropSysLib);

ifififif (GPropSysLib <> 0) thenthenthenthen beginbeginbeginbegin// InitPropVariantFromStringInitPropVariantFromStringVector :=

TInitPropVariantFromStringVector(GetProcAddress(GPropSysLib, 'InitPropVariantFromStringVector'));

InitPropVariantFromString :=TInitPropVariantFromString(GetProcAddress(GPropSysLib, 'InitPropVariantFromString'));

ifififif (not Assigned(InitPropVariantFromString)) thenthenthenthenInitPropVariantFromString := _InitPropVariantFromString;

// InitPropVariantFromBooleanInitPropVariantFromBooleanVector :=

TInitPropVariantFromBooleanVector(GetProcAddress(GPropSysLib, 'InitPropVariantFromBooleanVector'));

InitPropVariantFromBoolean :=TInitPropVariantFromBoolean(GetProcAddress(GPropSysLib, 'InitPropVariantFromBoolean'));

ifififif (not Assigned(InitPropVariantFromBoolean)) thenthenthenthenInitPropVariantFromBoolean := _InitPropVariantFromBoolean;

endendendend;

InitPropVariantFrom*

Page 31: Embarcadero Developer Network Home Page - FÆ B6 FÇ Delphiedn.embarcadero.com/jp/article/images/40256/b6.pdf · 2010. 2. 8. · 4.RAD Studio 2010 FþGeG{GFG5G=GVG8GeGEGuG FÛG FÂGwG

uPropSysForJumpList

31

GOle32Lib := LoadLibrary(COle32Lib);

ifififif (GOle32Lib <> 0) thenthenthenthen beginbeginbeginbegin// PropVariantClearPropVariantClear :=

TPropVariantClear(GetProcAddress(GOle32Lib, 'PropVariantClear'));endendendend;

endendendend;

procedureprocedureprocedureprocedure UnloadPropSys;beginbeginbeginbeginifififif (GPropSysLib <> 0) thenthenthenthenFreeLibrary(GPropSysLib);

ifififif (GOle32Lib <> 0) thenthenthenthenFreeLibrary(GOle32Lib);

endendendend;

initializationinitializationinitializationinitializationbeginbeginbeginbeginLoadPropSys;

endendendend;

finalizationfinalizationfinalizationfinalizationbeginbeginbeginbeginUnloadPropSys;

endendendend;

PropVariantClear

Page 32: Embarcadero Developer Network Home Page - FÆ B6 FÇ Delphiedn.embarcadero.com/jp/article/images/40256/b6.pdf · 2010. 2. 8. · 4.RAD Studio 2010 FþGeG{GFG5G=GVG8GeGEGuG FÛG FÂGwG

• PropSys

• IDestionationList

• AppID

• IDestionationList

• IShellLink

• IObjectCollection IShellLink

• IDestionationList

32

Page 33: Embarcadero Developer Network Home Page - FÆ B6 FÇ Delphiedn.embarcadero.com/jp/article/images/40256/b6.pdf · 2010. 2. 8. · 4.RAD Studio 2010 FþGeG{GFG5G=GVG8GeGEGuG FÛG FÂGwG

TJumpList

33

procedureprocedureprocedureprocedure TForm1.Button1Click(Sender: TObject);varvarvarvarExeName: StringStringStringString;

beginbeginbeginbeginExeName := Application.ExeName;

withwithwithwith TJumplist.Create(ExeName) dodododotrytrytrytryAddTask(ExeName, 'Test1', '-test1');AddTask(ExeName, 'Test2', '-test2');AddTask('', '', '');AddTask('notepad.exe', 'run notepad', '');

CreateJumplist;finallyfinallyfinallyfinallyFree;

endendendend;endendendend;

procedureprocedureprocedureprocedure TForm1.FormCreate(Sender: TObject);beginbeginbeginbeginSetCurrentProcessExplicitAppUserModelID(PChar(Application.ExeName));

ifififif (ParamStr(1) = '-test1') thenthenthenthenShowMessage('-test1 ');

ifififif (ParamStr(1) = '-test2') thenthenthenthenShowMessage('-test2 ');

endendendend;

AddTask CreateJumplist

Page 34: Embarcadero Developer Network Home Page - FÆ B6 FÇ Delphiedn.embarcadero.com/jp/article/images/40256/b6.pdf · 2010. 2. 8. · 4.RAD Studio 2010 FþGeG{GFG5G=GVG8GeGEGuG FÛG FÂGwG

uJumpList

34

unitunitunitunit uJumpList;

interfaceinterfaceinterfaceinterface

usesusesusesusesClasses, ShlObj;

typetypetypetypeTJumplist = classclassclassclassprivateprivateprivateprivate// VariablesFAppID: StringStringStringString;FParams: TStringList;FCategories: TStringList;// Methodsfunctionfunctionfunctionfunction AddTasksToList(constconstconstconst iCDL: ICustomDestinationList): Boolean;functionfunctionfunctionfunction CreateShellLink(const iExe, iTitle, iArg: String): IShellLink;functionfunctionfunctionfunction CreateSeparatorLink: IShellLink;

publicpublicpublicpublic// Constructor & Destructorconstructorconstructorconstructorconstructor Create(consconsconsconst iAppID: StringStringStringString); reintroducereintroducereintroducereintroduce;destructordestructordestructordestructor Destroy; overrideoverrideoverrideoverride;// Taskfunctionfunctionfunctionfunction AddTask(const iExe, iTitle, iArg: StringStringStringString): Integer;procedureprocedureprocedureprocedure DeleteTask(const iIndex: Integer);procedureprocedureprocedureprocedure ClearTask;procedureprocedureprocedureprocedure GetParams(constconstconstconst iIndex: integer; varvarvarvar oExe, oTitle, oArg: StringStringStringString);// Jumplistfunctionfunctionfunctionfunction CreateJumplist: Boolean;functionfunctionfunctionfunction DestroyJumplist: Boolean;

endendendend;

TJumplist

Page 35: Embarcadero Developer Network Home Page - FÆ B6 FÇ Delphiedn.embarcadero.com/jp/article/images/40256/b6.pdf · 2010. 2. 8. · 4.RAD Studio 2010 FþGeG{GFG5G=GVG8GeGEGuG FÛG FÂGwG

uJumpList

35

constructorconstructorconstructorconstructor TJumplist.Create(constconstconstconst iAppID: StringStringStringString);beginbeginbeginbegininheritedinheritedinheritedinherited Create;

FAppID := iAppID;

FCategories := TStringList.Create;FParams := TStringList.Create;

endendendend;

AppID

usesusesusesusesWindows, SysUtils, Ole2, ShellAPI, ActiveX, ObjectArray, PropSys, PropKey, uPropSysForJumpList;

ShlObj

Page 36: Embarcadero Developer Network Home Page - FÆ B6 FÇ Delphiedn.embarcadero.com/jp/article/images/40256/b6.pdf · 2010. 2. 8. · 4.RAD Studio 2010 FþGeG{GFG5G=GVG8GeGEGuG FÛG FÂGwG

uJumpList

36

functionfunctionfunctionfunction TJumplist.CreateShellLink(constconstconstconst iExe, iTitle, iArg: String): IShellLink;

varvarvarvarHR: HRESULT;SL: IShellLink;PS: IPropertyStore;PropVar: TPropVariant;

beginbeginbeginbeginResult := nil;

HR :=CoCreateInstance(

CLSID_ShellLink,nil,CLSCTX_INPROC_SERVER,IID_IShellLink,SL);

ifififif (Failed(HR)) thenthenthenthenExit;

HR := SL.SetPath(PChar(iExe));

ifififif (Failed(HR)) thenthenthenthenExit;

HR := SL.SetArguments(PChar(iArg));

ifififif (Failed(HR)) thenthenthenthenExit;

HR := SL.QueryInterface(IID_IPropertyStore, PS);

ifififif (Failed(HR)) thenthenthenthenExit;

HR := InitPropVariantFromString(PChar(iTitle), @PropVar);trytrytrytry

ifififif (Failed(HR)) thenthenthenthenExit;

HR := PS.SetValue(PKEY_Title, PropVar);

ifififif (Failed(HR)) thenthenthenthenExit;

HR := PS.Commit;

ifififif (Failed(HR)) thenthenthenthenExit;

HR := SL.QueryInterface(IID_IShellLink, Result);

ifififif (Failed(HR)) thenthenthenthenResult := nilnilnilnil;

finallyfinallyfinallyfinallyPropVariantClear(@PropVar);

endendendend;endendendend;

IShellLink

Page 37: Embarcadero Developer Network Home Page - FÆ B6 FÇ Delphiedn.embarcadero.com/jp/article/images/40256/b6.pdf · 2010. 2. 8. · 4.RAD Studio 2010 FþGeG{GFG5G=GVG8GeGEGuG FÛG FÂGwG

uJumpList

37

functionfunctionfunctionfunction TJumplist.CreateSeparatorLink: IShellLink;varvarvarvarPS: IPropertyStore;HR: HRESULT;PropVar: TPropVariant;

beginbeginbeginbeginResult := nil;

HR :=CoCreateInstance(

CLSID_ShellLink,nil,CLSCTX_INPROC_SERVER,IID_IPropertyStore,PS);

ifififif (Failed(HR)) thenthenthenthenExit;

HR := InitPropVariantFromBoolean(True, @PropVar);

ifififif (Failed(HR)) thenthenthenthenExit;

HR := PS.SetValue(PKEY_AppUserModel_IsDestListSeparator, PropVar);

ifififif (Failed(HR)) thenthenthenthenExit;

HR := PS.Commit;

ifififif (Failed(HR)) thenthenthenthenExit;

HR := PS.QueryInterface(IID_IShellLink, Result);

ifififif (Failed(HR)) thenthenthenthenResult := nil;

endendendend;

IShellLink

Page 38: Embarcadero Developer Network Home Page - FÆ B6 FÇ Delphiedn.embarcadero.com/jp/article/images/40256/b6.pdf · 2010. 2. 8. · 4.RAD Studio 2010 FþGeG{GFG5G=GVG8GeGEGuG FÛG FÂGwG

uJumpList

38

functionfunctionfunctionfunction TJumplist.AddTasksToList(constconstconstconst iCDL: ICustomDestinationList): Boolean;

varvarvarvarHR: HRESULT;OC: IObjectCollection;OA: IObjectArray;SL: IShellLink;i: Integer;Exe, Title, Arg: StringStringStringString;

beginbeginbeginbeginResult := False;

HR :=CoCreateInstance(

CLSID_EnumerableObjectCollection,nil,CLSCTX_INPROC,IID_IObjectCollection,OC);

ifififif (Failed(HR)) thenthenthenthenExit;

forforforfor i := 0 to FParams.Count - 1 dodododo beginbeginbeginbeginGetParams(i, Exe, Title, Arg);

ifififif (Exe <> '') thenthenthenthenSL := CreateShellLink(Exe, Title, Arg)

elseelseelseelseSL := CreateSeparatorLink;

ifififif (SL = nilnilnilnil) thenthenthenthenContinue;

HR := OC.AddObject(SL);

ifififif (Failed(HR)) thenthenthenthenContinue;

endendendend;

HR := OC.QueryInterface(IID_IObjectArray, OA);

ifififif (Failed(HR)) thenthenthenthenExit;

Result := Succeeded(iCDL.AddUserTasks(OA));endendendend;

ICustomDestinationList IShellLink

GetParams FParams Exe, Title, ArgAdd FParams

Page 39: Embarcadero Developer Network Home Page - FÆ B6 FÇ Delphiedn.embarcadero.com/jp/article/images/40256/b6.pdf · 2010. 2. 8. · 4.RAD Studio 2010 FþGeG{GFG5G=GVG8GeGEGuG FÛG FÂGwG

uJumpList

39

functionfunctionfunctionfunction TJumplist.CreateJumplist: Boolean;varvarvarvarHR: HRESULT;CDL: ICustomDestinationList;OARemoved: IObjectArray;MinSlots: Cardinal;

beginbeginbeginbeginResult := False;

ifififif (not PropSysLoaded) thenthenthenthenExit;

HR :=CoCreateInstance(

CLSID_DestinationList,nil,CLSCTX_INPROC_SERVER,IID_ICustomDestinationList,CDL);

ifififif (Failed(HR)) thenthenthenthenExit;

HR := CDL.SetAppID(PChar(FAppID));

ifififif (Failed(HR)) thenthenthenthenExit;

HR := CDL.BeginList(MinSlots, IID_IObjectArray, OARemoved);

ifififif (Failed(HR)) thenthenthenthenExit;

ifififif (AddTasksToList(CDL)) thenthenthenthenResult := Succeeded(CDL.CommitList)

elseelseelseelseCDL.AbortList;

endendendend;

Page 40: Embarcadero Developer Network Home Page - FÆ B6 FÇ Delphiedn.embarcadero.com/jp/article/images/40256/b6.pdf · 2010. 2. 8. · 4.RAD Studio 2010 FþGeG{GFG5G=GVG8GeGEGuG FÛG FÂGwG

uJumpList

40

functionfunctionfunctionfunction TJumplist.DestroyJumplist: Boolean;varvarvarvarHR: HRESULT;CDL: ICustomDestinationList;

beginbeginbeginbeginResult := False;

ifififif (not PropSysLoaded) thenthenthenthenExit;

HR :=CoCreateInstance(

CLSID_DestinationList,nil,CLSCTX_INPROC_SERVER,IID_ICustomDestinationList,CDL);

ifififif (Failed(HR)) thenthenthenthenExit;

Result := Succeeded(CDL.DeleteList(nil));endendendend;

Page 41: Embarcadero Developer Network Home Page - FÆ B6 FÇ Delphiedn.embarcadero.com/jp/article/images/40256/b6.pdf · 2010. 2. 8. · 4.RAD Studio 2010 FþGeG{GFG5G=GVG8GeGEGuG FÛG FÂGwG

• MSDN

• Windows7

• http://www.microsoft.com/japan/powerpro/developer/default.mspx

• Introducing The Taskbar APIs

• http://msdn.microsoft.com/en-us/magazine/dd942846.aspx

• MSDN Sample Code

• CustomJumpListSample

– http://msdn.microsoft.com/en-us/library/dd940352(VS.85).aspx

41

Page 42: Embarcadero Developer Network Home Page - FÆ B6 FÇ Delphiedn.embarcadero.com/jp/article/images/40256/b6.pdf · 2010. 2. 8. · 4.RAD Studio 2010 FþGeG{GFG5G=GVG8GeGEGuG FÛG FÂGwG

42