|
-
March 10th, 2007, 08:33 PM
#1
How do I get the size of a DC?
How do I get the size of a DC? Width and height?
I've tried GetObject Windows API without sucess. =(
All consequences are eternal in some way.
-
March 10th, 2007, 09:53 PM
#2
Re: How do I get the size of a DC?
I have managed to do it. But, i use GetWindowFromDC() API to get window that is the owner of the DC. Then I use GetWindowRect() API to retrive the DC size.
BUT! If the DC has no owner I cannot read it's bytes with GetDIBBits because I will not be able to determine it's size.
I need another method. I'm almost sure it iwll have to do with GetObject() API but I can't seem to do it.
Current code (VB):
I'm sure you will all understand VB code. i'm not asking a quetion about VB programming it's about WinAPI GDI programming and the code I have is VB:
Code:
' Returns an image from a given DC
Public Function atxLoadImageDC(SrcDC As Long) As atxImage
Dim iBitmap As Long, iDC As Long
Dim bmp As BITMAP, oldObj As Long
Dim tmpDC As Long, ArraySize As Long
Dim I As Long, x As Long, y As Long
Dim DCWinHwnd As Long, DCWinRECT As RECT
DCWinHwnd = WindowFromDC(SrcDC)
GetWindowRect DCWinHwnd, DCWinRECT
With atxLoadImageDC
.Width = DCWinRECT.Right - DCWinRECT.Left
.Height = DCWinRECT.Bottom - DCWinRECT.Top
.bmi.bmiHeader.bmSize = 40 'Size, in bytes, of the header (always 40)
.bmi.bmiHeader.bmPlanes = 1 'Number of planes (always one for this instance)
.bmi.bmiHeader.bmBitCount = 24 'Bits per pixel (always 24 for this instance)
.bmi.bmiHeader.bmCompression = BI_RGB 'Compression: standard/none or RLE
.bmi.bmiHeader.bmWidth = .Width
.bmi.bmiHeader.bmHeight = -.Height
ArraySize = ((.Width * 3) - 1) + (.Width Mod 4)
End With
ReDim atxLoadImageDC.Pixel(0 To ArraySize, 0 To atxLoadImageDC.Height)
iDC = CreateCompatibleDC(SrcDC)
iBitmap = CreateDIBSection(iDC, atxLoadImageDC.bmi, DIB_RGB_COLORS, ByVal 0&, ByVal 0&, ByVal 0&)
oldObj = SelectObject(iDC, iBitmap)
BitBlt iDC, 0, 0, atxLoadImageDC.Width, atxLoadImageDC.Height, SrcDC, 0, 0, vbSrcCopy
GetDIBits iDC, iBitmap, 0, atxLoadImageDC.Height, atxLoadImageDC.Pixel(0, 0), atxLoadImageDC.bmi, DIB_RGB_COLORS
DeleteObject SelectObject(iDC, oldObj)
DeleteDC iDC
DeleteObject iBitmap
End Function
Help please.
All consequences are eternal in some way.
-
March 13th, 2007, 06:42 PM
#3
Re: How do I get the size of a DC?
A Device Context doesn't have a size.
Henri Hein
Principal Engineer, Propel
Do not credit Propel with my views or opinions.
-
March 13th, 2007, 09:30 PM
#4
Re: How do I get the size of a DC?
Hmmm. You are sure? If so then it's great news to me. It means my current method of getting the bits from a given DC is correct: I'm assuming that the DC size is the same size of the window that owns it.
Thanks for attention.
All consequences are eternal in some way.
-
March 19th, 2007, 06:24 PM
#5
Re: How do I get the size of a DC?
That's correct. For an on-screen DC, the relevant size is that of the client area of the window. For an in-memory DC, the relevant size is that of the bitmap currently selected into the DC.
Henri Hein
Principal Engineer, Propel
Do not credit Propel with my views or opinions.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|