Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2003.09.11;
Скачать: CL | DM;

Вниз

Проблема с 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 вся ветка

Текущий архив: 2003.09.11;
Скачать: CL | DM;

Наверх




Память: 0.48 MB
Время: 0.021 c
14-33756
emike
2003-08-25 04:18
2003.09.11
c++->pascal


1-33633
tvic
2003-09-01 16:40
2003.09.11
Глюк с чтением файлов


14-33729
Knight
2003-08-22 10:46
2003.09.11
А у нас горячую воду дали!!!


1-33570
isff
2003-09-01 15:23
2003.09.11
dll, изменение в главной форме.


1-33678
Юлия
2003-08-29 09:41
2003.09.11
Можно ли для treeview сделать возможность отмечать узлы? (check)