Results 1 to 2 of 2

Thread: Does anyone have a demo or etc. to properly explain the usage of a "Offscreen DC"?

  1. #1

    Thread Starter
    Addicted Member Daniel_Christie's Avatar
    Join Date
    Jan 2000
    Location
    USA
    Posts
    245

    I could sure use some extra help on understanding fully how to efficiently use a offscreen DC.

    I thank you all for your help,
    Daniel Christie

  2. #2
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    I'm not sure exactly what you're trying to do so I can't taylor this example but I use Offscreen DCs all the time. They're exactly the same as normal DC's but you can't see them

    to create one you can use the following code

    Code:
    Public Sub CreateDC(WidthInPixels As Long, HeightInPixels As Long, Optional CompatibleDC as Long) As Long
    
    Dim hCompatibleDC As Long
    Dim hMemDC as Long
    
    'check there is a compatible DC
    If CompatibleDC=0 Then
    
        hCompatibleDC = GetDC(GetDesktopWindow)
    
    Else
    
        hCompatibleDC = CompatibleDC
    
    End If
    
    'CreateDC
    hMemDC = CreateCompatibleDC(hCompatibleDC)
    
    'Get Default Bitmap Out of DC and Delete it and Put New one in.
    
    DeleteObject SelectObject(hMemDC, CreateCompatibleBitmap(hCompatibleDC, WidthInPixels, HeightInPixels))
    
    'and We're Done
    CreateDC = hMemDC
    
    End Function
    This will Create a DC with The Width and Height you Specify, Make sure you always use the DeleteObject SelectObject(hMemDC..... line as the Default Bitmap inside a Memory DC is just a bit. make sure you delete your DC when you've finished otherwise you'll get a memory leak DeleteDC is handy for this.

    Oh, here's the API Calls you need

    Code:
    Private Declare Function CreateCompatibleBitmap Lib "gdi32" Alias "CreateCompatibleBitmap" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
    Private Declare Function CreateCompatibleDC Lib "gdi32" Alias "CreateCompatibleDC" (ByVal hdc As Long) As Long
    Private Declare Function DeleteDC Lib "gdi32" Alias "DeleteDC" (ByVal hdc As Long) As Long
    Private Declare Function DeleteObject Lib "gdi32" Alias "DeleteObject" (ByVal hObject As Long) As Long
    Private Declare Function SelectObject Lib "gdi32" Alias "SelectObject" (ByVal hdc As Long, ByVal hObject As Long) As Long
    Private Declare Function GetDC Lib "user32" Alias "GetDC" (ByVal hwnd As Long) As Long
    Private Declare Function GetDesktopWindow Lib "user32" Alias "GetDesktopWindow" () As Long
    you can just use them like normal DCs

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