简体   繁体   English

Windows 7 64位中的VB6 SetWindowLong导致刷新问题

[英]VB6 SetWindowLong Causing Refresh Issue in Windows 7 64-bit

I am still supporting and old vb6 application that utilizes GetWindowLong and SetWindowLong to remove the ControlBox at runtime depending on a setting. 我仍在支持旧的vb6应用程序,该应用程序利用GetWindowLong和SetWindowLong在运行时根据设置删除ControlBox。 This works great on all 32-bit systems but when it runs on a 64bit system the main window no longer refreshes properly. 这在所有32位系统上都很好用,但是当它在64位系统上运行时,主窗口将不再正确刷新。 The problem seems to be input controls like TextBox, ListBox, or CommandButton. 问题似乎出在诸如TextBox,ListBox或CommandButton之类的输入控件上。 After being covered up by certain windows they don't display until they receive the focus and even then their borders don't show up properly. 在被某些窗口遮盖后,它们直到得到焦点后才显示,甚至边框也无法正确显示。

I've read the MSDN documentation http://msdn.microsoft.com/en-us/library/ms633591%28v=vs.85%29.aspx that says these functions have been superseded by ...WindowLongPtr functions to be compatible with both 32-bit and 64-bit systems. 我已经阅读了MSDN文档http://msdn.microsoft.com/zh-cn/library/ms633591%28v=vs.85%29.aspx ,其中说这些功能已由... WindowLongPtr功能取代,以便兼容与32位和64位系统一起使用。 From everything I've been able to read that is really talking about compiling both 32-bit and 64-bit version instead of running on the different platforms. 从我已经阅读的所有内容中可以看出,这实际上是在编译32位和64位版本,而不是在不同的平台上运行。 I've tried changing my declare from 我尝试过将声明从

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

To

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

But I get the error "Can't find DLL entry point GetWindowLongPtrA in user32". 但是我收到错误消息“在user32中找不到DLL入口点GetWindowLongPtrA”。 So I tried leaving the Alias as "...WindowLongA" and that runs and as I would expect doesn't make any difference in the refresh problem. 因此,我尝试将Alias保留为“ ... WindowLongA”,并且可以运行,并且我希望刷新问题不会有任何不同。

Has anybody else seen this or have any suggestions. 有没有其他人看到这个或有任何建议。

Here is a sample of how the code is used. 这是代码使用示例。

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

Thanks 谢谢

dbl dbl

Try adding SWP_NOACTIVATE (&H10) bit to your swpFlags constant. 尝试将SWP_NOACTIVATE (&H10)位添加到swpFlags常量中。

Btw, this redraws non-client area only. 顺便说一句,这仅重绘了非客户区。 A name like RedrawNonclient would make it apparent. RedrawNonclient这样的名称将使其显而易见。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM