.586
.model flat, stdcall
option casemap :none ; case sensitive
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; Include 数据
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
include windows.inc
include user32.inc
include kernel32.inc
include comctl32.inc
include comdlg32.inc
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 子程序声明
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_ProcDlgMain PROTO :DWORD,:DWORD,:DWORD,:DWORD
.data
szSpeed db "你的CPU主频为 %d MHz",0
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 代码段
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.code
include Win.asm
;********************************************************************
_ProcDlgMain proc uses ebx edi esi, \
hWnd:DWORD,wMsg:DWORD,wParam:DWORD,lParam:DWORD
local @stPoint:POINT
local @hWindow
The SYSTEM_INFO structure contains information about the current computer system. This includes the architecture and type of the processor, the number of processors in the system, the page size, and other such information.
typedef struct _SYSTEM_INFO {
union {
DWORD dwOemId;
struct {
WORD wProcessorArchitecture;
WORD wReserved;
};
};
DWORD dwPageSize;
LPVOID lpMinimumApplicationAddress;
LPVOID lpMaximumApplicationAddress;
DWORD_PTR dwActiveProcessorMask;
DWORD dwNumberOfProcessors;
DWORD dwProcessorType;
DWORD dwAllocationGranularity;
WORD wProcessorLevel;
WORD wProcessorRevision;
} SYSTEM_INFO;
Members
dwOemId
An obsolete member that is retained for compatibility with Windows NT 3.5 and earlier. New applications should use the wProcessorArchitecture branch of the union.
Windows 95/98/Me: The system always sets this member to zero, the value defined for PROCESSOR_ARCHITECTURE_INTEL.
wProcessorArchitecture
Specifies the system's processor architecture. This value can be one of the following values:
PROCESSOR_ARCHITECTURE_UNKNOWN
PROCESSOR_ARCHITECTURE_INTEL
Windows NT 3.51: PROCESSOR_ARCHITECTURE_MIPS
Windows NT 4.0 and earlier: PROCESSOR_ARCHITECTURE_ALPHA
Windows NT 4.0 and earlier: PROCESSOR_ARCHITECTURE_PPC
64-bit Windows: PROCESSOR_ARCHITECTURE_IA64
64-bit Windows: PROCESSOR_ARCHITECTURE_IA32_ON_WIN64
64-bit Windows: PROCESSOR_ARCHITECTURE_AMD64
wReserved
Reserved for future use.
dwPageSize
Specifies the page size and the granularity of page protection and commitment. This is the page size used by the VirtualAlloc function.
lpMinimumApplicationAddress
Pointer to the lowest memory address accessible to applications and dynamic-link libraries (DLLs).
lpMaximumApplicationAddress
Pointer to the highest memory address accessible to applications and DLLs.
dwActiveProcessorMask
Specifies a mask representing the set of processors configured into the system. Bit 0 is processor 0; bit 31 is processor 31.
dwNumberOfProcessors
Specifies the number of processors in the system.
dwProcessorType
An obsolete member that is retained for compatibility with Windows NT 3.5 and earlier. Use the wProcessorArchitecture, wProcessorLevel, and wProcessorRevision members to determine the type of processor.
Windows 95/98/Me: Specifies the type of processor in the system. This member is one of the following values:
dwAllocationGranularity
Specifies the granularity with which virtual memory is allocated. For example, a VirtualAlloc request to allocate 1 byte will reserve an address space of dwAllocationGranularity bytes. This value was hard coded as 64K in the past, but other hardware architectures may require different values.
wProcessorLevel
Windows NT/2000/XP: Specifies the system's architecture-dependent processor level.
If wProcessorArchitecture is PROCESSOR_ARCHITECTURE_INTEL, wProcessorLevel can be one of the following values. Value Meaning
3 Intel 80386
4 Intel 80486
5 Intel Pentium
6 Intel Pentium Pro or Pentium II
If wProcessorArchitecture is PROCESSOR_ARCHITECTURE_IA64, wProcessorLevel is set to 1.
If wProcessorArchitecture is PROCESSOR_ARCHITECTURE_MIPS, wProcessorLevel is of the form 00xx, where xx is an 8-bit implementation number (bits 8-15 of the PRId register). The member can be the following value. Value Meaning
0004 MIPS R4000
If wProcessorArchitecture is PROCESSOR_ARCHITECTURE_ALPHA, wProcessorLevel is of the form xxxx, where xxxx is a 16-bit processor version number (the low-order 16 bits of a version number from the firmware). The member can be one of the following values. Value Meaning
21064 Alpha 21064
21066 Alpha 21066
21164 Alpha 21164
If wProcessorArchitecture is PROCESSOR_ARCHITECTURE_PPC, wProcessorLevel is of the form xxxx, where xxxx is a 16-bit processor version number (the high-order 16 bits of the Processor Version Register). The member can be one of the following values. Value Meaning
1 PPC 601
3 PPC 603
4 PPC 604
6 PPC 603+
9 PPC 604+
20 PPC 620
wProcessorRevision
Windows NT/2000/XP: Specifies an architecture-dependent processor revision. The following table shows how the revision value is assembled for each type of processor architecture. Processor Value
Intel 80386 or 80486 A value of the form xxyz.
If xx is equal to 0xFF, y - 0xA is the model number, and z is the stepping identifier. For example, an Intel 80486-D0 system returns 0xFFD0.
If xx is not equal to 0xFF, xx + 'A' is the stepping letter and yz is the minor stepping.
Intel Pentium, Cyrix, or NextGen 586 A value of the form xxyy, where xx is the model number and yy is the stepping. Display this value of 0x0201 as follows:
Model xx, Stepping yy
MIPS A value of the form 00xx, where xx is the 8-bit revision number of the processor (the low-order 8 bits of the PRId register).
ALPHA A value of the form xxyy, where xxyy is the low-order 16 bits of the processor revision number from the firmware. Display this value as follows:
Model A+xx, Pass yy
PPC A value of the form xxyy, where xxyy is the low-order 16 bits of the processor version register. Display this value as follows:
xx.yy
Getting Hardware Information
The following example uses the GetSystemInfo function to obtain hardware information such as the OEM identifier, processor type, page size, and so on. The example displays the information in a window's client area.
SYSTEM_INFO siSysInfo; // struct. for hardware information
int aTabs[1] = {260}; // tab stop for TabbedTextOut
TCHAR tchBuffer[BUFFER]; // buffer for expanded string
int nSize; // size of string
nSize = sprintf(tchBuffer,
"Active processor mask: %u",
siSysInfo.dwActiveProcessorMask);
TextOut(hdc, 25, 100, tchBuffer, nSize);
The following example uses the GetSystemMetrics function to determine whether a mouse is installed and whether the mouse buttons are swapped. The example also uses the SystemParametersInfo function to retrieve the mouse threshold and speed. It displays the information in a message box.
TCHAR tchBuffer[BUFFER]; // buffer for expanded string
int nSize; // size of string
BOOL fResult; // system shutdown flag
int aMouseInfo[3]; // array for mouse information
// Is there a mouse?
fResult = GetSystemMetrics(SM_MOUSEPRESENT);
if (fResult == 0)
{
// Indicate if there is no mouse.
nSize = sprintf(tchBuffer, "No mouse installed.");
}
else
{
// If there is a mouse, determine whether its buttons are swapped.
fResult = GetSystemMetrics(SM_SWAPBUTTON);
if (fResult == 0)
{
nSize = sprintf(tchBuffer, "Buttons not swapped.\r");
}
else
{
nSize = sprintf(tchBuffer, "Buttons swapped.\r");
}
// Get the mouse speed and the threshold values.
SystemParametersInfo(SPI_GETMOUSE, // get mouse information
NULL, // not used
&aMouseInfo, // holds mouse information
NULL); // not used
MessageBox(NULL, tchBuffer, "Mouse information",
MB_ICONINFORMATION);
This next example uses SystemParametersInfo to double the mouse speed and update the MouseSpeed value in the WIN.INI file.
TCHAR tchBuffer[BUFFER]; // buffer for expanded string
int nSize; // size of string
int aMouseInfo[3]; // array for mouse information
// Get the current mouse speed.
SystemParametersInfo(SPI_GETMOUSE, // get mouse information
NULL, // not used
&aMouseInfo, // holds mouse information
NULL); // not used
// Double it.
aMouseInfo[2] = 2 * aMouseInfo[2];
// Change the mouse speed to the new value and update WIN.INI.
SystemParametersInfo(SPI_SETMOUSE, // set mouse information
NULL, // not used
aMouseInfo, // mouse information
SPIF_UPDATEINIFILE); // update win.ini