|
-
Nov 17th, 2001, 10:28 AM
#1
Thread Starter
Member
painting on windows
I'm using the Rectangle, the CreateBrush and the CreatePen-functions to paint a red rectangle to a window's DC, let's say the notepad-window.
Question: How can I remove the rectangle?
I've tried the UpdateWindow-function. Even a
WM_PAINT-Message has no effect. A WM_ERASEBKGND-Message
would erase the window-background, but I want only the rectangle to disappear.
thx for your help,
Quix
-
Nov 17th, 2001, 01:35 PM
#2
I'm not sure where you rpoblem is:
Try the InvalidateRect api call.
Also, you can just paint the area background color to restore it.
-
Nov 18th, 2001, 06:11 AM
#3
Hmm
im not sure, but it might be your form has AutoRedraw set to True. Try set it to False and use Form.Cls to clear the form..
-
Nov 18th, 2001, 07:26 AM
#4
Conquistador
SendMessage Me.Hwnd, WM_REDRAW?
something like that?
-
Nov 18th, 2001, 02:00 PM
#5
Fanatic Member
try sending InvalidateRectangle, and then send WM_PAINT, that should force it to repaint.
GWDASH
[b]VB6, Perl, ASP, HTML, JavaScript, VBScript, SQL, C, C++, Linux , Java, PHP, MySQL, XML[b]
-
Nov 19th, 2001, 07:07 AM
#6
Thread Starter
Member
it works!
thx you guys, InvalidateRect does the job.
regards, Quix
-
Nov 21st, 2001, 05:02 AM
#7
Thread Starter
Member
there's still a problem...
@AngelFire: I'm painting the rectangle to an non-VB-window, so there's no Me.AutoRedraw
@DaSilvy: WM_REDRAW doesn't exist.
@jim mcnamara: I'm painting a transparent rectangle over a button on a toolbar in winword, so there's no background color.
I thought, InvalidateRectangle would do, but it only works for hwnd=0. This would refresh the whole screen (flicker, flicker....). I only want the painted rectangle to disappear. I've tried UpdateWindow, RedrawWindow, WM_PAINT, WM_NCPAINT etc. Since the rectangle is painted to the Winword application window, I also tried the VBA-function Application.ScreenRefresh. Nothing happens! The rectangle wouldn't disappear.
Please check the code I'm using, perhaps you have some suggestions, how to solve the problem.
Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function CreateBrushIndirect Lib "gdi32" (lpLogBrush As LOGBRUSH) As Long
Private Declare Function CreatePenIndirect Lib "gdi32" (lpLogPen As LOGPEN) 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 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 ReleaseDC Lib "user32" _
(ByVal hwnd As Long, ByVal hdc As Long) As Long
Private Declare Function InvalidateRect Lib "user32" _
(ByVal hwnd As Long, lpRect As RECT, ByVal bErase As Long) As Long
Private Declare Function UpdateWindow Lib "user32" (ByVal hwnd As Long) As Long
'--------------------------------
Private Sub PaintRect (hwnd As Long, lpRect As RECT, lgBrush As LOGBRUSH, lgPen As LOGPEN)
Dim dc As Long, _
hPen As Long, _
hOldPen As Long, _
hBrush As Long, _
hOldBrush As Long
dc = GetWindowDC(hwnd)
hBrush = CreateBrushIndirect(lgBrush)
hPen = CreatePenIndirect(lgPen)
hOldPen = SelectObject(dc, hPen)
hOldBrush = SelectObject(dc, hBrush)
With lpRect
Rectangle dc, .Left, .Top, .Right, .Bottom
End With
DeleteObject SelectObject(dc, hOldPen)
DeleteObject SelectObject(dc, hOldBrush)
ReleaseDC hwnd, dc
End Sub
'--------------------------------
Private Sub KillRect(hwnd As Long, lpRect As RECT)
InvalidateRect hwnd, lpRect, RECT_ERASE
UpdateWindow hwnd
End Sub
Thanks for your help, Quix
-
Nov 21st, 2001, 08:39 AM
#8
Hmmm
Im not sure, but try this:
[Highlight=VB]
Public Declare Function RedrawWindow Lib "user32" Alias "RedrawWindow" (ByVal hwnd As Long, lprcUpdate As long, ByVal hrgnUpdate As Long, ByVal fuRedraw As Long) As Long
Public Declare Function LockWindowUpdate Lib "user32" Alias "LockWindowUpdate" (ByVal hwndLock As Long) As Long
Public Const RDW_INVALIDATE = &H1
Private Sub KillRect(hwnd As Long, lpRect As RECT)
LockWindowUpdate hWnd
RedrawWindow hWnd, byval 0&, byval 0&, RDW_INVALIDATE
LockWindowUpdate 0
End Sub
[Highlight=VB]
-
Nov 21st, 2001, 01:27 PM
#9
Thread Starter
Member
thanks, AngelFire
It works ! Using InvalidateRect instead of RedrawWindow allows me to update only the region of the painted rectangle, so there's no flickering at all. This is the code:
Private Sub KillRect(hwnd As Long, lpRect As RECT)
RectScreenToClient hwnd, lpRect
EnlargeRect PEN_WIDTH \ 2, lpRect
LockWindowUpdate hwnd
InvalidateRect hwnd, lpRect, 0
LockWindowUpdate 0
End Sub
'-----------------------------------------
Private Function RectScreenToClient(ByVal hwnd As Long, ByRef lpRect As RECT) As Long
Dim lpPoint1 As POINTAPI, _
lpPoint2 As POINTAPI, _
lngRet As Long
With lpRect
lpPoint1.x = .Left
lpPoint1.y = .Top
lpPoint2.x = .Right
lpPoint2.y = .Bottom
lngRet = ScreenToClient(hwnd, lpPoint1)
lngRet = ScreenToClient(hwnd, lpPoint2)
.Left = lpPoint1.x
.Top = lpPoint1.y
.Right = lpPoint2.x
.Bottom = lpPoint2.y
End With
RectScreenToClient = lngRet
End Function
But tell me, what is the LockWindowUpdate-function for? It doesn't work without it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|