Code: Select all
UsePNGImageDecoder()
Procedure quitClicked()
;coordinates of the Superman emblem
If WindowMouseX(0) > 220 And WindowMouseX(0) < 280 And
WindowMouseY(0) > 110 And WindowMouseY(0) < 150
quitHotspot = #True
EndIf
ProcedureReturn quitHotspot
EndProcedure
;downloading a PNG image from my server
imgFile$ = GetTemporaryDirectory() + "superman.png"
If FileSize(imgFile$) < 1
ReceiveHTTPFile("syed.sg/tutorials/" + GetFilePart(imgFile$), imgFile$)
EndIf
LoadImage(0, imgFile$)
OpenWindow(0, 0, 0, ImageWidth(0), ImageHeight(0), "",
#PB_Window_ScreenCentered | #PB_Window_BorderLess)
CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
ImportC ""
sel_registerName(str.p-ascii)
class_addMethod(class, selector, imp, types.p-ascii)
EndImport
ProcedureC imageProc(obj, sel, notification)
Static lastEvent : Shared sharedApp
currentEvent = CocoaMessage(0, sharedApp, "currentEvent")
If currentEvent <> lastEvent
lastEvent = currentEvent
If currentEvent
Select CocoaMessage(0, currentEvent, "type")
Case #NSLeftMouseUp
If quitClicked()
If MessageRequester("Shaped Window", "Quit now?", 1) = 6
PostEvent(#PB_Event_CloseWindow)
EndIf
EndIf
EndSelect
EndIf
EndIf
EndProcedure
windowShape = CocoaMessage(0, 0, "NSColor colorWithPatternImage:", ImageID(0))
CocoaMessage(0, WindowID(0), "setOpaque:", #NO)
CocoaMessage(0, WindowID(0), "setHasShadow:", #YES)
CocoaMessage(0, WindowID(0), "setMovableByWindowBackground:", #YES)
CocoaMessage(0, WindowID(0), "setBackgroundColor:", windowShape)
sharedApp = CocoaMessage(0, 0, "NSApplication sharedApplication")
notiCenter = CocoaMessage(0, 0, "NSNotificationCenter defaultCenter")
appDelegate = CocoaMessage(0, sharedApp, "delegate")
delegateClass = CocoaMessage(0, appDelegate, "class")
eventsHandler = sel_registerName("EventsHandlerCallback:")
class_addMethod(delegateClass, eventsHandler, @imageProc(), "v@:@")
CocoaMessage(0, notiCenter, "addObserver:", appDelegate, "selector:",
eventsHandler, "name:", #Null, "object:", WindowID(0))
CompilerElseIf #PB_Compiler_OS = #PB_OS_Windows
Procedure imageProc(hwnd, msg, wParam, lParam)
Shared sysProc
Select msg
Case #WM_LBUTTONDOWN
If quitClicked()
If MessageRequester("Shaped Window", "Quit now?", 4) = 6
PostEvent(#PB_Event_CloseWindow)
EndIf
Else
SendMessage_(WindowID(0), #WM_NCLBUTTONDOWN, #HTCAPTION, 0)
EndIf
EndSelect
ProcedureReturn CallWindowProc_(sysProc, hwnd, msg, wParam, lParam)
EndProcedure
SetWindowColor(0, #White)
layeredStyle = GetWindowLongPtr_(WindowID(0), #GWL_EXSTYLE) | #WS_EX_LAYERED
SetWindowLongPtr_(WindowID(0), #GWL_EXSTYLE, layeredStyle)
SetLayeredWindowAttributes_(WindowID(0), #White, 0, #LWA_COLORKEY)
ImageGadget(0, 0, 0, WindowWidth(0), WindowHeight(0), ImageID(0))
sysProc = SetWindowLongPtr_(GadgetID(0), #GWL_WNDPROC, @imageProc())
CompilerEndIf
While WaitWindowEvent() ! #PB_Event_CloseWindow : Wend