home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 1995 May / pcw-0595.bin / demos / databeck / wsounds / setup.dir / wswsrc.exe / PLAYDLG.PAS < prev    next >
Pascal/Delphi Source File  |  1992-12-02  |  6KB  |  229 lines

  1. unit PlayDlg;
  2.  
  3. interface
  4.  
  5. uses WinTypes, WinProcs, WinDos, WObjects, Strings, MMSystem;
  6.  
  7. (*{$R PlayDlg.RES}*)
  8.  
  9. const
  10.   dn_PlayDlg = 'PlayDlg';
  11.  
  12.   id_FName = 400;
  13.   id_FPath = 401;
  14.   id_FList = 402;
  15.   id_DList = 403;
  16.   id_Play  = 404;
  17.   id_Normal= 405;
  18.   id_Loop  = 406;
  19.   id_Stop  = 407;
  20.  
  21. const
  22.   fsFileSpec = fsFileName + fsExtension;
  23.  
  24. type
  25.   PPlayDialog = ^TPlayDialog;
  26.   TPlayDialog = object(TDialog)
  27.     Caption: PChar;
  28.     FilePath: PChar;
  29.     PathName: array[0..fsPathName] of Char;
  30.     Extension: array[0..fsExtension] of Char;
  31.     FileSpec: array[0..fsFileSpec] of Char;
  32.     constructor Init(AParent: PWindowsObject; AName, AFilePath: PChar);
  33.     function CanClose: Boolean; virtual;
  34.     procedure SetupWindow; virtual;
  35.     procedure HandleFName(var Msg: TMessage); virtual id_First + id_FName;
  36.     procedure HandleFList(var Msg: TMessage); virtual id_First + id_FList;
  37.     procedure HandleDList(var Msg: TMessage); virtual id_First + id_DList;
  38.     procedure HandlePlay (var Msg: TMessage); virtual id_First + id_Play;
  39.     procedure HandleNormal (var Msg: TMessage); virtual id_First + id_Normal;
  40.     procedure HandleLoop (var Msg: TMessage); virtual id_First + id_Loop;
  41.     procedure HandleStop (var Msg : TMessage); virtual id_First + id_Stop;
  42.   private
  43.     procedure SelectFileName;
  44.     procedure UpdateFileName;
  45.     function UpdateListBoxes: Boolean;
  46.   end;
  47.  
  48. implementation
  49.  
  50. function GetFileName(FilePath: PChar): PChar;
  51. var
  52.   P: PChar;
  53. begin
  54.   P := StrRScan(FilePath, '\');
  55.   if P = nil then P := StrRScan(FilePath, ':');
  56.   if P = nil then GetFileName := FilePath else GetFileName := P + 1;
  57. end;
  58.  
  59. function GetExtension(FilePath: PChar): PChar;
  60. var
  61.   P: PChar;
  62. begin
  63.   P := StrScan(GetFileName(FilePath), '.');
  64.   if P = nil then GetExtension := StrEnd(FilePath) else GetExtension := P;
  65. end;
  66.  
  67. function HasWildCards(FilePath: PChar): Boolean;
  68. begin
  69.   HasWildCards := (StrScan(FilePath, '*') <> nil) or
  70.     (StrScan(FilePath, '?') <> nil);
  71. end;
  72.  
  73. { TPlayDialog }
  74.  
  75. constructor TPlayDialog.Init(AParent: PWindowsObject;
  76.   AName, AFilePath: PChar);
  77. begin
  78.   TDialog.Init(AParent, AName);
  79.   Caption := nil;
  80.   FilePath := AFilePath;
  81. end;
  82.  
  83. function TPlayDialog.CanClose: Boolean;
  84. var
  85.   PathLen: Word;
  86. begin
  87. {
  88.   CanClose := False;
  89.   GetDlgItemText(HWindow, id_FName, PathName, fsPathName + 1);
  90.   FileExpand(PathName, PathName);
  91.   PathLen := StrLen(PathName);
  92.   if (PathName[PathLen - 1] = '\') or HasWildCards(PathName) or
  93.     (GetFocus = GetDlgItem(HWindow, id_DList)) then
  94.   begin
  95.     if PathName[PathLen - 1] = '\' then
  96.       StrLCat(PathName, FileSpec, fsPathName);
  97.     if not UpdateListBoxes then
  98.     begin
  99.       MessageBeep(0);
  100.       SelectFileName;
  101.     end;
  102.     Exit;
  103.   end;
  104.   StrLCat(StrLCat(PathName, '\', fsPathName), FileSpec, fsPathName);
  105.   if UpdateListBoxes then Exit;
  106.   PathName[PathLen] := #0;
  107.   if GetExtension(PathName)[0] = #0 then
  108.     StrLCat(PathName, Extension, fsPathName);
  109.   AnsiLower(StrCopy(FilePath, PathName));
  110.   }
  111.   CanClose := True;
  112. end;
  113.  
  114. procedure TPlayDialog.SetupWindow;
  115. begin
  116.   SendDlgItemMessage(HWindow, id_FName, em_LimitText, fsPathName, 0);
  117.   CheckRadioButton(HWindow, id_Normal, id_Loop, id_Normal);
  118.   if Caption <> nil then SetWindowText(HWindow, Caption);
  119.   StrLCopy(PathName, FilePath, fsPathName);
  120.   StrLCopy(Extension, GetExtension(PathName), fsExtension);
  121.   if HasWildCards(Extension) then Extension[0] := #0;
  122.   if not UpdateListBoxes then
  123.   begin
  124.     StrCopy(PathName, '*.*');
  125.     UpdateListBoxes;
  126.   end;
  127.   SelectFileName;
  128. end;
  129.  
  130. procedure TPlayDialog.HandleFName(var Msg: TMessage);
  131. begin
  132.   if Msg.LParamHi = en_Change then
  133.     EnableWindow(GetDlgItem(HWindow, id_Ok),
  134.       SendMessage(Msg.LParamLo, wm_GetTextLength, 0, 0) <> 0);
  135. end;
  136.  
  137. procedure TPlayDialog.HandleFList(var Msg: TMessage);
  138. begin
  139.   case Msg.LParamHi of
  140.     lbn_SelChange, lbn_DblClk:
  141.       begin
  142.         DlgDirSelect(HWindow, PathName, id_FList);
  143.         UpdateFileName;
  144.         if Msg.LParamHi = lbn_DblClk then HandlePlay(Msg);
  145.       end;
  146.     lbn_KillFocus:
  147.       SendMessage(Msg.LParamLo, lb_SetCurSel, Word(-1), 0);
  148.   end;
  149. end;
  150.  
  151. procedure TPlayDialog.HandleDList(var Msg: TMessage);
  152. begin
  153.   case Msg.LParamHi of
  154.     lbn_SelChange, lbn_DblClk:
  155.       begin
  156.         DlgDirSelect(HWindow, PathName, id_DList);
  157.         StrCat(PathName, FileSpec);
  158.         if Msg.LParamHi = lbn_DblClk then
  159.           UpdateListBoxes else
  160.           UpdateFileName;
  161.       end;
  162.     lbn_KillFocus:
  163.       SendMessage(Msg.LParamLo, lb_SetCurSel, Word(-1), 0);
  164.   end;
  165. end;
  166.  
  167. procedure TPlayDialog.HandlePlay (var Msg: TMessage);
  168. BEGIN
  169.    if (IsDlgButtonChecked(HWindow, id_Loop) <> 0) THEN
  170.       SndPlaySound(PathName,SND_Async OR SND_Loop)
  171.    ELSE
  172.       SndPlaySound(PathName,SND_Async)
  173.    END;
  174.  
  175. procedure TPlayDialog.HandleNormal(var Msg: TMessage);
  176. BEGIN
  177.    CheckRadioButton(HWindow, id_Normal, id_Loop, id_Normal);
  178.    END;
  179.  
  180. procedure TPlayDialog.HandleLoop (var Msg: TMessage);
  181. BEGIN
  182.    CheckRadioButton(HWindow, id_Normal, id_Loop, id_Loop);
  183.    END;
  184.  
  185. procedure TPlayDialog.HandleStop(var Msg: TMessage);
  186. BEGIN
  187.    SndPlaySound(NIL,SND_Async)
  188.    END;
  189.  
  190. procedure TPlayDialog.SelectFileName;
  191. begin
  192.   SendDlgItemMessage(HWindow, id_FName, em_SetSel, 0, $7FFF0000);
  193.   SetFocus(GetDlgItem(HWindow, id_FName));
  194. end;
  195.  
  196. procedure TPlayDialog.UpdateFileName;
  197. begin
  198.   SetDlgItemText(HWindow, id_FName, AnsiLower(PathName));
  199.   SendDlgItemMessage(HWindow, id_FName, em_SetSel, 0, $7FFF0000);
  200. end;
  201.  
  202. function TPlayDialog.UpdateListBoxes: Boolean;
  203. var
  204.   Result: Integer;
  205.   Path: array[0..fsPathName] of Char;
  206. begin
  207.   UpdateListBoxes := False;
  208.   if GetDlgItem(HWindow, id_FList) <> 0 then
  209.   begin
  210.     StrCopy(Path, PathName);
  211.     Result := DlgDirList(HWindow, Path, id_FList, id_FPath, 0);
  212.     if Result <> 0 then DlgDirList(HWindow, '*.*', id_DList, 0, $C010);
  213.   end else
  214.   begin
  215.     StrLCopy(Path, PathName, GetFileName(PathName) - PathName);
  216.     StrLCat(Path, '*.*', fsPathName);
  217.     Result := DlgDirList(HWindow, Path, id_DList, id_FPath, $C010);
  218.   end;
  219.   if Result <> 0 then
  220.   begin
  221.     StrLCopy(FileSpec, GetFileName(PathName), fsFileSpec);
  222.     StrCopy(PathName, FileSpec);
  223.     UpdateFileName;
  224.     UpdateListBoxes := True;
  225.   end;
  226. end;
  227.  
  228. end.
  229.