Autor Beitrag
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Do 09.09.04 16:38 
Hallo!

Durch diesen Thread bin ich auf ein Problem gestoßen, welches mich vor ein großes Rätsel stellt. Es geht um das OnIncludeItem-Event des OpenDialogs. Dieses kann dazu benutzt werden, um die Dateien, welche im Dialog angezeigt werden, im Programm zu filtern. Um das Event zu benutzen muss die Option ofEnableOnIncludeNotify auf True gesetzt werden.

Um nun beispielsweise BMP-Dateien zu filtern, habe ich folgenden Code geschrieben:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
procedure TForm1.OpenDialog1IncludeItem(const OFN: TOFNotifyEx;
  var Include: Boolean);
var theName : Array[0..MAX_PATH+1] Of Char;
    ext : String;
begin
  SHGetPathFromIdList(PItemIdList(OFN.pidl),theName);
  ext := ExtractFileExt(String(theName));

  if ext <> '.bmp' then
    include := true
  else
    include := False;
end;


Öffne ich nun einen Ordner, der Dateien mit der Endung ".bmp" enthält, wird das Ereignis ordnungsgemäß für jede Datei aufgerufen, es wird festgestellt, dass die Dateiendung ".bmp" und "include" wird auf false gesetzt. Laut Delphi-Hilfe wird damit die entsprechende Datei nicht im Dialog angezeigt.

Wird sie aber doch! :shock:

Hat einer eine Idee, woran das liegen könnte?

MfG
Christian

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
Gast
Gast
Erhaltene Danke: 1



BeitragVerfasst: Di 21.09.04 23:09 
Also das von dir genannte Flag entspricht ja offenbar OFN_ENABLEINCLUDENOTIFY. Mehr konnte ich zum Thema nicht finden, da dies in D4 so noch nicht existiert. Das Flag "ofEnableOnIncludeNotify" existiert zwar auch unter D4, aber ich kann keinen Eventhandler deklarieren, da das Event schlicht nicht vorgegeben ist.

Meiner Meinung nach, könnte es sich um eine fehlerhafte Implementation seitens Borland handeln, zumal ja schon in D4 was nicht stimmt.

Poste doch mal relevante Teile der Common Dialog Unit.
Gast
Gast
Erhaltene Danke: 1



BeitragVerfasst: Di 21.09.04 23:34 
Zitat:
The CDN_INCLUDEITEM notification message provides another way to filter the names that the dialog box displays. To use this message, provide an OFNHookProc hook procedure and specify the OFN_ENABLEINCLUDENOTIFY flag in the OPENFILENAME structure when you create the dialog box. Each time the user opens a folder, the dialog box sends a CDN_INCLUDEITEM notification to your hook procedure for each item in the newly opened folder. The return value of the hook procedure indicates whether the dialog box should display the item in the folder's item list.


Schonmal versucht das Ganze in der Notification-Proc (siehe Parameter) zu tun? Ich kenne ja den Prototypen nicht ...
Christian S. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Mi 22.09.04 10:49 
Hi!

Danke für die Antwort(en).

Hier erst einmal die relevanten Teile des Borland-Sources:

ausblenden volle Höhe WndPrc
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
procedure WndProc(var Message: TMessage); override;
{...}
implementation
{...}
procedure TOpenDialog.WndProc(var Message: TMessage);
var
  Index: Integer;
  Include: Boolean;
begin
  Message.Result := 0;
  { If not ofOldStyleDialog then DoShow on CDN_INITDONE, not WM_INITDIALOG }
  if (Message.Msg = WM_INITDIALOG) and not (ofOldStyleDialog in Options) then Exit
  else if (Message.Msg = WM_NOTIFY) then
    case (POFNotify(Message.LParam)^.hdr.code) of
      CDN_FILEOK:
        if not CanClose(POFNotify(Message.LParam)^.lpOFN^) then
        begin
          Message.Result := 1;
          SetWindowLong(Handle, DWL_MSGRESULT, Message.Result);
          Exit;
        end;
      CDN_INITDONE: DoShow;
      CDN_SELCHANGE: DoSelectionChange;
      CDN_FOLDERCHANGE: DoFolderChange;
      CDN_TYPECHANGE:
        begin
          Index := POFNotify(Message.LParam)^.lpOFN^.nFilterIndex;
          if Index <> FCurrentFilterIndex then
          begin
            FCurrentFilterIndex := Index;
            DoTypeChange;
          end;
        end;
      CDN_INCLUDEITEM:
        if Message.LParam <> 0 then
        begin
          Include := True;
          DoIncludeItem(TOFNotifyEx(POFNotifyEx(Message.LParam)^), Include);
          Message.Result := Byte(Include);
        end;
    end;
  inherited WndProc(Message);
end;


ausblenden DoIncludeItem
1:
2:
3:
4:
5:
6:
7:
8:
procedure DoIncludeItem(const OFN: TOFNotifyEx; var Include: Boolean); dynamic;
{...}
implementation
{...}
procedure TOpenDialog.DoIncludeItem(const OFN: TOFNotifyEx; var Include: Boolean);
begin
  if Assigned(FOnIncludeItem) then FOnIncludeItem(OFN, Include);
end;


Das mit der Not.-Proc. probiere ich heute abend aus.

MfG
Christian

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
Gast
Gast
Erhaltene Danke: 1



BeitragVerfasst: Mi 22.09.04 13:21 
Christian S. hat folgendes geschrieben:

ausblenden volle Höhe WndPrc
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
procedure WndProc(var Message: TMessage); override;
{...}
implementation
{...}
procedure TOpenDialog.WndProc(var Message: TMessage);
var
  Index: Integer;
  Include: Boolean;
begin
  Message.Result := 0;
  { If not ofOldStyleDialog then DoShow on CDN_INITDONE, not WM_INITDIALOG }
  if (Message.Msg = WM_INITDIALOG) and not (ofOldStyleDialog in Options) then Exit
  else if (Message.Msg = WM_NOTIFY) then
    case (POFNotify(Message.LParam)^.hdr.code) of
      CDN_FILEOK:
        if not CanClose(POFNotify(Message.LParam)^.lpOFN^) then
        begin
          Message.Result := 1;
          SetWindowLong(Handle, DWL_MSGRESULT, Message.Result);
          Exit;
        end;
      CDN_INITDONE: DoShow;
      CDN_SELCHANGE: DoSelectionChange;
      CDN_FOLDERCHANGE: DoFolderChange;
      CDN_TYPECHANGE:
        begin
          Index := POFNotify(Message.LParam)^.lpOFN^.nFilterIndex;
          if Index <> FCurrentFilterIndex then
          begin
            FCurrentFilterIndex := Index;
            DoTypeChange;
          end;
        end;
      CDN_INCLUDEITEM:
        if Message.LParam <> 0 then
        begin
          Include := True;
          DoIncludeItem(TOFNotifyEx(POFNotifyEx(Message.LParam)^), Include);
          Message.Result := Byte(Include);
        end;
    end;
  inherited WndProc(Message);
end;


ausblenden volle Höhe Delphi 4 -> TOpenDialog.WndProc
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
procedure TOpenDialog.WndProc(var Message: TMessage);
var
  Index: Integer;
begin
  Message.Result := 0;
  { If not ofOldStyleDialog then DoShow on CDN_INITDONE, not WM_INITDIALOG }
  if (Message.Msg = WM_INITDIALOG) and not (ofOldStyleDialog in Options) then Exit
  else if (Message.Msg = WM_NOTIFY) then
    case (POFNotify(Message.LParam)^.hdr.code) of
      CDN_FILEOK:
        if not CanClose(POFNotify(Message.LParam)^.lpOFN^) then
        begin
          Message.Result := 1;
          SetWindowLong(Handle, DWL_MSGRESULT, Message.Result);
          Exit;
        end;
      CDN_INITDONE: DoShow;
      CDN_SELCHANGE: DoSelectionChange;
      CDN_FOLDERCHANGE: DoFolderChange;
      CDN_TYPECHANGE:
        begin
          Index := POFNotify(Message.LParam)^.lpOFN^.nFilterIndex;
          if Index <> FCurrentFilterIndex then
          begin
            FCurrentFilterIndex := Index;
            DoTypeChange;
          end;
        end;
    end;
  inherited WndProc(Message);
end;


Also wie man im Vergleich erstmal sieht, ist es unter Delphi 4 eben nicht vorhanden.

... und soweit ich das überschaue, gibt es keine Implementationsfehler an dieser Stelle. Also die WndProc-Implementation sieht mir erstmal okay aus. Interessant wäre jetzt die Stelle, wo die "of..."-Flags auf die "OFN_..."-Flags gemappt werden. Kannst du die nochmal eben rauskramen.

Übrigens das mit der Notification ... da wäre der Prototyp auch nochmal interessant. Ich vermute eigentlich, daß die Notifiaction nix dergleichen kann. Aber kannst das ja mal prüfen.
Christian S. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Mi 22.09.04 19:36 
Hi!

Das Mapping erfolgt in der Funktion DoExecute. Ich habe nur die Teile gekürzt, bei denen ich auf einen Blick gesehen habe, dass sie mit dem Problem nichts zu tun haben. Wahrscheinlich könnte man noch mehr kürzen, aber was soll's. Es lebe der Traffic! ;-)
ausblenden volle Höhe DoExecute
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
function TOpenDialog.DoExecute(Func: Pointer): Bool;
const
  MultiSelectBufferSize = High(Word) - 16;
  OpenOptions: array [TOpenOption] of DWORD = (
    OFN_READONLY, OFN_OVERWRITEPROMPT, OFN_HIDEREADONLY,
    OFN_NOCHANGEDIR, OFN_SHOWHELP, OFN_NOVALIDATE, OFN_ALLOWMULTISELECT,
    OFN_EXTENSIONDIFFERENT, OFN_PATHMUSTEXIST, OFN_FILEMUSTEXIST,
    OFN_CREATEPROMPT, OFN_SHAREAWARE, OFN_NOREADONLYRETURN,
    OFN_NOTESTFILECREATE, OFN_NONETWORKBUTTON, OFN_NOLONGNAMES,
    OFN_EXPLORER, OFN_NODEREFERENCELINKS, OFN_ENABLEINCLUDENOTIFY,
    OFN_ENABLESIZING, OFN_DONTADDTORECENT, OFN_FORCESHOWHIDDEN);

  OpenOptionsEx: array [TOpenOptionEx] of DWORD = (OFN_EX_NOPLACESBAR);
var
  Option: TOpenOption;
  OptionEx: TOpenOptionEx;
  OpenFilename: TOpenFilename;

  {... gekürzt ...}

var
  TempFilter, TempFilename, TempExt: string;
begin
  FFiles.Clear;
  FillChar(OpenFileName, SizeOf(OpenFileName), 0);
  with OpenFilename do
  begin

    {... gekürzt ...}

    Flags := OFN_ENABLEHOOK;
    FlagsEx := 0;

    for Option := Low(Option) to High(Option) do
      if Option in FOptions then
        Flags := Flags or OpenOptions[Option];
    if NewStyleControls then
    begin
      Flags := Flags xor OFN_EXPLORER;
      if (Win32MajorVersion >= 5) and (Win32Platform = VER_PLATFORM_WIN32_NT) or { Win2k }
      ((Win32Platform = VER_PLATFORM_WIN32_WINDOWS) and (Win32MajorVersion >= 4) and (Win32MinorVersion >= 90)) then { WinME }
        for OptionEx := Low(OptionEx) to High(OptionEx) do
          if OptionEx in FOptionsEx then
            FlagsEx := FlagsEx or OpenOptionsEx[OptionEx]; 
    end
    else
      Flags := Flags and not OFN_EXPLORER;

    {... gekürzt ...}

    if (ofOldStyleDialog in Options) or not NewStyleControls then
      lpfnHook := DialogHook
    else
      lpfnHook := ExplorerHook;

    if Template <> nil then
    begin
      Flags := Flags or OFN_ENABLETEMPLATE;
      lpTemplateName := Template;
    end;
    hWndOwner := Application.Handle;
    Result := TaskModalDialog(Func, OpenFileName);
    if Result then
    begin
      GetFileNames(OpenFilename);
      if (Flags and OFN_EXTENSIONDIFFERENT) <> 0 then
        Include(FOptions, ofExtensionDifferent) else
        Exclude(FOptions, ofExtensionDifferent);
      if (Flags and OFN_READONLY) <> 0 then
        Include(FOptions, ofReadOnly) else
        Exclude(FOptions, ofReadOnly);
      FFilterIndex := nFilterIndex;
    end;
  end;
end;


Dazu passend noch die OpenOptions:
ausblenden OpenOptions, OpenOptionsEx
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
  TOpenOption = (ofReadOnly, ofOverwritePrompt, ofHideReadOnly,
    ofNoChangeDir, ofShowHelp, ofNoValidate, ofAllowMultiSelect,
    ofExtensionDifferent, ofPathMustExist, ofFileMustExist, ofCreatePrompt,
    ofShareAware, ofNoReadOnlyReturn, ofNoTestFileCreate, ofNoNetworkButton,
    ofNoLongNames, ofOldStyleDialog, ofNoDereferenceLinks, ofEnableIncludeNotify,
    ofEnableSizing, ofDontAddToRecent, ofForceShowHidden);
  TOpenOptions = set of TOpenOption;

  TOpenOptionEx = (ofExNoPlacesBar);
  TOpenOptionsEx = set of TOpenOptionEx;

Sieht mir alles richtig aus.

Die ExplorerHook-Prozedur sieht so aus:
ausblenden ExplorerHook
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
function ExplorerHook(Wnd: HWnd; Msg: UINT; WParam: WPARAM; LParam: LPARAM): UINT; stdcall;
begin
  Result := 0;
  if Msg = WM_INITDIALOG then
  begin
    CreationControl.FHandle := Wnd;
    CreationControl.FDefWndProc := Pointer(SetWindowLong(Wnd, GWL_WNDPROC,
      Longint(CreationControl.FObjectInstance)));
    CallWindowProc(CreationControl.FObjectInstance, Wnd, Msg, WParam, LParam);
    CreationControl := nil;
  end
  else if (Msg = WM_NOTIFY) and (POFNotify(LParam)^.hdr.code = CDN_INITDONE) then
    CenterWindow(GetWindowLong(Wnd, GWL_HWNDPARENT));
end;


Sieht (für mich, der da wenig Ahnung hat und wahrscheinlich besser still wäre) irgendwie so aus, als würde die WndProc gar nicht aufgerufen, denn CDN_INCLUDEITEM wird ja mittels WM_NOTIFY gesendet und da tut sich nur was, nachdem die Initialisierung beendet ist und es wird auch nur das Fenster zentriert.

MfG
Christian

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
Gast
Gast
Erhaltene Danke: 1



BeitragVerfasst: Do 23.09.04 08:39 
Also das Mapping haut hin ... das einzige was mit noch auffällt ist, daß du versuchen könntest im ExplorerHook/DialogHook mal ein wenig Debugging-Code unterzubringen (sichere dir vorher die entsprechende Unit). Dann würdest du sehen, wann und wie sie aufgerufen werden.

Schau mal, ob zB die entsprechenden Hook-Funktionen öfter als die TOpenDialog.WndProc aufgerufen werden. Ansonsten habe ich auch keine richtige Idee, zumal ich es hier nicht austesten kann, mangels D7 Pro.
Logikmensch
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 390

Win XP
Delphi 2007 Prof., XE2, XE5
BeitragVerfasst: Sa 02.08.08 16:46 
Hallo!

Dieser Thread ist zwar schon etwas alt, aber er passt genau.
Nachdem ich bei einem Filter für ein TOpenDialog, der sehr viele Dateitypen als "Supported files" definiert, feststellen musste, dass nach dem 40. Eintrag der durch Semikolon getrennten Extension-Aufzählung alle nachfolgenden nicht mehr ausgewertet werden (die entsprechenden Dateien erscheinen trotzdem sie im Filter stehen, nicht im OpenDialog),
wollte ich Christian S.' Beispiel nutzen, um mit OnIncludeItem die Sache in den Griff zu bekommen.

Leider habe ich auch das Phänomen, dass OnIncludeItem nicht funzt. Selbst wenn ich immer Include auf False setze, wird stets nur das gelistet, was im Filter steht. Es sieht so aus, dass das Ereignis völlig ignoriert wird.
Ich nutze Delphi 2006.

@Christian S.: Hast Du mittlerweile einen Ausweg gefunden, der funzt?

Warum ich nicht einfach "All files (*.*)|*.*" nutze, wenn ich schon mehr als 60 Dateitypen unterstütze? Nun ja: Ich will im Öffnen-Dialog halt nur diese Dateien dem Benutzer anbieten, die mein Programm unterstützt. Nicht mehr und nicht weniger.
Unnötig zu sagen, dass ich die vielen Dateitypen im Filter natürlich noch einzeln darunter gesetzt habe. Diese Filter funktionieren auch gut. Es scheint nur Probleme bei zu vielen Filtern zu geben, die in der Semikolonliste stehen.

Die Sache mit OnIncludeItem könnte mir helfen, wenn ich sie nur zum funktionieren bekäme....

_________________
Es gibt keine Probleme - nur Lösungen!
Christian S. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Sa 02.08.08 16:57 
user profile iconLogikmensch hat folgendes geschrieben:
@Christian S.: Hast Du mittlerweile einen Ausweg gefunden, der funzt?
Wenn ich mich recht entsinne, nicht. Ich weiß allerdings noch nichtmal mehr, wozu ich das brauchte ;-)

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
Logikmensch
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 390

Win XP
Delphi 2007 Prof., XE2, XE5
BeitragVerfasst: So 03.08.08 10:03 
Schade, dann muss ich also entweder
- einen eigenen OpenDialog schreiben, der ohne die typischen Themes auskommt (weil keine Ahnung hab)
- mich auf weniger Dateitypen beschränken oder
- doch *.* anbieten.

Naja. Übrigens habe ich mittlerweile die Idee, dass das Problem im Windows selber liegt. Offenbar darf der Filterstring rund 240 Zeichen nicht überschreiten. Hab's noch nicht genau analysieren können.

_________________
Es gibt keine Probleme - nur Lösungen!