$TYPECHECK ON
DECLARE SUB BMPresize()
DECLARE SUB FormKeyPress(TheKey AS WORD, Shift AS INTEGER)
DECLARE SUB OpenBMP
DECLARE SUB FormRePaint
$INCLUDE <RapidQ2.inc>
'this allows the program to run easy! no DLL to find for user
$RESOURCE jpeg_DLL AS "jpeg.dll" 'or use jpeg.dll
'$RESOURCE NviewLib_DLL AS "nviewlib.dll" 'or use this
IF NViewLibPresent = 0 THEN
EXTRACTRESOURCE Resource(0), "jpeg.dll"
NViewLibPresent = 2 'signal we have jpeg
' EXTRACTRESOURCE Resource(0), "nviewlib.dll"
' NViewLibPresent = 1 'signal nviewlib
END IF
CREATE Form AS QFORM
Caption = "Click to open file <Ctrl-C,Ctrl-V to copy/paste"
Width = 200
Height = 200
BorderStyle = bsSizeToolWin
OnClick = OpenBMP
OnKeyDown = FormKeyPress
OnResize = BMPresize
OnPaint = FormRePaint
END CREATE
CREATE TheBMP AS QBITMAPEx
Width = Form.ClientWidth
Height = Form.ClientHeight
PixelFormat = pf24bit
END CREATE
DIM TmpBMP AS QBITMAPEx 'sorry QbitmapEx must be declared global
Form.ShowModal
SUB OpenBMP
DIM OpenDialog AS QOPENDIALOG
OpenDialog.Caption = "Open a BitmapFile"
OpenDialog.Filename = ""
OpenDialog.filter = "images|*.BMP;*.JPG|All Files|*.*"
OpenDialog.FilterIndex = 1 ' Use ".bmp" as our default
IF OpenDialog.Execute THEN
IF INSTR(UCASE$(OpenDialog.FileName), ".BMP") THEN
TheBMP.LoadFromFile(OpenDialog.FileName)
ELSE
TheBMP.LoadOtherImage(OpenDialog.FileName, 0, "")
END IF
Form.ClientWidth = TheBMP.Width
Form.ClientHeight = TheBMP.Height
Form.Repaint 'force bmp draw
END IF
END SUB
SUB FormKeyPress(TheKey AS WORD, Shift AS INTEGER)
' CONST CtrlDown = 1
' CONST ShiftDown = 256
DIM x as integer, y as integer
IF TheKey = 67 THEN 'C key
IF (Shift = CtrlDown) THEN
DIM TheRect AS QRECT
TheRect.Right = Form.ClientWidth
TheRect.Bottom = Form.ClientHeight
TheRect.Top = 0
TheRect.Left = 0
TmpBMP.Width = Form.ClientWidth
TmpBMP.Height = Form.ClientHeight
TmpBMP.PixelFormat = pf24bit 'TheBMP.PixelFormat
TmpBMP.StretchDraw(TheRect, TheBMP.BMP)
TmpBMP.CopyToClipboard
END IF
END IF
IF TheKey = 86 THEN 'V key
IF (Shift = CtrlDown) THEN
IF TheBMP.CanPaste THEN
TheBMP.Width = TheBMP.GetWidthClipboard
TheBMP.Height = TheBMP.GetHeightClipboard
TheBMP.PasteFromClipboard(0,0)
Form.ClientWidth = TheBMP.Width
Form.ClientHeight = TheBMP.Height
Form.Repaint 'force bmp draw
END IF
END IF
END IF
END SUB
SUB BMPresize()
Form.Repaint
END SUB
SUB FormRePaint
DIM TheRect AS QRECT
TheRect.Right = Form.ClientWidth
TheRect.Bottom = Form.ClientHeight
TheRect.Top = 0
TheRect.Left = 0
Form.StretchDraw(TheRect, TheBMP.BMP)
END SUB