Страница: 1 |
Вопрос: Окно произвольного размера. Помогите!
Добавлено: 01.02.09 16:40
Автор вопроса: AleXandr | ICQ: 490033736
Как сделать окно произвольного размера, с красивой тенью как в висте. есть png картинка у которой центр непрозрачный,а края полупрозрачные и углы закругленные как наложить ее на форму чтобы просвечивался задний план там где картинка полупрозрачна. Помогите!!! Заранее спасибо.
Ответить
Номер ответа: 3Автор ответа: VβÐ
Вопросов: 15Ответов: 194
Web-сайт: www.homacosoft.com Профиль | | #3
Добавлено: 01.02.09 18:56
Option Explicit
Private Const ULW_ALPHA = &H2
Private Const DIB_RGB_COLORS As Long = 0
Private Const AC_SRC_ALPHA As Long = &H1
Private Const AC_SRC_OVER = &H0
Private Const WS_EX_LAYERED = &H80000
Private Const GWL_EXSTYLE As Long = -20
Private Const HWND_TOPMOST As Long = -1
Private Const SWP_NOMOVE As Long = &H2
Private Const SWP_NOSIZE As Long = &H1
Private Type BLENDFUNCTION
BlendOp As Byte
BlendFlags As Byte
SourceConstantAlpha As Byte
AlphaFormat As Byte
End Type
Private Type Size
cx As Long
cy As Long
End Type
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Type RGBQUAD
rgbBlue As Byte
rgbGreen As Byte
rgbRed As Byte
rgbReserved As Byte
End Type
Private Type BITMAPINFOHEADER
biSize As Long
biWidth As Long
biHeight As Long
biPlanes As Integer
biBitCount As Integer
biCompression As Long
biSizeImage As Long
biXPelsPerMeter As Long
biYPelsPerMeter As Long
biClrUsed As Long
biClrImportant As Long
End Type
Private Type BITMAPINFO
bmiHeader As BITMAPINFOHEADER
bmiColors As RGBQUAD
End Type
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 UpdateLayeredWindow Lib "user32.dll" (ByVal hwnd As Long , _
ByVal hdcDst As Long , pptDst As Any, psize As Any, ByVal hdcSrc As Long , pptSrc As Any, ByVal crKey As Long , ByRef pblend As BLENDFUNCTION, ByVal dwFlags As Long ) As Long
Private Declare Function CreateDIBSection Lib "gdi32.dll" (ByVal hdc As Long , _
pBitmapInfo As BITMAPINFO, ByVal un As Long , ByRef lplpVoid As Any, _
ByVal handle As Long , ByVal dw As Long ) As Long
Private Declare Function CreateCompatibleDC Lib "gdi32.dll" (ByVal hdc As Long ) As Long
Private Declare Function SelectObject Lib "gdi32.dll" (ByVal hdc As Long , _
ByVal hObject As Long ) As Long
Private Declare Function SetWindowPos Lib "user32.dll" (ByVal hwnd As Long , _
ByVal hWndInsertAfter As Long , ByVal X As Long , ByVal Y As Long , ByVal cx As Long , ByVal cy As Long , ByVal wFlags As Long ) As Long
Private Declare Function GetWindowLong Lib "user32.dll" Alias "GetWindowLongA" _
(ByVal hwnd As Long , ByVal nIndex As Long ) As Long
Private mDC As Long
Private mainBitmap As Long
Private blendFunc32bpp As BLENDFUNCTION
Private token As Long
Private oldBitmap As Long
Private Declare Sub ReleaseCapture Lib "user32" ()
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long , ByVal wMsg As Long , ByVal wparam As Integer , ByVal iparam As Long ) As Long
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long , ByVal lpOperation As String , ByVal lpFile As String , ByVal lpParameters As String , ByVal lpDirectory As String , ByVal nShowCmd As Long ) As Long
Private Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Long ) As Long
Private Function MakeTrans(pngPath As String ) As Boolean
Dim tempBI As BITMAPINFO
Dim lngHeight As Long
Dim lngWidth As Long
Dim curWinLong As Long
Dim img As Long
Dim graphics As Long
Dim winSize As Size
Dim srcPoint As POINTAPI
With tempBI.bmiHeader
.biSize = Len(tempBI.bmiHeader)
.biBitCount = 32
.biHeight = ScaleHeight
.biWidth = ScaleWidth
.biPlanes = 1
.biSizeImage = .biWidth * .biHeight * (.biBitCount / 8)
End With
mDC = CreateCompatibleDC(hdc)
mainBitmap = CreateDIBSection(mDC, tempBI, DIB_RGB_COLORS, ByVal 0, 0, 0)
oldBitmap = SelectObject(mDC, mainBitmap)
Call GdipCreateFromHDC(mDC, graphics)
Call GdipLoadImageFromFile(StrConv(pngPath, vbUnicode), img)
Call GdipGetImageHeight(img, lngHeight)
Call GdipGetImageWidth(img, lngWidth)
Call GdipDrawImageRect(graphics, img, 0, 0, lngWidth, lngHeight)
curWinLong = GetWindowLong(hwnd, GWL_EXSTYLE)
SetWindowLong hwnd, GWL_EXSTYLE, curWinLong Or WS_EX_LAYERED
SetWindowPos hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
srcPoint.X = 0
srcPoint.Y = 0
winSize.cx = ScaleWidth
winSize.cy = ScaleHeight
With blendFunc32bpp
.AlphaFormat = AC_SRC_ALPHA
.BlendFlags = 0
.BlendOp = AC_SRC_OVER
.SourceConstantAlpha = 255
End With
Call GdipDisposeImage(img)
Call GdipDeleteGraphics(graphics)
Call UpdateLayeredWindow(hwnd, hdc, ByVal 0&, winSize, mDC, srcPoint, 0, blendFunc32bpp, ULW_ALPHA)
End Function
Пример:
Private Sub Form_Load()
MakeTrans App.Path & "\Back.png"
End Sub
Ответить
Страница: 1 |
Поиск по форуму