Code: Select all
Procedure Error(message.s, fatal.b)
ErrorBuffer$ = Space(256)
FormatMessage_(#FORMAT_MESSAGE_FROM_SYSTEM, 0, GetLastError_(), 0, ErrorBuffer$, Len(ErrorBuffer$), 0)
MessageRequester("Error", message+Chr(10)+Chr(10)+ErrorBuffer$, 0)
If fatal
End
EndIf
EndProcedure
Global MDIFrame, MDIClient, hChild, hStatus, hToolBar, hMainMenu, hChildMenu, ActiveMDIChild
Global xPos, yPos, WindowWidth, WindowHeight, ChildNumber, ExtraWidth, ExtraHeight
Global hInstance
Global wc.WNDCLASSEX
Global ClassName$
Structure GdiplusStartupInput
GdiplusVersion.l
DebugEventCallback.l
SuppressBackgroundThread.l
SuppressExternalCodecs.l
EndStructure
; Structure CLSID
; Data1.l
; Data2.w
; Data3.w
; Data4.b
; EndStructure
Structure bsize
Width.l
Height.l
EndStructure
Structure bpoint
x.l
y.l
EndStructure
Structure ARGB
blue.b
green.b
red.b
alpha.b
EndStructure
Structure blendfunction
blendop.b
blendflags.b
sourceconstant.b
alphaformat.b
EndStructure
;Structure GUID
; Data1.l
; Data2.w
; Data3.w
; Data4.b
;EndStructure
Structure ImageItemInfo
Clsid.CLSID ; Codec identifier.
FormatID.GUID ; File format identifier. GUIDs that identify various file formats (ImageFormatBMP, ImageFormatEMF, And the like) are defined in Gdiplusimaging.h.
CodecName.s ; WCHAR * Pointer To a null-terminated string that contains the codec name.
DllName.s ; WCHAR * Pointer To a null-terminated string that contains the path name of the DLL in which the codec resides. If the codec is not in a DLL, this pointer is NULL.
FormatDescription.s ; WCHAR * Pointer To a null-terminated string that contains the name of the file format used by the codec.
FilenameExtension.s ; WCHAR * Pointer To a null-terminated string that contains all file-name extensions associated with the codec. The extensions are separated by semicolons.
MimeType.s ; WCHAR * Pointer To a null-terminated string that contains the mime type of the codec.
flags.l ; DWORD Combination of flags from the ImageCodecFlags enumeration.
Version.l ; DWORD Integer that indicates the version of the codec.
SigCount.l ; DWORD Integer that indicates the number of signatures used by the file format associated with the codec.
SigSize.l ; DWORD Integer that indicates the number of bytes in each signature.
SigPattern.l ; BYTE * Pointer To an array of bytes that contains the pattern For each signature.
SigMask.l ; BYTE * Pointer To an array of bytes that contains the mask For each signature.
EndStructure
Global Gdiplus, gdiplusToken, Bitmap, hbmReturn, encoderClsid
Global *GdiplusStartup, *GdipCreateBitmapFromFile, *GdipCreateHBITMAPFromBitmap, *GdipGetImageHeight, *GdipGetImageWidth, *GdiplusShutdown, *GdipSaveImageToFile, *GdipGetImageEncodersSize, *GdipGetImageEncoders, *GdipCreateBitmapFromHBITMAP
Procedure OpenImageFile(File$)
result = 0
If Gdiplus
FileWSize = (Len(File$)*2)+2
*FileW = CoTaskMemAlloc_(FileWSize)
If *FileW
If MultiByteToWideChar_(#CP_ACP, 0, File$, -1, *FileW, FileWSize)
Bitmap.l = 0
CallFunctionFast(*GdipCreateBitmapFromFile, *FileW, @Bitmap)
If Bitmap
hbmReturn.l = 0
;Dim argbtest.argb(0)
; argbtest(0)\blue=0
;;argbtest(0)\green=0
; argbtest(0)\red=0
; argbtest(0)\alpha=0
CallFunctionFast(*GdipCreateHBITMAPFromBitmap, Bitmap, @hbmReturn, 0)
;CallDebugger
;Error("hbitmap.", 0)
If hbmReturn
;hChild = CreateWindowEx_(#WS_EX_MDICHILD, ClassName$, "", #WS_CHILDWINDOW|#WS_TILEDWINDOW|#WS_CLIPSIBLINGS|#WS_CLIPCHILDREN|#WS_VISIBLE|$0000C000|#MDIS_ALLCHILDSTYLES, #CW_USEDEFAULT, #CW_USEDEFAULT, #CW_USEDEFAULT, #CW_USEDEFAULT, MDIClient, #NULL, hInstance, #NULL)
;If hChild
; SetWindowText_(hChild, File$)
; ShowWindow_(hChild, #SW_SHOW)
; ChildNumber+1
; result = 1
;EndIf
EndIf
Else
Error("GdipCreateBitmapFromFile() failed."+Chr(10)+File$+" is not a valid image file.", 0)
EndIf
EndIf
Else
SetLastError_(#ERROR_NOT_ENOUGH_MEMORY)
EndIf
CoTaskMemFree_(*FileW)
EndIf
ProcedureReturn hbmReturn
EndProcedure
CoInitialize_(#Null)
Gdiplus = OpenLibrary(0, "GDIPLUS.DLL")
If Gdiplus
*GdiplusStartup = GetFunction(0, "GdiplusStartup")
If *GdiplusStartup
gdpsi.GdiplusStartupInput
gdpsi\GdiplusVersion = 1
gdpsi\DebugEventCallback = 0
gdpsi\SuppressBackgroundThread = 0
gdpsi\SuppressExternalCodecs = 0
CallFunctionFast(*GdiplusStartup, @gdiplusToken, gdpsi, #Null)
If gdiplusToken
*GdipCreateBitmapFromFile = GetFunction(0, "GdipCreateBitmapFromFile")
*GdipCreateHBITMAPFromBitmap = GetFunction(0, "GdipCreateHBITMAPFromBitmap")
*GdipGetImageWidth = GetFunction(0, "GdipGetImageWidth")
*GdipGetImageHeight = GetFunction(0, "GdipGetImageHeight")
*GdipGetImageEncodersSize = GetFunction(0, "GdipGetImageEncodersSize")
*GdipGetImageEncoders = GetFunction(0, "GdipGetImageEncoders")
*GdipCreateBitmapFromHBITMAP = GetFunction(0, "GdipCreateBitmapFromHBITMAP")
*GdipSaveImageToFile = GetFunction(0, "GdipSaveImageToFile")
*GdiplusShutdown = GetFunction(0, "GdiplusShutdown")
Else
Gdiplus = 0
EndIf
Else
Gdiplus = 0
EndIf
Else
Gdiplus = 0
EndIf
hwnd=OpenWindow(0,400,400,400,400,#PB_Window_BorderLess,"alpha")
;Error("Set Window Long.", 0)
;File$ = OpenFileRequester("Open image file:", "", "BMP image (*.bmp)|*.bmp|JPEG image (*.jpg)|*.jpg|PNG image (*.png)|*.png|TIFF image (*.tif)|*.tif|GIF image (*.gif)|*.gif|All files (*.*)|*.*", #PB_Requester_MultiSelection)
CreateGadgetList(WindowID(0))
ButtonGadget(1,10,10,100,20,"HELLO WORLD")
showwindow_(WindowID(0), #SW_SHOW)
updatewindow_(WindowID(0))
hdc = getdc_(WindowID(0))
mdc = createcompatibledc_(hdc)
hbm = createcompatiblebitmap_(hdc, GadgetWidth(1), GadgetHeight(1))
oldb = Selectobject_(mdc, hbm)
bitblt_(mdc, 0, 0, GadgetWidth(1), GadgetHeight(1), hdc, GadgetX(1), GadgetY(1), #SRCCOPY)
releasedc_(WindowID(0), hdc)
SetWindowLong_(WindowID(0),#GWL_EXSTYLE,GetWindowLong_(WindowID(0),#GWL_EXSTYLE)|$00080000)
bitmap1=OpenImageFile("test.png")
;File$ = NextSelectedFileName()
;Error("Open Image.", 0)
width1.l=0
;CallFunctionFast(*GdipGetImageWidth, bitmap1, @width1)
screenDc=GetDC_(WindowID(0))
;Error("GetDc.", 0)
memDc=CreateCompatibleDC_(screenDc)
;Error("Create Compat.", 0)
oldbitmap=SelectObject_(memDc, bitmap1)
bitblt_(memDc, GadgetX(1), GadgetY(1), GadgetWidth(1), GadgetHeight(1), mdc, 0, 0, #SRCCOPY)
Selectobject_(mdc, oldb)
deleteobject_(hbm)
deleteobject_(mdc)
;Error("SelectObj.", 0)
;Code now gets BMP SIze dynamically thanks to PolyVector!
GetObject_(bitmap1,SizeOf(BITMAP),bmInfo.BITMAP)
bitmapsize.bsize
bitmapsize\Width=bmInfo\bmWidth
bitmapsize\Height=bmInfo\bmHeight
;Old code for hardcoded size
;bitmapsize.bsize
;bitmapsize\width=450
;bitmapsize\height=175
pointsource.bpoint
pointsource\x=0
pointsource\y=0
topPos.bpoint
topPos\x=400
topPos\y=400
BlendFunc.blendfunction
BlendFunc\blendop=0
BlendFunc\blendflags=0
BlendFunc\sourceconstant=255;
BlendFunc\alphaformat=1
UpdateLayeredWindow_(WindowID(0), screenDc, #Null, bitmapsize, memDc, pointsource, 0, BlendFunc, 2);
;Error("Update Layered failed.", 0)
;
;
;hbitmap=gethbitmap_(0)
ReleaseDC_(#Null,screenDc)
SelectObject_(memDc,oldbitmap)
DeleteObject_(hbitmap)
DeleteDC_(memDc)
Repeat
ev=WaitWindowEvent()
If ev=#WM_LBUTTONDOWN
ReleaseCapture_()
SendMessage_(WindowID(0), #WM_NCLBUTTONDOWN, #HTCAPTION, 0)
EndIf
Until ev=#WM_RBUTTONDOWN
End
Layered windows are not meant to be used with controls. You would have to handle all mouse stuff yourself.