I use the following code. Some code parts came from this forum.
Code: Select all
UsePNGImageDecoder()
Enumeration
#MsgWindow = $FFF
#Msg_cont_title
#Msg_canvas_title
#Msg_txt_title
#Msg_img_close
#Msg_cont_message
#Msg_canvas_message_back
#Msg_img_message_back
#Msg_txt_message
#Msg_img_main
#Msg_OK
#Msg_Yes
#Msg_No
#Font
EndEnumeration
Procedure LftMouseDown()
Shared MouseDown, OffsetX, OffsetY
MouseDown=#True
offsetX=WindowMouseX(#MsgWindow)/DesktopResolutionX()
OffsetY=WindowMouseY(#MsgWindow)/DesktopResolutionY()
EndProcedure
Procedure MouseMve()
Shared MouseDown, OffsetX, OffsetY
If MouseDown And GetGadgetAttribute(#Msg_canvas_title,#PB_Canvas_Buttons)&#PB_Canvas_LeftButton
ResizeWindow(#MsgWindow, DesktopMouseX()/DesktopResolutionX()-OffsetX, DesktopMouseY()/DesktopResolutionY()-OffsetY, #PB_Ignore, #PB_Ignore)
EndIf
EndProcedure
Procedure.i GetTextHeight(text.s, Width.i, Font.i)
Protected TempGadget.i, txtHeight.i, TextLine.s, NbLine.i, I.i
TempGadget = TextGadget(#PB_Any, 0, 0, Width, 20, text)
SetGadgetFont(TempGadget,FontID(Font))
txtHeight = GadgetHeight(TempGadget, #PB_Gadget_RequiredSize) - 2 ; -2 for the TextGadget Border
NbLine = 1
If GadgetWidth(TempGadget, #PB_Gadget_RequiredSize) > Width - 2
For I = 1 To CountString(text, " ") + 1
If TextLine = "" : TextLine = StringField(text, I, " ") : Else : TextLine + " " + StringField(text, I, " ") : EndIf
SetGadgetText(TempGadget, TextLine)
If GadgetWidth(TempGadget, #PB_Gadget_RequiredSize) > Width - 2
NbLine + 1
If TextLine = StringField(text, I, " ")
TextLine = ""
Else
TextLine = StringField(text, I, " ")
EndIf
EndIf
Next
If TextLine = "" : NbLine - 1 : EndIf
EndIf
FreeGadget(TempGadget)
ProcedureReturn NbLine * txtHeight ;+ 2
EndProcedure
Procedure.i GetTextWidth(text.s, Font.i)
Protected TempGadget.i, txtWidth
TempGadget = TextGadget(#PB_Any, 0, 0, 20, 20, text)
SetGadgetFont(TempGadget,FontID(Font))
txtWidth = GadgetWidth(TempGadget, #PB_Gadget_RequiredSize) ;- 2
FreeGadget(TempGadget)
ProcedureReturn txtWidth
EndProcedure
Procedure.i MessageRequesterEx(Title.s, Message.s, Flags.i=0)
Protected GdtWidth.i, GdtHeight.i, WndWidth.i, WndHeight.i, Icon.i
Protected DPI.f = DesktopResolutionX()
Debug RSet(Bin(Flags),8,"0")
Debug (Flags >> 6) & 1
Debug (Flags >> 5) & 1
Debug (Flags >> 4) & 1
If (Flags >> 6) & 1 = 1;INFORMATION
Icon = CatchImage(#PB_Any, ?InfoStart, ?InfoEnd - ?InfoStart)
ElseIf (Flags >> 4) & 3 = 2;QUESTION
Icon = CatchImage(#PB_Any, ?QuestionStart, ?QuestionEnd - ?QuestionStart)
ElseIf (Flags >> 4) & 3 = 3;WARNING
Icon = CatchImage(#PB_Any, ?WarningStart, ?WarningEnd - ?WarningStart)
ElseIf (Flags >> 4) & 1 = 1;ERROR
Icon = CatchImage(#PB_Any, ?ErrorStart, ?ErrorEnd - ?ErrorStart)
EndIf
Window = GetActiveWindow()
LoadFont(#Font,"Arial",16)
If Window < 1
OpenWindow(#MsgWindow, 0, 0, 200, 200, "", #PB_Window_ScreenCentered|#PB_Window_BorderLess)
Else
OpenWindow(#MsgWindow, 0, 0, 200, 200, "", #PB_Window_WindowCentered|#PB_Window_BorderLess,WindowID(window))
EndIf
;SetGadgetFont(#PB_Default,FontID(#Font))
GdtWidth = GetTextWidth(Message, #Font)
If GdtWidth > 400: GdtWidth = 400: EndIf
If GdtWidth < 100: GdtWidth = 100: EndIf
GdtHeight = Gettextheight(Message,GdtWidth, #Font)
;Debug GdtHeight
;Debug GdtWidth
If Icon = 0
WndWidth = GdtWidth + 42
WndHeight = GdtHeight + 119
txtX = 20
If WndWidth < 260: WndWidth = 260: GdtWidth = 218 : EndIf
Else
txtX = 100
WndWidth = GdtWidth+132;100 (txtX) + 30 (txt right) + 2 (lines)
WndHeight = GdtHeight+119;32 (title) + 15 (txtY) + 15 (txt bottom) + 55 (button space, 35 +10Y + 10 bottom) + 2 (lines)
If WndHeight < 189: WndHeight = 189: EndIf; 192 = 32 + 15 + 72 + 15 + 55
If WndWidth < 260: WndWidth = 260: EndIf
EndIf
X = WindowX(#MsgWindow)
Y = WindowY(#MsgWindow)
ResizeWindow(#MsgWindow,X-(WndWidth-200)/2,Y-(WndHeight-200)/2,WndWidth,WndHeight)
ContainerGadget(#Msg_cont_title,1,1,WndWidth-2,32)
;i = CreateImage(#PB_Any,GdtWidth+38,GdtHeight+78,24,$FFF4EF)
;ImageGadget(#Msg_img_back,0,0,GdtWidth+38,GdtHeight+78,ImageID(i))
CanvasGadget(#Msg_canvas_title, 0,0,WndWidth-34,32)
If StartDrawing(CanvasOutput(#Msg_canvas_title))
Box(0,0,WndWidth-2,32,$FFF4EF)
DrawingFont(FontID(#Font))
Height = TextHeight(Title)
DrawText(15,(32-Height)/2,Title,1,$FFF4EF)
StopDrawing()
EndIf
CloseIcon = CatchImage(#PB_Any, ?CloseMsgStart, ?CloseMsgEnd - ?CloseMsgStart)
ImageGadget(#Msg_img_close,WndWidth-33,0,32,32,ImageID(CloseIcon))
CloseGadgetList()
If Icon = 0
ContHeight = GdtHeight + 30
Else
If (GdtHeight + 30) > 102; 15 (txtX) + 72 (imgW) + 15 (img bottom)
ContHeight = GdtHeight + 30
Else
ContHeight = 102
EndIf
EndIf
ContainerGadget(#Msg_cont_message,1,34,WndWidth-2,ContHeight)
i = CreateImage(#PB_Any,WndWidth-2,ContHeight,24,$FFFFFF)
ImageGadget(#Msg_img_message_back,0,0,WndWidth-2,ContHeight,ImageID(i))
DisableGadget(#Msg_img_message_back,#True)
If Icon <> 0;no icon
ImageGadget(#Msg_img_main,20,15,72,72,ImageID(Icon))
EndIf
TextGadget(#Msg_txt_message,txtX, 15,GdtWidth,GdtHeight,Message)
SetGadgetFont(#Msg_txt_message,FontID(#Font))
CloseGadgetList()
SetGadgetColor(#Msg_txt_message,#PB_Gadget_BackColor,$FFFFFF)
SetWindowLongPtr_(GadgetID(#Msg_img_message_back), #GWL_STYLE, GetWindowLongPtr_(GadgetID(#Msg_img_message_back), #GWL_STYLE) | #WS_CLIPSIBLINGS)
SetWindowPos_(GadgetID(#Msg_img_message_back), #HWND_BOTTOM, -1, -1, -1, -1, #SWP_NOSIZE | #SWP_NOMOVE)
;buttons
If Flags & #PB_MessageRequester_Ok
ButtonGadget(#Msg_OK,(WndWidth-100)/2,ContHeight + 43,100,35,"OK") ;1 (line) + 32(title) + 10
SetGadgetFont(#Msg_OK,FontID(#Font))
ElseIf Flags & #PB_MessageRequester_YesNo
ButtonGadget(#Msg_Yes,WndWidth - 240,ContHeight + 43,100,35,"Yes")
ButtonGadget(#Msg_No,WndWidth - 120,ContHeight + 43,100,35,"No")
SetGadgetFont(#Msg_Yes,FontID(#Font))
SetGadgetFont(#Msg_No,FontID(#Font))
SetActiveGadget(#Msg_Yes)
Else
ButtonGadget(#Msg_OK,(WndWidth-100)/2,ContHeight + 43,100,35,"OK")
SetGadgetFont(#Msg_OK,FontID(#Font))
SetActiveGadget(#Msg_OK)
EndIf
;border
StartDrawing(WindowOutput(#MsgWindow))
LineXY(0,0,WndWidth*DPI,0,$646464)
LineXY(WndWidth*DPI-1,0,WndWidth*DPI-1,WndHeight*DPI,$646464)
LineXY(0,WndHeight*DPI-1,WndWidth*DPI,WndHeight*DPI-1,$646464)
LineXY(0,0,0,WndHeight*DPI,$646464)
StopDrawing()
AddKeyboardShortcut(#MsgWindow, #PB_Shortcut_Return, 15)
BindEvent(#PB_Event_Gadget,@LftMouseDown(),#MsgWindow,#Msg_canvas_title,#PB_EventType_LeftButtonDown)
BindEvent(#PB_Event_Gadget,@MouseMve(),#MsgWindow,#Msg_canvas_title,#PB_EventType_MouseMove)
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_CloseWindow
Quit = 1
ElseIf Event = #PB_Event_Menu
If EventMenu() = 15
If GetActiveGadget() = #Msg_OK
CloseWindow(#MsgWindow)
ProcedureReturn #PB_MessageRequester_Ok
EndIf
EndIf
ElseIf Event = #PB_Event_Gadget
Select EventGadget()
Case #Msg_OK
CloseWindow(#MsgWindow)
ProcedureReturn #PB_MessageRequester_Ok
Case #Msg_Yes
CloseWindow(#MsgWindow)
ProcedureReturn #PB_MessageRequester_Yes
Case #Msg_No
CloseWindow(#MsgWindow)
ProcedureReturn #PB_MessageRequester_No
Case #Msg_img_close
Quit = 1
EndSelect
EndIf
Until Quit = 1
CloseWindow(#MsgWindow)
EndProcedure
MessageRequesterEx("Attention!","Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.",#MB_ICONWARNING|#PB_MessageRequester_YesNo)
DataSection
CloseMsgStart:
IncludeBinary "closeBtn.png"
CloseMsgEnd:
InfoStart:
IncludeBinary "info.png"
InfoEnd:
ErrorStart:
IncludeBinary "error.png"
ErrorEnd:
WarningStart:
IncludeBinary "warning.png"
WarningEnd:
QuestionStart:
IncludeBinary "question.png"
QuestionEnd:
EndDataSection