This window looks rather careless:

Would you mind sharing it?Korolev Michael wrote:Already did.
Here you are. But for OS Windows only.Would you mind sharing it?
Code: Select all
caption$ = "Caption"
message$ = "teeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeest test test test"+#CRLF$+"carriage return"
Enumeration
#Wnd
#Text
#Button
EndEnumeration
hWnd = OpenWindow(#Wnd,#PB_Ignore,#PB_Ignore,250,100,caption$,#PB_Window_Invisible)
hText = TextGadget(#Text,10,10,0,0,message$,#PB_Text_Center) ; remove #PB_Text_Center if you need
;;Calculate text bounds in gadget
rc.RECT ; RECT structure,it defines coords of rectangle
hdc=GetDC_(hText) ; get handle of device context (DC)
SelectObject_(hdc,SendMessage_(hText,#WM_GETFONT,0,0)) ; choose bitmap in our DC
DrawText_(hdc,GetGadgetText(#Text),Len(GetGadgetText(#Text)),rc,#DT_CALCRECT) ; draw text and calculate rectangle around it
ReleaseDC_(hText,hdc) ; free DC
;;Resize window
GW = rc\right+2*GetSystemMetrics_(#SM_CXEDGE) ; From known rectangle, calculate gadget size
GH = rc\bottom+2*GetSystemMetrics_(#SM_CYEDGE)
ResizeGadget(#Text,#PB_Ignore,#PB_Ignore, GW, GH)
ResizeWindow(#Wnd,#PB_Ignore,#PB_Ignore, GW+20, GH+55) ; calc windows size
WW = WindowWidth(#Wnd) ; final window width
WH = WindowHeight(#Wnd) ; final window height
ResizeGadget(#Text,WW/2-GadgetWidth(#Text)/2,#PB_Ignore,#PB_Ignore,#PB_Ignore)
ButtonGadget(#Button,WW/2-45,WH-35,90,25,"OK")
;;Center window
ResizeWindow(#Wnd,GetSystemMetrics_(#SM_CXSCREEN)/2-WW/2,GetSystemMetrics_(#SM_CYSCREEN)/2-WH/2,#PB_Ignore,#PB_Ignore)
;;Little gloss
If OSVersion() < #PB_OS_Windows_Vista
AnimateWindow_(hWnd,200,#AW_BLEND)
Else
HideWindow(#Wnd,#False)
EndIf
StickyWindow(#Wnd,#True)
Repeat
Event = WaitWindowEvent(50)
Until Event = #PB_Event_Gadget
Code: Select all
Procedure myMsgBox(msg.s, parentWnd)
DisableWindow(parentWnd, 1)
msgBox = OpenWindow(#PB_Any, #PB_Any, #PB_Any, 800, 120, "My MessageBox",
#PB_Window_WindowCentered, WindowID(parentWnd))
msgTxt = TextGadget(#PB_Any, 20, 35, 760, 30, msg, #PB_Text_Center)
msgBtn = ButtonGadget(#PB_Any, 350, 75, 100, 30, "OK")
While WaitWindowEvent() <> #PB_Event_Gadget And EventGadget() <> msgBtn : Wend
CloseWindow(msgBox)
DisableWindow(parentWnd, 0)
EndProcedure
;usage demo
wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
mainWnd = OpenWindow(#PB_Any, #PB_Any, #PB_Any, 640, 480, "Custom MessageBox Example", wFlags)
showBtn = ButtonGadget(#PB_Any, 220, 220, 200, 40, "Show Custom MessageBox")
msg.s = "This is a very, very long line of text to accommodate in a single-line " +
"message box, but if you gatta have it, you gatta have it. So here you go!"
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
appQuit = 1
Case #PB_Event_Gadget
Select EventGadget()
Case showBtn
myMsgBox(msg, mainWnd)
EndSelect
EndSelect
Until appQuit = 1
Code: Select all
Procedure myMsgBox(title.s, msg.s, parentWnd)
Protected border = 20 ; border around the edge of the window
;we could calculate these dimenstions in a similar way to the text if the button text was passed in
Protected buttonWidth = 100
Protected buttonHeight = 30
DisableWindow(parentWnd, 1)
Protected msgBox = OpenWindow(#PB_Any, #PB_Any, #PB_Any, 100, 100, title,
#PB_Window_WindowCentered|#PB_Window_Invisible, WindowID(parentWnd))
Protected msgTxt = TextGadget(#PB_Any, border, border, 760, 30, msg, #PB_Text_Center)
Protected longestString = 0
Protected totalHeight = 0
Protected rows = CountString(msg, #CRLF$) + 1
Protected counter
StartDrawing(WindowOutput(parentWnd))
DrawingFont(GetGadgetFont(msgTxt))
For counter = 1 To rows
Protected txt.s = StringField(msg, counter, #CRLF$)
Protected wWidth = TextWidth(txt)
If wwidth > longestString
longestString = wWidth
EndIf
totalHeight = totalHeight + TextHeight(msg)
Next
StopDrawing()
ResizeWindow(msgBox, #PB_Ignore, #PB_Ignore, longestString + border * 2, totalHeight + (border * 2) + border + buttonHeight) ; text height + top and bottom border + gap between button and text + buttonheight
ResizeGadget(msgTxt, (WindowWidth(msgBox) / 2) - (longestString / 2), #PB_Ignore, longestString, totalHeight) ; resize the text gadget incase the window has a minimum width
Protected msgBtn = ButtonGadget(#PB_Any, (WindowWidth(msgBox) / 2) - (buttonWidth / 2), GadgetHeight(msgTxt) + border + border, buttonWidth, buttonHeight, "OK")
HideWindow(msgBox, #False, #PB_Window_WindowCentered)
While WaitWindowEvent() <> #PB_Event_Gadget And EventGadget() <> msgBtn : Wend
CloseWindow(msgBox)
DisableWindow(parentWnd, 0)
EndProcedure
;usage demo
wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
mainWnd = OpenWindow(#PB_Any, #PB_Any, #PB_Any, 640, 480, "Custom MessageBox Example", wFlags)
showBtn = ButtonGadget(#PB_Any, 220, 220, 200, 40, "Show Custom MessageBox")
msg.s = "teeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeest test test test"+#CRLF$+"carriage return"
;msg.s = "teeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeest test test test"+#CRLF$+"carriage return sadfdsfg sdfg asdf asdf asdf asdf asdf asdf as dfsdfg sdfg sdfg fasdf asdf asdf asdf asdf asdf asdf asdf sda f sdfg dsfg dsfg sdfg dsfg dfgsdf asdfasdfklajsdflkjasdlfkj asdlkfj aslkjdf as kld fjsalkd fljksd "
;msg.s = "1" + #CRLF$ + "2" + #CRLF$ + "3" + #CRLF$ + "4" + #CRLF$ + "5" + #CRLF$ + "6"
;msg.s = "Moo"
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
appQuit = 1
Case #PB_Event_Gadget
Select EventGadget()
Case showBtn
myMsgBox("My MessageBox", msg, mainWnd)
EndSelect
EndSelect
Until appQuit = 1
Nice!fromVB wrote:@Julian: Take a look at TI994A's timer message box. You can adjust the max width of the box to get the same effect. The button size and position can also be adjusted.
http://www.purebasic.fr/english/viewtop ... essage+box