2

我仍然支持使用 GetWindowLong 和 SetWindowLong 在运行时根据设置删除 ControlBox 的旧 vb6 应用程序。这适用于所有 32 位系统,但是当它在 64 位系统上运行时,主窗口不再正确刷新。问题似乎是文本框、列表框或命令按钮等输入控件。在被某些窗口覆盖后,它们在获得焦点之前不会显示,即使这样它们的边框也不会正确显示。

我已阅读 MSDN 文档http://msdn.microsoft.com/en-us/library/ms633591%28v=vs.85%29.aspx说这些函数已被 ...WindowLongPtr 函数取代以兼容支持 32 位和 64 位系统。从我能读到的所有内容中,真正谈论的是编译 32 位和 64 位版本,而不是在不同的平台上运行。我试过改变我的声明

Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Public Declare Function GetWindowLongPtr Lib "user32" Alias "GetWindowLongPtrA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Public Declare Function SetWindowLongPtr Lib "user32" Alias "SetWindowLongPtrA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

但我收到错误“在 user32 中找不到 DLL 入口点 GetWindowLongPtrA”。因此,我尝试将 Alias 保留为“...WindowLongA”并运行,并且正如我所料,刷新问题没有任何区别。

有没有其他人看到这个或有任何建议。

这是如何使用代码的示例。

Private Sub Form_Activate()
   ...
   Call SetControlBox(Me.hWnd, DisableFullScreen)
End Sub


Public Sub SetControlBox(ByVal hWnd As Long, ByVal Value As Boolean)
   ' Set WS_SYSMENU On or Off as requested.
   Call FlipBit(hWnd, WS_SYSMENU, Value)
End Sub

Public Function FlipBit(ByVal hWnd As Long, ByVal Bit As Long, ByVal Value As Boolean) As Boolean
   Dim nStyle As Long

   ' Retrieve current style bits.
   nStyle = GetWindowLongPtr(hWnd, GWL_STYLE)

   ' Attempt to set requested bit On or Off,
   ' and redraw
   If Value Then
      nStyle = nStyle Or Bit
   Else
      nStyle = nStyle And Not Bit
   End If
   Call SetWindowLongPtr(hWnd, GWL_STYLE, nStyle)
   Call Redraw(hWnd)

   ' Return success code.
   FlipBit = (nStyle = GetWindowLongPtr(hWnd, GWL_STYLE))
End Function

Public Sub Redraw(ByVal hWnd As Long)
   ' Redraw window with new style.
   Const swpFlags As Long = SWP_FRAMECHANGED Or SWP_NOMOVE Or SWP_NOZORDER Or SWP_NOSIZE
   SetWindowPos hWnd, 0, 0, 0, 0, 0, swpFlags
End Sub

谢谢

dbl

4

1 回答 1

0

尝试在常量中添加SWP_NOACTIVATE (&H10)位。swpFlags

顺便说一句,这仅重绘非客户区。像这样的名字RedrawNonclient会很明显。

于 2014-07-17T14:01:41.863 回答