Не помню задавал ли я этот вопрос или нет, во всяком случае он опять меня мучает.. итак: есть несколько пикчербоксов с картинками и объект StdPicture. Вопрос: как сделать так, чтобы содержимое пикчербоксов скопировалось (определённые координаты вставки) в объект StdPicture, т.е. сначала одна картинка потом вторая...
И как это всё потом сохранить ?
Дело вот в чём.. StdPicture - объект как бы виртуальный, т.е. это рисунок, но мы его не видим (временное хранилище). Но ведь он назначается только так:
Dim X as new StdPicture
Set X = Picture1.Image
. Получается он с BitBlt никак не может быть связан.. Или я что-то путаю ? Короче, надо просто сделать что-то вроде ленточки из трёх кадров и сохранить..
Нда, похоже, чтобы не было проблем, надо пользоваться таким кодом:
Private 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
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Private Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function EmptyClipboard Lib "user32" () As Long
Private Declare Function SetClipboardData Lib "user32" (ByVal wFormat As Long, ByVal hMem As Long) As Long
Private Declare Function CloseClipboard Lib "user32" () As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function CreateDC Lib "gdi32" Alias "CreateDCA" (ByVal lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As String, lpInitData As DEVMODE) As Long
Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Const CCHDEVICENAME = 32
Private Const CCHFORMNAME = 32
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type DEVMODE
dmDeviceName As String * CCHDEVICENAME
dmSpecVersion As Integer
dmDriverVersion As Integer
dmSize As Integer
dmDriverExtra As Integer
dmFields As Long
dmOrientation As Integer
dmPaperSize As Integer
dmPaperLength As Integer
dmPaperWidth As Integer
dmScale As Integer
dmCopies As Integer
dmDefaultSource As Integer
dmPrintQuality As Integer
dmColor As Integer
dmDuplex As Integer
dmYResolution As Integer
dmTTOption As Integer
dmCollate As Integer
dmFormName As String * CCHFORMNAME
dmUnusedPadding As Integer
dmBitsPerPel As Integer
dmPelsWidth As Long
dmPelsHeight As Long
dmDisplayFlags As Long
dmDisplayFrequency As Long
End Type
Public Sub Capture(control_hWnd As Long, fNAME As String, Optional OnlyToClipBoard As Boolean = False)
Dim sp As RECT, x As Long
If fNAME <> "" Then
x = GetWindowRect(control_hWnd, sp)
ScrnCap sp.Left, sp.Top, sp.Right, sp.Bottom
If OnlyToClipBoard = False Then
SavePicture Clipboard.GetData, fNAME
End If
End If
End Sub
Private Sub ScrnCap(Lt, Top, Rt, Bot)
Dim rWIDTH As Long, rHEIGHT As Long
Dim SourceDC As Long, DestDC As Long, bHANDLE As Long, Wnd As Long
Dim dHANDLE As Long, dm As DEVMODE
rWIDTH = Rt - Lt
rHEIGHT = Bot - Top
SourceDC = CreateDC("ISPLAY", 0&, 0&, dm)
DestDC = CreateCompatibleDC(SourceDC)
bHANDLE = CreateCompatibleBitmap(SourceDC, rWIDTH, rHEIGHT)
SelectObject DestDC, bHANDLE
BitBlt DestDC, 0, 0, rWIDTH, rHEIGHT, SourceDC, Lt, Top, &HCC0020
Wnd = 0
OpenClipboard Wnd
EmptyClipboard
SetClipboardData 2, bHANDLE
CloseClipboard
DeleteDC DestDC
ReleaseDC dHANDLE, SourceDC
End Sub
Private Sub Command1_Click()
BitBlt StdPicture.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, Picture1.hdc, 0, 0, vbSrcCopy
BitBlt StdPicture.hdc, 32, 0, Picture2.ScaleWidth, Picture2.ScaleHeight, Picture2.hdc, 0, 0, vbSrcCopy
Call Capture(StdPicture.hwnd, ":\1.bmp"
End Sub
Рисунок сохраняется при нажатии на кнопку Command1, там же функции BitBlt стыкуют 2 Picture-box и результат выводиться на третий (StdPicture – это тоже Picture-box), чтобы все правильно работало, надо изменить значения размеров изображения на нужные. И свойство всех Picture-box ScaleMode должно равняться 3 (пиксел).
Может тогда проще использовать какой-нибудь скрытый Picture3 и в нем склеивать? StdPicture используют когда памяти жалко и хочется скорости (StdPicture - не PictureBox)