VB 拖动控件时在桌面上绘制虚框

VB 拖动控件时在桌面上绘制虚框

'Private Declare Function DrawFocusRect Lib "user32 " Alias "DrawFocusRect " (ByVal hdc As Long, lpRect As RECT) As Long
'说明   http://topic.csdn.net/t/20020820/15/955771.html
'画一个焦点矩形。这个矩形是在标志焦点的样式中通过异或运算完成的(焦点通常用一个点线表示)。如用同样的参数再次调用这个函数,就表示删除焦点矩形
'返回值
'Long,非零表示成功,零表示失败。会设置GetLastError
'参数表
'参数 类型及说明
'hdc   Long,设备场景的句柄
'lpRect   RECT,要在逻辑坐标中描绘的矩形
Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function RestoreDC Lib "GDI32" (ByVal hdc As Long, ByVal nSavedDC As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function DrawFocusRect Lib "user32" (ByVal hdc As Long, lpRect As RECT) As Long
Private Declare Function SaveDC Lib "GDI32" (ByVal hdc As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Private Type RECT
    Left                   As Long
    Top As Long
    Right                  As Long
    Bottom                 As Long
End Type
'lDesktop=GetDesktopWindow()取得桌面窗口  http://www.sudu.cn/info/index.php?op=article&id=58266
'lDC=GetDC(lDesktop)取得桌面窗口的设备场景
'---- 另一种用法。。很多人不愿意使用一个ID变量,在RestoreDC中可以把ID参数设为-1,表示恢复最近保存的HDC。
'http://www.cnblogs.com/lin1270/archive/2011/12/27/2302998.html
'SaveDC (hdc);
'
'/** ... */
'
'RestoreDC (hdc, -1);

Private Sub Command1_Click()
    Dim fRect As RECT
    fRect.Bottom = 300
    fRect.Right = 800
    fRect.Left = 100
    fRect.Top = 100
    lDesktop = GetDesktopWindow()                                               '取得桌面窗口
    fg = GetWindowDC(lDesktop)
    SaveDC fg                                                                   '保存操作的DC,以便操作完毕后恢复
    DrawFocusRect fg, fRect                                                     '---------
    RestoreDC fg, -1                                                            '恢复DC
End Sub
                                                                        

你可能感兴趣的:(VB 拖动控件时在桌面上绘制虚框)