This article was collected and compiled by lanyus from "DELPHI for Wonderful Programming". Please indicate this when reprinting.
1. Hide the taskbar
In WINDOWS, the system's taskbar is essentially a window, with its window class name "Shell_TrayWnd". To implement operations on it, you can use the API function
FindWindow and
ShowWindow to achieve its goal.
var
wndHandle:THandle;
wndClass:Array[0..50] of char;
Begin
StrPCopy(@wndClass[0],'Shell_TrayWnd');
wndHandle:=FindWindow(@wndClass[0],nil);
ShowWindow(wndHandle,SW_HIDE); //sw_restore
end;
2. Hidden shortcuts on the desktop
Like the taskbar, the desktop is actually a window. Its class name is "PRogMan". Use FindWindow to find the window handle, and then post ShowWindow.
to decide whether to display.
3. Get the taskbar size and location
Use FindWindow to find the handle, and then use GetWindowRect to get the current taskbar size.
GetWindowRect(HWND hWnd, //The handle of the requested window
LPRECT lpRect //The address of the structure that stores the window coordinates
):Boolean;
4. Obtain CPU information
The relevant information of the CPU is stored in a structure, which is encapsulated by DELPHI with TSYSTEMINFO and is defined as follows:
typedef struct_SYSTEM_INFO{
union{
DWord dwOemId; //The following structure branch has been used instead of the use of this variable
struct{
WORD wProcessorArchitecture; //Denotes the architecture of the processor
word wReserved; //Reserve words
};
};
DWORD swPageSiae; //Pagination size
LPVOID lpMinimumapplicationAddress; //The minimum address that applications and dynamic link libraries can access
LPVOID lpMaximumApplicationAddress; //The maximum address that applications and dynamic link libraries can access
DWORD swActiveProcessorMask; //Mask of the active processor
DWORD dwNumberOfProcessors; //Number of processors
DWORD dwProcessorType; //Processor category
DWORD dwAllocationGranularity; //The interval of virtual memory address allocation
WORD wProcessorLevel; //Processor Level
WORD wProcessorRevision; //Processor modification information
}SYSTEM_INFO;
Among them, dwProcessorType is determined by three members: wProcessorArchitecture, wProcessorLevel and wProcessorRevision, and its value is:
PROCESSOR_INTEL_386:INTEL80386 series;
PROCESSOR_ITNEL_486:INTEL80486 series;
PROCESSOR_INTEL_PENTIUM:INTEL PENTIUM series;
PROCESSOR_MipS_R4000: MIPS's 4000 series (only applicable to WINDOWS NT);
PROCESSOR_ALPHA_21064: ALPHA's 21064 series (only applicable to WINDOWS NT);
In addition, just call the API function GetSystemInfo after obtaining CPU information.
5. Obtain memory information.
Just like obtaining CPU, the system still uses a structure to store memory information. The definition of this stored internal state information is as follows:
typedef struct_MEMORYSTATUS{
DWORD dwLength; //SIZEOF(MEMORYSTATUS) is the size of this structure
DWORD dwMemoryLoad; //The percentage of current memory used to total intrinsic
DWORD dwTotalPhys; //Total physical memory size
DWORD dwAvailPhys; //Available physical memory size
DWORD dwTotalPageFile; //Total page file size
DWORD dwAvailPageFile; //The size of available page files
DWORD dwTotalVirtual; //The size of total virtual memory
DWORD dwAvailVirtual; //The size of available virtual memory
}MEMORYSTATUS,*LPMEMORYSTATUS;
Finally, call the API function GlobalMemoryStatus to obtain memory information.
6. Get the disk space size. (The test found inaccurate)
Use the API function GetDiskFreeSpace.
BOOL GetDiskFreeSpace(
LPCTSTR lpRootPathName, //root directory
LPDWORD lpSectorsPerCluster, //Number of sectors per cluster
LPDWORD lpBytesPerSector, //Number of bytes per sector
LPDWORD lpNumberOfFreeClusters, //The number of available clusters
LPDWORD lpTotalNumberOfClusters //Total number of clusters
);
procedure TForm1.BitBtn1Click(Sender: TObject);
var
Secspclu, Bytespsc, Freeclu, Totalclu, Ts, Fs: DWORD;
Begin
GetDiskFreeSpace('c:/',Secspclu,Bytespsec,Freeclu,Totalclu);
Fs:=Freeclu*Secspclu*Bytespsec;
Ts:=Totalclu*Secspclu*Bytespsec;
Edit1.text:=FormatFloat('##,###',Ts); //Total space
Edit2.text:=FormatFloat('##,###',Fs); //Available space
end;
7. Limit the mouse movement range.
There is a ready-made API function in WINDOWS ClipCursor that can restrict the cursor from moving the area.
BOOL ClipCursor(
CONST RECT *lpRect //Point to a structure that stores rectangular range data
);
With this function, you can limit the range of movement of the cursor on the screen. However, if you want to control the mouse to move within a fixed range of a certain window, you need to call Ca
A function
MapWindowPoints, which converts the coordinates of one form into another related form coordinates.
int MapWindowPoints(
HWND hWndFrom, //Source window handle
HWND hWndTo, //Target form handle
LPPOINT lpPoints, //Point to the structure array, containing the coordinates that need to be converted
UINT cPoints //Number of structures in array
);
When the parameter hWndForm or hWndTo is NULL or HWND_DESKTOP, it indicates that the source form or target form is a screen form. Parameter lpPoints can point to a
Rect structure, at this time cPoints
The value of 2 will be set to 2.
procedure TForm1.BitBtn1Click(Sender: TObject);
var
sc:TRect;
Begin
sc:=BitBtn2.BoundsRect;
MapWindowPoints(handle,0,sc,2);
ClipCursor(@sc);
end;
procedure TForm1.BitBtn2Click(Sender: TObject);
var
sc:TRect;
Begin
sc:=RECT(0,0,screen.Width,screen.Height);
ClipCursor(@sc);
end;
8. How to start the screen saver.
Use SendMessage or PostMessage functions.
procedure TForm1.BitBtn3Click(Sender: TObject);
Begin
sendmessage(HWND_BROADCAST,WM_SYSCOMMAND,SC_SCREENSAVE,0);
end;
There is also a method to start the screen saver, calling the function SystemParametersInfo, which can start or close the screen saver through its parameter settings.
SystemParametersInfo(SPI_SETSCREENSAVEACTIVE,1,nil,0); //Start screen saver
SystemParametersInfo(SPI_SETSCREENSAVEACTIVE,0,nil,0); //Close screen security
9. Check whether the drive is ready.
There is no special function to detect whether the drive is ready, nor can it be directly called a one-person API function to implement this operation. But, we
DiskSize can be used to detect disk capacity. If the drive does not exist or is not ready, it will return -1, and in other cases the disk or CD's
capacity.
Function DiskSize(Drive:Byte):Int64;
When the parameter is 0, it means that the current drive is specified; when it is 1, it means disk A, 2 means disk B, and so on.
Increased...