www.pudn.com > Jiayu.rar > Untmain.pas


unit Untmain; 
 
interface 
 
uses 
  Windows, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
  Dialogs, StdCtrls, ExtCtrls, ActnList, Buttons, Menus,  
  Spin,MMSystem, jpeg; 
 
type 
  TFrmmain = class(TForm) 
    pnl1: TPanel; 
    rg1: TRadioGroup; 
    pnl2: TPanel; 
    pnl3: TPanel; 
    grp1: TGroupBox; 
    cbb1: TComboBox; 
    rg2: TRadioGroup; 
    lbl2: TLabel; 
    actlst1: TActionList; 
    actman: TAction; 
    actauto: TAction; 
    tmr1: TTimer; 
    dlgFontLBL: TFontDialog; 
    img1: TImage; 
    lbl1: TLabel; 
    btn2: TSpeedButton; 
    btn1: TSpeedButton; 
    btn3: TSpeedButton; 
    grp2: TGroupBox; 
    se1: TSpinEdit; 
    pm1: TPopupMenu; 
    N1: TMenuItem; 
    N2: TMenuItem; 
    N3: TMenuItem; 
    pb1: TPaintBox; 
    pb2: TPaintBox; 
    img2: TImage; 
    lbl3: TLabel; 
    lbl4: TLabel; 
    lbl5: TLabel; 
    lbl6: TLabel; 
    btn4: TSpeedButton; 
    btn5: TSpeedButton; 
    procedure FormCreate(Sender: TObject); 
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean); 
    procedure cbb1Change(Sender: TObject); 
    procedure tmr1Timer(Sender: TObject); 
    procedure rg2Click(Sender: TObject); 
    procedure FormKeyDown(Sender: TObject; var Key: Word; 
      Shift: TShiftState); 
    procedure btn1Click(Sender: TObject); 
    procedure btn2Click(Sender: TObject); 
    procedure btn3Click(Sender: TObject); 
    procedure lbl1MouseDown(Sender: TObject; Button: TMouseButton; 
      Shift: TShiftState; X, Y: Integer); 
    procedure img1MouseDown(Sender: TObject; Button: TMouseButton; 
      Shift: TShiftState; X, Y: Integer); 
    procedure se1Change(Sender: TObject); 
    procedure N1Click(Sender: TObject); 
    procedure N3Click(Sender: TObject); 
    procedure btn4Click(Sender: TObject); 
    procedure btn5Click(Sender: TObject); 
  private 
    
    function showword:string; 
    procedure Showword_lbl; 
    { Private declarations } 
  public 
    wordfilename:string; 
    strslist,wordlist:TStringList; 
    wordrec:Integer; 
    { Public declarations } 
    procedure file_tostrslist; 
  end; 
 
var 
  Frmmain: TFrmmain; 
  yesbmp,nobmp:TBitmap ; 
  rightsound,wrongsound:pchar; 
  hRes:THandle ; 
implementation 
   uses Untfun,UntInput ; 
{$R *.dfm} 
{$R WINDOWSXP.RES} 
{$R MYRES.res} 
procedure TFrmmain.FormCreate(Sender: TObject); 
var 
  stream:TStream ; 
  S:string ; 
  hResInfo : THandle; 
begin 
  yesbmp :=TBitmap.Create ; 
  nobmp :=TBitmap.Create ; 
  Stream:=TResourceStream.Create(HINSTANCE,'yes','bmp'); 
  yesbmp.LoadFromStream(Stream); 
 
  stream:=TResourceStream.Create(HInstance,'no','bmp'); 
  nobmp.LoadFromStream(stream); 
 
  Stream.Free ; 
 
  hResInfo := FindResource(HInstance, 'right', 'WAVE'); 
  hRes := LoadResource(HInstance,hResInfo); 
  if hRes > 32 then {its a good load} 
  begin {lock the resource} 
  rightSound:=LockResource(hRes); 
  end; 
 
  hResInfo := FindResource(HInstance, 'wrong', 'WAVE'); 
  hRes := LoadResource(HInstance,hResInfo); 
  if hRes > 32 then {its a good load} 
  begin {lock the resource} 
  wrongSound:=LockResource(hRes); 
  end; 
 
 
 
//  PlaySound('Sounds\123',0,SND_ASYNC); 
 
  S:=getAppPath+'lujiayu.txt'; 
  if FileExists(S) then 
  wordfilename:=S 
  else 
  wordfilename:=PathGetWindowsPath +'lujiayu.txt' ; 
 
 // getAppPath+'lujiayu.txt'; 
  wordlist:=TStringList.Create ; 
  strslist:=TStringList.Create ; 
 
  file_tostrslist; 
  if cbb1.Items.Count>0 then 
  begin 
    cbb1.ItemIndex:=0; 
    TxttoWords(strslist.Strings[0],wordlist); 
    wordrec:=0; 
  end; 
  
end; 
 
procedure TFrmmain.FormCloseQuery(Sender: TObject; var CanClose: Boolean); 
begin 
  wordlist.Free ; 
  strslist.Free ; 
  yesbmp.Free ; 
  nobmp.Free; 
 
end; 
 
procedure TFrmmain.cbb1Change(Sender: TObject); 
var 
  s:string; 
begin 
  s:=strslist.Strings[cbb1.ItemIndex]; 
 
  wordlist.Clear ; 
  TxttoWords(s,wordlist); 
  wordrec:=0; 
end; 
 
procedure TFrmmain.file_tostrslist; 
var 
  temlist:TStringList ; 
  temstr,str1,str2:string; 
  i,j:Integer; 
begin 
  temlist:=TStringList.Create ; 
  cbb1.Items.Clear ; 
  strslist.Clear ; 
  if FileExists(wordfilename) then 
  begin 
    temlist.LoadFromFile(wordfilename); 
    for i:=0 to temlist.Count-1 do 
    begin 
      temstr:=temlist.Strings[i]; 
      j:=Pos('=',temstr); 
      if j>0 then 
      begin 
        str1:=StrLeft(temstr,j-1); 
        str2:=StrRight(temstr,(Length(temstr)-j)); 
        cbb1.Items.Add(str1); 
        strslist.Add(str2); 
 
      end; 
    end; 
  end; 
  temlist.Free ; 
end; 
 
 function TFrmmain.showword:string; 
var 
  s:string; 
begin 
  if wordlist.Count>0 then 
  begin 
    if rg1.ItemIndex=0 then //如果是随机取字# 
    begin 
      randomize;//随机种子 
      wordrec:=1+Random(wordlist.Count) ; 
    end 
    else           //如果是顺序取字 
    begin 
      if wordrec