Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compiler PBWin 10
#Compile Exe
#Dim All
%Unicode=1
#Include "Win32API.inc"
%IDC_TextBox = 500
%IDC_Button = 501
Global hDlg As Dword
Function PBMain() As Long
Dialog New Pixels, 0, "Save Control Image",300,300,240,160, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, %IDC_Button,"Copy Control", 50,10,120,20
Control Add TextBox, hDlg, %IDC_TextBox,"The best time is now!", 10,40,100,100, %WS_Child Or %WS_Visible Or %ES_MultiLine Or %WS_TabStop Or %WS_Border
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
If Cb.Msg = %WM_Command And Cb.Ctl = %IDC_Button Then
Local w,h As Long, pt As Point
Control Get Loc hDlg, %IDC_TextBox To pt.x, pt.y
ClientToScreen hDlg, pt
Control Get Size hDlg, %IDC_TextBox To w,h
CopyPartOfScreenToFile(pt.x, pt.y,w,h, "control.bmp")
End If
End Function
Sub CopyPartOfScreenToFile (x As Long, y As Long, w As Long, h As Long, FileName As String)
Local hBMP, hBMPDC, hDeskTopDC As Dword
Graphic Bitmap New w,h To hBMP 'create memory bitmap the size of the dialog
Graphic Attach hBMP,0
Graphic Get DC To hBMPDC
hDeskTopDC = GetDC(%Null)
BitBlt hBMPDC, 0,0,w,h, hDeskTopDC, x,y, %SRCCopy 'copy specified section of desktop image to memory bitmap
ReleaseDC(%Null,hDeskTopDC)
Graphic Save FileName 'save to file
End Sub
'gbs_01283
'Date: 05-11-2013
http://www.garybeene.com/sw/gbsnippets.htm