Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compile Exe
#Dim All
%Unicode=1
#Include "Win32api.inc"
%IDC_Graphic = 500
Global hDlg, hBMP, hGraphic As Dword
Global hBMPDC, hDeskTopDC As Dword
Global wDeskTop, hDeskTop, ClickCount As Long
Global ptA, ptB As Point
Function PBMain() As Long
Desktop Get Size To wDeskTop, hDeskTop
Dialog New Pixels, 0, "",0,0,wDeskTOp,hDeskTop, %WS_Popup To hDlg
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case Cb.Msg
Case %WM_InitDialog
CreateMemoryBitmapSameSizeAsDeskTop
PutDeskTopImageIntoMemoryBitmap
CreateGraphicControl
Graphic Copy hBMP, 0
Case %WM_ContextMenu : Dialog End hDlg
Case %WM_Help : SaveImage
Case %WM_Command
Select Case Cb.Ctl
Case %IdCancel : Dialog End hDlg
Case %IDC_Graphic
Select Case Cb.CtlMsg
Case %STN_Clicked : RespondToClick
End Select
End Select
End Select
End Function
Sub CreateMemoryBitmapSameSizeAsDeskTop
'create memory bitmap the size of the desktop
Graphic Bitmap New wDeskTop,hDeskTop To hBMP
Graphic Attach hBMP,0
Graphic Get DC To hBMPDC
End Sub
Sub PutDeskTopImageIntoMemoryBitmap
'bitblt desktop image memory bitmap
hDeskTopDC = GetDC(%Null)
BitBlt hBMPDC, 0,0,wDeskTop,hDeskTop, hDeskTopDC, 0,0, %SRCCopy
ReleaseDC(%Null,hDeskTopDC)
End Sub
Sub CreateGraphicControl
Control Add Graphic, hDlg, %IDC_Graphic,"", 0,0,wDeskTop,hDeskTop, %SS_Notify
Control Handle hDlg, %IDC_Graphic To hGraphic
Graphic Attach hDlg, %IDC_Graphic
End Sub
Sub RespondToClick
Graphic Width 11
If ClickCount Then
Graphic Copy hBMP, 0
GetCursorPos ptB : ScreenToClient hDlg, ptB
SaveImage 'bounded by ptA and ptB
ClickCount = 0
Graphic Box (ptA.x-5,ptA.y-5)-(ptB.x+5,ptB.y+5),,%Red
Graphic ReDraw
Sleep 1000
Dialog End hDlg
Else
GetCursorPos ptA : ScreenToClient hDlg, ptA
Graphic Box (ptA.x-5,ptA.y-5)-(ptA.x+5,ptA.y+5),,%Red 'outside the area to save
Graphic ReDraw
ClickCount = 1
End If
End Sub
Sub SaveImage
Local hBMP_Small As Dword
Graphic Bitmap New ptB.x-ptA.x,ptB.y-ptA.y To hBMP_Small
Graphic Attach hBMP_Small, 0
Graphic Copy hGraphic,0, (ptA.x,ptA.y)-(ptB.x,ptB.y) To (0,0), %Mix_CopySrc
'send to clipboard so can see resuljts
Clipboard Reset
Clipboard Set Bitmap hBMP_Small
'back to the main graphic
Graphic Attach hDlg, %IDC_Graphic
End Sub
http://www.garybeene.com/sw/gbsnippets.htm