Displaying strings in a dialog window

This is a discussion on Displaying strings in a dialog window within the Windows Programming forums, part of the Platform Specific Boards category; Hello: I've created a dialog for a math C program, the outputs of which are stored in an array. An ...

  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    37

    Displaying strings in a dialog window

    Hello:

    I've created a dialog for a math C program, the outputs of which are stored in an array.
    An associated custom dialog that pops when pressing a button in the main dialog should display the outputs let's say as a string list.
    What should I do to get that display ?
    Any idea ?
    Thanks.
    Frandy

  2. #2
    Registered User AtomRiot's Avatar
    Join Date
    Jan 2003
    Posts
    120
    string list?
    in testing for values i always use something similar to this:
    PHP Code:
    char chTmp[1024];
    sprintf(chTmp,"Value x=%d Value y=%d",x,y);
    MessageBox(hWnd,chTmp,"values",0); 
    where using a message box the usage is
    PHP Code:
    MessageBox(
        
    HWND parent,
        
    Text value in body,
        
    header value,
        
    popup type); 
    the header value can also be a variable
    its handy for quick testing, there are better techniques when used for actual output that users will see but this is the general idea.
    All Your Base Are Still Belong to Someone!!!
    And you Remember that!!!

  3. #3
    Registered User
    Join Date
    Aug 2004
    Posts
    37
    Tnx for your reply AtomRiot.
    Unfortunately, when the data listing is very long (let's say more than 70 lines), without a vertical scrollbar, you can't read the data at the bottom. Moreover, no printing can be done with a message box.
    Any other idea ?

  4. #4
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,265
    no printing can be done with a message box
    Well that isnt very hard to change. I wrote this utility function for my windows programs:

    Code:
    int MessageBoxf(UINT uType, LPCTSTR lpText, ... )
    {
    	va_list args;
    	char szMessage[512];
    
    	va_start(args,lpText);
    	vsprintf(szMessage,lpText,args);
    	va_end(args);
    
    	return MessageBox(NULL,szMessage,"",uType);
    }
    If you want a verticle scroll bar, then you need to create a new modal dialog, and place a List Box control on it. This way you can display your list of strings in this list box. Obviously this requires a lot more work than just a simple MessageBox solution.

  5. #5
    Registered User
    Join Date
    Aug 2004
    Posts
    37
    I am way from being a programmer. So, please show how to use your function in a simple example. Tnx again.

  6. #6
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,265
    Code:
    MessageBoxf(MB_OK,"There are %d continents on planet %s",7,"Earth");
    Also, you will need to include stdarg.h for the MessageBoxf() function to compile.

  7. #7
    Registered User
    Join Date
    Aug 2004
    Posts
    37
    Tnx bithub.
    I inserted the include stdarg.h at the beginning of my TryagainDlg.cpp.
    As my string is in chTmp[1024], I typed MessageBoxf(MB_OK,chTmp); in
    void CTryagainDlg::OutputButton()
    but got the error C2065 : 'MessageBoxf' undeclared identifier.
    Where did I make a mistake or did I forget anything ?

  8. #8
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,265
    did I forget anything ?
    Sounds like you forgot to put the MessageBoxf function somewhere in your code. This is not a predefined function, it is just a utility function to help format messagebox strings (similar to the printf format).

  9. #9
    Registered User
    Join Date
    Aug 2004
    Posts
    37
    Your function works fine !
    But it still remain the problem of reading the last strings when the list consists of more than 72 strings.
    The list box instead seems to refuse more than about 40 strings. Why ?

  10. #10
    Registered User
    Join Date
    Aug 2004
    Posts
    37
    The list box revealed its secrets to me in the meanwhile ...
    But :
    In the ListBox properties/Styles, if I choose Selection/Single, I get perfect strings.
    Now, if I add a 'Multi-column' check, the strings are shortened.
    It seems to be due to an insufficient column width.
    As I intend to make screen shots of the list - as no printing button is available - I'd like to modify that width.
    Is it possible ?
    Tns for any help.

  11. #11
    Registered User Rare177's Avatar
    Join Date
    May 2004
    Posts
    214
    does it need to be in a list box or are you just finding a way to list the data?

  12. #12
    Registered User
    Join Date
    Aug 2004
    Posts
    37
    Not necessarily.
    I'm just looking for a way to list data and print them on my printer.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 02-13-2008, 02:59 PM
  2. Why only 32x32? (OpenGL) [Please help]
    By Queatrix in forum Game Programming
    Replies: 2
    Last Post: 01-23-2006, 02:39 PM
  3. Displaying an IplImage in an Extended Windows Styles window
    By Tankndozer in forum Windows Programming
    Replies: 0
    Last Post: 08-10-2005, 06:22 AM
  4. my wndProc is out of scope
    By Raison in forum Windows Programming
    Replies: 35
    Last Post: 06-25-2004, 08:23 AM
  5. Invoking MSWord
    By Donn in forum C Programming
    Replies: 21
    Last Post: 09-08-2001, 05:08 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21