(**************************************************)
(*                                                *)
(*   Sample3D - Shows the use of CTL3D.DLL        *)
(*                                                *)
(*   submitted by Andreas Furrer                  *)
(*                                                *)
(**************************************************)

program Sample3D;

{$R ctl3d.res}


uses WinTypes, WinProcs, WObjects, CommDlg, Ctl3d;

type
   Applikation =
      object(TApplication)
         procedure InitMainWindow; virtual;
      end;

   PMainwindow = ^TMainwindow;
   TMainwindow =
      object(TDialog)
         procedure WMSysColorChange(var Msg : TMessage); virtual wm_first + wm_SysColorChange;
         procedure Msgbox(var Msg : TMessage);   virtual id_first + 130;
         procedure Fileopen(var Msg : TMessage); virtual id_first + 131;
      end;



procedure TMainwindow.WMSysColorChange;
begin
  Ctl3dColorChange;
end;

procedure TMainwindow.Msgbox;
begin
  MessageBox(HWindow,'This is a sample Message Box','3D Look',mb_Ok);
end;


function HookProc(HWindow: HWnd; Msg, wParam: word; lParam: longint): word;far;
var p : TFarProc;
begin
  IF Msg=wm_InitDialog then begin
    Ctl3dSubClassDlg(HWindow,Ctl3d_All);
  end;
  HookProc:=0;
end;

procedure TMainwindow.Fileopen;
var FileName : array[0..255] of char;
    Ofn :  TOpenFileName;
begin
  FileName[0]:=#0;
  Ofn.lStructSize       := sizeof(TOpenFileName);
  Ofn.hwndOwner         := HWindow;
  Ofn.hInstance         := HInstance;
  Ofn.lpstrFilter       :='Text Files (*.TXT)'+#0+'*.TXT'+#0+'All Files (*.*)'+#0+'*.*'+#0+#0;
  Ofn.lpstrCustomFilter := nil;
  Ofn.nMaxCustFilter    := 0;
  Ofn.nFilterIndex      := 1;
  Ofn.lpstrFile         := FileName;
  Ofn.nMaxFile          := sizeof(FileName);
  Ofn.lpstrFileTitle    := nil;
  Ofn.nMaxFileTitle     := 0;
  Ofn.lpstrInitialDir   := nil;
  Ofn.lpstrTitle        := '3D Look';
  Ofn.Flags             := ofn_HideReadonly or ofn_EnableHook;
  Ofn.nFileOffset       := 0;
  Ofn.nFileExtension    := 0;
  Ofn.lpstrDefExt       := NIL;
  Ofn.lpTemplateName    := 'FileOpen';
  Ofn.lpfnHook:=HookProc;
  Ofn.lCustData         := 0;

  GetOpenFileName(Ofn);
end;

procedure Applikation.InitMainWindow;
begin
  MainWindow := New(PMainwindow, Init(nil, MakeIntResource(100)));
end;

var Prg : Applikation;

begin
   Ctl3dRegister(HInstance);
   Ctl3dAutoSubclass(HInstance);

   Prg.Init('Sample3D');
   Prg.Run;
   Prg.Done;

   Ctl3dUnregister(HInstance);
end.