|
-
Feb 9th, 2002, 09:11 AM
#1
Thread Starter
New Member
Please Help: Cant load MemoryDC properly in NT, XP, 2000
I am in search of a work around for loading an image from file into a memory DC. I really hope someone can help as I have been looking for a solution for months.
It appears to me that when a single image is loaded into a memory DC, that NT, XP, and 2000 work correctly. In my case, I am loading many images into separate memory DC's, and the problem occurs consistently.
The following code to load the memory DC's works wonderfully for Windows 95,98,ME. It also works sometimes under Windows NT,2000,XP when small single images are loaded. Unfortunately, when large and high quantity images are loaded under Windows NT,2000,XP, I get strange results. (including image trailing, unloaded dc's, etc)
Here is the subroutine I use to load my Memory DC's (a modified version of Soren's):
'=====================================================
'LOAD A MEMORY DC WITH THE BITMAP
'=====================================================
Public Function GenerateDC(FileName As String) As Long
On Error GoTo BugTrap
Dim DC As Long
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
'Delete the bitmap handle object
DeleteObject hBitmap
'=====================================================
Exit Function
BugTrap:
BugReport ("System/GenerateDC")
'=====================================================
End Function
'=====================================================
Thank you all in advance, and I hope someone can help me out! Please feel free to email me at [email protected] if you would like to discuss it further.
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
|