Welcome to Egypt Forums Mark forums read | Egypt Main Page
Egypt Forums
Arabic Movies



Delphi Delphi, automotive, commercial vehicle, components, parts, auto, Delco, Packard, diesel, gas, engine management, connectors, radio, electronics, consumer electronics, satellite radio, delphiauto, Delphi auto, medical, technology licensing, innovations in commercial vehicle industry, automotive safety system assemblers, automotive electrical architecture design, consumer marine electronics, fiber optic cable connector types, advanced auto parts, xm satellite radio, ultimate electronics, fiber optics, delphi connection systems catalog

Delphi Thread, How to write a Shell Search by Implementing IShellExtInit, IContextMenu in Programming Languages; How to write a Shell Search by Implementing IShellExtInit, IContextMenu The Shell supports several search utilities that allow users to ...

Short Link: http://forum.egypt.com/enforum/showthread.php?t=6725


Reply
LinkBack Thread Tools Display Modes
How to write a Shell Search by Implementing IShellExtInit, IContextMenu
 
 
The God Father
Developer's Avatar

Reply With Quote
 
Join Date: Jul 2008
Location: NDC
Posts: 5,425
27-11-2008, 05:30 AM
 
How to write a Shell Search by Implementing IShellExtInit, IContextMenu

The Shell supports several search utilities that allow users to locate namespace objects such as files or printers. You can create a custom search engine and make it available to users by implementing and registering a search handler.
Users have two ways to select a search engine. The first way is from the Start menu. With systems earlier than Microsoft Windows 2000, selecting the Find command on the Start menu displays a submenu of the available search engines. With Windows 2000 and later, the Start menu's Find command is renamed Search. The following illustration shows the Search button on a Windows XP system.


Egypt.Com EnForum
Users can also launch a search from Windows Explorer. On systems earlier than Windows 2000, they click the Find command on the Tools menu to display essentially the same menu as the one associated with the Start menu. However, Windows Explorer for Windows 2000 handles search engines in a very different way. Instead of handling search engines as a submenu of the Tools menu, there is now a Search button on the toolbar. Clicking this button opens the Explorer bar's Search pane.
The following example shows how to implement Shell Search Handler using Borland Delphi. As any Shell Extension it must be implemented as in-process Component Object Model (COM) object. It must be assigned a globally unique identifier (GUID) and registered using regsvr32.exe
library SearchHandler;

uses
ComServ,
HandlerM in 'HandlerM.pas';

{$R *.RES}

exports
DllGetClassObject,
DllCanUnloadNow,
DllRegisterServer,
DllUnregisterServer;

begin
end
.


{************************************************* ****************************
Name : TSearchEngine
Author : Perevoznyk Serhiy
Description : Shell Search Handler
************************************************** ***************************}

unit HandlerM;

interface

uses
Windows, ActiveX, ComObj, ShlObj, Dialogs;

type
TSearchEngine = class(TComObject, IShellExtInit, IContextMenu)
protected
{ IShellExtInit }
function IShellExtInit.Initialize = SEIInitialize; // Avoid compiler warning
function SEIInitialize(pidlFolder: PItemIDList; lpdobj: IDataObject;
hKeyProgID: HKEY): HResult; stdcall;
{ IContextMenu }
function QueryContextMenu(Menu: HMENU; indexMenu, idCmdFirst, idCmdLast,
uFlags: UINT): HResult; stdcall;
function InvokeCommand(var lpici: TCMInvokeCommandInfo): HResult; stdcall;
function GetCommandString(idCmd, uType: UINT; pwReserved: PUINT;
pszName: LPSTR; cchMax: UINT): HResult; stdcall;
end;


const
Class_SearchEngine: TGUID = '{B8091A44-1F5E-4EFE-8F26-194ACBDE4465}';

implementation

uses
ComServ, SysUtils, ShellApi, Registry;

function TSearchEngine.SEIInitialize(pidlFolder: PItemIDList; lpdobj: IDataObject;
hKeyProgID: HKEY): HResult;
begin
Result := NOERROR;
end;

function TSearchEngine.QueryContextMenu(Menu: HMENU; indexMenu, idCmdFirst,
idCmdLast, uFlags: UINT): HResult;
begin
Result := 0;
end;



function TSearchEngine.InvokeCommand(var lpici: TCMInvokeCommandInfo): HResult;
begin
//enter your code here
ShowMessage('Executed');
Result := NOERROR;
end;

function TSearchEngine.GetCommandString(idCmd, uType: UINT; pwReserved: PUINT;
pszName: LPSTR; cchMax: UINT): HRESULT;
begin
if
(idCmd = 0) then
begin
if
(uType = GCS_HELPTEXT) then
// return help string for menu item
StrCopy(pszName, 'Find document');
Result := NOERROR;
end
else
Result := E_INVALIDARG;

end;

type
TSearchEngineFactory = class(TComObjectFactory)
public
procedure
UpdateRegistry(Register: Boolean); override;
end;


procedure CreateKey(const Key, ValueName, Value: string);

var
Handle: HKey;
Status, Disposition: Integer;
begin
Status := RegCreateKeyEx(HKEY_LOCAL_MACHINE, PChar(Key), 0, '',
REG_OPTION_NON_VOLATILE, KEY_READ or KEY_WRITE, nil, Handle,
@Disposition);
if Status = 0 then
begin
RegSetValueEx(Handle, PChar(ValueName), 0, REG_SZ,
PChar(Value), Length(Value) + 1);
RegCloseKey(Handle);
end;
end;



procedure DeleteKey(const Key: string);
begin
RegDeleteKey(HKEY_LOCAL_MACHINE, PChar(Key));
end;


procedure TSearchEngineFactory.UpdateRegistry(Register: Boolean);
var
ClassID: string;
FileName: array [0..MAX_PATH] of Char;

begin
if Register then
begin
inherited
UpdateRegistry(Register);
ClassID := GUIDToString(Class_SearchEngine);
GetModuleFileName(HInstance, FileName, SizeOf(FileName));
CreateKey('Software\Microsoft\Windows\CurrentVersion\Explore r\FindExtensions\Static\SearchHandler', '', ClassID);
CreateKey('Software\Microsoft\Windows\CurrentVersion\Explore r\FindExtensions\Static\SearchHandler\0', '', 'Using Delphi...');
CreateKey('Software\Microsoft\Windows\CurrentVersion\Explore r\FindExtensions\Static\SearchHandler\0\DefaultIco n', '', FileName + ',0');
end
else
begin
DeleteKey('Software\Microsoft\Windows\CurrentVersion\Explore r\FindExtensions\Static\SearchHandler\0\DefaultIco n');
DeleteKey('Software\Microsoft\Windows\CurrentVersion\Explore r\FindExtensions\Static\SearchHandler\0');
DeleteKey('Software\Microsoft\Windows\CurrentVersion\Explore r\FindExtensions\Static\SearchHandler');
inherited UpdateRegistry(Register);
end;

end;

initialization
TSearchEngineFactory.Create(ComServer, TSearchEngine, Class_SearchEngine,
'', 'Delphi Search Engine Example', ciMultiInstance,
tmApartment);
end.
__________________
I Love Walking In The Rain Cuz Nobody Know I'm Crying !!
 
 
 
Reply

Delphi Thread, How to write a Shell Search by Implementing IShellExtInit, IContextMenu in Programming Languages; How to write a Shell Search by Implementing IShellExtInit, IContextMenu The Shell supports several search utilities that allow users to ...

Short Link: http://forum.egypt.com/enforum/showthread.php?t=6725


Bookmarks

Tags
icontextmenu, implementing, ishellextinit, search, shell, write


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Implementing CSRF Protection in modifications Developer Articles 4 08-04-2009 09:27 PM
How to Write For the Web Developer Articles 0 16-12-2008 01:20 AM
Implementing Click-To-Seek For The FLVPlayback Component SABRAWY Flash Media Server 0 17-09-2008 08:29 AM
Implementing CSRF Protection in modifications Developer Articles 0 10-09-2008 06:32 PM
Write To Windows Event Log ... Developer Classes & Source Code 0 31-08-2008 08:02 PM