开发环境Delphi XE11.3
Unit
unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, winapi.ShellAPI, ShlObj, TLHelp32; type TForm1 = class(TForm) Button1: TButton; Button2: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} function FindProcess(AFileName:string):boolean; var hSnapshot:THandle; lppe:TProcessEntry32; Found:Boolean; begin Result:=False; hSnapshot:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0); lppe.dwSize:=SizeOf(TProcessEntry32); Found:=Process32First(hSnapshot,lppe); while Found do begin if(lppe.szExeFile = AFileName) then Result:=True; Found:=Process32Next(hSnapshot,lppe); end; end; procedure TForm1.Button1Click(Sender: TObject); var vWinDir: array[0..255] of Char; vSysDir: array[0..255] of Char; vPathStr, vWinDirStr, vSysDirStr: string; begin GetWindowsDirectory(vWinDir, 256); GetSystemDirectory(vSysDir, 256); vSysDirStr := StrPas(vSysDir); if FileExists(vSysDirStr+'\osk.exe') then vPathStr := vSysDirStr+'\osk.exe' else begin vWinDirStr := StrPas(vWinDir); vPathStr := vWinDirStr+'\SysNative\osk.exe'; end; ShellExecute(0, 'open', PChar(vPathStr), nil, nil, SW_SHOWNORMAL); end; procedure TForm1.Button2Click(Sender: TObject); begin if FindProcess('osk.exe') then MessageBox(0, PChar('软键盘已运行'), PChar('提示'), MB_OK); end; end.
object Form1: TForm1 Left = 0 Top = 0 Caption = 'Form1' ClientHeight = 174 ClientWidth = 308 Color = clBtnFace Font.Charset = DEFAULT_CHARSET Font.Color = clWindowText Font.Height = -12 Font.Name = 'Segoe UI' Font.Style = [] Position = poScreenCenter TextHeight = 15 object Button1: TButton Left = 104 Top = 32 Width = 75 Height = 25 Caption = 'Button1' TabOrder = 0 OnClick = Button1Click end object Button2: TButton Left = 104 Top = 96 Width = 75 Height = 25 Caption = 'Button2' TabOrder = 1 OnClick = Button2Click end end
标签:exe,end,lppe,Delphi,osk,TForm1,软键盘,Font From: https://www.cnblogs.com/dmqhjp/p/18346420