我仍然支持和旧的vb6应用程序,它利用GetWindowLong和SetWindowLong在运行时根据设置删除ControlBox。这适用于所有32位系统,但当它在64位系统上运行时,主窗口不再正常刷新。问题似乎是TextBox,ListBox或CommandButton等输入控件。在被某些窗户遮盖后,他们不会显示,直到他们收到焦点,即使这样他们的边框也没有正确显示。
我已阅读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
答案 0 :(得分:0)
尝试将SWP_NOACTIVATE (&H10)
位添加到swpFlags
常量。
顺便说一下,这只重绘非客户区域。像RedrawNonclient
这样的名字会让它显而易见。