首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >VBA6 -> VBA7 -将代码转换为64位的问题-将窗口带到前台(AutoCAD,2014年)

VBA6 -> VBA7 -将代码转换为64位的问题-将窗口带到前台(AutoCAD,2014年)
EN

Stack Overflow用户
提问于 2014-09-07 23:36:17
回答 1查看 4K关注 0票数 1

我正在将一些非常老的VBA代码转换为在AutoCAD 2014上运行。到目前为止,我已经转换了所有内容,但是表单存在一个问题(它们是非模态的,需要激活回调才能修改window propertis)。以下是VBA6源代码:

形式如下:

代码语言:javascript
复制
Private Sub UserForm_Activate()
#If ACAD2000 = 0 Then
    If Not bPopup Then
        Call EnumWindows(AddressOf EnumWindowsProc, vbNull)
        Call SubClass
        bPopup = True
    End If
#End If
End Sub

模块(名为modModeLessFormFocus):

代码语言:javascript
复制
Option Explicit

Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long

Private ThisHwnd As Long
Public Const GWL_STYLE = -16
Public Const WS_POPUP = &H80000000

Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Integer

    Dim title As String * 32
    Call GetWindowText(hwnd, ByVal title, 32)
    If InStr(title, "About") Then
        ThisHwnd = hwnd
        EnumWindowsProc = False
    ElseIf InStr(title, "Preferences") Then
        ThisHwnd = hwnd
        EnumWindowsProc = False
    ElseIf InStr(title, "Display Block Attributes") Then
        ThisHwnd = hwnd
        EnumWindowsProc = False
    Else
        EnumWindowsProc = True
    End If
End Function

Public Function SubClass() As Long
    Dim Flags As Long
    Flags = GetWindowLong(ThisHwnd, GWL_STYLE)
    Flags = Flags Xor WS_POPUP
    SetWindowLong ThisHwnd, GWL_STYLE, Flags
End Function

运行时所遇到的错误是'AddressOf EnumWindowsProc‘上的AddressOf中的“类型错配”。我试图使用PtrSafe和PtrLong将其转换为64位,但不可避免的是,它失败了,程序崩溃了。

如果有人足够聪明地改变这一点或指出我的正确方向,我会非常感激。

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-09-08 02:29:27

我在http://www.jkp-ads.com/articles/apideclarations.asp中找到了64位http://www.jkp-ads.com/articles/apideclarations.asp的API。

代码语言:javascript
复制
#If VBA7 Then
    #If Win64 Then
        Private Declare PtrSafe Function GetWindowLongPtr Lib "USER32" Alias "GetWindowLongPtrA" (ByVal hWnd As LongPtr, ByVal nIndex As Long) As LongPtr
    #Else
        Private Declare PtrSafe Function GetWindowLongPtr Lib "USER32" Alias "GetWindowLongA" (ByVal hWnd As LongPtr, ByVal nIndex As Long) As LongPtr
    #End If
    Private Declare PtrSafe Function GetWindowText Lib "USER32" Alias "GetWindowTextA" _
                                      (ByVal hWnd As LongPtr, ByVal lpString As String, _
                                       ByVal cch As LongPtr) As Long

#Else
    Private Declare Function GetWindowLongPtr Lib "USER32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long 
    Private Declare Function GetWindowText Lib "USER32" Alias "GetWindowTextA" _
                                      (ByVal hWnd As Long, ByVal lpString As String, _
                                       ByVal cch As Long) As Long
#End If

您还可以查看更新后的API的http://msdn.microsoft.com/en-us/library/aa383663(VS.85).aspx

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25715740

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档