Newsgroups : Borland : borland.public.delphi.nativeapi.win32 : 2005 Jul : GetOpenFileName in Windows 98

www.cryer.info
Managed Newsgroup Archive

GetOpenFileName in Windows 98

Subject:GetOpenFileName in Windows 98
Posted by:"Jean" (jea..@mail.ru)
Date:Sun, 31 Jul 2005 20:30:21 +0400

Hi again.

    After hard shock with combo boxes I got another problem with Open
dialog box. It doesn't appear in Windows 98 at all. But in Windows XP it
works fine. Take a look at the code below and the comments inside:

...
var
  ofn     : OPENFILENAME;
  strFile : PChar;         //  String to hold selected file name
  offFile,
  offExt  : Word;

begin
  GetMem(strFile, MAX_PATH);

  strFile[0] := #0;   // I do not need initial file name

  ZeroMemory(@ofn, SizeOf(OPENFILENAME));

  with ofn do begin
    ofn.lStructSize     := SizeOf(OPENFILENAME);
    ofn.hWndOwner       := 0;
    ofn.hInstance       := HInstance;
    ofn.lpstrFilter     := PChar('All files'#0'*.*'#0);
    ofn.nFilterIndex    := 1;
    ofn.lpstrFile       := strFile;
    ofn.nMaxFile        := MAX_PATH;
    ofn.Flags           := 0;
    ofn.nFileOffset     := offFile;
    ofn.nFileExtension  := offExt;
  end;

  //  Let's try to show dialog: ...
  if GetOpenFileName(ofn) then
    MessageBox(0, strFile, '', 0)            //  ... show selected file
name if successful ...
  else
    MessageBox(0, 'FALSE returned', '', 0);  //  ... or show failure
message.
                                             //  This line is always
executed in Windows 98 because Open dialog was not shown at all.
                                             //  And it is never
executed in Windows XP if I accept selected file.
end;
...

Jean.

Glossary

Replies:

www.cryer.info
Managed Newsgroup Archive