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

📄 windows.htm

📁 对于学习很有帮助
💻 HTM
📖 第 1 页 / 共 4 页
字号:
    ini.free;
  END;
end;

procedure TWinRestorer.SaveChildren;
var i: integer;
begin
  if TheMDIForm.formstyle <> fsMDIForm then
    raise EWinRestorer.create('Attempting to restore window sizes of children for a non MDI parent window.')

  else
    for i := 0 to TheMDIForm.MDIChildCount - 1 do
      SaveWin( TheMDIForm.MDIChildren[i], what);
end;

INITIALIZATION
END.</PRE><HR>

{<I> This code came from Lloyd's help file! }</I>

<!---------------------------------------------------------------------------------------------------------------------------------------------------->
<P><H1><A NAME="windows16">How: to determine name of StartUp group<IMG SRC="../images/new.gif" WIDTH=28 HEIGHT=11 BORDER=0 ALT=" [NEW]"></P></A></H1>
<I>From: Allan Carlton &lt;zephyr@athene.co.uk&gt;</I> <P>

<PRE>
In each language version of Windows the 'StartUp' folder has als a different name.
Is there any way to determine the correct name of this folder ??
</PRE>

There is an entry in the registry under:
<HR><PRE>HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Start Menu
</PRE><HR>
Which might give you the info you need

<p><H1><A NAME="windows17">Finding Boot Drive<img src="../images/new.gif" width=28 height=11 border=0 alt=" [NEW]"></p></A></H1>
From: "HIKI Takehito"  &lt;f8498008@ca.aif.or.jp&gt;

<pre>Is there a function or API call to find the boot drive?</PRE>

 I found it in the Registry.<p>

<hr><pre> HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup</pre><hr>

 "BootDir" value may be BootDrive.

<p><H1><A NAME="windows18">How to make a window system modal ?<img src="../images/new.gif" width=28 height=11 border=0 alt=" [NEW]"></p></A></H1>
<i>From: "Eric Lawrence" &lt;deltagrp@keynetcorp.net&gt;</i><p>

<hr><pre>SetSystemModalWindow(Form1.handle);</pre><hr>

<p><H1><A NAME="windows19">Sending Keystrokes/Text to a Window...<img src="../images/new.gif" width=28 height=11 border=0 alt=" [NEW]"></p></A></H1>
From: "David Zajac" &lt;dzajac@HiWAAY.net&gt;

Hope this helps:

<HR><pre>unit Unit1;

interface

uses
  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  Forms, Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormKeyPress(Sender: TObject; var Key: Char);
  private
    AppInst: THandle;
    AppWind: THandle;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

uses ShellAPI;
 

procedure SendShift(H: HWnd; Down: Boolean);
var vKey, ScanCode, wParam: Word;
    lParam: longint;
begin
  vKey:= $10;
  ScanCode:= MapVirtualKey(vKey, 0);
  wParam:= vKey or ScanCode shl 8;
  lParam:= longint(ScanCode) shl 16 or 1;
  if not(Down) then lParam:= lParam or $C0000000;
  SendMessage(H, WM_KEYDOWN, vKey, lParam);
end;

procedure SendCtrl(H: HWnd; Down: Boolean);
var vKey, ScanCode, wParam: Word;
    lParam: longint;
begin
  vKey:= $11;
  ScanCode:= MapVirtualKey(vKey, 0);
  wParam:= vKey or ScanCode shl 8;
  lParam:= longint(ScanCode) shl 16 or 1;
  if not(Down) then lParam:= lParam or $C0000000;
  SendMessage(H, WM_KEYDOWN, vKey, lParam);
end;

procedure SendKey(H: Hwnd; Key: char);
var vKey, ScanCode, wParam: Word;
    lParam, ConvKey: longint;
    Shift, Ctrl: boolean;
begin
  ConvKey:= OemKeyScan(ord(Key));
  Shift:= (ConvKey and $00020000) &lt;&gt; 0;
  Ctrl:= (ConvKey and $00040000) &lt;&gt; 0;
  ScanCode:= ConvKey and $000000FF or $FF00;
  vKey:= ord(Key);
  wParam:= vKey;
  lParam:= longint(ScanCode) shl 16 or 1;
  if Shift then SendShift(H, true);
  if Ctrl then SendCtrl(H, true);
  SendMessage(H, WM_KEYDOWN, vKey, lParam);
  SendMessage(H, WM_CHAR, vKey, lParam);
  lParam:= lParam or $C0000000;
  SendMessage(H, WM_KEYUP, vKey, lParam);
  if Shift then SendShift(H, false);
  if Ctrl then SendCtrl(H, false);
end;

function EnumFunc(Handle: HWnd; TF: TForm1): Bool; Far;
begin
  TF.AppWind:= 0;
  if GetWindowWord(Handle, GWW_HINSTANCE) = TF.AppInst then
    TF.AppWind:= Handle;
  result:= (TF.AppWind = 0);
end;

procedure TForm1.Button1Click(Sender: TObject);
var Text: Array[0..255] of char;
begin
  AppInst:= ShellExecute(Handle, 'open', 'notepad.exe', nil, '', SW_NORMAL);
  EnumWindows(@EnumFunc, longint(self));
  AppWind:= GetWindow(AppWind, GW_CHILD);
end;


procedure TForm1.Button2Click(Sender: TObject);
begin
  SendKey(AppWind, 'T');
  SendKey(AppWind, 'e');
  SendKey(AppWind, 's');
  SendKey(AppWind, 't');
end;

procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
  if AppWind &lt;&gt; 0 then SendKey(AppWind, Key);
end;

end.
</PRE><HR>

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

<PRE>Can anybody out there send me some basic stuff about Windows Messages
related to Delphi. All this WM_*** stuff is getting on my nerves, since I
can't understand it.</PRE>

<I>[Jim Stanley, Jim.Stanley@jacobs.com]</I><P>
All the Windows messages are listed in the Windows API
help in your Delphi help topics.  (I'm using D1, assume the same for
future versions).<p>

The WM_ (and other) messages are essential to the way Windows works.
You're well aware that Delphi is primarily an *event-driven* system; all
those OnKeyPress, OnThis, OnThat methods.  If you have the VCL source
code, you'll find in there somewhere that those event handler methods
are designed to *receive* particular Windows messages (and there are
some threads in here showing how you can subclass a component and
"teach" it to respond to other messages as well).  Windows is constantly
sending out those messages in response to actions performed by the user,
and it's the business of the Delphi app (and of all Windows apps) to
intercept them and handle them in ways you decide.  Delphi puts a
wrapper over most of the message system by creating the event handlers
for components described above.<p>

In addition to recieving those messages, you can also *send* them as
well.  There are a couple of ways to work this:
check out SendMessage and PostMessage (both native Win API functions),
as well as the Delphi Perform method.  The first two require you to use
the Handle parameter of the component you're sending the message to,
while Perform is a method belonging to that component.  The messages go
into the standard Windows message queue and are processed like every
other message.<p>

Here's a trivial example:  I want (for some bizarre reason) to insert a
'y' character whenever I type a '4' in a TMemo.  [Think of automatically
inserting a begin-end block or a closing parenthesis.) Now I could do a
lot with the Memo's Lines property, but that gets pretty complex.  A
much simpler way of going about it is:

<HR><PRE>
procedure TForm1.Memo1KeyPress(Sender: TObject; var Key: Char);
begin
  if Key = '4' then
    SendMessage(Memo1.Handle, WM_CHAR, Word('y'), 0);
end;
</PRE><HR>

Another example is something we were doing here at Jacobs that used a
lot of combo boxes.  We wanted them to automatically drop down when the
user pressed a key, which is (unfortunately) not standard behavior.
Here's what we did:

<HR><PRE>
procedure TFormEffortRates.ComboBoxMaterialKeyDown(Sender: TObject; var
Key: Word;
  Shift: TShiftState);
var iShowing : integer;

{ other code, then... }
    begin
      { This tells you whether the combo is already dropped }
      iShowing := SendMessage((Sender as TComboBox).Handle, CB_GETDROPPEDSTATE, 0, 0);
      if iShowing = 0 then
        { drop the combo box }
        SendMessage((Sender as TComboBox).Handle, CB_SHOWDROPDOWN, 1,0);
    end;
</PRE><HR>

Another good example is getting the line and column from a TMemo.  You
have to go into the API to do it.  Here's a (not particularly efficient
- no flames please!!) method of determining them:

<HR><PRE>
function TMDIChild.GetMemoColumn(const TheMemo : TMemo) : integer;
begin
  Result := TheMemo.SelStart -
    (SendMessage(TheMemo.Handle, EM_LINEINDEX,
    GetMemoLine(TheMemo), 0));
end;

function TMDIChild.GetMemoLine(const TheMemo : TMemo) : integer;
begin
  Result := SendMessage(TheMemo.Handle, EM_LINEFROMCHAR,
TheMemo.SelStart, 0);
end;
</PRE><HR>

Again, all these messages can be found in your API help.  The
instructions for using them are a little vague, but I'm sure everyone
will be glad to help you should you need it.<P>

In short, API messages provide you with a way to fine-tune your
applications to respond in exactly the way you want them to.  I would
consider it an advanced Delphi topic, but it sounds like one you're more
than ready for.

<P><H1><A NAME="windows21">Buttons in Win95 task bar<IMG SRC="../images/new.gif" WIDTH=28 HEIGHT=11 BORDER=0 ALT=" [NEW]"></P></A></H1>


<PRE>Can anyone tell me of a way or a component or whatever else that will allow
delphi 2 or 3 to place a button on the task bar much like what PowerDesk
2.0 Toolbar does.</PRE>

<I>[Joolz@emarkt.com]</I><P>
Here are the code snipits to do just that!<p>

<HR><PRE>
// This needs to be in your public declarations @ the top of the pas file
procedure TForm1.IconCallBackMessage( var Mess : TMessage ); message WM_USER
+ 100;
</PRE><HR>

<HR><PRE>
procedure TForm1.FormCreate(Sender: TObject);
var
   nid : TNotifyIconData;
begin
     with nid do
     begin
           cbSize := SizeOf( TNotifyIconData );
           Wnd := Form1.Handle;
           uID := 1;
           uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP;
           uCallbackMessage := WM_USER + 100;
           hIcon := Application.Icon.Handle;
           szTip := 'This is the hint!';
     end;
     Shell_NotifyIcon( NIM_ADD, @nid );
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
var
   nid : TNotifyIconData;
begin
     with nid do
     begin
           cbSize := SizeOf( TNotifyIconData );
           Wnd := Form1.Handle;
           uID := 1;
           uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP;
           uCallbackMessage := WM_USER + 100;
           hIcon := Application.Icon.Handle;
           szTip := 'This is the hint!';
// All the above is probably not needed.
     end;
     Shell_NotifyIcon( NIM_DELETE, @nid );
end;

procedure TForm1.IconCallBackMessage( var Mess : TMessage );
var
   sEventLog : String;
begin
     case Mess.lParam of
// Do whatever you wish here. For example popup up a menu on a right click.
          WM_LBUTTONDBLCLK  : sEventLog := 'Left Double Click';
          WM_LBUTTONDOWN    : sEventLog := 'Left Down';
          WM_LBUTTONUP      : sEventLog := 'Left Up';
          WM_MBUTTONDBLCLK  : sEventLog := 'M Dbl';
          WM_MBUTTONDOWN    : sEventLog := 'M D';
          WM_MBUTTONUP      : sEventLog := 'M U';
          WM_MOUSEMOVE      : sEventLog :=  'movement';
          WM_MOUSEWHEEL     : sEventLog := 'Wheel';
          WM_RBUTTONDBLCLK  : sEventLog := 'r dbl';
          WM_RBUTTONDOWN    : sEventLog := 'r down';
          WM_RBUTTONUP      : sEventLog := 'r up';
     end;
end;
</PRE><HR>

<HR SIZE="6" color="#00FF00">
<FONT SIZE="2">
<a href="mailto:rdb@ktibv.nl">Please email me</a> and tell me if you liked this page.<BR>
<SCRIPT LANGUAGE="JavaScript">
<!--
	document.write("Last modified " + document.lastModified);
// -->
</SCRIPT><P>
<TABLE BORDER=0 ALIGN="CENTER">
<TR>
	<TD>This page has been created with </TD>
	<TD> <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>

</FONT>


</BODY>
</HTML>

⌨️ 快捷键说明

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