Device Contexts

1)what are the DLLs used to manipulate the device context objects
2)what are the objects containd the DC structure.
3)is it possible to save a picture using the device context only.
4)why dose the auto redraw stop the action of the action of the bitblt DLL
the answer may be Examples,refrence name or location
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Following are all the functions used with device contexts.
As you can see they are all in gdi32.dll and user32.dll (see also my answer to point 2).

Declare Function CancelDC Lib "gdi32" Alias "CancelDC" (ByVal hdc As Long) As Long
Declare Function CreateCompatibleDC Lib "gdi32" Alias "CreateCompatibleDC" (ByVal hdc As Long) As Long
Declare Function CreateDC Lib "gdi32" Alias "CreateDCA" (ByVal lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As String, lpInitData As DEVMODE) As Long
Declare Function CreateIC Lib "gdi32" Alias "CreateICA" (ByVal lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As String, lpInitData As DEVMODE) As Long
Declare Function DeleteDC Lib "gdi32" Alias "DeleteDC" (ByVal hdc As Long) As Long
Declare Function DeleteObject Lib "gdi32" Alias "DeleteObject" (ByVal hObject As Long) As Long
Declare Function DeviceCapabilities Lib "winspool.drv" Alias "DeviceCapabilitiesA" (ByVal lpDeviceName As String, ByVal lpPort As String, ByVal iIndex As Long, ByVal lpOutput As String, lpDevMode As DEVMODE) As Long
Declare Function DrawEscape Lib "gdi32" Alias "DrawEscape" (ByVal hdc As Long, ByVal nEscape As Long, ByVal cbInput As Long, ByVal lpszInData As String) As Long
Declare Function EnumObjects Lib "gdi32" Alias "EnumObjects" (ByVal hDC As Long, ByVal n As Long, ByVal lpGOBJEnumProc As Long, lpVoid As Any) As Long
Declare Function GetCurrentObject Lib "gdi32" Alias "GetCurrentObject" (ByVal hdc As Long, ByVal uObjectType As Long) As Long
Declare Function GetDC Lib "user32" Alias "GetDC" (ByVal hwnd As Long) As Long
Declare Function GetDCEx Lib "user32" Alias "GetDCEx" (ByVal hwnd As Long, ByVal hrgnclip As Long, ByVal fdwOptions As Long) As Long
Declare Function GetDCOrgEx Lib "gdi32" Alias "GetDCOrgEx" (ByVal hdc As Long, lpPoint As POINTAPI) As Long
Declare Function GetDeviceCaps Lib "gdi32" Alias "GetDeviceCaps" (ByVal hdc As Long, ByVal nIndex As Long) As Long
Declare Function GetGraphicsMode Lib "gdi32" Alias "GetGraphicsMode" (ByVal hdc As Long) As Long
Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
Declare Function GetObjectType Lib "gdi32" Alias "GetObjectType" (ByVal hgdiobj As Long) As Long
Declare Function GetStockObject Lib "gdi32" Alias "GetStockObject" (ByVal nIndex As Long) As Long
Declare Function ReleaseDC Lib "user32" Alias "ReleaseDC" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Declare Function ResetDC Lib "gdi32" Alias "ResetDCA" (ByVal hdc As Long, lpInitData As DEVMODE) As Long
Declare Function RestoreDC Lib "gdi32" Alias "RestoreDC" (ByVal hdc As Long, ByVal nSavedDC As Long) As Long
Declare Function SaveDC Lib "gdi32" Alias "SaveDC" (ByVal hdc As Long) As Long
Declare Function SelectObject Lib "gdi32" Alias "SelectObject" (ByVal hdc As Long, ByVal hObject As Long) As Long

Here is some article from Microsoft which clearly explains the concept of DC's in general. It also explaines something about used dlls in addition to the above:

One of the chief features of the Microsoft® Win32® application programming interface (API) is device independence. Win32-based applications can draw and print output on a variety of devices. The software that supports this device independence is contained in two dynamic-link libraries. The first, GDI.DLL, is referred to as the graphics device interface (GDI); the second is referred to as a device driver. The name of the second depends on the device where the application draws output. For example, if the application draws output in the client area of its window on a VGA display, this library is VGA.DLL; if the application prints output on an Epson® FX-80 printer, this library is EPSON9.DLL.

An application must inform GDI to load a particular device driver and, once the driver is loaded, to prepare the device for drawing operations (such as selecting a line color and width, a brush pattern and color, a font typeface, a clipping region, and so on). These tasks are accomplished by creating and maintaining a device context. A device context is a structure that defines a set of graphic objects and their associated attributes, and the graphic modes that affect output. The graphic objects include a pen for line drawing, a brush for painting and filling, a bitmap for copying or scrolling parts of the screen, a palette for defining the set of available colors, a region for clipping and other operations, and a path for painting and drawing operations. Unlike most of the Win32 structures, an application never has direct access to the device context; instead, it operates on the structure indirectly by calling various functions.

I assume you mean saving to disk?
If you mean saving to memory it's just SaveDC and RestoreDC. SaveDC stores the DC on some kinda context-stack, the integer you get back can be used in RestoreDC.

For saving to disk I'll look that up.

Do you actually want a 'reason' (you ask 'why') or do you need a workaround? Or do you want to know what causes stopping the action? Please explain more exact. I'll see your comment for that.

Hope this is a bit what you needed. If I answered the wrong way, or if you need more explanation, please say so, I'll be happy to explain my answer more precisely.

Regards, Abel

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Here's a full example how to get the DC-bitmap to a file. I've translated it from C++ to VB. In stead of using CreateFile and WriteFile I think it would be easier to use Open and Put from VB. I haven't tested it in VB yet, but I guess you get the picture on how to accomplish the task.
I didn't include the Declarations since you can find that in the API-viewer.

Sub CreateBMPFile(hwnd As Long, lpFileName as String, BITMAPINFO pbi, _
                  hBMP As Any, hDC As Long)

    Dim Tmp as Long
    Dim hf as Integer
    Dim cb As Long
    Dim dwTotal as Long
    Dim hp As Any

    LSet pbih = pbi
    'Retrieve the color table (RGBQUAD array) and the bits
    ' (array of palette indices) from the DIB.
    GetDIBits hDC, hBMP, 0, pbih.biHeight, Bits, pbi, DIB_RGB_COLORS)
    'Create the .BMP file.
    hf = CreateFile(lpFileName, _
                   GENERIC_READ | GENERIC_WRITE, _
                   (DWORD) 0, 0, CREATE_ALWAYS, _
                   FILE_ATTRIBUTE_NORMAL, 0)
    hdr.bfType = &H4d42        '0x42 = "B" 0x4d = "M"
    'Compute the size of the entire file.
    hdr.bfSize = Len(BITMAPFILEHEADER) + pbih.biSize + pbih.biClrUsed _
                 * Len(RGBQUAD) + pbih.biSizeImage)
    hdr.bfReserved1 = 0
    hdr.bfReserved2 = 0
    'Compute the offset to the array of color indices.
    hdr.bfOffBits = Len(BITMAPFILEHEADER) + pbih.biSize + pbih.biClrUsed * _
                              Len (RGBQUAD)
    'Copy the BITMAPFILEHEADER into the .BMP file.
    WriteFile hf, hdr, Len(BITMAPFILEHEADER), Tmp, 0
    'Copy the BITMAPINFOHEADER and RGBQUAD array into the file.
    WriteFile hf, pbih, Len(BITMAPINFOHEADER)  + pbih.biClrUsed *_
                     Len(RGBQUAD), Tmp, 0

    'Copy the array of color indices into the .BMP file.
    dwTotal = pbih.biSizeImage
    cb = pbih.biSizeImage
    Set hp = lpBits
    While cb > MAXWRITE
            WriteFile hf, hp, MAXWRITE, Tmp, 0
            cb = cb- MAXWRITE
            hp = hp + MAXWRITE

     WriteFile hf, hp, cb, Tmp, 0
    'Close the .BMP file.
    CloseHandle hf

End Sub
neverAuthor Commented:
2) i know these objects from the win32 help file , but how can i use them?
4)Yes i want to get around it
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Can you tell me what you want to do with the Device Contexts (if my example above isn't enough, tell me)? Or do you want a full explanation to any of them? I have the documentation, also explanations on how to use them, but in text that's much too much to post it here. Maybe I can email them to you.

About 4:
I need to have a look at your code to help you out with that. Maybe it isn't necessary to set AutoRedraw to TRUE, but if you have to, you'll have to use BitBlt probably in a different way. Can you pos some code?

neverAuthor Commented:
it would be great if you send me any documentation via e-mail
Ok, I'll do that in a day. The documentation will be C-style, but is easy enough to understand and implement in you VB-applications. Just look up the functions in API-viewer and look up the corresponding documentation about the functions and the variables they use, and you'll be a long way in the right direction.

I've send them on the thirteenth. Let me know if the documentation is what you needed.
Never, are you still there? Do you need some more explanation and/or sample code?
neverAuthor Commented:
I am ,i've been disconnected from the net for a while, anyway i didn't recieve the the mail you sent me, please try this e-mail address
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.