⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 api.htm

📁 对于学习很有帮助
💻 HTM
📖 第 1 页 / 共 2 页
字号:
  {---------------------------------------------------------------}
  procedure WMQueryEndSession(
             var Message: TWMQueryEndSession); message WM_QUERYENDSESSION;
  public
    { Public declarations }
  end;
var
  Form1    : TForm1;

implementation
{$R *.DFM}

{---------------------------------------------------------------}
{ Custom procedure to respond to the WM_QUERYENDSESSION message }
{ The application will only receive this message in the event   }
{ that Windows is requesing to exit.                            }
{---------------------------------------------------------------}
procedure TForm1.WMQueryEndSession(var Message: TWMQueryEndSession);
begin
  inherited;         { let the inherited message handler respond first }
  {--------------------------------------------------------------------}
  { at this point, you can either prevent windows from closing...      }
  { Message.Result:=0;                                                 }
  {---------------------------or---------------------------------------}
  { just call the same cleanup procedure that you call in FormClose... }
  { MyCleanUpProcedure;                                                }
  {--------------------------------------------------------------------}
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  MyCleanUpProcedure;
end;

end.</PRE><HR>
<P>I have not tested this code, but I think it will work correctly. Let me know how it turns out!</P>

<!---------------------------------------------------------------------------------------------------------------------------------------------------->
<H1><A NAME="api2">Windows API about Printer</A></H1>
<I><P>From: David and Rhonda Crowder &lt;dcrowder@bridge.net&gt;</P>
</I><P>&gt;&gt; I want to obtain the values (left, right, top, bottom) of &quot;unprintable area&quot; from the printer. </P>
<P>In August Delphi Developer &quot;Take Control of your printer with a custom Delphi Class&quot;: </P>
<P>To get the Left and Top Printer Margins use the Windows Escape Function with the parameter GETPRINTINGOFFSET.</P>
<HR><PRE>var
  pntMargins : TPoint;
begin
  { @ means &quot; the address of the variable&quot; }
  Escape(Printer.Handle, GETPRINTINGOFFSET,0,nil,@prntMargins);
end;</PRE><HR>
<P>Getting the Right and Bottom Margins aren't quite so straightforward. 
There isn't an equivalent Escape call. You obtain these values by getting the physical width 
(physWidth) and height (physHeight) of the page, the printable width (PrintWidth) and 
height (PrintHeight) of the page, and then carrying out the following sums:</P>
<PRE>RightMargin    := physWidth  - PrintWidth  - LeftMargin
BottomMargin := physHeight - PrintHeight - TopMargin</PRE>
<P>The physical page size is found using Escape, this time with the GETPHYSPAGESIZE parameter. 
The point pntPageSize contains the page width in pntPageSize.x and page height in pntPageSize.y</P>
<HR><PRE>var
  pntPageSize : TPoint;
begin
   Escape(Printer.Handle, GETPHYSPAGESIZE,o,nil,@pntPageSize);
end;</PRE><HR>

<!---------------------------------------------------------------------------------------------------------------------------------------------------->
<H1><A NAME="api3">Getting DOS Variables</A></H1>
<I><P>From: &quot;Bob Findley&quot; &lt;bfindley@cheney.net&gt;</P>
</I><P>I assume you mean environment variables?</P>
<P>The GetEnvironmentStrings function returns the address of the environment block for the current process. 
Each environment variable is null terminated. The set of strings is double null terminated.</P>
<P>The GetEnvironmentVariable function retrieves the value of the specified variable from the environment block of the calling process. 
The value is in the form of a null-terminated string of characters.</P>

<H1><A NAME="api4">GetModuleFileName</A></H1>
<P>Here is an answer for you. I have used this on many occasions and it works well.</P>
<HR><PRE>procedure TForm1.Button1Click(Sender: TObject);
var
   szFileName : array[0..49] of char;
   szModuleName : array[0..19] of char;
   iSize : integer;
begin
   StrPCopy(szModuleName, 'NameOfModule');
   iSize := GetModuleFileName(GetModuleHandle(szModuleName),szFileName,
                  SizeOf(szFileName));
   if iSize &gt; 0 then
      ShowMessage('Full path name is : ' + StrPas(szFileName))
   else
      ShowMessage('Path of module not found');
end;</PRE><HR>

<!---------------------------------------------------------------------------------------------------------------------------------------------------->
<H1><A NAME="api5">Setting time system with Delphi</A></H1>
<I><P>abeldup@unison.co.za (Abel du Plessis)</P>
</I><PRE>
&quot;Vitor Martins&quot; &lt;nop47019@mail.telecom.pt wrote:


How can I set the clock system time and date in a program  with Delphi 2.0
in Win 95
</PRE>
<P>This works for us:</P>
<HR><PRE>//******************************************************************************
//Public function SetPCSystemTime changes the system date and time.
//Parameter(s): tDati  The new date and time
//Returns:      True if successful
//              False if not
//******************************************************************************
function SetPCSystemTime(tDati: TDateTime): Boolean;
var
   tSetDati: TDateTime;
   vDatiBias: Variant;
   tTZI: TTimeZoneInformation;
   tST: TSystemTime;
begin
   GetTimeZoneInformation(tTZI);
   vDatiBias := tTZI.Bias / 1440;
   tSetDati := tDati + vDatiBias;
   with tST do
   begin
        wYear := StrToInt(FormatDateTime('yyyy', tSetDati));
        wMonth := StrToInt(FormatDateTime('mm', tSetDati));
        wDay := StrToInt(FormatDateTime('dd', tSetDati));
        wHour := StrToInt(FormatDateTime('hh', tSetDati));
        wMinute := StrToInt(FormatDateTime('nn', tSetDati));
        wSecond := StrToInt(FormatDateTime('ss', tSetDati));
        wMilliseconds := 0;
   end;
   SetPCSystemTime := SetSystemTime(tST);
end;</PRE><HR>

<!---------------------------------------------------------------------------------------------------------------------------------------------------->
<P><H1><A NAME="api6">How do I execute a program and have my code wait until it is finished?</P></A></H1>
<P><I>From: Noel Rice  &lt;nrice@ix.netcom.com&gt;</I></P>

A:  Here is the 16 bit version:<P>

<HR><PRE>uses Wintypes,WinProcs,Toolhelp,Classes,Forms;

Function WinExecAndWait(Path : string; Visibility : word) : word;
var
  InstanceID : THandle;
  PathLen : integer;
begin
  { inplace conversion of a String to a PChar }
  PathLen := Length(Path);
  Move(Path[1],Path[0],PathLen);
  Path[PathLen] := #00;
  { Try to run the application }
  InstanceID := WinExec(@Path,Visibility);
  if InstanceID < 32 then { a value less than 32 indicates an Exec error }
     WinExecAndWait := InstanceID

  else begin
    Repeat
      Application.ProcessMessages;
    until Application.Terminated or (GetModuleUsage(InstanceID) = 0);
    WinExecAndWait := 32;
  end;
end;
</PRE><HR>
Here is the 32 bit version:<P>

<HR><PRE>function WinExecAndWait32(FileName:String; Visibility : integer):integer;
var
  zAppName:array[0..512] of char;
  zCurDir:array[0..255] of char;
  WorkDir:String;
  StartupInfo:TStartupInfo;
  ProcessInfo:TProcessInformation;
begin
  StrPCopy(zAppName,FileName);
  GetDir(0,WorkDir);
  StrPCopy(zCurDir,WorkDir);
  FillChar(StartupInfo,Sizeof(StartupInfo),#0);
  StartupInfo.cb := Sizeof(StartupInfo);

  StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
  StartupInfo.wShowWindow := Visibility;
  if not CreateProcess(nil,
    zAppName,                      { pointer to command line string }
    nil,                           { pointer to process security attributes }
    nil,                           { pointer to thread security attributes }
    false,                         { handle inheritance flag }
    CREATE_NEW_CONSOLE or          { creation flags }
    NORMAL_PRIORITY_CLASS,
    nil,                           { pointer to new environment block }
    nil,                           { pointer to current directory name }
    StartupInfo,                   { pointer to STARTUPINFO }
    ProcessInfo) then Result := -1 { pointer to PROCESS_INF }

  else begin
    WaitforSingleObject(ProcessInfo.hProcess,INFINITE);
    GetExitCodeProcess(ProcessInfo.hProcess,Result);
  end;
end;

</PRE><HR>

{Thanks to Pat Ritchey for these functions.}<P>

{ This code came from Lloyd's help file!  Ldelphi.zip }<P>

<!---------------------------------------------------------------------------------------------------------------------------------------------------->
<P><H1><A NAME="api7">disable Ctrl-Alt-Del</P></A></H1>
<P><I>From: Richard Leigh &lt;rleigh@deakin.edu.au&gt;</I></P>

Issues : <p>

The program should be nice and small so it can load before a user can
hit CTRL-ALT-DEL.<p>

My Solution :<p>

Compile a single WIN32API call into a small .exe in delphi.  <p>

The Program :<p>

<HR><PRE>program small;

{written by Richard Leigh, Deakin Univesity 1997}

uses
  WinProcs;

{$R *.RES}

var
   Dummy : integer;

begin
  Dummy := 0;
  {Disable ALT-TAB}
  SystemParametersInfo( SPI_SETFASTTASKSWITCH, 1, @Dummy, 0);
  {Disable CTRL-ALT-DEL}
  SystemParametersInfo( SPI_SCREENSAVERRUNNING, 1, @Dummy, 0);
end.
</PRE><HR>
This is the main unit - No forms and compiles small. <p>

<!---------------------------------------------------------------------------------------------------------------------------------------------------->
<P><H1><A NAME="api8">ExtractAssIcon and paint into Timage?<IMG SRC="../images/new.gif" WIDTH=28 HEIGHT=11 BORDER=0 ALT=" [NEW]"></P></A></H1>
<P><I>From: "Joe C. Hecht (Borland)" &lt;jhecht@corp.borland.com&gt;
</I></P>

<pre> 
&gt; How can I extract the associated icon (ExtractAssociatedIcon) and draw it into
&gt; a Timage or a small area of the form?
</pre> 

<HR><PRE>uses ShellApi;

procedure TForm1.Button1Click(Sender: TObject);
var
  IconIndex : word;
  h : hIcon;
begin
  IconIndex := 0;
  h :=
    ExtractAssociatedIcon(hInstance,
                        'C:\WINDOWS\NOTEPAD.EXE',
                         IconINdex);

  DrawIcon(Form1.Canvas.Handle,
             10,
             10,
             h);
</PRE><HR>

-----------------------------------------------------------------------------

<P><H1><A NAME="api9">ExitWindows<IMG SRC="../images/new.gif" WIDTH=28 HEIGHT=11 BORDER=0 ALT=" [NEW]"></P></A></H1>

<PRE>Does anyone know how to access the function ExitWindows in
User.exe. I would like to use this function to restart windows
without restarting the computer.</PRE>

<I>[Mike O'Hanlon, TMike@IAfrica.com]</I><P>
  Here are examples of how to restart Windows and also how to
  reboot the system: <p>

<HR><PRE>
    procedure TMainForm.RestartWindowsBtnClick(Sender: TObject);
    begin
      if not ExitWindows(EW_RestartWindows, 0) then
        ShowMessage('An application refused to terminate');
    end;
</PRE><HR>

<HR><PRE>
    procedure TMainForm.RebootSystemBtnClick(Sender: TObject);
    begin
      if not ExitWindows(EW_RebootSystem, 0) then
        ShowMessage('An application refused to terminate');
    end;
</PRE><HR>


  The ExitWindows function has always been wrongly documented -
  Microsoft got it wrong in their documents and every one else
  followed along with the incorrect info.  I believe the correct
  definition is: <p>

<HR><PRE>
    function ExitWindows (dwReturnCode: Longint;
                          Reserved: Word): Bool;
</PRE><HR>


<HR SIZE="6" COLOR="LIME">
<P><A HREF="mailto:rdb@ktibv.nl"><FONT SIZE=2>Please email me</FONT></A><FONT SIZE=2> and tell me if you liked this page.<p>
<SCRIPT LANGUAGE="JavaScript"><!--
	document.write("Last modified " + document.lastModified);
// --></SCRIPT></FONT>
<P ALIGN="CENTER"><CENTER><TABLE CELLSPACING=0 BORDER=0>
<TR><TD VALIGN="MIDDLE">
<P><FONT SIZE=2>This page has been created with </FONT></TD>
<TD VALIGN="MIDDLE">
<P><A HREF="http://www.dexnet.com./homesite.html"><IMG SRC="../images/hs25ani.gif" WIDTH=88 HEIGHT=31 BORDER=0 ALT="HomeSite 2.5b"></A></TD>
</TR>
</TABLE>
</CENTER></P>

<P>&nbsp;</P></BODY>
</HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -