'模塊中
創(chuàng)新互聯(lián)公司專注于企業(yè)成都營銷網(wǎng)站建設(shè)、網(wǎng)站重做改版、下花園網(wǎng)站定制設(shè)計、自適應(yīng)品牌網(wǎng)站建設(shè)、HTML5建站、商城網(wǎng)站定制開發(fā)、集團公司官網(wǎng)建設(shè)、成都外貿(mào)網(wǎng)站建設(shè)、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁設(shè)計等建站業(yè)務(wù),價格優(yōu)惠性價比高,為下花園等各大城市提供網(wǎng)站開發(fā)制作服務(wù)。
Declare Function GetDC Lib "user32" (ByVal hwnd As Long) _
As Long
Public Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc 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
'form1中
Private Sub Command1_Click()
Dim hDCtmp As Long, picWidth As Double, picHeight As Double
Dim x As Double
Dim y As Double
x = Val(Text2.Text)
y = Val(Text3.Text)
picWidth = Val(Text3.Text)
picHeight = Val(Text4.Text)
hDCtmp = GetDC(0)
BitBlt Picture1.hdc, 0, 0, picWidth, picHeight, hDCtmp, x, y, vbSrcCopy
ReleaseDC 0, hDCtmp
End Sub
目的: 將屏幕按照指定坐標和大小進行截取成圖,在picture1顯示
問題: 大小是相同了,為什么截取的坐標不對,只是屏幕上的左上
相信大家都用過QQ截圖功能。不過很多人并沒有真正掌握好它的用法。將QQ截圖與其它截屏和制圖軟件配合使用,會有意想不到的效果。
獲取顏色的RGB值
我們在編輯圖片或網(wǎng)頁的時候,經(jīng)常需要獲取某種顏色的“RGB值”,所以很多人都安裝了第三方的顏色吸取工具。其時用QQ截圖鍵即可獲取屏幕上任意顏色的RGB值。
當按下“Ctrl+Shift+A”彈出“截圖”提示框時,提示框中的“當前像素RGB”即為當前鼠標屏幕位置的顏色RGB值,將鼠標移動到你想查看的屏幕顏色上即可獲得相應(yīng)的RGB值(如圖1)。
圖1精確截取圖片大小
有時我們對要使用的截圖尺寸有嚴格要求,比如論壇簽名或QQ頭像等。用QQ截圖鍵可以按尺寸精確截取,一步到位無需再進行后期裁剪了。
按下QQ截圖鍵,按住鼠標不放選取截取范圍時,在鼠標上方會有一個信息框顯示當前范圍的詳細信息,其中“矩形大小”就是以像素來表示的圖片的尺寸大小,括號內(nèi)的數(shù)字分別表示的是長和高(如圖2)。松開鼠標調(diào)整截圖框時,對照“矩形大小”就可以按需要的尺寸來精確截圖范圍,然后用鼠標點住截圖框?qū)⒔貓D框拖到要截取的圖片上,雙擊即可獲得所需尺寸的圖片了。
圖2圖片拼貼好幫手
大部分的截圖軟件一次只能截取一張圖片,當要截取多張圖片并進行拼貼組合時,就需要一張一張截取全部保存后再進行拼貼操作,非常麻煩。
我們知道用QQ截圖鍵截取的圖片可以在任一個可以粘貼圖片的程序中使用,這樣只需用截圖軟件進行一次截圖操作,剩下的圖片用QQ截圖鍵來截取,然后依次粘貼到截圖軟件的窗口中即可快速進行拼貼操作了,是不是很方便啊。
小提示:QQ截圖鍵無需打開聊天窗口即可使用,截取的圖片在任一可粘貼圖片的程序窗口中如畫圖、Word等,使用“粘貼”命令即可使用
既然能夠取得整個屏幕,可以取到整個屏幕以后創(chuàng)建一個全屏窗體顯示靜態(tài)的屏幕圖像,然后在窗體上實現(xiàn)部分截取。
估計別的截圖也是這個原理,因為一點開始截圖屏幕就變?yōu)殪o態(tài)不動了,肯定是在截圖初期復(fù)制了當時的屏幕場景
用datagridview
排序的話datagridview自身的功能就能實現(xiàn)
你說的標簽如果是指雙擊或者單擊或者右擊有相應(yīng)的反應(yīng)的話
需要在后臺編寫相應(yīng)事件
操作還是比較方便的
可以將Webbroser的位置記錄下來,然后按照位置屏幕截圖,就截取到了webbroser里面的圖片,再通過picture顯示出來就可以了;
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
' CreateBitmapPicture
' - Creates a bitmap type Picture object from a bitmap and
' palette.
'
' hBmp
' - Handle to a bitmap.
'
' hPal
' - Handle to a Palette.
' - Can be null if the bitmap doesn't use a palette.
'
' Returns
' - Returns a Picture object containing the bitmap.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
Public Function CreateBitmapPicture(ByVal hBmp As Long, ByVal hPal As Long) As Picture
Dim r As Long
Dim Pic As PicBmp
' IPicture requires a reference to "Standard OLE Types."
Dim IPic As IPicture
Dim IID_IDispatch As GUID
' Fill in with IDispatch Interface ID.
With IID_IDispatch
.Data1 = H20400
.Data4(0) = HC0
.Data4(7) = H46
End With
' Fill Pic with necessary parts.
With Pic
.Size = Len(Pic) ' Length of structure.
.Type = vbPicTypeBitmap ' Type of Picture (bitmap).
.hBmp = hBmp ' Handle to bitmap.
.hPal = hPal ' Handle to palette (may be null).
End With
' Create Picture object.
r = OleCreatePictureIndirect(Pic, IID_IDispatch, 1, IPic)
' Return the new Picture object.
Set CreateBitmapPicture = IPic
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
' CaptureWindow
' - Captures any portion of a window.
'
' hWndSrc
' - Handle to the window to be captured.
'
' Client
' - If True CaptureWindow captures from the client area of the
' window.
' - If False CaptureWindow captures from the entire window.
'
' LeftSrc, TopSrc, WidthSrc, HeightSrc
' - Specify the portion of the window to capture.
' - Dimensions need to be specified in pixels.
'
' Returns
' - Returns a Picture object containing a bitmap of the specified
' portion of the window that was captured.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''
'
Public Function CaptureWindow(ByVal hWndSrc As Long, ByVal Client As Boolean, ByVal LeftSrc As Long, ByVal TopSrc As Long, ByVal WidthSrc As Long, ByVal HeightSrc As Long) As Picture
Dim hDCMemory As Long
Dim hBmp As Long
Dim hBmpPrev As Long
Dim r As Long
Dim hDCSrc As Long
Dim hPal As Long
Dim hPalPrev As Long
Dim RasterCapsScrn As Long
Dim HasPaletteScrn As Long
Dim PaletteSizeScrn As Long
Dim LogPal As LOGPALETTE
' Depending on the value of Client get the proper device context.
If Client Then
hDCSrc = GetDC(hWndSrc) ' Get device context for client area.
Else
hDCSrc = GetWindowDC(hWndSrc) ' Get device context for entire window.
End If
' Create a memory device context for the copy process.
hDCMemory = CreateCompatibleDC(hDCSrc)
' Create a bitmap and place it in the memory DC.
hBmp = CreateCompatibleBitmap(hDCSrc, WidthSrc, HeightSrc)
hBmpPrev = SelectObject(hDCMemory, hBmp)
' Get screen properties.
RasterCapsScrn = GetDeviceCaps(hDCSrc, RASTERCAPS) ' Raster
' capabilities.
HasPaletteScrn = RasterCapsScrn And RC_PALETTE ' Palette
' support.
PaletteSizeScrn = GetDeviceCaps(hDCSrc, SIZEPALETTE) ' Size of
' palette.
' If the screen has a palette make a copy and realize it.
If HasPaletteScrn And (PaletteSizeScrn = 256) Then
' Create a copy of the system palette.
LogPal.palVersion = H300
LogPal.palNumEntries = 256
r = GetSystemPaletteEntries(hDCSrc, 0, 256, LogPal.palPalEntry(0))
hPal = CreatePalette(LogPal)
' Select the new palette into the memory DC and realize it.
hPalPrev = SelectPalette(hDCMemory, hPal, 0)
r = RealizePalette(hDCMemory)
End If
' Copy the on-screen image into the memory DC.
r = BitBlt(hDCMemory, 0, 0, WidthSrc, HeightSrc, hDCSrc, LeftSrc, TopSrc, vbSrcCopy)
' Remove the new copy of the on-screen image.
hBmp = SelectObject(hDCMemory, hBmpPrev)
' If the screen has a palette get back the palette that was
' selected in previously.
If HasPaletteScrn And (PaletteSizeScrn = 256) Then
hPal = SelectPalette(hDCMemory, hPalPrev, 0)
End If
' Release the device context resources back to the system.
r = DeleteDC(hDCMemory)
r = ReleaseDC(hWndSrc, hDCSrc)
' Call CreateBitmapPicture to create a picture object from the
' bitmap and palette handles. Then return the resulting picture
' object.
Set CaptureWindow = CreateBitmapPicture(hBmp, hPal)
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
' CaptureScreen
' - Captures the entire screen.
'
' Returns
' - Returns a Picture object containing a bitmap of the screen.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
Public Function CaptureScreen() As Picture
Dim hWndScreen As Long
Dim Wwidth As Long
Dim Wheight As Long
Wwidth = GetSystemMetrics(SM_CXSCREEN)
Wheight = GetSystemMetrics(SM_CYSCREEN)
' Get a handle to the desktop window.
hWndScreen = GetDesktopWindow()
' Call CaptureWindow to capture the entire desktop give the handle
' and return the resulting Picture object. Screen.width / Screen.TwipsPerPixelX**********Screen.Height / Screen.TwipsPerPixelY
Set CaptureScreen = CaptureWindow(hWndScreen, True, 0, 0, Wwidth, Wheight)
End Function
把上面的代碼放到一個bas模塊中,在窗體上放一個Picture控件,然后用類似下面的代碼來抓屏:
Visual Basic code?
1
2
3
Private Sub Command1_Click()
Set Picture1.Picture = CaptureScreen
End Sub
另外代碼中那個CaptureWindow是抓取窗口的。
參考:
這是捕捉鍵盤熱鍵,例如QQ寫的一個抓屏功能,同時按下Ctrl+Alt+A 就會自動 跳出抓屏。
也就是說上面這段代碼自動獲取到的熱鍵符合Ctrl+Alt+A 的命令,所以才會執(zhí)行事件。
If m.Msg = WM_SYSCOMMAND Then' 如果m 的熱鍵碼 有系統(tǒng)命令 執(zhí)行以下事件。