📄 windows.htm
字号:
PMapData will point to a 1000 byte buffer in this example, this buffer being initialized to #0's the first time in.
One potential problem is synchronizing access to the memory. You may accomplish this through the use of mutexes. Here's an example of that:</P>
<HR><PRE>{ Call LockMap before writing (and reading?) to the memory mapped file. Be sure to call UnlockMap immediately when done updating. }
var
HMapMutex: THandle;
const
REQUEST_TIMEOUT = 1000;
function LockMap:Boolean;
begin
Result := true;
HMapMutex := CreateMutex(nil, false, pchar('MY MUTEX NAME GOES HERE'));
if HMixMutex = 0 then begin
ShowMessage('Can''t create map mutex');
Result := false;
end else begin
if WaitForSingleObject(HMapMutex,REQUEST_TIMEOUT) = WAIT_FAILED then begin
// timeout
ShowMessage('Can''t lock memory mapped file');
Result := false;
end;
end;
end;
procedure UnlockMap;
begin
ReleaseMutex(HMixMutex);
CloseHandle(HMixMutex);
end;
</PRE><HR>
<P>Please excuse my unnecessary begin..end's. I come from a Clipper background, and I prefer to see my logic blocks capped off with end's - easier to follow.</P>
<P><H1><A NAME="windows4">Shell_NotifyIcon</P></A></H1>
<P><I>From: "Neil Clayton" <100101.602@compuserve.com></I></P>
<PRE>Rainer Perl <Rainer.Perl@iddc.via.at> wrote in article
> I have a question to the Shell_NotifyIcon function:
> I can add an icon to the taskbar
> I can modify an icon
> I can delete an icon.
> What I can't do: I can't receive Messages from the Icon!!
</PRE>
<P>To receive messages you must add the NIF_MESSAGE flag to your notify structure and tell it what message to send and to which window. This is the code that I use:</P>
<HR><PRE>procedure TMainForm.UpdateTaskBar; // update the win95 taskbar icon area
var
NotifyData: TNotifyIconData;
begin
With NotifyData do // set up the data structure
begin
cbSize := SizeOf(TNotifyIconData);
Wnd := MyForm.Handle;
uID := 0;
uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP; // ... the aspects to modify ...
uCallbackMessage := WM_MY_MESSAGE; // ... the message to send back to us ...
hIcon := hMyIcon;
szTip := 'Tool Tip To Display'; // ... and the tool tip
end;
Shell_NotifyIcon(dwMessage, @NotifyData); // now do the update
end;
</PRE><HR>
<P>WM_MYMESSAGE is a user defined message. Usually defined as:</P>
<HR><PRE>const
WM_MYMESSAGE = WM_USER + <some number - can be zero>;
</PRE><HR>
<P><H1><A NAME="windows5">How do I make completely invisible main forms??</P></A></H1>
<P><I>From: gt6298d@prism.gatech.edu (Chris Randall)</I></P>
<PRE>"J.J. Bakker" <J.J.Bakker@stud.rgl.ruu.nl> wrote:
>Does anyone know the answer, I', trying to make an app that has an icon in the notification area with a popupmenu. However the application is still visible on the taskbar.
Using Application.ShowMainForm:=False; is not enough.
>
</PRE>
<P>I have run into the same problem but found the answer. This little bit of code works great.</P>
<HR><PRE>procedure TMainForm.FormCreate(Sender: TObject);
begin
Application.OnMinimize:=AppMinimize;
Application.OnRestore:=AppMinimize;
Application.Minimize;
AppMinimize(@Self);
end;
procedure TMainForm.AppMinimize(Sender: TObject);
begin
ShowWindow(Application.Handle, SW_HIDE);
end;
</PRE><HR>
<P><H1><A NAME="windows6">HELP !! STAY-ON-TOP !!!</P></A></H1>
<P><I>From: "James D. Rofkar" <jim_rofkar%lotusnotes1@instinet.com></I></P>
<PRE>JAAD wrote:
>
> I want to make a Delphi-Form to REALLY stay on top, But not only within it own application (thats simpel)
No I want it to stay on top even when I am using for instance EXCEL.
>
</PRE>
<P>Try using the Windows API function SetWindowPos(). Something like...</P>
<HR><PRE> with MyForm do
SetWindowPos(Handle,
HWND_TOPMOST,
Left,
Top,
Width,
Height,
SWP_NOACTIVATE or SWP_NOMOVE or SWP_NOSIZE);
</PRE><HR>
<P>You may need to call this function in your Form's OnShow(), OnDeactivate(), and OnActivate() event handlers.</P>
<P><H1><A NAME="windows7">Hardware port access in DELPHI 2</P></A></H1>
<HR><PRE>function InPort(PortAddr: word): byte;
{$IFDEF VER90}
assembler; stdcall;
asm
mov dx,PortAddr
in al,dx
end;
{$ELSE}
begin
Result := Port[PortAddr];
end;
{$ENDIF}
procedure OutPort(PortAddr: word; Databyte: byte);
{$IFDEF VER90}
assembler; stdcall;
asm
mov al,Databyte
mov dx,PortAddr
out dx,al
end;
{$ELSE}
begin
Port[PortAddr] := DataByte;
end;
{$ENDIF}
</PRE><HR>
<P><H1><A NAME="windows8">Hiding Windows 95 Taskbar</P></A></H1>
<P><I>From: "James D. Rofkar" <jim_rofkar%lotusnotes1@instinet.com></I></P>
<PRE>Robert Copier wrote:
> Is there a way to hide the Windows 95 statusbar when i start my application made in delphi 2.01. When the user close the application the statusbar must become visible again.
</PRE>
<P>I'm guessing you're referring to the Windows 95 taskbar and system tray window, and not a statusbar. The answer: Sure you can! And what a cool idea! Here's how:</P>
<OL>
<LI> First declare a variable of type HWND to store the Window handle of the Windows 95 taskbar.
<HR><PRE> TForm1 = class(TForm)
...
private
hTaskBar: HWND;
...
end;
</PRE><HR>
<LI> In your main form's OnCreate() event handler, place some code that resembles:
<HR><PRE> hTaskBar := FindWindow('Shell_TrayWnd', nil);
ShowWindow(hTaskBar, SW_HIDE);
</PRE><HR>
<LI> Finally, in your main form's OnDestroy() event handler, code something like:
<HR><PRE> ShowWindow(hTaskBar, SW_SHOW);</PRE><HR>
</OL>
<P><H1><A NAME="windows9">A Catch-a-Maximize Command Question</P></A></H1>
<P><I>From: "Chami" <72223.10@compuserve.com></I></P>
<PRE>> I need to have a form in my application that zooms to half of
> the screen when the Maximize button is pressed, not to full
> screen.
>
</PRE>
<P>you could handle the WM_GETMINMAXINFO message from your form.</P>
<P>for example, add the following declaration to the protected section of your form (interface):</P>
<HR><PRE>procedure _WM_GETMINMAXINFO( var mmInfo : TWMGETMINMAXINFO ); message wm_GetMinMaxInfo;
</PRE><HR>
<P>then define (implementation) the above message handler as follows (TForm1 being the name of your form of course):</P>
<HR><PRE>procedure TForm1._WM_GETMINMAXINFO( var mmInfo : TWMGETMINMAXINFO );
begin
// set the position and the size of your form when maximized:
with mmInfo.minmaxinfo^ do
begin
ptmaxposition.x := Screen.Width div 4;
ptmaxposition.y := Screen.Height div 4;
ptmaxsize.x := Screen.Width div 2;
ptmaxsize.y := Screen.Height div 2;
end;
end;
</PRE><HR>
<P><H1><A NAME="windows10">How do you detect Windows version?</P></A></H1>
<P><I>From: mdiluglio@aol.com</I></P>
<P>Check the API help
In the WINPROCS unit try the function GetVersion: LongInt;
</P>
<P>The GetVersion function retrieves the current version numbers of the Windows and MS-DOS operation systems.</P>
<P>NOTE there is a error in the orginal API documentation, the major/minor Win version are reversed!</P>
<P>As I have used it:</P>
<P><B>Windows 3.1 show up as 3.1, WIN95 shows up as 3.95</B></P>
<P><H1><A NAME="windows11">How can I change the wallpaper programmatically?</P></A></H1>
<H2>Solution 1 </H2>
<P>The following code comes from Loyds Help File (it can be found on most delphi web pages).
I haven't tried it but I will use it in one of my apps as soon as I get the bitmap from the client. let me know if it works for you.</P>
<HR><PRE>unit Unit1;
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormPaint(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Bitmap: TBitmap;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
Bitmap := TBitmap.Create;
Bitmap.LoadFromFile('C:\WINDOWS\cars.BMP');
end;
procedure TForm1.FormPaint(Sender: TObject);
var
X, Y, W, H: LongInt;
begin
with Bitmap do begin
W := Width;
H := Height;
end;
Y := 0;
while Y < Height do begin
X := 0;
while X < Width do begin
Canvas.Draw(X, Y, Bitmap);
Inc(X, W);
end;
Inc(Y, H);
end;
end;
end.
</PRE><HR>
<H2> Solution 2 </H2>
<P><I>From: "Dirk Faber " <d.j.faber@student.utwente.nl></I></P>
<PRE>Rob Wilson <wilson@pelops.compd.com> wrote
> Does anyone know how I can change the wallpaper at runtime using a
> filename that I specifiy?
</PRE>
<HR><PRE>procedure ChangeWallpaper(bitmap: string); {bitmap contains filename: *.bmp}
var pBitmap : pchar;
begin
bitmap:=bitmap+#0;
pBitmap:=@bitmap[1];
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, pBitmap, SPIF_UPDATEINIFILE);
end;
</PRE><HR>
<PRE>> Also, is there a way of saving it to the INI file for next session?</PRE>
<OL>
<LI> add inifiles to the uses list.
<LI> create an inifile with a texteditor like this:
<HR><PRE>[LastUsedBitmap]
LUBitmap= c:\mybitmap.bmp
</PRE><HR>
<LI> use a procedure like this: (supposed the inifile is like above, and is named c:\Bitmap.ini)
<HR><PRE>procedure WriteToIniFile(bitmap : string);
var MyIniFile : TInifile;
begin
MyIniFile := Tinifile.Create( 'c:\Bitmap.ini' );
MyIniFile.WriteString( 'LastUsedBitmap', 'LUBitmap', bitmap);
MyIniFile.Free;
end;
procedure ReadFromIniFile(var bitmap: string);
var MyIniFile : TInifile;
begin
MyIniFile := Tinifile.Create( 'c:\Bitmap.ini' );
bitmap:= MyIniFile.ReadString('LastUsedBitmap', 'LUBitmap');
MyIniFile.Free;
end;
</PRE><HR>
</OL>
<P><H1><A NAME="windows12">Path / directory name for 'My Computer'</P></A></H1>
<P><I>Christian Piene Gundersen <j.c.p.gundersen@jusstud.uio.no></I></P>
This is a rather complicated matter, so if it isn't vital to your
application, I suggest that you spend your time better than digging into
it. However, I'll try to point you in the right direction. <p>
The windows 32 operating system is based on a shell which uses virtual
folders, like 'my computer', 'desktop' and 'recycle bin'. Some of these
folders are part of the physical file system. That is they have a
corresponding directory in the file system. This is the case with
'desktop' and 'recycle bin'. These directories can be used as InitialDir
for the TOpenDialog, but first you have to get their physical location,
which can be different on different computers. To get the physical
location of these folders, you have to use some special API calls (see
example below). Other folders, like 'my computer' and 'printers' are not
part of the file system - they are only virtual. I've noticed that you
can browse to these folders using the TOpenDialog, but I don't think
they can be used as InitialDir. <p>
Virtual folders are (a bit simplified) of the type SHITEMID (item
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -