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_Button = 500
%IDC_TextBox = 501
Global hDlg As Dword
Function PBMain() As Long
Dialog New Pixels, 0, "Save Control Image",300,300,250,150, %WS_SysMenu, 0 To hDlg
Control Add Button, hDlg, %IDC_Button,"Save to File", 120,10,90,30
Control Add TextBox, hDlg, %IDC_TextBox,"cowgirl", 10,10,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 And Cb.CtlMsg = %STN_Clicked Then
Local hSource As Dword, w,h As Long
Control Get Size hDlg, %IDC_TextBox To w,h
Control Handle hDlg, %IDC_TextBox To hSource
SaveControlImage hSource, w,h, "control.bmp"
End If
End Function
Sub SaveControlImage(hWin As Dword, w As Long, h As Long, FileName As String)
Local hDCSource, hBMP, hDCdest As Dword
hDCSource = GetDC(hWin) 'get handle of source
Graphic Bitmap New w,h To hBMP
Graphic Attach hBMP, 0
Graphic Get DC To hDCDest 'get destination DC (hBMP is destination)
BitBlt hDCdest,0,0,w-1,h-1,hDCsource, 0,0, %SRCCopy 'copy source to destination
ReleaseDC(hWin, hDCSource) 'release control DC
Graphic Save FileName 'save
End Sub
'gbs_01282
'Date: 05-11-2013
http://www.garybeene.com/sw/gbsnippets.htm