2

我们为 3rd 方应用程序开发插件扩展(工具栏)。新版本的应用程序也是 64 位的 - 问题来了。我们的插件是在VB6下开发的。在 32 位应用程序中一切正常。

应用程序的制造商还提供包装器(64 位版本),它为 32 位插件自动运行,因此我们的插件运行“进程外”。通常它工作正常,但它需要(显然)一些必要的解决方法。

我们的插件只有模态形式。当它运行 64 位应用程序的“进程外”时,需要像这样设置所有者和父级

Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Declare Function BringWindowToTop Lib "user32" (ByVal hwnd As Long) As Long
Declare Function GetLastActivePopup Lib "user32" (ByVal hwnd As Long) As Long
Declare Function SetParent Lib "user32" (ByVal hwndC As Long, ByVal hwndP As Long) As Long
Declare Function GetCurrentProcessId Lib "kernel32" () As Long
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

Public Sub PopupWindow(formHwnd As Long)
  '(Declarations here...)
  If (App.GetProcessId() <> GetCurrentProcessId()) Then
    hWndMain = FindWindow(vbNullString, App.Caption)
    hWndParent = GetLastActivePopup(hWndMain)
    CurrentStyle = GetWindowLong(formHwnd, GWL_STYLE)

    If (hWndParent = 0) Then
      hWndParent = hWndMain
      BringWindowToTop hWndParent
      SetWindowLong formHwnd, GWL_STYLE, CurrentStyle Or WS_POPUP
      SetParent formHwnd, hWndMain
    Else
      SetWindowLong formHwnd, GWL_STYLE, CurrentStyle Or WS_POPUP
      SetWindowLong formHwnd, GWL_HWNDPARENT, hWndParent
    End If
  End If
End Sub

显示表单的代码现在是:

PopupWindow formType.hwnd
formType.Show vbModal, [OwnerForm]

1)第一个小问题是,单击“父”应用程序窗口会导致我们的窗口从插件失去焦点(但插件窗口仍然在顶部并且父应用程序已禁用控件)。在 32 位版本中,它以标准方式运行 - 在模式对话框窗口上播放“哔”并聚焦闪光灯 - 如何在“进程外”完成它?

The Old New Thing 博客上描述了这个问题(黄色矩形),之后的解决方案就像

在进程 B 中调用 DialogBox 时,将 hwndA 作为所有者窗口传递

但是在 VB6 中,你有函数Form.Show([Modal], [OwnerForm]),其中OwnerForm意味着type,而不是hWnd

申请表的类型在其界面中不可用。我找不到使用 WinAPI 的解决方案。

2)第二个问题(我认为原因是一样的)是,当我显示插件模式对话框时,然后单击“查看桌面”(或 Win+M),然后我将返回应用程序(单击图标在面板中),它只播放“哔”声,什么也不做。(解决方案只是杀死应用程序)。同样,32 位版本工作正常。

感谢您的回答并为我的英语道歉。是的,我知道VB6现在不支持了,插件只处于维护模式,基于C#的新版本的开发正在进行中。在完成之前,VB6 必须工作。


编辑:

在 Spy++ 中,在 32 位应用程序和 64 位应用程序中运行时窗口属性的差异:

32 位与 64 位 App 下的插件窗口样式差异:

WS_CAPTION
*** WS_POPUP (only with 64bit App, because of code above)
WS_VISIBLE
WS_CLIPSBLINGS
WS_CLIPCHILDREN
WS_SYSMENU
WS_THICKFRAME
*** WS_OVERLAPPED (only with 32bit App)
WS_MINIMIZEBOX

32 位与 64 位应用程序下的插件窗口父/所有者差异:

*** Parent Window (32bit App None, 64bit App - Main Application hWnd) 
Owner Window (32bit and 64bit App - Main Application hWnd)
4

0 回答 0