I only know the HDC of an object, and I need to redraw it. What API call would I use?
The object would normally be a picture box, but it may also be a form, or any other object with a HDC.
Printable View
I only know the HDC of an object, and I need to redraw it. What API call would I use?
The object would normally be a picture box, but it may also be a form, or any other object with a HDC.
I'm not sure there is a way, hDC's are pointers to a surface, redrawing is done buy the object.
Yes, so you use this:
Public Declare Function RedrawWindow Lib "user32" Alias "RedrawWindow" (ByVal hwnd As Long, lprcUpdate As RECT, ByVal hrgnUpdate As Long, ByVal fuRedraw As Long) As Long
Make a region using the region tutorial on the VBW site. For hwnd, pass the picbox's hWnd property, or Null to redraw the screen. For fuRedraw, I would say it's a safe bet it should be 1, like the ShowCursor API (bShow). Don't quote me on that last one, though :D
I saw that one in the API viewer, but sience I didn't know how to use it I ignored it.
I am unable to find the tutorial on the VBW site (you do mean VB world right?).
Okay, if you don't want to specify a current area you can just use "ByVal 0&", I didn't know that at the time.
Call it like this:And that will correctly redraw the window.VB Code:
RedrawWindow Me.hWnd, ByVal 0&, ByVal 0&, &H1
By the way, I am looking for an API equivalent to .cls found on pictureboxes, for DCs or HWNDs. If anyone knows, gimme a holler :)
FillRect? :)
Okay, you could get away with this then:Just ask me if you have any more trouble.VB Code:
Declare Function CreateRectRgn Lib "gdi32" Alias "CreateRectRgn" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long RedrawWindow Me.hWnd, ByVal 0&, CreateRectRgn(X, Y, X + Width, Y + Height), &H1
This wount work:
VB Code:
RedrawWindow hdc, ByVal 0&, RedrawRegion, &H1
This is due to the fact that the ByVal 0& is where it wants the UD of rect:
VB Code:
Public Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type
Oh really :eek:
Well then try passing the same parameters for the RECT as you did with the CreateRectRgn API. Here's a quick tip, for creating RECTs on the fly:VB Code:
Function MKRect(X1 As Long, Y1 As Long, X2 As Long, Y2 As Long) As RECT With MKRect .Left = X1 .Top = Y1 .Right = X2 .Bottom = Y2 End With End Function
RedrawWindow hWnd, Rect, ----, &H1
What then do you place where I have the -'s?
The region I'd guess.... maybe try ByVal 0&. I don't know why it needs both, but first try with the 0& and then with the region code mentioned before.
Both may work...
neither worked...
*BUMP*
well all those answeres needed the hwnd, but if you got no window there wont be an hwnd so I think nirces was right.
As was said, I was tring to redraw a picture box though use of HDC or HWND, ect.
Well, how about this:
Quote:
WindowFromDC
The WindowFromDC function returns a handle to the window associated with the specified display device context (DC). Output functions that use the specified device context draw into this window.
HWND WindowFromDC(
HDC hDC // handle to window
);
Then use UpdateWindow on the returned handle. UpdateWindow has two 'weird' things:
1. it bypasses the window queue, thus instantly updating
2. it will only update if there is a region to update
To update a window even if Windows thinks it wouldn't have to (had a lot of problems before with this btw) use InvalidateRect:
Quote:
BOOL InvalidateRect(
HWND hWnd, // handle to window
CONST RECT* lpRect, // rectangle coordinates
BOOL bErase // erase state
);
hWnd
[in] Handle to the window whose update region has changed. If this parameter is NULL, the system invalidates and redraws all windows, and sends the WM_ERASEBKGND and WM_NCPAINT messages to the window procedure before the function returns.
lpRect
[in] Pointer to a RECT structure that contains the client coordinates of the rectangle to be added to the update region. If this parameter is NULL, the entire client area is added to the update region. (!!!)
bErase
[in] Specifies whether the background within the update region is to be erased when the update region is processed. If this parameter is TRUE, the background is erased when the BeginPaint function is called. If this parameter is FALSE, the background remains unchanged.
Thats gonna take some time to convert to VB...
Oh well, that just means that I will get a little bit of pratcice with C.