Results 1 to 18 of 18

Thread: Redraw Picture Box

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Oregon
    Posts
    962

    Redraw Picture Box

    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.
    Involved in: Sentience

  2. #2
    Addicted Member
    Join Date
    Apr 2000
    Location
    England
    Posts
    246
    I'm not sure there is a way, hDC's are pointers to a surface, redrawing is done buy the object.
    Some Days, i just get this feeling that i'm helping to write dozens of Viruses...

  3. #3
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    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
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Oregon
    Posts
    962
    I saw that one in the API viewer, but sience I didn't know how to use it I ignored it.
    Involved in: Sentience

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Oregon
    Posts
    962
    I am unable to find the tutorial on the VBW site (you do mean VB world right?).
    Involved in: Sentience

  6. #6
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    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:
    VB Code:
    1. RedrawWindow Me.hWnd, ByVal 0&, ByVal 0&, &H1
    And that will correctly redraw the window.

    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
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  7. #7
    Fanatic Member PsychoMark's Avatar
    Join Date
    Feb 2001
    Location
    Netherlands
    Posts
    540
    FillRect?
    Teaudirenopossum.Musasapientumfixaestinaure.
    (I can't hear you. There's a banana in my ear)

  8. #8
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Okay, you could get away with this then:
    VB Code:
    1. 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
    2.  
    3. RedrawWindow Me.hWnd, ByVal 0&, CreateRectRgn(X, Y, X + Width, Y + Height), &H1
    Just ask me if you have any more trouble.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Oregon
    Posts
    962
    This wount work:

    VB Code:
    1. 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:
    1. Public Type RECT
    2.   Left As Long
    3.   Top As Long
    4.   Right As Long
    5.   Bottom As Long
    6.  End Type
    Involved in: Sentience

  10. #10
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Oh really

    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:
    1. Function MKRect(X1 As Long, Y1 As Long, X2 As Long, Y2 As Long) As RECT
    2.     With MKRect
    3.         .Left = X1
    4.         .Top = Y1
    5.         .Right = X2
    6.         .Bottom = Y2
    7.     End With
    8. End Function
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Oregon
    Posts
    962
    RedrawWindow hWnd, Rect, ----, &H1

    What then do you place where I have the -'s?
    Involved in: Sentience

  12. #12
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    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...
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  13. #13

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Oregon
    Posts
    962
    neither worked...
    Involved in: Sentience

  14. #14

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Oregon
    Posts
    962
    *BUMP*
    Involved in: Sentience

  15. #15
    Frenzied Member /\/\isanThr0p's Avatar
    Join Date
    Jul 2000
    Location
    They can't stop us! We're on a misson from God.
    Posts
    1,181
    well all those answeres needed the hwnd, but if you got no window there wont be an hwnd so I think nirces was right.
    Sanity is a full time job

    Puh das war harter Stoff!

  16. #16

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Oregon
    Posts
    962
    As was said, I was tring to redraw a picture box though use of HDC or HWND, ect.
    Involved in: Sentience

  17. #17
    Fanatic Member PsychoMark's Avatar
    Join Date
    Feb 2001
    Location
    Netherlands
    Posts
    540
    Well, how about this:


    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:


    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.
    Teaudirenopossum.Musasapientumfixaestinaure.
    (I can't hear you. There's a banana in my ear)

  18. #18

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Oregon
    Posts
    962
    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.
    Involved in: Sentience

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width