Windows API Function Using Skills Get Windows System Path: Method: Var MySyspath: Pchar; Begin getmem (mysyspath, 255); getSystemDirectory (mysyspath, 255); end; Note: MySyspath is 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;
VAR
Tempdir: array [0..255] of char;
Begin
GetTemppath (255, @Tempdir);
Result: = STRPAS (Tempdir);
END;
Note: The principle of determining the temporary directory:
1. If there is a TMP environment variable, the temporary directory is the directory specified by TMP.
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 not defined, take the current directory as a temporary directory.
The program does not appear in the taskbar
General Windows 95 When the program is running the program, the button appears on the taskbar. 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');
Control hot start
To make the system's thermal start key (Ctrl Alt Del), use the following statement SystemParametersInfo (SPI_SCREENSAVERRUNNING, 1, 0); to restore the system's thermal start button (Ctrl Alt Del), use the following statement SystemParametersInfo SPI_SCREENSAVERRunning, 0, 0, 0);
Temporary path
Sometimes you need to do a backup of the temporary path to do backups, then you must know where the path is. The following program helps you: Var aa: pchar; begingeTemPath (20, aa); file: // Return path Name Edit1.Text: = AA; END;
Returns execution parameters
For the command column parameters for Delphi incoming application, refer to the following instructions: Number of command parameters: Call paramstr (0), pass the file name (including path) call paramstr (n), Transfer to the nth parameter Procedure TFORM1.FormCreate (Sender: Tobject); VARSFileName: String; Beginif Paramcount> 0 THEN BEGIN (* has an execution parameter incoming *) sfilename: = paramstr (1); (* acquisition parameter content *) If FileExists (SFileName) ThenMemo1.Lines.LoadFromFile (sfilename) elseApplication.MessageBox ('found specified file', 'message', 48); end; end; turn off Windows
Control Windows switch: If Windows is closed, restart Windows et al, EXITWINDOWSEX (DWRSERD); is the API function that implements this function first defines constant constewx_force = 4; file: // Close all programs and other user identities Log in to EWX_LOGOFF = 0; 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 the HOW assignment, let him equal EWX_SHUTDOWN or other Call the following statement EXITWINDOWSEX (How, 0);
Close external application
How to close 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 (hwndcalculator, wm_close, 0, 0);
Get the directory of the executive
There are two similar functions of extractfiledir and extractfilepath in the SYSUTILS unit. Which one is 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 "/".
Example Samples use GetFileVersionInfo by using GetFileVersionInfo get version information?
Answer 1: procedure GetBuildInfo (var V1, V2, V3, V4: Word); var VerInfoSize: DWORD; VerInfo: Pointer; VerValueSize: DWORD; VerValue: PVSFixedFileInfo; Dummy: DWORD; begin VerInfoSize: = GetFileVersionInfoSize (PChar (ParamStr (0 ))), Dummy); getMem (Verinfo, Verinfosize); getFileVersionInfo (Pchar (Pramstr (0)), 0, VerinFosize, Verinfo; VerQueryValue (VerInfo, '/', Pointer (VERVALUE), VERVALUESIZE); with VERVALUE ^ DO Begin V1: = DWFILEVERSIONMS SHR 16; V2: = DWFileVersionms and $ fff; v3: = dwfileversionls shr 16; v4: = dwfileversionls and $ fff; end; freemem (verinfo, verinfosize); end; ---------------- ---------------------------------- Answer 2IF You Want A Component, Check Out TVERSIONFORESOURESOTTTTP: / / WWW. POBOX.COM/~Bstowers/delphi/ in the my stuff section. D1 / d2 / d3 / c bcompatible, freeware with ful sace code and a small demo.and you can see the http://www.aye.net / ~ bstowers / delphi / another Component VersionInfo.zip Prevent Procedure Run multiple routines? More Tan One Instance of Program?
Answer this is copied direct from my * .dpr file. You can work it for your w w.
var hMutex: Thandle; WaitResult: word; BroadcastList: DWORD; begin MessageID: = RegisterWindowMessage ( 'Check For Choice Previous Inst'); // register a message to use later on hMutex: = createMutex (nil, false, pchar ( 'App_Choice ')); // grab a mutexhandle WaitResult: = WaitForSingleObject (hMutex, 10); // wait to seeif we can have exclusive use of the mutex if (waitResult = WAIT_TIMEOUT) then // if we can not then broadcastthe message to make the owner of the mutex respond {request that the running application takes focus} begin BroadcastList: = BSM_APPLICATIONS; BroadcastSystemMessage (BSF_POSTMESSAGE, @ BroadcastList, MessageID, 0,0); file: // 32 bit - broadcast themessage to all apps - only a prev inst will hear it end else begin {do the normal stuff} Application.Title:. = 'Choice Organics Purchase & Sales System'; Application.CreateForm (TMainForm, MainForm); Application.Run; ReleaseMutex (hMutex); // Releas e the mutex as a politeness end; closehandle (hmutex); // Close the Mutex Handlend.This Goes in the Mainform
procedure Tmainform.OnAppMessage (var Msg: TMsg; Var Handled: Boolean); begin {If it's the special message then focus on this window} if Msg.Message = MessageID then // if we get the broadcast message from ananother instance of this app That is trying to start up begin show; windowstate: = wsmaximized; bringtofront; setfocus; handled: = true; end;
File: // and this goes in the tMAINFORM.FORMCREATE; - -
Application.onMessage: = onappMessage;
4. Get the name of Win 95?
Question How Can I Learn Windows'95 Machine Name?
Answer; var cnamebuffer: pchar; fl_loaded: boolean; clen: ^ DWORD;
Begin
GetMem (CNameBuffer, 255); New (CLEN); clen ^: = 255;
FL_Loaded: = getComputerName (CNameBuffer, Clen ^);
IF fl_loaded then computername: = strpas (cnamebuffer) else computename: = 'unkown';
FreeMem (CNameBuffer, 255); Dispose (CLEN);
END;
7. Stop a thread? Q Stop A Thread Answer You can Terminate your thread in two ways:?. 1) Assign ThreadDone to OnTerminate when you create it In the Execute method, exit when the terminated property is True At the point where you want to stop, issue the. Terminate Method.2) Just Call The Suspend Method.After One of these Stes You May Free The Thread.i Hope The Following Snippets Will Help.
/ / -------------------------------------------------------------------------------------------- -------------- // Interface
TYPE TXYZ = Class (TTHREAD) PUBLISHED Procedure Execute; Override;
Var xyzthread: txyz;
IMPLEMENTATION
Procedure TXYZ.EXECUTE; Begin While True Do Application.ProcessMESSAGES;
Procedure tform1.button1click (sender: TOBJECT); begin xyzthread: = txyz.create (false);
Procedure tForm1.button2click (sender: TOBJECT); begin xyzthread2.suspend; xyzthread2.free;
End.
How to control the length width of the print font under UCDOS in Windows, and is not limited to SIZE limits.
First, in order to achieve this function, you can use createFont or createFontIndirect to define any desired fonts using createFont or CreateFontIndirect, because CreateFont needs to use CreateFontIndire to build the required The logical font, this API function is declared in Delphi as function createfontIndirect (const p1: tlogfont): hfont; stdcall; where only one parameter P1: Tlogfont, all the parameters of the font pass through this TLogFont structure, Windows will be based on the TLOGFont structure The content in the structure creates corresponding logical fonts, in the windows.pas of Delphi, TLOGFont is the definition
TLogFontA = packed recordlfHeight: Longint; lfWidth: Longint; lfEscapement: Longint; lfOrientation: Longint; lfWeight: Longint; lfItalic: Byte; lfUnderline: Byte; lfStrikeOut: Byte; lfCharSet: Byte; lfOutPrecision: Byte; lfClipPrecision: Byte; lfQuality: Byte ; lfPitchAndFamily: Byte; lfFaceName: array [0..LF_FACESIZE - 1] of AnsiChar; end; TLogFontW = packed recordlfHeight: Longint; lfWidth: Longint; lfEscapement: Longint; lfOrientation: Longint; lfWeight: Longint; lfItalic: Byte; lfUnderline: byte; lfStrikeOut: byte; lfCharSet: byte; lfOutPrecision: byte; lfClipPrecision: byte; lfQuality: byte; lfPitchAndFamily: byte; lfFaceName: array [0..LF_FACESIZE - 1] of WideChar; end; TLogFont = TLogFontA; involving many Parameters, where
LFHEIGHT: longint; specifies the font height calibrated with a logical unit, and the value can be positive or zero, and the negative value is usually taken to the case where the font height needs to be arbitrarily defined, to ensure the actual size font.
LfWidth: longint; used to specify the average width of the font, because most of the digital bodies under the Windows system are proportional fonts thus using the average width. If specified as 0, the system automatically processes the width according to the appropriate proportion.
LFESCAPEMENT: longint; specifies the angle between the output direction and the current coordinate system X-axis.
LirtAthation: longint; Specifies the angle between each character and the current coordinate system x-axis. This value is equivalent to LFESCPEMENT in Windows 95.
LfWeight: longint; Specifies the extent of font weight from 0 to 1000, 400 is the standard font 700 is a weighting font, 0 indicates the use of the default value.
Lfitalic: Byte; not 0 means using a bevel word.
Lfunderline: Byte; not 0 indicates a downline.
Lfstrikeout: Byte; not 0 indicates the linen line.
Lfcharset: byte; specifies font sets.
LFoutPrecision: Byte; Specifies the output accuracy. Used to determine the accuracy of some of the previous settings.
LFCLIPPRecision: Byte; Specifies the cropping precision. Crop is a special treatment in a Windows graphics environment, simply that it is to remove a portion other than the view in the figure, help to increase the processing speed of the graphics.
LFQUALITY: BYTE; Specifies the quality of the output.
LFPITCHANDFAMILY: BYTE; Specifies the Pitch and Family of the font.
LFFACENAME: Array [0.Lf_facesize - 1] of ansichar; Specifies the font name.
When establishing a logical font, we usually use