CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Oct 2008
    Posts
    15

    Scrollbar within an AfxMessageBox

    Hello everybody,

    my problem is that i have an AfxMessageBox(msg) where msg is a CString object.
    msg is too long, it does not fit on the screen, so i need a scrollbar.

    I did not found anything, so i hope i am retrieving some help in this forum ?!

    My mainclass where the AfxMessageBox has to show some important messages is
    class CMyMainClass : public CDocument

    I am programming with MS VS 6.

    I hope that someone could help me on !


    Best regards,
    #50

  2. #2
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: Scrollbar within an AfxMessageBox

    Why don't you add some newlines to the string so it wont be to long ?

  3. #3
    Join Date
    Oct 2008
    Posts
    15

    Re: Scrollbar within an AfxMessageBox

    i need a vertically scrollbar, because there are to many lines ...

  4. #4
    Join Date
    Feb 2002
    Posts
    3,788

    Re: Scrollbar within an AfxMessageBox

    if you really need a scrollbar you need to write your own messagebox class. if the message you are showing in the message box is too long, no one will spend time reading it. keep it concise.

  5. #5
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,244

    Re: Scrollbar within an AfxMessageBox

    As already discussed here a message box is only for displaying (short) messages.
    However, let's say, we have a requirement:
    "Must be possible to close any informative message-box either by pushing the <OK> button or after a pre-defined time; additionally it has to display a vertical progress-bar showing the remaining time".
    Our MFC application already has hundreds of AfxMessageBox calls so writing our own message-box function/class to replace them is not the best solution.
    Weird or not, is has to be done...

    A message box which is shown by a call of MessageBox API function (or AfxMessageBox if using MFC) is a modal dialog so normally we have not any control after creating it.
    Luckily, we can start by taking a look at Fancy Custom MessageBox article to get the idea: using a CBT hook to subclass the message-box dialog window. After that, once we have one application-defined procedure attached, it's a piece of cake to add controls, set timers, and so on...

    We can adapt that to a MFC application knowing that
    AfxMessageBox internally calls the CWinApp:: DoMessageBox virtual function.
    So, we have to override that function and install a CBT hook before calling the base class method.

    Attached here is an example.

    [ later edit ]

    Intentionally, I have chosen a different scenario just to be a little bit more interesting/practical/fun .
    Returning to the OP requirements: normally, the message-box is used for short messages which make no sense to use scroll-bars. For long messages use multi-line edit controls or edit views which have built-in scroll capability.
    Attached Files Attached Files
    Last edited by ovidiucucu; October 31st, 2008 at 07:54 AM.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  6. #6
    Join Date
    Oct 2008
    Posts
    15

    Re: Scrollbar within an AfxMessageBox

    Quote Originally Posted by ovidiucucu
    Returning to the OP requirements: normally, the message-box is used for short messages which make no sense to use scroll-bars. For long messages use multi-line edit controls or edit views which have built-in scroll capability.

    Thanks a lot for the answers.

    one point why i am using AfxMessageBox is, that i did not know another possibility in this special situation ...
    can you give me a more detailed hint what you think i should use ... please ?!

    i am a totally novice in programming ... especially with the MFC.

    so an explicit code what other options to print messages to the screen i could use in my problem setting would be a huge help !

    best regards,
    #50

  7. #7
    Join Date
    Oct 2008
    Posts
    15

    Re: Scrollbar within an AfxMessageBox

    Hello everybody ...


    i am still working on solving my problem ... unfortunately ...

    my new way is to use another box to show the message.

    first question:
    what kind of message box would you prefer ?


    i played a little bit with the wizards and wanted to use the edit boxes, with some scrolling bars. but instead of beginning a newline there is a black |.
    This is of course not what i want ?!

    second question:
    Can anybody give me another possibility to show my (very very long message) ?!


    Best regards!
    #50

  8. #8
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: Scrollbar within an AfxMessageBox

    Quote Originally Posted by Raute50
    ... but instead of beginning a newline there is a black |.
    This is of course not what i want ?!
    You sould use two symbols CR LF ("\r\n") to force the text in the edit control to go to the new line.

    Quote Originally Posted by Raute50
    second question:
    Can anybody give me another possibility to show my (very very long message) ?
    Again: who is supposed to read such a "very very long message"?
    Almost no one ans Alin already poined out, would do it!
    Victor Nijegorodov

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured