如何象SPY++一样能让任意一个窗体(包括不规则)的边框发生闪动呢?

biku 2006-02-08 08:08:16
这个问题我在DELPHI版块中问过了,不知道这里的高手有什么新的方法或思路。
最好是能让类似WINDOWS MEDIEA PLAYER的窗体也发生闪动。

送上50分,一点小意思。
...全文
216 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
唐古拉山 2006-02-17
  • 打赏
  • 举报
回复

vb最具可亲性

biku 2006-02-17
  • 打赏
  • 举报
回复
非常感谢!!在VB中通过了。
正在转换成DELPHI。晚上结帖。还是VB的人气好啊!
yinweihong 2006-02-16
  • 打赏
  • 举报
回复
加上上面那个方法就可以了
yinweihong 2006-02-16
  • 打赏
  • 举报
回复
完整代码,测试通过
窗体:
Option Explicit
Private Declare Function SetCapture Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function WindowFromPointXY Lib "user32" Alias "WindowFromPoint" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd As Long) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Private m_hWnd As Long
Private m_Picking As Boolean
Private Sub Form_Load()
Picture1.Picture = Picture1.DragIcon
Me.MouseIcon = Picture1.DragIcon
End Sub
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Me.MousePointer = vbCustom
Set Picture1.Picture = Nothing
m_Picking = True
Call SetCapture(Picture1.hWnd)
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
Static pt As POINTAPI
Static hWnd As Long

If m_Picking Then
Call GetCursorPos(pt)
hWnd = WindowFromPointXY(pt.x, pt.y)
If hWnd <> m_hWnd Then
' Erase previous highlight.
Call FrameWindow(m_hWnd)
' Cache new handle, update caption, and highlight.
m_hWnd = hWnd
Me.Caption = Hex(m_hWnd)
Call FrameWindow(m_hWnd)
End If
End If
End Sub
Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
' have done picking
m_Picking = False

' Erase highlight.
Call FrameWindow(m_hWnd)
Picture1.Picture = Picture1.DragIcon
Me.MousePointer = vbDefault

Call ReleaseCapture

MsgBox Hex(m_hWnd)
End Sub
模块:
Option Explicit

Private Declare Function IsWindow Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function GetWindowDC Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hWnd As Long, ByVal hDC As Long) As Long
Private Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function CreatePen Lib "gdi32" (ByVal nPenStyle As Long, ByVal nWidth As Long, ByVal crColor As Long) As Long
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hDC As Long, ByVal hObject As Long) As Long
Private Declare Function GetStockObject Lib "gdi32" (ByVal nIndex As Long) As Long
Private Declare Function SetROP2 Lib "gdi32" (ByVal hDC As Long, ByVal nDrawMode As Long) As Long
Private Declare Function CreateHatchBrush Lib "gdi32" (ByVal nIndex As Long, ByVal crColor As Long) As Long
Private Declare Function GetSysColor Lib "user32" (ByVal nIndex As Long) As Long
Private Declare Function GetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long) As Long
Private Declare Function FrameRgn Lib "gdi32" (ByVal hDC As Long, ByVal hRgn As Long, ByVal hBrush As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As Long
Private Declare Function IsZoomed Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function Rectangle Lib "gdi32" (ByVal hDC As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hDC As Long) As Long


Private Const PS_INSIDEFRAME As Long = 6
Private Const SM_CXSCREEN As Long = 0
Private Const SM_CYSCREEN As Long = 1
Private Const SM_CXBORDER As Long = 5
Private Const SM_CYBORDER As Long = 6
Private Const SM_CXFRAME As Long = 32
Private Const SM_CYFRAME As Long = 33
Private Const NULL_BRUSH As Long = 5
Private Const NULL_PEN As Long = 8
Private Const R2_NOT As Long = 6
Private Const HS_DIAGCROSS As Long = 5
Private Const CTLCOLOR_STATIC As Long = 6


Private Const ERRORAPI As Long = 0
Private Const NULLREGION As Long = 1
Private Const SIMPLEREGION As Long = 2
Private Const COMPLEXREGION As Long = 3

Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

PLK_XiaoWei 2006-02-16
  • 打赏
  • 举报
回复
肯定是要画的
biku 2006-02-14
  • 打赏
  • 举报
回复
谢谢,明天我试试看。
yinweihong 2006-02-14
  • 打赏
  • 举报
回复
http://www.pscode.com/vb/scripts/ShowCode.asp?txtCodeId=6362&lngWId=1
这里有个
lsftest 2006-02-13
  • 打赏
  • 举报
回复
http://tips.vvsoft.com/powerba/develop/vc/article/20011113002.htm
看里面画红色边框那部分的原理。。。。。。。。。。。
yinweihong 2006-02-13
  • 打赏
  • 举报
回复
如果是模拟spy++的话,我下午给段代码,楼主说清楚看看
yinweihong 2006-02-13
  • 打赏
  • 举报
回复
什么叫 最好是能让类似WINDOWS MEDIEA PLAYER的窗体也发生闪动。?

如果是类似spy++那样勾选句柄的话,到是没问题
yinweihong 2006-02-13
  • 打赏
  • 举报
回复
勾选图形主要算法
Public Sub FrameWindow(ByVal hWnd As Long, Optional PenWidth As Long = 2)
Dim hDC As Long
Dim hRgn As Long
Dim hPen As Long
Dim hOldPen As Long
Dim hBrush As Long
Dim hOldBrush As Long
Dim OldMixMode As Long
Dim cxFrame As Long
Dim cyFrame As Long
Dim r As RECT
If IsWindow(hWnd) Then
hDC = GetWindowDC(hWnd)
hRgn = CreateRectRgn(0, 0, 0, 0)
hPen = CreatePen(PS_INSIDEFRAME, GetSystemMetrics(SM_CXBORDER) * PenWidth, RGB(0, 0, 0))
hOldPen = SelectObject(hDC, hPen)
hOldBrush = SelectObject(hDC, GetStockObject(NULL_BRUSH))
OldMixMode = SetROP2(hDC, R2_NOT)
If GetWindowRgn(hWnd, hRgn) <> ERRORAPI Then
hBrush = CreateHatchBrush(HS_DIAGCROSS, GetSysColor(CTLCOLOR_STATIC))
Call FrameRgn(hDC, hRgn, hBrush, GetSystemMetrics(SM_CXBORDER) * PenWidth, GetSystemMetrics(SM_CYBORDER) * PenWidth)
Else
cxFrame = GetSystemMetrics(SM_CXFRAME): cyFrame = GetSystemMetrics(SM_CYFRAME)
Call GetWindowRect(hWnd, r)
If IsZoomed(hWnd) Then
Call Rectangle(hDC, cxFrame, cyFrame, GetSystemMetrics(SM_CXSCREEN) + cxFrame, GetSystemMetrics(SM_CYSCREEN) + cyFrame)
Else
Call Rectangle(hDC, 0, 0, r.Right - r.Left, r.Bottom - r.Top)
End If
End If
'Cleanup
Call SelectObject(hDC, hOldPen)
Call SelectObject(hDC, hOldBrush)
Call SetROP2(hDC, OldMixMode)
Call DeleteObject(hPen)
Call DeleteObject(hBrush)
Call DeleteObject(hRgn)
Call ReleaseDC(hWnd, hDC)
End If
End Sub
biku 2006-02-13
  • 打赏
  • 举报
回复
大家可以看一下,这是DESKPINS添加规则后,把焦点拖到MEDIA PLAYER 后MEDIEA PLAYER的窗体发生了闪动。大家注意,我们用一般的让窗体闪动的软件是达不到这样的效果的,只能是一个矩形(跟拖动MEDIEA PLAYER时所产生的虚框一样大。)。

http://img263.photo.163.com/biku/31501462/833572152.jpg
http://img263.photo.163.com/biku/31501462/833571610.jpg
zyl910 2006-02-12
  • 打赏
  • 举报
回复
// 大家可以去下载一个叫DESKPINS的软件,它能描绘出WINDOWS MEDIEA PLAYER的不规则边框。不知道怎么实现的。

用GetWindowRgn可以得到不规则窗口的区域
再用FrameRgn绘制区域边框就行

它们都是Win32 API,有什么不明白的查MSDN就行



Call GetWindowRgn(hWnd, hRgn)
Call FrameRgn(hDC, hRgn, hBr, 1, 1)
biku 2006-02-10
  • 打赏
  • 举报
回复
小顶一下。可否说说代码。另,大家可以去下载一个叫DESKPINS的软件,它能描绘出WINDOWS MEDIEA PLAYER的不规则边框。不知道怎么实现的。
zyl910 2006-02-08
  • 打赏
  • 举报
回复
用GetWindowRgn获得窗口区域
再用FrameRgn绘制区域边框
vansoft 2006-02-08
  • 打赏
  • 举报
回复
是标题栏吗?
可以发消息给消息。根据窗口的句柄。

1,486

社区成员

发帖
与我相关
我的任务
社区描述
VB API
社区管理员
  • API
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧