微软.net精简框架常见问题及回答(中文版)(18)

王朝c#·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

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

Private Const SW_MINIMIZE As Integer = 6

Protected Overrides Sub OnGotFocus(ByVal e As EventArgs)

Dim hwnd As IntPtr = FindWindow(Nothing, Me.Text)

ShowWindow(hwnd, SW_MINIMIZE)

MyBase.OnGotFocus(e)

End Sub 'OnGotFocus

6.7. 在微软.net精简框架上调用系统函数时,如何装配数据类型?

见本问答的 "6.1. 如何调用本地写的DLL中的函数? " 章节。

6.8. 如何得到一个窗体或控件的句柄 (HWND) ?

其实有一些使用调用本地代码的方法可以获得控件的句柄HWND。下面列出其中两种,一种使用GetCapture,另一个使用FindWindow。 //C#

[DllImport("coredll.dll"]

public static extern IntPtr GetCapture();

[DllImport("coredll.dll")]

public static extern IntPtr FindWindow(String lpClassName, String lpWindowName);

this.Text = "FindMe";

IntPtr hwnd1 = FindWindow(null, "FindMe");

this.Capture = true;

IntPtr hwnd2 = GetCapture();

this.Capture = false;

'VB

<DllImport("coredll.dll", SetLastError:=True)> _

Public Shared Function GetCapture() As IntPtr

End Function

<DllImport("coredll.dll", SetLastError:=True)> _

Public Shared Function FindWindow(ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr

End Function

第一頁    上一頁    第18頁/共78頁    下一頁    最後頁
第01頁 第02頁 第03頁 第04頁 第05頁 第06頁 第07頁 第08頁 第09頁 第10頁 
第11頁 第12頁 第13頁 第14頁 第15頁 第16頁 第17頁 第18頁 第19頁 第20頁 
第21頁 第22頁 第23頁 第24頁 第25頁 第26頁 第27頁 第28頁 第29頁 第30頁 
第31頁 第32頁 第33頁 第34頁 第35頁 第36頁 第37頁 第38頁 第39頁 第40頁 
第41頁 第42頁 第43頁 第44頁 第45頁 第46頁 第47頁 第48頁 第49頁 第50頁 
第51頁 第52頁 第53頁 第54頁 第55頁 第56頁 第57頁 第58頁 第59頁 第60頁 
第61頁 第62頁 第63頁 第64頁 第65頁 第66頁 第67頁 第68頁 第69頁 第70頁 
第71頁 第72頁 第73頁 第74頁 第75頁 第76頁 第77頁 第78頁 
 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航