行空雕 发表于 2014-7-29 08:04:36

没法做,打算采用链接

wwswwswws 发表于 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
不知道你的具体情况,你只能试试

wuyunpeng888 发表于 2014-10-15 14:46:06

在窗口加载时重新设置一下窗口的父窗口为CAD主窗口就行了用setparent

wuyunpeng888 发表于 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 static/image/common/back.gif
用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 static/image/common/back.gif
窗口的Initialze事件里加上一句
SetParent FindWindow(vbNullString, Me.Caption),Application.hwnd
这两 ...

我试试,谢谢您的指教,

hector 发表于 2018-12-30 03:43:03

wuyunpeng888 发表于 2014-10-15 15:21
窗口的Initialze事件里加上一句
SetParent FindWindow(vbNullString, Me.Caption),Application.hwnd
这两 ...

正解,多谢大神。

wuyunpeng888 发表于 2024-12-27 00:17:05

其实这个并不是正解,最正确的是用API函数把弹出窗口的属性去掉

wuyunpeng888 发表于 2024-12-27 00:20:15

flags = GetWindowLong(FindWindow(vbNullString, Me.Caption), GWL_STYLE)
flags = flags Xor WS_POPUP
SetWindowLong FindWindow(vbNullString, Me.Caption), GWL_STYLE, flags
页: 1 [2]
查看完整版本: 求助:VBA创建的非模态界面与CAD干涉