Page 1 of 1
More wide MessageRequester() window
Posted: Tue Jul 07, 2015 2:04 pm
by Korolev Michael
PB automatically resizes width of MessageRequester() window. But why it has so little maximum? Can I control width of window myself and decide when I need for carriage return?
This window looks rather careless:

Re: More wide MessageRequester() window
Posted: Tue Jul 07, 2015 4:49 pm
by Julian
These are part of the operating system and its functionality is limited to displaying information and waiting for a few simple button clicks.
If you want something with more functionality, just make your own procedure to open a window and sit in a separate loop waiting for input which will have the same effect as this.
Re: More wide MessageRequester() window
Posted: Tue Jul 07, 2015 4:52 pm
by Korolev Michael
Already did.
Re: More wide MessageRequester() window
Posted: Tue Jul 07, 2015 5:11 pm
by ostapas
Korolev Michael wrote:Already did.
Would you mind sharing it?
Re: More wide MessageRequester() window
Posted: Tue Jul 07, 2015 6:15 pm
by c4s
Re: More wide MessageRequester() window
Posted: Wed Jul 08, 2015 4:31 am
by Korolev Michael
Would you mind sharing it?
Here you are. But for OS Windows only.
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
Re: More wide MessageRequester() window
Posted: Wed Jul 08, 2015 5:41 am
by TI-994A
Here's a simple PureBasic way, which should also be cross-platform:
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
Encapsulated within a procedure for
plug-&-play convenience!

Re: More wide MessageRequester() window
Posted: Wed Jul 08, 2015 7:30 am
by Julian
I've taken TI's a bit further and done things like calculate the window and gadget size depending on the text, this could be taken further again to calculate button sizing and a few other things, but this should be cross platform:
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
Re: More wide MessageRequester() window
Posted: Wed Jul 08, 2015 7:48 am
by fromVB
@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 
Re: More wide MessageRequester() window
Posted: Wed Jul 08, 2015 8:17 am
by Julian
Nice!

Re: More wide MessageRequester() window
Posted: Thu Jul 09, 2015 11:06 am
by Korolev Michael
My god, I invented a damn sophisticated bicycle
