[DllImport("CoreDll.dll")]
public static extern void GlobalMemoryStatus
(
MEMORYSTATUS lpBuffer
);
[DllImport("CoreDll.dll")]
public static extern int GetSystemMemoryDivision
(
ref uint lpdwStorePages,
ref uint lpdwRamPages,
ref uint lpdwPageSize
);
public void Test()
{
uint storePages = 0;
uint ramPages = 0;
uint pageSize = 0;
int res = GetSystemMemoryDivision(ref storePages, ref ramPages, ref pageSize);
MEMORYSTATUS memStatus = new MEMORYSTATUS();
GlobalMemoryStatus(memStatus);
}
'VB
Imports System.Runtime.InteropServices
Public Structure MEMORYSTATUS
Public dwLength As UInt32
Public dwMemoryLoad As UInt32
Public dwTotalPhys As UInt32
Public dwAvailPhys As UInt32
Public dwTotalPageFile As UInt32
Public dwAvailPageFile As UInt32
Public dwTotalVirtual As UInt32
Public dwAvailVirtual As UInt32
End Structure 'MEMORYSTATUS
<DllImport("coredll.dll")> _
Private Shared Sub GlobalMemoryStatus(ByRef ms As MEMORYSTATUS)
End Sub
<DllImport("CoreDll.dll")> _
Public Shared Function GetSystemMemoryDivision( _
ByRef lpdwStorePages As UInt32, _
ByRef lpdwRamPages As UInt32, _
ByRef lpdwPageSize As UInt32) As Integer
End Function
Public Shared Sub Test()
Dim storePages As UInt32
Dim ramPages As UInt32
Dim pageSize As UInt32
Dim res As Integer = GetSystemMemoryDivision(storePages, ramPages, pageSize)
Dim memStatus As New MEMORYSTATUS
GlobalMemoryStatus(memStatus)
End Sub 'Test
6.6. 如何是窗口一直保持最小化?
继承窗体的OnGotFocus方法。
找到窗体的窗口句柄。
调用ShowWindow(hwnd, SW_MINIMIZE)强制窗体最小化。 //C#
using System.Runtime.InteropServices;
[DllImport("CoreDll")]
public static extern IntPtr FindWindow(string className,string WindowsName);
[DllImport("CoreDll")]
public static extern bool ShowWindow(IntPtr hwnd,int nCmdShow);
const int SW_MINIMIZE = 6;
protected override void OnGotFocus(EventArgs e)
{
IntPtr hwnd = FindWindow(null, this.Text);
ShowWindow(hwnd, SW_MINIMIZE);
base.OnGotFocus(e);
}
'VB
Imports System.Runtime.InteropServices
<DllImport("CoreDll")> _
Public Shared Function FindWindow(ByVal className As String, ByVal WindowsName As String) As IntPtr
End Function
<DllImport("CoreDll")> _
Public Shared Function ShowWindow(ByVal hwnd As IntPtr,ByVal nCmdShow As Integer) As Boolean
End Function