⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 u00502.pas

📁 Delphi编程五大妙招源程序
💻 PAS
字号:
unit U00502;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button3: TButton;
    Button4: TButton;
    Button5: TButton;
    Label1: TLabel;
    Button1: TButton;
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure FormCreate(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
    bClose : Boolean ;
    //function ThreadFunc(P: Pointer): LongInt; stdcall;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  function ThreadFunc(P: Pointer): LongInt; stdcall;
  function waveOutGetNumDevs: longint; stdcall; external 'winmm.dll' name 'waveOutGetNumDevs';
  function midiOutGetNumDevs: longint; stdcall; external 'winmm.dll' name 'midiOutGetNumDevs';
implementation

{$R *.DFM}


procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
  CanClose := bClose ;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  bClose := False ;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  bClose := True ;
  Close ;
end;

//定义一个函数,供线程调用
function ThreadFunc(P: Pointer): LongInt; stdcall;
var
  i: Integer;
  DC: HDC;
  S: string;
begin
  Result := 0 ;
  DC := GetDC(Form1.Handle);
  SetBkColor(DC, GetSysColor(color_btnface));
  for i := 0 to 100000 do begin
    S := IntToStr(i);
    TextOut(DC, 10, 10, PChar(S), Length(S));

  end;
  ReleaseDC(Form1.Handle, DC);
end;

//采用一个多线程
procedure TForm1.Button4Click(Sender: TObject);
var
  hThread: THandle;
  ThreadID: DWord;
begin
  hthread := CreateThread(nil,         //Security attribute
                          0,           //Initial Stack
                          @ThreadFunc, //Starting address of thread
                          nil,         // argument of thread
                          0,           // Create flags
                          ThreadID);   // thread ID

  if hthread = 0 then
    MessageBox(Handle, 'No Thread', nil, MB_OK);
end;

//采用单线程
procedure TForm1.Button5Click(Sender: TObject);
begin
  ThreadFunc(nil);
end;

Function IsSoundcardInstalled : Boolean ;
Var
  WaveOutPutDeviceCount: Integer ;
  MidiOutPutDeviceCount : Integer ;
Begin
  WaveOutPutDeviceCount := waveOutGetNumDevs ;
  MidiOutPutDeviceCount := midiOutGetNumDevs ;
  if (WaveOutPutDeviceCount>0) and (MidiOutPutDeviceCount>0) Then Result := True
                                                             Else Result := False ;
End ;

procedure TForm1.Button1Click(Sender: TObject);
Begin
  if IsSoundcardInstalled Then ShowMessage('系统已经安装了声卡')
                          Else ShowMessage('系统没有安装声卡') ;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -