Screen.TwipsPerPixelX编译错误:方法和成员未找到.求解决方法!

liu171450371 2016-11-15 12:22:23


Option Explicit

Public OldWindowProc As Long
Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA"
(ByVal hwnd As Long, ByVal nIndex As Long) As Long
'从指定的窗口结构中取得信息
'参数/类型 说明
'hwnd(long): 欲为其获取信息的窗口的句柄
'nIndex(long): 欲取回的信息,可以是下述任何一个常数
'GWL_EXSTYLE:扩展窗口样式
'GWL_STYLE:窗口样式
'GWL_WNDPROC:该窗口的窗口函数的地址
'GWL_HINSTANCE:拥有窗口的实例的句柄
'GWL_HWNDPARENT:该窗口之父的句柄.不要用 SetWindowWord 来改变这个值
'GWL_ID:对话框中一个子窗口的标识符
'GWL_USERDATA:含义由应用程序规定
'对话框亦可指定下列常数
'DWL_DLGPROC:这个窗口的对话框函数地址
'DWL_MSGRESULT:在对话框函数中处理的一条消息返回的值
'DWL_USER:含义由应用程序规定
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA"
(ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long)
As Long
'在窗体结构中为指定的窗口设置信息
'参数/类型 说明
'hwnd(long) 欲为其获取信息的窗口的句柄
'nIndex(long) 参考GetWindowLong函数
'dwNewLong(long) 由nIndex指定的窗口信息的新值
Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDest
As Any, pSource As Any, ByVal ByteLen As Long)
'这就是在VisualBasic中处理指针的"短柄斧"--CopyMemory.你可能在API文档中找不到它,但它确实存在,并且功能异常强大
'参数/类型 说明
'pDest 你想写入字节到其中的任何变量的ByRef参数(地址)
'pSource 要从其中进行复制的ByRef变量
'ByteLen 要复制的字节数
Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA"
(ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long,
ByVal wParam As Long, ByVal lParam As Long) As Long
'把控制权传回给原来的窗口过程
Public Const WM_GETMINMAXINFO = &H24
Type POINTAPI
 x As Long
 y As Long
End Type
' This is the structure that is passed by reference(ByRef)(ie an
address) to your message handler(消息侦听器)
' The key items in this structure are ptMinTrackSize and
ptMaxTrackSize
Type MINMAXINFO
 ptReserved As POINTAPI
 ptMaxSize As POINTAPI
 ptMaxPosition As POINTAPI
 ptMinTrackSize As POINTAPI
 ptMaxTrackSize As POINTAPI
End Type
Public Function SubClass1_WndMessage(ByVal hwnd As Long, ByVal Msg
As Long, ByVal wp As Long, ByVal lp As Long) As Long
' Watch for the pertinent message to come in
 If Msg = WM_GETMINMAXINFO Then
  Dim MinMax As MINMAXINFO
'  This is necessary because the structure was passed by its address
and there
'  is currently no intrinsic way to use an address in Visual Basic
  CopyMemory MinMax, ByVal lp, Len(MinMax)
' This is where you set the values of the MinX,MinY,MaxX, and MaxY
' The values placed in the structure must be in pixels. The values
' normally used in Visual Basic are in twips. The conversion is as
follows:
'  pixels = twips\twipsperpixel
  MinMax.ptMinTrackSize.x = 3975 \ Screen.TwipsPerPixelX
  MinMax.ptMinTrackSize.y = 1740 \ Screen.TwipsPerPixelY

  MinMax.ptMaxTrackSize.x = Screen.Width \ Screen.TwipsPerPixelX \ 2
  MinMax.ptMaxTrackSize.y = 3480 \ Screen.TwipsPerPixelY
' Here we copy the datastructure back up to the address passed in
the parameters
' because Windows will look there for the information.
  CopyMemory ByVal lp, MinMax, Len(MinMax)
' This message tells Windows that the message was handled
successfully
  SubClass1_WndMessage = 1
  Exit Function
 End If
' Here, we forward all irrelevant messages on to the default message
handler.
 SubClass1_WndMessage = CallWindowProc(OldWindowProc, hwnd, Msg, wp,
lp)
End Function

窗体代码:
Option Explicit

Private Const GWL_WNDPROC = (-4)
Private Sub Form_Load()
' First, we need to store the address of the existing Message
Handler
 OldWindowProc = GetWindowLong(Me.hwnd, GWL_WNDPROC)
' Now we can tell windows to forward all messages to out own Message
Handler
 Call SetWindowLong(Me.hwnd, GWL_WNDPROC, AddressOf
SubClass1_WndMessage)
End Sub

Private Sub Form_Unload(Cancel As Integer)
' We must return control of the messages back to windows before the
program exits
Call SetWindowLong(Me.hwnd, GWL_WNDPROC, OldWindowProc)
End Sub
...全文
244 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
舉杯邀明月 2016-11-16
  • 打赏
  • 举报
回复
引用 6 楼 liu171450371 的回复:
[quote=引用 1 楼 Chen8013 的回复:] 你先把“窗体”搞一个出来再说……………… 不知道你的代码从哪来的,那个根本就不是用在“Access”的VBA环境中的吧! 我看了一下Access的VBE,它根本就没有窗体、控件这些“可视对象”,你的“窗体自适应缩放”从何谈起!!! 你如果想在VBA环境中试验,就用Excel的VBE来试吧。 不过,我觉得这种代码,其实在VB6中可能更适合吧。
自适窗体我有,不过没往上面贴。[/quote] 有? 有又怎样,你根本没明白我说的是什么!!!
赵4老师 2016-11-15
  • 打赏
  • 举报
回复
VBScript、VBA、VB6、VB.NET都不是一回事!
liu171450371 2016-11-15
  • 打赏
  • 举报
回复
引用 1 楼 Chen8013 的回复:
你先把“窗体”搞一个出来再说……………… 不知道你的代码从哪来的,那个根本就不是用在“Access”的VBA环境中的吧! 我看了一下Access的VBE,它根本就没有窗体、控件这些“可视对象”,你的“窗体自适应缩放”从何谈起!!! 你如果想在VBA环境中试验,就用Excel的VBE来试吧。 不过,我觉得这种代码,其实在VB6中可能更适合吧。
自适窗体我有,不过没往上面贴。
liu171450371 2016-11-15
  • 打赏
  • 举报
回复
我刚学,不太懂。
舉杯邀明月 2016-11-15
  • 打赏
  • 举报
回复
引用 2 楼 Topc008 的回复:
VBA里有screen吗? Screen.TwipsPerPixelX等用法只有vb里才有的....
还真是VB6中才有的。 之前我还以为支持“窗体”的VBA环境中,比如Excel、Word的VBA就有这个呢。
一如既往哈 2016-11-15
  • 打赏
  • 举报
回复
VBA里有screen吗? Screen.TwipsPerPixelX等用法只有vb里才有的....
舉杯邀明月 2016-11-15
  • 打赏
  • 举报
回复
你先把“窗体”搞一个出来再说……………… 不知道你的代码从哪来的,那个根本就不是用在“Access”的VBA环境中的吧! 我看了一下Access的VBE,它根本就没有窗体、控件这些“可视对象”,你的“窗体自适应缩放”从何谈起!!! 你如果想在VBA环境中试验,就用Excel的VBE来试吧。 不过,我觉得这种代码,其实在VB6中可能更适合吧。

2,503

社区成员

发帖
与我相关
我的任务
社区描述
VBA(Visual Basic for Applications)是Visual Basic的一种宏语言,是在其桌面应用程序中执行通用的自动化(OLE)任务的编程语言。
社区管理员
  • VBA
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧