明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
12
返回列表 发新帖
楼主: 行空雕

求助:VBA创建的非模态界面与CAD干涉

[复制链接]
 楼主| 发表于 2014-7-29 08:04:36 | 显示全部楼层
没法做,打算采用链接
发表于 2014-10-12 23:11:00 | 显示全部楼层
用API试试看
Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex 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
Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam 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

Dim ThisHwnd As Long
Public sCurrentCaption As String

Private Sub UserForm_Activate()
    sCurrentCaption = BatPlot.Caption
    Call EnumWindows(AddressOf EnumWindowsProc, vbNull)
    Call SubClass
End Sub
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, "示例窗体") Then      '根据窗体的"Caption"值来枚举
    If InStr(title, sCurrentCaption) 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
不知道你的具体情况,你只能试试
发表于 2014-10-15 14:46:06 | 显示全部楼层
在窗口加载时重新设置一下窗口的父窗口为CAD主窗口就行了用setparent
发表于 2014-10-15 15:21:41 | 显示全部楼层
窗口的Initialze事件里加上一句
SetParent FindWindow(vbNullString, Me.Caption),Application.hwnd
这两个API函数你自己声明一下就行了
 楼主| 发表于 2015-1-26 23:50:25 | 显示全部楼层
wwswwswws 发表于 2014-10-12 23:11
用API试试看
Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ...

谢谢! API 还不太会,目前是学习中,多谢
 楼主| 发表于 2015-1-26 23:51:25 | 显示全部楼层
wuyunpeng888 发表于 2014-10-15 15:21
窗口的Initialze事件里加上一句
SetParent FindWindow(vbNullString, Me.Caption),Application.hwnd
这两 ...

我试试,谢谢您的指教,
发表于 2018-12-30 03:43:03 | 显示全部楼层
wuyunpeng888 发表于 2014-10-15 15:21
窗口的Initialze事件里加上一句
SetParent FindWindow(vbNullString, Me.Caption),Application.hwnd
这两 ...

正解,多谢大神。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-23 04:55 , Processed in 0.174471 second(s), 16 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表