Date: 02-16-2022
Return to Index
'Compilable Example: (Jose Includes)
created by gbSnippets
#Compiler PBWin 10
#Compile Exe
#Dim All
%Unicode = 1
#Include "Win32API.inc"
Enum Equates Singular
IDC_Button = 500
IDC_TextBox
End Enum
Global hDlg,hTextBox,hButton As Dword
Function PBMain() As Long
Dialog New Pixels, 0, "PowerBASIC",300,300,250,150, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, %IDC_Button,"Capture OffScreen TextBox", 10,10,180,20
Control Handle hDlg, %IDC_Button To hButton
Control Add TextBox, hDlg, %IDC_TextBox,"OffScreen TextBox", 10,50,150,20
Control Handle hDlg, %IDC_TextBox To hTextBox
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local hBMP,hDC_Graphic,hDC_TextBox,hBitmap As Dword, iResult As Long
Select Case Cb.Msg
Case %WM_Command
Select Case Cb.Ctl
Case %IDC_Button
'create memory DC
Graphic Bitmap New 150,20 To hBMP
Graphic Attach hBMP, 0
Graphic Get DC To hDC_Graphic
'create TextBox DC
hDC_TextBox = GetWindowDC(hTextBox)
hBitmap = CreateCompatibleBitmap(hDC_Graphic, 150,20)
SelectObject hDC_TextBox,hBitmap
'copy textbox to memory DC
iResult = PrintWindow(hTextBox, hDC_Graphic, %PW_ClientOnly)
' iResult = PrintWindow(hDLG, hDC_Graphic, %PW_ClientOnly)
Graphic ReDraw
'put memory bitmap on clipboard
Clipboard Reset
Clipboard Set Bitmap hBMP
'cleanup
ReleaseDC hDC_TextBox, hDC_TextBox
Graphic Bitmap End
? "TextBox image placed on clipboard!" + Str$(iResult)
End Select
End Select
End Function
'gbs_01433
'Date: 10-17-2014
http://www.garybeene.com/sw/gbsnippets.htm