Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Length of string available in Messagebox 4

Status
Not open for further replies.

Bryan - Gendev

Programmer
Jan 9, 2011
408
AU
I have had success using messagebox() for a short information screen.
It worked so well that I tried using it for a longer 'info' type screen.
It worked well but for the cutoff of the number of lines showing. A number were not shown.

Is the length of the cMessage stated anywhere and can it be extended?

Thanks

GenDev
 
As my long message is in 2 parts I have created 2 messagebox messages. The second runs after an [OK] on the first.

This may be an OK solution if there is a limit.

GenDev
 
Or you could just simply create a form that looks like a messagebox.
Then you can display as much text as you like, and control the layout of the text.
You could probably make the form model, for better behaviour.
 
Messageboxes surely are only for shorter messages. They halt your program and are modal. That's intended, as the user should react to them.
If merely showing an info you should rather use your own form, then you're also not limited.

As a sidenote, what was difficult and hindering you to make use of Messagebox earlier?
The concept is very well known and not a foxpro thing. Javascript Alert VBA MsgBox, Common Dialogs. Its some of the basic things people use to output debug messages, though DEBUGOUT and the debugger is better for that, but its a thing people usually know and use before debuggers.

Bye, Olaf.
 
I guees the maximum number of characters the VFP Messagebox can display, is 1024
Code:
MessageBox(SPACE(1023)+"123", "Message title", 0)

You can use the API Messagebox

Code:
DECLARE INTEGER MessageBox IN user32 as MessageBoxA;
    INTEGER hWindow, STRING lpText,;
    STRING lpCaption, LONG uType
 
= MessageBoxA(_screen.HWnd, SPACE(5000)+"123", "Message title", 0)

Respectfully,
Vilhelm-Ion Praisach
Resita, Romania
 
I'm with Olaf on this one. Messageboxes should be used for short messages that must grab the user's attention, and which the user has to explicitly acknowledge. If you want to display a lot of information which the user has to read carefully, better to use your own form, and to display formatted text that includes sub-headings, bullet points, or similar.

Another point about messageboxes with long text is that the lines don't necessarily break where you would want them to. If you don't insert your own line breaks - using CHR(13) - the lines will be broken based on the physical width of the box, not on the number of characters in the line. The maximum physical width of the box is a fixed number of pixels, not of characters.

Mike





__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I understand what you are saying - but rules are always made to be broken.<VBG>

I use chr(10)+chr(13) at the end of my lines and see perfectly arranged messages. They are intended to be read through and modal is ideal.

I'm happy..though I do use my own form in my larger apps to display information but this is a single form app.

Thanks to all

GenDev
 
If you don't see the advantage of non modal then skip reading this. Modal forms can hinder shutdowns, also hinder users to continue. You always can need to use another part of an app - in your case the only main - if you need that to answer a call right away, whatever. It won't help your rebel soul if I'd say I live by the rule modal forms are bad.

Anyway, this is how it can be done non modal:

Code:
Text To lcText NoShow
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut 
labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores 
et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. 

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut 
labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores 
et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
Endtext

o = CreateObject("infobox",lcText,"infobox")
o.Show(1) && normal use in an application with o.Show() only, but you CAN show it modal, too.

Define Class infobox as Form
   WindowType=0
   Add Object edit1 as editbox with Scrollbars=0, Borderstyle=0, Backstyle=0, Enabled=.f., DisabledForecolor=0
   
   Procedure init()
      LParameters lcMessage, lcTitle
      
      This.edit1.value = lcMessage
      This.Caption = lcTitle
      
      this.edit1.Width = Thisform.TextWidth(lcMessage)+Thisform.TextWidth("W")
      this.edit1.Height = Thisform.TextHeight(lcMessage)+Thisform.TextHeight("W")
      Thisform.Width = this.edit1.Width
      Thisform.Height = this.edit1.Height
   EndProc 
Enddefine

The form is defined modeless and I am only showing it modal here because of not adding a read events you'll have in main anyway. Also to demonstrate it can be used both modal and non modal. See comment inside code.

The Infobox form adapts its size to the text via form TextWidth/Height methods. If you change editbox fontname and fontsize, set the same properties of the form, because the form TextWidth/Height methods will take into account the form fontname/size settings only. The sizing will respect the line breaks passed in, they are considered for calculating text height.

The bad thing about measuring text size is, if you define a max width that'll make the editbox wordwrap but is not considered from the Textheight calculation. In an extreme case passing in a text without any line breaks you'll see a very wide and thin form.

These solution is easy to overcome, simply pass in a text preformatted in the way you want, by defining that text in TEXT..ENDTEXT. You won't need string delimiters and CHR(13)+CHR(10), its much more comfortable to write texts this way in source code, isn't it? And I'm sure that was mentioned not only once even only in your own threads, if you ognore learning from other peoples questions.

You may add whatever symbols or buttons after adding space, you may shift the edit1.left and .top and make the form larger to have a margin. What am I saying? You know you are free to do everything you need.

Bye, Olaf.
 
By the way, for anybody wondering why I don't use the Label.Autosize and Wordwrap, which is making this even easier. The Label.caption has about the same 1K limit for its Caption text length, so you better use an Editbox for long texts. You can at least make use of the Editbox wordwrap capabilities, if just defining a large enough height and/or activate the vertical scrollbar. That's best, if a text only has line breaks and empty lines to break and separate paragraphs.

Bye, Olaf.
 
Very nice example [smile]
Indeed, long messages are better handled this way.

For short messages, here are some features of the API MessageBox (taken from - Right allign => 0x80000
Code:
DECLARE INTEGER MessageBoxA IN user32 INTEGER hWindow, STRING lpText,STRING lpCaption, LONG uType
= MessageBoxA(_screen.HWnd, "Well ?"+CHR(13)+"Oh, no, no, no!", "Message title", 0x80000)
- Another set of buttons => 6
Code:
DECLARE INTEGER MessageBoxA IN user32 INTEGER hWindow, STRING lpText,STRING lpCaption, LONG uType
= MessageBoxA(_screen.HWnd, "Well ?", "Message title", 6)
- The messagebox in front of all windows (WS_EX_TOPMOST style) => 0x1000
Code:
DECLARE INTEGER MessageBoxA IN user32 INTEGER hWindow, STRING lpText,STRING lpCaption, LONG uType
= MessageBoxA(_screen.HWnd, "Well ?", "Message title", 0x1000)
This style can be applied even to VFP messagebox (this trick was shown by Mr. Chuanbing Chen)
Code:
MESSAGEBOX("AAAAA !",0x1000)

The ability to display Unicode characters.
To achieve this, instead of MessageBoxA must be used MessageBoxW.
The message and the title are strings ended with a CHR(0).
Regular text must be converted with STRCON(...,5) (See but can be used characters Unicode as a blob constant.
Example for regular text
Code:
DECLARE INTEGER MessageBoxW IN user32 INTEGER hWindow, STRING lpText, STRING lpCaption, LONG uType
= MessageBoxW(_screen.HWnd, STRCONV("Well ?"+CHR(13)+"Oh, no, no, no!"+CHR(0),5), STRCONV("Message title"+CHR(0),5), 0)
Example for blob constant (for Unicode, see Character "0" is Unicode 0x0030. As blob constant will be written 0h3000 (note the reversed order of the two bytes). Because the string must be ended with a CHR(0), displaying a "0" become :
Code:
DECLARE INTEGER MessageBoxW IN user32 INTEGER hWindow, STRING lpText, STRING lpCaption, LONG uType
= MessageBoxW(_screen.HWnd, 0h300000, STRCONV("Message title"+CHR(0),5), 0)
To display "01", the blob constant will be 0h3000310000, where 3000 is Unicode "0", 3100 is Unicode "1" and 00 is the string terminator.
Code:
DECLARE INTEGER MessageBoxW IN user32 INTEGER hWindow, STRING lpText, STRING lpCaption, LONG uType
= MessageBoxW(_screen.HWnd, 0h3000310000, STRCONV("Message title"+CHR(0),5), 0)
Note that some characters might not be displayed.
Another Unicode message.
Code:
DECLARE INTEGER MessageBoxW IN user32 INTEGER hWindow, STRING lpText, STRING lpCaption, LONG uType
= MessageBoxW(_screen.HWnd, 0h300031003200D0058006D00700, STRCONV("Message title"+CHR(0),5), 0)



Respectfully,
Vilhelm-Ion Praisach
Resita, Romania
 
If you are displaying that much text in a Messagebox, you're going about this all wrong. People will not read that much text. They rarely read the brief messages in a Messagebox.

Craig Berntson
MCSD, Visual C# MVP,
 
If you are displaying that much text in a Messagebox, you're going about this all wrong. People will not read that much text. They rarely read the brief messages in a Messagebox.

Craig, that's exactly the point several of us made at the start of the thread.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Yes, but "People will not read that much text" made me think why actually not?

If it's really a main aspect of the application to show such texts and people choose them in your main form and want to read them, then you could also show a DOC(X) or PDF. It'll even be another application, then. It all depends on the intentions of the application.

Bye, Olaf.
 
Another approach might be to display the text in a web browser control. Because that would support just about any formatting you might want - not to mention graphics - it would let you make the text very attractive and readable. And unlike with a PDF or DOCX, the user would stay within your application. There would be a higher overhead than with a simple message box, but I doubt that would be a limiting factor.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top