More wide MessageRequester() window

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Korolev Michael
Enthusiast
Enthusiast
Posts: 200
Joined: Wed Feb 01, 2012 5:30 pm
Location: Russian Federation

More wide MessageRequester() window

Post 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:
Image
Former user of pirated PB.
Now registered user :].
Julian
Enthusiast
Enthusiast
Posts: 276
Joined: Tue May 24, 2011 1:36 pm

Re: More wide MessageRequester() window

Post 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.
Korolev Michael
Enthusiast
Enthusiast
Posts: 200
Joined: Wed Feb 01, 2012 5:30 pm
Location: Russian Federation

Re: More wide MessageRequester() window

Post by Korolev Michael »

Already did.
Former user of pirated PB.
Now registered user :].
User avatar
ostapas
Enthusiast
Enthusiast
Posts: 192
Joined: Thu Feb 18, 2010 11:10 pm

Re: More wide MessageRequester() window

Post by ostapas »

Korolev Michael wrote:Already did.
Would you mind sharing it?
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Re: More wide MessageRequester() window

Post by c4s »

If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
Korolev Michael
Enthusiast
Enthusiast
Posts: 200
Joined: Wed Feb 01, 2012 5:30 pm
Location: Russian Federation

Re: More wide MessageRequester() window

Post 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
Former user of pirated PB.
Now registered user :].
User avatar
TI-994A
Addict
Addict
Posts: 2704
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: More wide MessageRequester() window

Post 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! :wink:
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
Julian
Enthusiast
Enthusiast
Posts: 276
Joined: Tue May 24, 2011 1:36 pm

Re: More wide MessageRequester() window

Post 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
fromVB
User
User
Posts: 82
Joined: Sun Jul 29, 2012 2:27 am

Re: More wide MessageRequester() window

Post 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 :D
Julian
Enthusiast
Enthusiast
Posts: 276
Joined: Tue May 24, 2011 1:36 pm

Re: More wide MessageRequester() window

Post by Julian »

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 :D
Nice! :)
Korolev Michael
Enthusiast
Enthusiast
Posts: 200
Joined: Wed Feb 01, 2012 5:30 pm
Location: Russian Federation

Re: More wide MessageRequester() window

Post by Korolev Michael »

My god, I invented a damn sophisticated bicycle :(
Former user of pirated PB.
Now registered user :].
Post Reply