Delphi Common Function Application

xiaoxiao2021-03-05  25

Get windows SYSTEM path: method: var mysyspath: pchar; begin getmem (mysyspath, 255); getSystemDirectory (mysyspath, 255); end; Note: MySyspath is the System path

Get the path of the program EXTRACTFILEDIR (Application.exename);

Look at the file for fileexists (filename: string): boolean;

Change file extension ChangeFileExt (filename: string)

Get the extension of the file extractfileext (filename: string): String;

How to get a temporary file directory for Windows? Suitable for version: Delphi 3, 2.0, 1.0

Both Windows 95 & NT specify a directory where a temporary file is placed, however, users can change the location of the temporary directory without using the default directory. The purpose of this article is to tell you how to get the current temporary directory location of Windows 95 & NT. This Windows API function getTemppath is to solve this problem. Its function is:

DWORD GetTemppath (DWORD NBUFFERLENGTH, LPTSTR LPBUFFER);

The following example demonstrates how to use:

Function GetTempdirectory: String; VARTEMPDIR: Array [0..255] of char; begingetTemppath (255, @tempdir); result: = strpas (tempdir);

Note: Determination of Tempory Directory: 1. If there is a TMP environment variable, the temporary directory is TMP specified directory 2. If there is no TMP environment variable, there is a TEMP environment variable, the directory specified by the TEMP variable 3, if TMP and TEMP are No definition, take the current directory as a temporary directory

The program does not appear in the taskbar General Windows 95 will appear on the taskbar when the program is running the program. If your program is a monitor, then the button is not a wise. To implement this feature, you must use the API function setWindowlongProcedure TFORM1.FormCreate (Sender: TOBJECT); BeginSetWindowlong (Application, Handle, GWL_EXSTYLE, WS_EX_TOOLWINDOW);

Change the computer name

Changing the name in the network, then take effect after restarting to setComputerName ('Hello World');

Controlling thermal start to make the system's thermal start key (Ctrl Alt Del), using the following statement systemParametersInfo (spi_screensaverrunning, 1, 0, 0); to restore the system's thermal start button (Ctrl Alt Del), use the following Statements SystemParametersInfo (SPI_Screensaverrunning, 0, 0, 0);

The temporary path sometimes requires Windows's temporary path to do backups, then you must know where the path is, the following program helps you: Var aa: pchar; begingetTemppath (20, aa); file: // Return the path name Edit1. TEXT: = aa;

Returns execution parameters About the command column parameters for Delphi incoming application, please refer to the following description: Number of command parameters with paramcount function: Call paramstr (0), return the file name (including path) Call Paramstr (n), the contents of the Nth parameter procedure tform1.form1.FormCreate (Sender: TOBJECT); VARSFILENAME: STRING; Beginif Paramcount> 0 Then Begin (* has an execution parameter incoming *) sfilename: = paramstr (1); * Getting parameters *) ifeexists (sfilename) ThenMEMO1.LINES.LOADFROMFILE (SFileName) ElseApplication.MessageBox ('found specified file', 'message', 48); end; end; turn off Windows Control Windows Switch: If Windows, restart Windows et al, EXITWINDOWSEX (UINT UFLAGS, DWORD DWRESERVED); is the API function that implements this function first defines constant constewx_force = 4; file: // Turns all programs and log in to EWX_LOGOFF = 0 as other users; FILE: / / Restart the computer and switch to the MS-DOS mode EWX_reboot = 2; file: // Restart the computer EWX_SHUTDOWN = 1; // Turn off the computer to assign the HOW, let him equal to EWX_SHUTDOWN or other, call the following statement EXITWINDOWSEX (How, 0);

Turn off the external application How to turn off the externally opened application in the Delphi application? The following is given in Delphi to close the "calculator" program as an example: VarhWndcalculator: hw; begin // Find the exist calculator windowhwndcalculator: = WinProcs.FindWindow (NIL, 'Calculator'); // Close The Exist Calculatorif HWNDCALCULATOR < > 0 THENSENDMESSAGE (HWNDCALCAL, WM_CLOSE, 0, 0); END;

Get the executable directory SYSUTILS unit with both similar functions and extractfilepath, which one? There is no big relationship. However, the following difference: The last character of the ExtractFilePath transfer value is a backslash "/". procedure TForm1.Button1Click (Sender: TObject); beginShowMessage (ExtractFileDir (Application.Exename)); // ie: c: / tempShowMessage (ExtractFilePath (Application.Exename)); // ie:; similarities / temp / end: c : If the execution file is in the root of the root (such as: c: /sample.exe), the passage of the two is the same, and the last character is "/".

转载请注明原文地址:https://www.9cbs.com/read-35130.html

New Post(0)