2021年11月13日土曜日

Delphi10 など ShellExecute

 

参照:

https://www.greelane.com/ja/%e7%a7%91%e5%ad%a6%e6%8a%80%e8%a1%93%e6%95%b0%e5%ad%a6/%e3%82%b3%e3%83%b3%e3%83%94%e3%83%a5%e3%83%bc%e3%82%bf%e3%82%b5%e3%82%a4%e3%82%a8%e3%83%b3%e3%82%b9/execute-and-run-applications-1058462/

メモ帳を実行する

ShellApiを使用します。
...
ShellExecute(Handle、 'open'、
'c:\ Windows \ notepad.exe'、nil、nil、SW_SHOWNORMAL);

メモ帳でSomeText.txtを開く

ShellExecute(Handle、 'open'、
'c:\ windows \ notepad.exe'、
'c:\ SomeText.txt'、nil、SW_SHOWNORMAL);

「DelphiDownload」フォルダの内容を表示する

ShellExecute(Handle、 'open'、
'c:\ DelphiDownload'、nil、nil、SW_SHOWNORMAL);

拡張子に従ってファイルを実行する

ShellExecute(Handle、 'open'、
'c:\ MyDocuments \ Letter.doc'、nil、nil、SW_SHOWNORMAL);

拡張機能に関連付けられているアプリケーションを見つける方法は次のとおりです。

デフォルトのWebエクスプローラーでWebサイトまたは* .htmファイルを開く

ShellExecute(Handle、 'open'、
'http://delphi.about.com'、nil、nil、SW_SHOWNORMAL);

件名とメッセージ本文を記載したメールを送信する

var em_subject、em_body、em_mail:文字列; 
begin
em_subject:= 'これは件名です';
em_body:= 'メッセージ本文テキストはここにあります';

em_mail:= 'mailto:delphi@aboutguide.com?subject =' +
em_subject + '&body =' + em_body;

ShellExecute(Handle、 'open'、
PChar(em_mail)、nil、nil、SW_SHOWNORMAL);
終わり;

添付ファイル付きのメール送信する方法は次のとおりです。

プログラムを実行し、終了するまで待ちます

次の例では、ShellExecuteExAPI関数を使用しています。

// Windows Calculatorを実行し
、計算が終了すると//メッセージをポップアップします。
ShellApiを使用します。
...
var
SEInfo:TShellExecuteInfo;
ExitCode:DWORD;
ExecuteFile、ParamString、StartInString:文字列;
開始
EXECUTEFILEを:= 'C:\ WINDOWS \ CALC.EXE';

FillChar(SEInfo、SizeOf(SEInfo)、0);
SEInfo.cbSize:= SizeOf(TShellExecuteInfo);
SEInfoを使用してfMaskを開始し
ます:= SEE_MASK_NOCLOSEPROCESS;
Wnd:= Application.Handle;
lpFile:= PChar(ExecuteFile);
{
ParamStringには、
アプリケーションパラメータを含めることができます。
}
// lpParameters:= PChar(ParamString);
{
StartInStringは、
作業ディレクトリの名前。
省略した場合は、現在のディレクトリが使用されます。
}
// lpDirectory:= PChar(StartInString);
nShow:= SW_SHOWNORMAL;
終わり;
ShellExecuteEx(@SEInfo)の場合、Application.ProcessMessagesの
繰り返しを開始し
ます。
GetExitCodeProcess(SEInfo.hProcess、ExitCode);
(ExitCode <> STILL_ACTIVE)または
Application.Terminatedまで;
ShowMessage( '電卓が終了しました');
end
else ShowMessage( 'Calcの開始中にエラーが発生しました!');
終わり;

ShellExecute in Delphi – Launch external applications.

ShellExecute is Delphi Windows API function that is mostly used for launch external applications from our Delphi application. This function is linked to the ShellExecute Windows API function. The function returns an integer that corresponds to an error code which is very useful when we need to show some status if the function worked or not.

By using ShellExecute we can also do following operations....

  • Can print documents from within my program, without explicitly starting the application that created the document, such as: print a Word-document without starting Word.
  • Can open browser with a local HTML page
  • Can surf to a site i.e. open an external URL link from a Delphi application
  • Can send mails thorugh outlook
Syntax of Windows API function

HINSTANCE ShellExecute(
  _In_opt_        HWND hwnd,
  _In_opt_        LPCTSTR lpOperation,
  _In_              LPCTSTR lpFile,
  _In_opt_        LPCTSTR lpParameters,
  _In_opt_        LPCTSTR lpDirectory,
  _In_INT         nShowCmd
);

Parameters Details

_In_opt_  HWND hwnd,
A handle to the parent window used for displaying a UI or error messages. Ex - handle

_In_opt_  LPCTSTR lpOperation,
Operations to perform.
edit      = Launches an editor and opens the document for editing
explore = Explores a folder 
find      = Initiates a search beginning in the directory 
open     = Opens an item, file, folder, link
print     = Prints the file

_In_      LPCTSTR lpFile,
FileName, link URL to open and modify. EX - PChar(filename)

_In_opt_  LPCTSTR lpParameters
the parameters to be passed to the application delimited by space. Ex - '-c -i -v'

_In_opt_  LPCTSTR lpDirectory,
the default (working) directory for the action. 

_In_      INT nShowCmd
how an application is to be displayed when it is opened. 
SW_HIDE = Hides the window and activates another window
SW_MAXIMIZE  = Maximizes the specified window
SW_MINIMIZE = Minimizes the specified window and activates the next top-level window in the z-order
SW_RESTORE  = Activates and displays the window.
SW_SHOW  = Activates the window and displays it in its current size and position.
SW_SHOWDEFAULT  = Sets the show state based on the SW_ flag specified in the STARTUPINFO
SW_SHOWMAXIMIZED  = Activates the window and displays it as a maximized window.
SW_SHOWMINIMIZED  = Activates the window and displays it as a minimized window.
SW_SHOWMINNOACTIVE  = Displays the window as a minimized window. The active window remains active
SW_SHOWNA  = Displays the window in its current state. The active window remains active.
SW_SHOWNOACTIVATE  = Displays a window in its most recent size and position. The active window remains active.
SW_SHOWNORMAL  = Activates and displays a window. If the window is minimized or maximized, Windows restores it to its original size and position. 

Return Values from ShellExecute function

If the return value of ShellExecute is greater than 32, the application was executed successfully.
If its less than 33 then the function failed.
Here is a complete list of the possible return values of ShellExecute:
0 = The operating system is out of memory or resources.
2 = The specified file was not found
3 = The specified path was not found.
5 = Windows 95 only: The operating system denied access to the specified file
8 = Windows 95 only: There was not enough memory to complete the operation.
10 = Wrong Windows version
11 = The .EXE file is invalid (non-Win32 .EXE or error in .EXE image)
12 = Application was designed for a different operating system
13 = Application was designed for MS-DOS 4.0
15 = Attempt to load a real-mode program
16 = Attempt to load a second instance of an application with non-readonly data segments.
19 = Attempt to load a compressed application file.
20 = Dynamic-link library (DLL) file failure.
26 = A sharing violation occurred.
27 = The filename association is incomplete or invalid.
28 = The DDE transaction could not be completed because the request timed out.
29 = The DDE transaction failed.
30 = The DDE transaction could not be completed because other DDE transactions were being processed.
31 = There is no application associated with the given filename extension.
32 = Windows 95 only: The specified dynamic-link library was not found.

Example...

Procedure OpenMyURL(sUrl: string)
var
  iRes: Integer;
  sMsg: String;
begin
  // If the return value of ShellExecute is greater than 32, the application was executed successfully.
  // If its less than 33 then the function failed.
  try
    iRes := -1;
    sMsg := '';
    iRes := ShellExecute(Handle, 'open', Pchar(sUrl), '', '', SW_SHOWNORMAL);
    case iRes of
      0:
        sMsg := 'The operating system is out of memory or resources.';
      2:
        sMsg := 'The specified file was not found';
      3:
        sMsg := 'The specified path was not found.';
      5:
        sMsg := 'Windows 95 only: The operating system denied access to the specified file';
      8:
        sMsg := 'Windows 95 only: There was not enough memory to complete the operation.';
      10:
        sMsg := 'Wrong Windows version';
      11:
        sMsg := 'The .EXE file is invalid (non-Win32 .EXE or error in .EXE image)';
      12:
        sMsg := 'Application was designed for a different operating system';
      13:
        sMsg := 'Application was designed for MS-DOS 4.0';
      15:
        sMsg := 'Attempt to load a real-mode program';
      16:
        sMsg := 'Attempt to load a second instance of an application with non-readonly data segments.';
      19:
        sMsg := 'Attempt to load a compressed application file.'
      20
        sMsg := 'Dynamic-link library (DLL) file failure.';
      26:
        sMsg := 'A sharing violation occurred.';
      27:
        sMsg := 'The filename association is incomplete or invalid.';
      28:
        sMsg := 'The DDE transaction could not be completed because the request timed out.';
      29:
        sMsg := 'The DDE transaction failed.';
      30:
        sMsg := 'The DDE transaction could not be completed because other DDE transactions were being processed.';
      31:
        sMsg := 'There is no application associated with the given extension.';
      32:
        sMsg := 'Windows 95 only: The specified dynamic-link library was not found.';
    end;
    if sMsg <> EmptyStr then
      MessageDlg(sMsg, mtError, [mbOK], 0);
  except
    on E: Exception do
      MessageDlg(E.Message, mtError, [mbOK], 0);
  end;
end;

Note*
In order to use the function, you first need to add the ShellApi to your uses clause, like : 

uses 
   ShellApi;

Use of ShellExecute with Example

Start an application:
ShellExecute(Handle, 'open', PChar('c:\test\app.exe'), nil, nil, SW_SHOW); 

Start NotePad and load a file (the system "knows" the location of NotePad.exe, therefore we don't have to specify the full path):
ShellExecute(Handle, 'open', PChar('notepad'), PChar('c:\test\readme.txt'), nil, SW_SHOW);

Print a document:
ShellExecute(Handle, 'print', PChar('c:\test\test.doc'), nil, nil, SW_SHOW);  

Note: probably you will see the window of Word open very briefly, but it is closed automatically.

Open an HTML page, local or remote:
ShellExecute(Handle, 'open', PChar('http://www.google.com/'), nil, nil, SW_SHOW);

You can do the previuos trick with any type of registered data-file, e.g. open a Text file:
ShellExecute(Handle, 'open', PChar('c:\test\readme.txt'), nil, nil, SW_SHOW);

HTML Help File:
ShellExecute(Handle, 'open', PChar('c:\windows\help\calc.chm'), nil, nil, SW_SHOW);

Explore a folder with Windows Explorer:
ShellExecute(Handle, 'explore', PChar('c:\windows)', nil, nil, SW_SHOW);

Run a DOS command and return immediately:
ShellExecute(Handle, 'open', PChar('command.com'), PChar('/c copy file1.txt file2.txt'), nil, SW_SHOW);

Run a DOS command and keep the DOS-window open ("stay in DOS"):
ShellExecute(Handle, 'open', PChar('command.com'), PChar('/k dir'), nil, SW_SHOW);

Run an executable and show it:
filename := 'c:\program.exe';
ShellExecute(handle,'open',PChar(filename), '','',SW_SHOWNORMAL);

Run an executable and minimize it:
filename := 'c:\program.exe';
ShellExecute(handle,'open',PChar(filename), '','',SW_MINIMIZE);

Run an executable and maximize it:
filename := 'c:\program.exe';
ShellExecute(handle,'open',PChar(filename), '','',SW_MAXIMIZE);

Run an executable and hide it:
filename := 'c:\program.exe';
ShellExecute(handle,'open',PChar(filename), '','',SW_HIDE);

Run an executable with parameters:
filename := 'c:\program.exe';
parameters := '-c -i -v';
ShellExecute(handle,'open',PChar(filename), PChar(parameters), '', SW_SHOWNORMAL);

Send a mail with attachment
ShellExecute(Self.Handle,
             nil,
             'mailto:' +
             'jiten.g.s001@gmail.com' +
             '?Subject=Test Message Subject' +
             '&Body=Test Message Body' +
             '&Attach="c:\Mail\attachment.txt"',
             nil,
             nil,
             SW_NORMAL);

2021年9月28日火曜日

Install Fedora Workstation 33 to Ras Pi4

 


https://linuxhint.com/install_fedora_33_raspberry_pi4/  から。

保管のために。著者名にリンク埋め込みあり

Raspberry Pi

How to Install Fedora 33 on Raspberry Pi 4

At the time of this writing, Fedora has official support for ARM devices like the Raspberry Pi 4. So, you can easily install Fedora 33 – the latest release of Fedora Linux distribution on your Raspberry Pi 4.

In this article, I am going to show you how to install Fedora Workstation 33 on the Raspberry Pi 4. So, let’s get started.

Things You Will Need:

To follow this article, you will need the following things:

  1. A Raspberry Pi 4 single-board computer.
  2. A USB Type-C power adapter.
  3. A 32 GB or higher capacity microSD card.
  4. A keyboard.
  5. A mouse.
  6. A monitor.
  7. A laptop or a desktop computer for downloading and flashing the Fedora 33 image on the microSD card.

Downloading Fedora 33 ARM Image:

To download the Fedora 33 ARM image, visit the official website of Fedora from your favourite web browser.

Once the page loads, click on Download Now from the Fedora Workstation section as marked in the screenshot below.


Click on the Download button from the Fedora 33 ARM section as marked in the screenshot below.


Your browser should prompt you to save the Fedora Workstation 33 ARM image file. Select a directory where you want to save the image file and click on Save.

Fedora Workstation 33 ARM image is being downloaded. It will take a while to complete.

Flashing Fedora 33 ARM Image on the MicroSD Card:

To flash the Fedora Workstation 33 ARM image on the microSD card, you can use many programs like Balena Etcher, Raspberry Pi Imager, Fedora Media Writer, and so on. In this article, I am going to use the Raspberry Pi Imager for the demonstration. Feel free to use any tool you like for this purpose.

If you need any assistance on installing the Raspberry Pi Imager, check my article How to Install and Use Raspberry Pi Imager.

First, insert the microSD card into your computer.


Start the Raspberry Pi Imager app and click on CHOOSE OS.


Scroll down a little bit and click on Use custom.


A file picker should be opened. Select the Fedora Workstation 33 ARM image that you just downloaded and click on Open.


Once the operating system image is selected, click on CHOOSE SD CARD.


Click on your microSD card from the list.


Once the MicroSD card is selected, click on WRITE.


All the existing data on your microSD card will be erased. To confirm the action, click on YES.


The Fedora Workstation 33 ARM image is being written to the microSD card. It may take a while to complete.


Once the Fedora Workstation 33 ARM image is flashed on to the microSD card,  you should see the following Write Successful window. Click on CONTINUE, close Raspberry Pi Imager, and remove the microSD card from your computer.

Booting Fedora 33 on Raspberry Pi 4:

  1. Insert the microSD card on your Raspberry Pi 4.
  2. Then, insert the micro HDMI cable of your monitor to the micro HDMI port of the Raspberry Pi 4.
  3. Also, Insert the keyboard and mouse to the USB 2.0 port of your Raspberry Pi 4.
  4. Optionally, you can plug in the network cable to the RJ45 Ethernet port of your Raspberry Pi 4.
  5. Finally, insert the USB Type-C power cable on the Raspberry Pi 4 and power it on.


Fedora Workstation 33 is being booted.


You have to configure Fedora Workstation 33 when it boots for the first time.


To start the configuration wizard, click on Start Setup, as shown in the image below.


You can configure the Wi-Fi network from here. I will use a wired Ethernet network. So, I will click on Skip.

NOTE: I could not connect to the Wi-Fi network. Maybe there are some bugs in the graphical user interface of Fedora Workstation 33. In a later update, the bugs may be fixed. As of now, you should be able to connect to your Wi-Fi network using the Network Manager’s command-line tools. But, I recommend using an Ethernet cable for network connectivity if you don’t strictly need Wi-Fi.


Click on Next.


Type in your Full Name and login Username. Once you’re done, click on Next.


Type in a login password and click on Next.


Click on Start Using Fedora.


Fedora Workstation 33 should be ready to use.


As you can see, I am using Fedora 33, and it’s using the Linux kernel 5.8.15.

cat /etc/redhat-release

uname -r


Fedora Workstation 33 uses about 1.2 GB of memory when no extra programs are running.

Removing Black Edges from the Monitor Display:

Fedora Workstation 33 may show black borders around your screen. It is because of overscan. In some monitors, overscan leaves exclusion zones around your monitor.

By default, overscan is enabled on Fedora Workstation 33. To fix this problem, all you have to do is disable overscan.


You should find a config.txt file in the /boot/efi/ directory, as you can see in the screenshot below.


To disable overscan, open the /boot/efi/config.txt file with the nano text editor as follows:

sudo nano /boot/efi/config.txt


The /boot/efi/config.txt file should be opened.


Scroll down to the end of the config.txt file and type in disable_overscan=1, as shown in the screenshot below.

Once you’re done, press <Ctrl> + followed by and <Enter> to save the config.txt file.


For the changes to take effect, reboot your Raspberry Pi 4 with the following command:

sudo reboot


Once your Raspberry Pi 4 boots, the black borders should be gone.

Expanding the BTRFS Filesystem:

The default filesystem of Fedora Workstation 33 is BTRFS.

By default, only a portion of the microSD card is used for storing the operating system files and user data. The rest of the disk space is kept unallocated.

As you can see in the screenshot below, only 9.5 GB of disk space (out of 32 GB) from my microSD card is used for the root (/) filesystem.

df -h


To expand the file system, you have to expand the partition first.

To do that, open the microSD card with the fdisk command-line partitioning tool as follows:

sudo fdisk /dev/mmcblk1


fdisk should open the microSD card.

To list all the existing partitions of the microSD card, press and then press <Enter>.


As you can see, the 9.4 GB partition is the 3rd partition of the microSD card. You have to remove the 3rd partition and re-create it. Don’t worry. You won’t lose any data.

To delete a partition, press and press <Enter>.


Type in 3 as the partition number and press <Enter>.


The 3rd partition should be removed.

To re-create the 3rd partition, press n and then press <Enter>.


Press and then press <Enter>.


Type in as the partition number and press <Enter>.


Press <Enter> to select the default first sector number.


Press <Enter> to select the default last sector number.

The default last sector number should be the last allocable sector number (from the unallocated space of the microSD card) of the microSD card.


Press n and then press <Enter> to keep the existing partition signature.

NOTE: Be extra careful in this step. If you remove the existing partition signature, you won’t be able to recover your existing files very easily.


The 3rd partition should be recreated.

To save the changes, press and then press <Enter>.


The updated partition table should be written to the microSD card, and the fdisk should be closed.


To resize the BTRFS root (/) filesystem to the max available space of the partition, run the following command:

sudo btrfs filesystem resize max /


The BTRFS root (/) filesystem should be resized.


As you can see, the root (/) filesystem is resized to 28 GB (from 9.4 GB).

Conclusion:

In this article, I have shown you how to install Fedora Workstation 33 on Raspberry Pi 4. I have also shown you how to remove the black edges from the monitor and expand the BTRFS root filesystem. This article should help you get started with Fedora Workstation 33 on the Raspberry Pi 4.