PDA

Click to See Complete Forum and Search --> : Paint Pic over Systray clock using BitBlt


wey97
Apr 6th, 2001, 08:20 PM
I have been attempting to paint part of an image over the Systray clock using BitBlt. I can get the size and
position of the clock, but when I try to paint part of the image, I only get a black box painted over the clock.

Here is my code. On Form1, just insert a picturebox and timer.


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

Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) 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 SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long

Private Sub Form_Load()
Timer1.Interval = 1
End Sub

Private Sub Timer1_Timer()
Dim tRECT As RECT
Dim lDC As Long
Dim lHwnd As Long

lHwnd = FindWindowEx(0, 0, "Shell_TrayWnd", vbNullString)

lHwnd = FindWindowEx(lHwnd, 0, "TrayNotifyWnd", vbNullString)

lHwnd = FindWindowEx(lHwnd, 0, "TrayClockWClass", vbNullString)

lDC = GetWindowDC(lHwnd)

Call GetWindowRect(lHwnd, tRECT)

Call BitBlt(lDC, 0, 0, tRECT.Right - tRECT.Left, tRECT.Bottom - tRECT.Top, Picture1.hdc, 0, 0, SRCCOPY)

Call ReleaseDC(lHwnd, lDC)
End Sub

kedaman
Apr 7th, 2001, 07:34 AM
SRCCOPY probably not declared as a constant :)
you could use vbsrccopy

wey97
Apr 7th, 2001, 09:41 AM
:eek: Hey, it works.

How can I get rid of flashing?

How can I paint the pic if the form is minimized or
is hidden?

kedaman
Apr 7th, 2001, 11:15 AM
hmm it's going to flash every time it updates, you could subclass it though but not using vb.
set autoredraw on on the source picturebox