PDA

View Full Version : Xin chi giao voi



hunken_captain
28-03-2004, 10:18
Ba con nao co code load file PNG,TIF,TARGA khong,neu co demo cang tot,tui dang rat can no.Ah ma lam cach nao Transparent Form va picture vay ba con
xin chi dum, tai bo lau qua nen quen het tron roi. Cam on nhieu

Nhắc bạn đọc nội quy diễn đàn
http://www.diendantinhoc.com/announcement.htm?f=7

ITbaby
31-03-2004, 04:09
Cháu xin nhắc nhở anh hunken_captain là đã vi phạm qui định của diễn đàn ( Gõ tiếng việt không dấu: Mới làm Mod :D :D).
Còn về các đoạn Code về Transparent Form và Picture thì từ trước đến nay đã có rất nhiều bài thảo luận về vấn đề này, bữa sau nhớ dùng tính năng Search của diễn đàn anh nhen :D
Anh hãy search lại trong BOX này lại các bài viết về Transparent nhé.
Sẵn đây thì cháu cũng Post luôn Code dùng đề Trangsparent Form và Picture :
1: Transparent Form : anh tạo Project mới và chép hết Code sau vào nhé

'Requires Windows 2000 or later; Win9x/ME: Not supported
Const LWA_COLORKEY = &H1
Const LWA_ALPHA = &H2
Const GWL_EXSTYLE = (-20)
Const WS_EX_LAYERED = &H80000
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hWnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Private Sub Form_Load()
'KPD-Team 2000
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
Dim Ret As Long
'Set the window style to 'Layered'
Ret = GetWindowLong(Me.hWnd, GWL_EXSTYLE)
Ret = Ret Or WS_EX_LAYERED
SetWindowLong Me.hWnd, GWL_EXSTYLE, Ret
'Set the opacity of the layered window to 128
SetLayeredWindowAttributes Me.hWnd, 0, 128, LWA_ALPHA
End Sub

2: Transparent Picture :
anh dùng hàm TransparentBlt nhé, anh có thể tham khảo đoạn Code sau cũng được

Option Explicit

Private Declare Function TransparentBlt Lib "msimg32.dll" (ByVal hdc 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 nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal crTransparent As Long) As Boolean
Private Sub Form_Load()
'KPD-Team 1999
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
Picture1.AutoSize = True
'API uses pixels
Picture1.ScaleMode = vbPixels
Picture2.ScaleMode = vbPixels
End Sub
Private Sub Picture2_Paint()
'If we don't call DoEvents first, our transparent image will be completely wrong
DoEvents
TransparentBlt Picture2.hdc, 0, 0, Picture2.ScaleWidth, Picture2.ScaleHeight, Picture1.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, vbWhite
End Sub

Còn các cái kia thì cháu chịu :D :D
Nhớ nhá, gõ tiếng Việt có dấu đàng hòang nhen