我看了很多VB程序中获得本窗体的句柄都是用:Me.hwnd,可是我的.net上显示错误,好像只有Me.Handle.我想用的语句是:
Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
Dim hMenu As Long
hMenu = GetSystemMenu(Me.hwnd, 0)
其中最后一句的Me.hwnd显示错误。
---------------------------------------------------------------
注意:在vb.net里面long数据类型占8个字节,而vb6里面long是4个字节,所以必须更改。另外me.Handle的确是窗体的句柄,不过在vs.net里面都统一成为intptr数据类型,用于表示指针或句柄的平台特定类型。
方法1:
改 Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
为
Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As intptr, ByVal bRevert As integer) As intptr
Dim hMenu As intptr = GetSystemMenu(Me.Handle, 0)
方法2:
改 Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
为
Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As integer, ByVal bRevert As integer) As integer
Dim hMenu As integer= GetSystemMenu(Me.Handle.toint32(), 0)