用GlobalMemoryStatus查看内存信息

吼吼,总算进入内存和文件的章节了,,虽然略过了GDI和通用对话框等等的学习。。

本章第一个练手的程序:

.asm文件:

.386
.model flat,stdcall
option casemap:none
include windows.inc
include kernel32.inc
include user32.inc
include gdi32.inc
includelib kernel32.lib
includelib user32.lib
includelib gdi32.lib
IDD_DIALOG1           equ                  100
IDC_STATIC              equ                    101
TIMER1                equ                        1
.data
.data?
hInstance    dd    ?
hWinMain    dd    ?
.const
szFormat    db    ’物理内存总数        %lu 字节’,0dh,0ah
db    ’可用物理内存        %lu 字节’,0dh,0ah
db    ’交换文件总大小        %lu 字节’,0dh,0ah
db    ’空闲交换文件大小    %lu 字节’,0dh,0ah
db    ’用户可用地址空间    %lu 字节’,0dh,0ah
db    ’当前空闲地址空间    %lu 字节’,0dh,0ah,0

.code
_ShowMemory    proc
local @stMemoryStatus:MEMORYSTATUS
local @szBuffer[1024]:byte
;pushad
mov @stMemoryStatus.dwLength,sizeof @stMemoryStatus
invoke GlobalMemoryStatus,addr @stMemoryStatus
invoke wsprintf,addr @szBuffer,addr szFormat,
@stMemoryStatus.dwTotalPhys,
@stMemoryStatus.dwAvailPhys,
@stMemoryStatus.dwTotalPageFile,
@stMemoryStatus.dwAvailPageFile,
@stMemoryStatus.dwTotalVirtual,
@stMemoryStatus.dwAvailVirtual
invoke SetDlgItemText,hWinMain,IDC_STATIC,addr @szBuffer
;popad
ret
_ShowMemory endp
_ProcDlgMain proc uses ebx edi esi hWnd,uMsg,wParam,lParam
mov eax,uMsg

.if eax==WM_TIMER
call _ShowMemory
.elseif eax==WM_INITDIALOG
push hWnd
pop hWinMain
invoke SetTimer,hWnd,TIMER1,1000,0
call _ShowMemory
.elseif eax==WM_CLOSE
invoke KillTimer,hWnd,TIMER1
invoke EndDialog,hWnd,NULL
.else
mov eax,FALSE
ret
.endif
mov eax,TRUE
ret
_ProcDlgMain endp
start:
invoke GetModuleHandle,NULL
mov hInstance,eax
invoke DialogBoxParam,hInstance,IDD_DIALOG1,NULL,offset _ProcDlgMain,NULL
invoke ExitProcess,NULL
end start
rc文件较简单,此处略去。。

第一次nmake的时候出现instruction or register not accept in current CPU mode的奇怪错误,百思不得其解,将代码复制到新文件后编译就通过了,,,

windows消息数值对照

 

WM_NULL = $0000;

WM_CREATE = $0001;
WM_DESTROY = $0002;
WM_MOVE = $0003;
WM_SIZE = $0005;
WM_ACTIVATE = $0006;
WM_SETFOCUS = $0007;
WM_KILLFOCUS = $0008;
WM_ENABLE = $000A;
WM_SETREDRAW = $000B;
WM_SETTEXT = $000C;
WM_GETTEXT = $000D;
WM_GETTEXTLENGTH = $000E;
WM_PAINT = $000F;
WM_CLOSE = $0010;
WM_QUERYENDSESSION = $0011;
WM_QUIT = $0012;
WM_QUERYOPEN = $0013;
WM_ERASEBKGND = $0014;
WM_SYSCOLORCHANGE = $0015;
WM_ENDSESSION = $0016;
WM_SYSTEMERROR = $0017;

 

WM_SHOWWINDOW = $0018;
WM_ACTIVATEAPP = $001C;
WM_FONTCHANGE = $001D;
WM_TIMECHANGE = $001E;
WM_CANCELMODE = $001F;
WM_SETCURSOR = $0020;
WM_MOUSEACTIVATE = $0021;
WM_CHILDACTIVATE = $0022;
WM_QUEUESYNC = $0023;
WM_GETMINMAXINFO = $0024;
WM_PAINTICON = $0026;
WM_ICONERASEBKGND = $0027;
WM_NEXTDLGCTL = $0028;
WM_SPOOLERSTATUS = $002A;
WM_DRAWITEM = $002B;
WM_MEASUREITEM = $002C;
WM_DELETEITEM = $002D;
WM_VKEYTOITEM = $002E;
WM_CHARTOITEM = $002F;
WM_SETFONT = $0030;
WM_GETFONT = $0031;
WM_SETHOTKEY = $0032;

 

WM_GETHOTKEY = $0033;
WM_QUERYDRAGICON = $0037;
WM_COMPAREITEM = $0039;
WM_GETOBJECT = $003D;
WM_COMPACTING = $0041;
WM_WINDOWPOSCHANGING = $0046;
WM_WINDOWPOSCHANGED = $0047;
WM_COPYDATA = $004A;
WM_CANCELJOURNAL = $004B;
WM_NOTIFY = $004E;
WM_INPUTLANGCHANGEREQUEST = $0050;
WM_INPUTLANGCHANGE = $0051;
WM_TCARD = $0052;
WM_HELP = $0053;
WM_USERCHANGED = $0054;;
WM_NOTIFYFORMAT = $0055;
WM_CONTEXTMENU = $007B;
WM_STYLECHANGING = $007C;
WM_STYLECHANGED = $007D;
WM_DISPLAYCHANGE = $007E;
WM_GETICON = $007F;

WM_SETICON = $0080;;

WM_NCCREATE = $0081;
WM_NCDESTROY = $0082;
WM_NCCALCSIZE = $0083;
WM_NCHITTEST = $0084
WM_NCPAINT = $0085;
WM_NCACTIVATE = $0086;
WM_GETDLGCODE = $0087;

更多消息详见msdn。。。