VB icon

___Fast Masks!___ (Error fixed)

Email
Submitted on: 2/4/2015 8:50:00 PM
By: Mathieu Chartier (from psc cd)  
Level: Intermediate
User Rating: By 3 Users
Compatibility: VB 4.0 (32-bit), VB 5.0, VB 6.0
Views: 1024
 
     Have you ever wanted to create your bitblt masks when the application starts without having the user wait 5 minutes, now u can!
 

Windows API/Global Declarations:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
'**************************************
'Windows API/Global Declarations for :___Fast Masks!___ (Error fixed)
'**************************************
See the code below.
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: ___Fast Masks!___ (Error fixed)
' Description:Have you ever wanted to create your bitblt masks when the application starts without having the user wait 5 minutes, now u can!
' By: Mathieu Chartier (from psc cd)
'
' Assumes:This code creates masks for bitblt during runtime really fast!
'**************************************

Declare Function GetBkColor Lib "gdi32" (ByVal hDC As Long) As Long
Declare Function SetBkColor Lib "gdi32" (ByVal hDC As Long, ByVal crColor As Long) As Long
Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hDC As Long) As Long
Declare Function DeleteDC Lib "gdi32" (ByVal hDC As Long) As Long
Declare Function SelectObject Lib "gdi32" (ByVal hDC As Long, ByVal hObject As Long) As Long
Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal XSrc As Long, ByVal YSrc As Long, ByVal dwRop As Long) As Long
Declare Function SetTextColor Lib "gdi32" (ByVal hDC As Long, ByVal crColor As Long) As Long
Declare Function GetTextColor Lib "gdi32" (ByVal hDC As Long) As Long
Declare Function CreateBitmap Lib "gdi32" (ByVal nWidth As Long, ByVal nHeight As Long, ByVal nPlanes As Long, ByVal nBitCount As Long, lpBits As Any) As Long
Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hDC As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Sub CreateMask(hDestDC As Long, X As Long, Y As Long, nWidth As Long, nHeight As Long, hSrcDC As Long, XSrc As Long, YSrc As Long, TransColor As Long)
 Dim OrigColor As Long' Holds source original background color
 Dim DestBKColor As Long' Holds destination original background color
 Dim OrigTextColor As Long
 
 Dim hMaskBmp As Long
 Dim hMaskPrevBmp As Long
 Dim MaskDC As Long
 
 MaskDC = CreateCompatibleDC(hDestDC)
 hMaskBmp = CreateBitmap(nWidth, nHeight, 1, 1, ByVal 0&) '//Create a monochrome bitmap for our mask
 hMaskPrevBmp = SelectObject(MaskDC, hMaskBmp)
 
 OrigColor = SetBkColor(hSrcDC, TransColor)
Call BitBlt(MaskDC, 0, 0, nWidth, nHeight, hSrcDC, XSrc, YSrc, vbSrcCopy) '//Copy hSrcDc into our mask bitmap
 SetBkColor hSrcDC, OrigColor '//Restore the original color
 
 DestBKColor = SetBkColor(hDestDC, vbWhite) '//All the white in our bitmap hasto be white
 OrigTextColor = SetTextColor(hDestDC, vbBlack)
BitBlt hDestDC, X, Y, nWidth, nHeight, MaskDC, 0, 0, vbSrcCopy
 SetTextColor hDestDC, OrigTextColor
 SetBkColor hDestDC, DestBKColor '//Restore the original back color bak
 
 Call SelectObject(MaskDC, hMaskPrevBmp) 'Select our original bitmap bak
 
 Call DeleteObject(hMaskBmp) 'Delete our mask bitmap
 Call DeleteDC(MaskDC) 'Delete MaskDC
End Sub


Other 1 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.