VB仿大漠GDI模式后台找图找色-揭秘后台图色窗口不黑的原理

记得老版的梦工厂论坛曾经有人讨论过,为什么youxi使用PrintWindow有时能截图有时却不能(有的youxi压根没成功过),

其实大漠的GDI模式的图色,截图同样使用的是这个函数,只不过它在printwindow前对窗口做了处理(为什么窗口要部分移出屏幕,为什么会有绑定窗口这一步),关键函数 SetWindowLong   GetWindowLong

Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
 
'常量
Private Const GWL_EXSTYLE = (-20)
Private Const WS_EX_LAYERED = &H80000
Private Const LWA_ALPHA = &H2
 
private Old as long '记录老的,解绑用
大漠GDI绑定所做的处理,记得窗口移出屏幕一部分哦
Public Function GdiInt(hwnd As Long) As Long
Dim l As Long, m As Long
Old = GetWindowLong(hwnd, GWL_EXSTYLE) '记录
l = Old Or WS_EX_LAYERED
GdiInt = SetWindowLong(hwnd, GWL_EXSTYLE, l) '设置GDI图色绑定
SetLayeredWindowAttributes hwnd, 0, 255, LWA_ALPHA '这一步不能少,少了窗口是一直黑的
End Function
 
'还原
 
Public Function GdiUn(hwnd As Long) As Long
GdiUn = SetWindowLong(hwnd, GWL_EXSTYLE, Old)
End Function
 
绑定处理后,使用PrintWindow看看,必须是大漠GDI图色支持的youxi啊- -

你可能感兴趣的:(VB)