Форум: "WinAPI";
Текущий архив: 2003.09.11;
Скачать: [xml.tar.bz2];
ВнизПроблема с SHChangeNotifyRegister Найти похожие ветки
← →
GaricT (2003-07-14 11:56) [0]Следующий код не работает, то есть после SHChangeNotifyRegister, программа не получает уведомлений от оболочки, не могу понять в чем ошибка.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,ActiveX, ComObj, ShlObj;
type
NOTIFYREGISTER = record
pidlPath : PItemIDList;
bWatchSubtree : boolean;
end;
PNOTIFYREGISTER = ^NOTIFYREGISTER;
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
procedure WndProc(var M: TMessage);
{ Public declarations }
end;
const
SNM_SHELLNOTIFICATION = WM_USER +23;
SHCNF_ACCEPT_INTERRUPTS = $0001;
SHCNF_ACCEPT_NON_INTERRUPTS = $0002;
SHCNRF_RecursiveInterrupt = $1000;
SHCNF_NO_PROXY = $8000;
var
Form1: TForm1;
Handle:HWND;
function SHChangeNotifyRegister( hWnd: HWND; dwFlags: integer;
wEventMask : cardinal; uMsg: UINT; cItems : integer;
lpItems : PNOTIFYREGISTER) : HWND; stdcall;
function SHChangeNotifyDeregister(hWnd: HWND) : boolean; stdcall;
function SHILCreateFromPath(Path: Pointer; PIDL: PItemIDList;
var Attributes: ULONG):HResult; stdcall;
implementation
const Shell32DLL = "shell32.dll";
function SHChangeNotifyRegister; external Shell32DLL index 2;
function SHChangeNotifyDeregister; external Shell32DLL index 4;
function SHILCreateFromPath; external Shell32DLL index 28;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
h:HWND;
NotifyRecord: NOTIFYREGISTER;
Pidl: PItemIDList;
NotyfyRecord:NOTIFYREGISTER;
PNotyfyRecord:PNOTIFYREGISTER;
begin
SHGetSpecialFolderLocation(Handle,CSIDL_DRIVES,Pidl);
NotifyRecord.pidlPath:=pidl;
NotifyRecord.bWatchSubtree:=true;
PNotyfyRecord:=@NotifyRecord;
h:=SHChangeNotifyRegister(
Handle,
SHCNF_ACCEPT_INTERRUPTS or SHCNRF_RecursiveInterrupt or SHCNF_ACCEPT_NON_INTERRUPTS,
SHCNE_MKDIR or SHCNE_RENAMEFOLDER or SHCNE_RMDIR or SHCNE_UPDATEDIR or SHCNE_CREATE,
SNM_SHELLNOTIFICATION,
1,
PNotyfyRecord);
if h=null then ShowMessage ("Неудача!") else Showmessage("Зарегистрировали");
end;
procedure TForm1.WndProc(var M:TMessage);
begin
( "Получили")Следующий код не работает, то есть после SHChangeNotifyRegister, программа не получает уведомлений от оболочки, не могу понять в чем ошибка.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,ActiveX, ComObj, ShlObj;
type
NOTIFYREGISTER = record
pidlPath : PItemIDList;
bWatchSubtree : boolean;
end;
PNOTIFYREGISTER = ^NOTIFYREGISTER;
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
procedure WndProc(var M: TMessage);
{ Public declarations }
end;
const
SNM_SHELLNOTIFICATION = WM_USER +23;
SHCNF_ACCEPT_INTERRUPTS = $0001;
SHCNF_ACCEPT_NON_INTERRUPTS = $0002;
SHCNRF_RecursiveInterrupt = $1000;
SHCNF_NO_PROXY = $8000;
var
Form1: TForm1;
Handle:HWND;
function SHChangeNotifyRegister( hWnd: HWND; dwFlags: integer;
wEventMask : cardinal; uMsg: UINT; cItems : integer;
lpItems : PNOTIFYREGISTER) : HWND; stdcall;
function SHChangeNotifyDeregister(hWnd: HWND) : boolean; stdcall;
function SHILCreateFromPath(Path: Pointer; PIDL: PItemIDList;
var Attributes: ULONG):HResult; stdcall;
implementation
const Shell32DLL = "shell32.dll";
function SHChangeNotifyRegister; external Shell32DLL index 2;
function SHChangeNotifyDeregister; external Shell32DLL index 4;
function SHILCreateFromPath; external Shell32DLL index 28;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
h:HWND;
NotifyRecord: NOTIFYREGISTER;
Pidl: PItemIDList;
NotyfyRecord:NOTIFYREGISTER;
PNotyfyRecord:PNOTIFYREGISTER;
begin
SHGetSpecialFolderLocation(Handle,CSIDL_DRIVES,Pidl);
NotifyRecord.pidlPath:=pidl;
NotifyRecord.bWatchSubtree:=true;
PNotyfyRecord:=@NotifyRecord;
h:=SHChangeNotifyRegister(
Handle,
SHCNF_ACCEPT_INTERRUPTS or SHCNRF_RecursiveInterrupt or SHCNF_ACCEPT_NON_INTERRUPTS,
SHCNE_MKDIR or SHCNE_RENAMEFOLDER or SHCNE_RMDIR or SHCNE_UPDATEDIR or SHCNE_CREATE,
SNM_SHELLNOTIFICATION,
1,
PNotyfyRecord);
if h=null then ShowMessage ("Неудача!") else Showmessage("Зарегистрировали");
end;
procedure TForm1.WndProc(var M:TMessage);
begin
if M.Msg=SNM_SHELLNOTIFICATION then ShowMessage("Получили");
end;
end.
← →
Cobalt (2003-07-14 22:10) [1]глянь это:
http://www.howtodothings.com/showarticle.asp?article=314
← →
GaricT (2003-07-14 22:38) [2]Пасиба. Данный код работает. Только требует замены
procedure TShellNotification.ShellNotifyRegister;
.................
SHILCreatefromPath( PChar(fPath), Addr(Pidl), Attributes);
.................
на
procedure TShellNotification.ShellNotifyRegister;
.................
SHGetSpecialFolderLocation(Handle,CSIDL_DRIVES,Pidl);
.................
В силу того что SHILCreatefromPath в WindowsXP и Win2k возвращает Pidl=nil при любых параметрах
Страницы: 1 вся ветка
Форум: "WinAPI";
Текущий архив: 2003.09.11;
Скачать: [xml.tar.bz2];
Память: 0.46 MB
Время: 0.007 c