{Uses ShellAPI} procedure TForm1.Image1Click(Sender: TObject); Const URL: PChar = 'http://ourworld.compuserve.com/homepages/MichaelBrick'; begin ShellExecute(Application.MainForm.Handle, Nil, URL, Nil, Nil, SW_SHOWNORMAL); end;
{Uses WINPROCS} procedure TForm1.ExitWindows; begin {$IFDEF WIN32} ExitWindowsEx(EWX_SHUTDOWN {EWX_LOGOFF}, 0); {$ELSE} WinExec('Rundll.exe User,ExitWindows',SW_HIDE); {$ENDIF} end; procedure TForm1.RestartWindows; begin {$IFDEF WIN32} ExitWindowsEx(EWX_REBOOT, 0) {$ELSE} ExitWindows(EW_RESTARTWINDOWS {EW_REBOOTSYSTEM}, 0) {$ENDIF} end;
{Uses WINPROCS} procedure TForm1.Delay(ms: Longint); {ms = milliseconds} var TimeOut: Longint; begin TimeOut:= GetTickCount + ms; While GetTickCount < TimeOut do begin {... do something or do nothing} end; end;
{Public-Declarations} Path: String; procedure TForm1.FormCreate(Sender: TObject); begin Path:= ExtractFilePath(Application.ExeName); {Returns ?:\...\} {... ...} end;
{Uses WINPROCS} function TForm1.GetWinDir: String; var WinDir: PChar; begin GetMem(WinDir, 144); GetWindowsDirectory(WinDir, 144); Result:= StrPas(WinDir); {Returns ?:\...} FreeMem(WinDir, 144); end; function TForm1.GetSysDir: String; var SysDir: PChar; begin GetMem(SysDir, 144); GetSystemDirectory(SysDir, 144); Result:= StrPas(SysDir); {Returns ?:\...} FreeMem(SysDir, 144); end; function TForm1.GetAppDir: String; begin Result:= ExtractFilePath(ParamStr(0)); Result:= Copy(Result,1,Length(Result)-1); {Returns ?:\...} end;
{Uses MMSystem} The form contains a TMediaPlayer Component (MediaPlayer1) and a TComboBox Component (ComboBox1). procedure TForm1.FormCreate(Sender: TObject); var thisDevice: Integer; NumDevs: Integer; midioutCaps: TmidioutCaps; begin NumDevs:= MidioutGetNumDevs; for thisDevice:= 0 To NumDevs - 1 do begin midioutGetDevCaps(thisDevice, @midioutCaps, sizeof(TmidioutCaps)); ComboBox1.Items.Add(StrPas(midiOutCaps.szPname)); end; ComboBox1.Items.Add('MIDI-Mapper'); ComboBox1.ItemIndex:= 0; end; procedure TForm1.ComboBox1Change(Sender: TObject); var Parms: TMCI_SEQ_Set_Parms; begin if MediaPlayer1.Mode <> mpNotReady then begin if ComboBox1.Text = 'MIDI-Mapper' then Parms.dwPort:= MIDIMAPPER else Parms.dwPort:= ComboBox1.ItemIndex; mciSendCommand(MediaPlayer1.DeviceID, MCI_SET, MCI_SEQ_SET_PORT, Longint(@Parms)); end; end;
{This function returns true if system is using Windows 95/98 or NT 4.0} function TForm1.CheckGUI: Boolean; begin {$IFDEF WIN32} Result := Lo(GetVersion) >= 4; {$ELSE} Result := GetProcAddress(GetModuleHandle('KERNEL'), 'GetVersionEx') <> nil; {$ENDIF} end;
{Uses IniFiles} function TForm1.GetMCIfileTypes: String; var WinIni: TIniFile; S: String; FExt: TStrings; I: Integer; begin Result:= ''; try WinIni:= TIniFile.Create('WIN.INI'); if WinIni <> Nil then begin FExt:= TStringList.Create; WinIni.ReadSection('mci extensions', FExt); for I:= 0 to FExt.Count-1 do begin S:= FExt[I]; Result:= Result + '*.' + Lowercase(S) + ';'; end; end; finally FExt.Free; WinIni.Free; end; end;
{Make sure that the main form's Visible Property is set to FALSE and modify the program's DPR file as follows...} program abc; uses SysUtils, Windows, Forms, ....., xyz1 in 'xyz1.pas' {Form1}, xyz2 in 'xyz2.pas' {Form2}; ..... begin Application.Initialize; Application.CreateForm(TForm1, Form1); Application.CreateForm(TForm2, Form2); ..... ShowWindow(Application.Handle, SW_HIDE); Application.ShowMainForm := FALSE; Application.Run; end.