簡體   English   中英

Windows 7 64位中的VB6 SetWindowLong導致刷新問題

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

我仍在支持舊的vb6應用程序,該應用程序利用GetWindowLong和SetWindowLong在運行時根據設置刪除ControlBox。 這在所有32位系統上都很好用,但是當它在64位系統上運行時,主窗口將不再正確刷新。 問題似乎出在諸如TextBox,ListBox或CommandButton之類的輸入控件上。 在被某些窗口遮蓋后,它們直到得到焦點后才顯示,甚至邊框也無法正確顯示。

我已經閱讀了MSDN文檔http://msdn.microsoft.com/zh-cn/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

嘗試將SWP_NOACTIVATE (&H10)位添加到swpFlags常量中。

順便說一句,這僅重繪了非客戶區。 RedrawNonclient這樣的名稱將使其顯而易見。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM