16,554
社区成员
发帖
与我相关
我的任务
分享
Imports System.Net
Imports System.IO
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim bmp As Bitmap = CaptureImage(Nothing)
Dim topWindow As New Form
msgText = "提示信息修改为这样,可以么?"
AddHandler topWindow.Load, AddressOf Form_Load
topWindow.FormBorderStyle = Windows.Forms.FormBorderStyle.None
topWindow.WindowState = FormWindowState.Maximized
topWindow.TopMost = True
topWindow.BackgroundImage = bmp
topWindow.Show()
End Sub
Private msgText As String = "这样提示可以么?"
Private Sub Form_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
MessageBox.Show(msgText)
CType(sender, Form).Close()
End Sub
'PictureBox1.Image = CaptureImage(Nothing)
'---save the video data into the Image global variable---
Public Function CaptureImage(ByRef c As Control) As Bitmap
Dim hDC, hMDC As Integer
Dim hBMP, hBMPOld As Integer
Dim sw, sh As Integer
If c Is Nothing Then
hDC = GetDC(0)
sw = Screen.PrimaryScreen.Bounds.Width
sh = Screen.PrimaryScreen.Bounds.Height
Else
hDC = GetDC(c.Handle)
sw = c.Width
sh = c.Height
End If
hMDC = CreateCompatibleDC(hDC)
hBMP = CreateCompatibleBitmap(hDC, sw, sh)
hBMPOld = SelectObject(hMDC, hBMP)
BitBlt(hMDC, 0, 0, sw, sh, hDC, 0, 0, SRCCOPY)
hBMP = SelectObject(hMDC, hBMPOld)
Dim result = Image.FromHbitmap(New IntPtr(hBMP))
DeleteDC(hDC)
DeleteDC(hMDC)
DeleteObject(hBMP)
Return result
End Function
Public Declare Function GetDC Lib "user32" Alias "GetDC" (ByVal hwnd As Integer) As Integer
Public Declare Function CreateCompatibleDC Lib "gdi32" Alias "CreateCompatibleDC" (ByVal hdc As Integer) As Integer
Public Declare Function CreateCompatibleBitmap Lib "gdi32" Alias "CreateCompatibleBitmap" (ByVal hdc As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer) As Integer
Public Declare Function BitBlt Lib "gdi32" Alias "BitBlt" (ByVal hDestDC As Integer, ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hSrcDC As Integer, ByVal xSrc As Integer, ByVal ySrc As Integer, ByVal dwRop As Integer) As Integer
Public Declare Function SelectObject Lib "gdi32" Alias "SelectObject" (ByVal hdc As Integer, ByVal hObject As Integer) As Integer
Public Declare Function DeleteDC Lib "gdi32" Alias "DeleteDC" (ByVal hdc As Integer) As Integer
Public Declare Function DeleteObject Lib "gdi32" Alias "DeleteObject" (ByVal hObject As Integer) As Integer
Public Const SRCCOPY = &HCC0020
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Object) As Integer
Private Const WM_CAP_START = &H400
Private Const WM_CAP_EDIT_COPY = (WM_CAP_START + 30)
End Class