CreateDC() And CreateCompatibleDC()
Can someone tell me, what's the difference between CreateDC() and CreateCompatibleDC()
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
CreateDC?
I am loading all the printer names into a combo box from the Printers collection. How can I get a hDC from these printers using the API? Does anyone have some sample code using the CreateDC call?
Need Help With CreateDC, Or Something Similar.
This is my problem:
I have a function that Draws a image using BitBlt, BitBlt wants to know TargetDC and DestDC, and here's my problem, I want to draw my picture on a TargetDC, without having to load the picture to a PictureBox or a Form, I want to load it to a variable then Draw it from there on TargetDC.
I thought about using CreateDC, but I really don't know how to use it, so some sample code on how to Create a DC to a StdPicture would be very great.
:: Thanks, KeLi
Bitmap Print Using CreateDC/StartDoc/EndDoc
By the way, I hate converting VB 3.0 to 6.0
Can anyone tell me how I can print a bitmap that exists on a form in my app to a specified location on a page? This is the code I have so far (pardon the lack of Dims, I didn't think they were necessary):
lf.lfHeight = yfntSm%
lf.lfWidth = xFntSm%
lf.lfEscapement = 0 ' normal
lf.lfWeight = 400
lf.lfFaceName = "Times New Roman" + Chr$(0)
lf.lfOutPrecision = OUT_DEFAULT_PRECIS
lf.lfClipPrecision = OUT_DEFAULT_PRECIS
lf.lfQuality = DEFAULT_QUALITY
lf.lfPitchAndFamily = DEFAULT_PITCH Or FF_DONTCARE
lf.lfCharSet = DEFAULT_CHARSET
hFont = CreateFontIndirect(lf) 'Create the font
di.cbSize = 20 ' Size of DOCINFO structure
di.lpszDocName = "My Document" ' Set name of print job (Optional)
Printer.TrackDefault = true 'Use default printer
hPrintDC = CreateDC(Printer.DriverName, Printer.DeviceName, 0, 0)
result = StartDoc(hPrintDC, di) 'Start a new print document
result = StartPage(hPrintDC) 'Start a new page
' Select our font structure and save previous font info
hOldfont = SelectObject(hPrintDC, hFont)
' Print some sample text
result = TextOut(hPrintDC, 1000, 1000, "Hello World", 11)
(Right here, I'd like to print frmSig!picSignature, which is a PictureBox, to the page. How do I do that!??)
result = EndPage(hPrintDC) 'End the page
result = EndDoc(hPrintDC) 'End the print job
result = DeleteDC(hPrintDC) 'Delete the printer device context
result = DeleteObject(hFont) 'Delete the font object
I'm interfacing with various DLLs to access the Windows API, but I don't know which functions in the API that I need to print the bitmap. Any suggestions would be great!
Thank you!!
killRoy
CreateCompatibleDC
When you use CreatecompatibleDC(&0) create a compatible with the screen.
Few years ago the screen was 24bpp today the screems are 32bpp.
What happen with this.
We use to create a compatible and then draw and work with the DC, in 24bpp because the frame grabber work with 24bpp, what will happen when I use BitBlt to paint in the screen.
Could I use Create CompatibleDC(&0) and create the binfo with bitsperpixel=24 in order to receive the frame capture?
...Julio
Createcompatibledc
hdc as long
hdc = CreateCompatibleDC(0)
I'm getting a negative result in hdc. Is this an error condition?
I'm having a GetDIBits call crash VB later in the program and I'm wondering if this is the problem?
CreateCompatibleDC...
I have been learning the different aspects of game programming in VB lately before I undertake a larger game project. Currently I am trying to learn how to open graphics straight into memory (no picture boxes involved) and then use them with BitBlt from there. It makes sense how it CAN work but for me it just WON'T work. I have downloaded 3 different examples and tried to use them but none of them seem to work the way I want them too. I know that I use some API's like CreateCompaitbleDC, DeleteDC, BitBlt, ect. But I can't seem to get the image into memory. So can anybody point me to a good tutorial or help explain the different steps that need to happen? Thanks.
CreateCompatibleDC
Well, I've heard of it, read a little bit about it, can't really find much about it on the forums.. so
How do I use it??
I have a bitmap, that i want to load into memory, so I can bitblt using the DC in memory..
how can I acheive this?
Thanks in advance,
Problem With CreateCompatibleDC()
I am using CreateCompatibleDC() in my code, and the problem is that it is only working to load the picture half the time. Here is the function I use.
Code:
Public Function CreateDC(FileName As String) As Long
Dim DC As Long
Dim hBitmap As Long
'Create a Device Context
DC = CreateCompatibleDC(frmZeldaMapEditor.picTileset.hdc)
If DC < 1 Then 'Failed
GenerateDC = 0
MsgBox "Error creating DC"
Exit Function
End If
'Load image
hBitmap = LoadImage(0, FileName, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION)
If hBitmap = 0 Then 'Failed
DeleteDC DC
GenerateDC = 0
MsgBox "Error loading image"
Exit Function
End If
'Loads the image into the DC
SelectObject DC, hBitmap
'Returns the DC
CreateDC = DC
DeleteObject hBitmap
End Function
The problem is that I am getting the "Error creating DC", indicating a problem with CreateCompatibleDC(), approximately 50% of the time. Obviously this is unacceptable as the program is unuseable when this happens. Is there something I am doing wrong. If you need more info please let me know, Thanks.
CreateCompatibleDC Always Returns 0
Hi,
I am just experimenting with CreateCompatibleDC, in order to BitBlt from memory, but it always returns 0. I am using VB6 and running on Windows 2000 Pro.
As I have never used these APIs before, I don't even know where to look, can anyone help me?
Thanks in advance
CreateCompatibleDC - Do It Once, Or Each Time?
My usercontrol has an option to tile the background with a bitmap. This is an owner-drawn control so the actual bitmap will not be saved in something with a hdc property. Should I...
1. create a memory dc each time the control is redrawn using only local variables and destroy them at the end of the sub?
2. or just create a module-level memory dc if/when a backgroundbitmap is assigned and reuse it each time.
I am not sure what kind of resources it would use up, and I am new enough at all this GDI stuff that I am still confused about how to prevent memory leaks. Thanks
God Bless America
GDI CreateCompatibleDC - Hatched Styles?
OK this is driving me crazy:
I wrote this code to create a back buffer DC and fill it with a colour:
Code:
GetWindowRect hwnd, WinR
aRect.Right = 40
aRect.Bottom = WinR.Bottom - WinR.Top
hDC = GetWindowDC(hwnd)
mDC = CreateCompatibleDC(hDC)
hBitmap = CreateCompatibleBitmap(mDC, 40, WinR.Bottom - WinR.Top)
DeleteObject SelectObject(mDC, hBitmap)
hBrush = CreateSolidBrush(RGB(222, 222, 222))
FillRect mDC, aRect, hBrush
DeleteObject hBrush
Technically, this works, but when I Blt it to a control, it appears that the DC has some hatched style over the top, even though I used CreateSolidBrush
Can't seem to find a way around this, hoping someone knows.
Thanks.
EDIT: Sorry, posted the thread in the wrong place... Can someone move it?
A Problem With CreateCompatibleDC, My Computer, Or My Brain?
A good 3-4 times out of 5, when using CreateCompatibleDC (Context included later), a handle is returned whose value is < 1. I've made my own set of code from scratch, tried various examples from here on xVBt, and I'm consistantly encountering this problem. While I can work around it, it's certainly a hassle, slower, and I'd prefer to understand why it's happening, even if I can't fix it.
The following is code from SOMEONE's mDC tutorial from here, just spent 15 minutes looking for where I got it from, can't find it.
Code:
Public Function GenerateDC(FileName As String) As Long
Dim DC As Long
Dim n As Integer
Dim hBitmap As Long
'Create a Device Context, compatible with the screen
DC = CreateCompatibleDC(0)
If DC < 1 Then
GenerateDC = 0
Exit Function
End If
'Load the image....BIG NOTE: This function is not supported under NT, there you can not
'specify the LR_LOADFROMFILE flag
hBitmap = LoadImage(0, FileName, IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE Or LR_LOADFROMFILE Or LR_CREATEDIBSECTION)
'If hBitmap = 0 Then 'Failure in loading bitmap
' DeleteDC DC
' GenerateDC = 0
' Exit Function
'End If
'Throw the Bitmap into the Device Context
SelectObject DC, hBitmap
'Return the device context
GenerateDC = DC
'Delte the bitmap handle object
DeleteObject hBitmap
End Function
Where the line 'DC = CreateCompatibleDC(0)' often produces negative numbers. What is causing this?
|