Solved

Device Contexts

Posted on 1998-03-03
9
498 Views
Last Modified: 2008-02-01
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
0
Comment
Question by:never
  • 6
  • 3
9 Comments
 
LVL 39

Accepted Solution

by:
abel earned 400 total points
Comment Utility
1.
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



2.
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.


3.
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.

4.
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
0
 
LVL 39

Expert Comment

by:abel
Comment Utility
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 pbih As BITMAPINFOHEADER
    Dim hdr As BITMAPFILEHEADER
    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
    Wend

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

End Sub
0
 

Author Comment

by:never
Comment Utility
2) i know these objects from the win32 help file , but how can i use them?
4)Yes i want to get around it
0
 
LVL 39

Expert Comment

by:abel
Comment Utility
Never,
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?

Regards,
Abel
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:never
Comment Utility
it would be great if you send me any documentation via e-mail
e-mail: neversay.die@mailcity.com
0
 
LVL 39

Expert Comment

by:abel
Comment Utility
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.

0
 
LVL 39

Expert Comment

by:abel
Comment Utility
I've send them on the thirteenth. Let me know if the documentation is what you needed.
0
 
LVL 39

Expert Comment

by:abel
Comment Utility
Never, are you still there? Do you need some more explanation and/or sample code?
0
 

Author Comment

by:never
Comment Utility
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
hbadr@softhome.net
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Excel 2010 Macro to Format Number to Remove the .0 at the End 4 40
Access 2016 VB code 9 86
VBA filters 2 37
Copy a row 12 52
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now