Thread: MessageBox questions...

  1. #1
    Unregistered
    Guest

    Question MessageBox questions...

    Hello.

    I was wondering how i can output numbers using a MessageBox. In DOS i might do something like this (very simple example):

    Code:
    printf("The cube of %f is: %f\n", input, answer);
    But if i try that in a message box i get errors stating that it can't convert numbers to characters. How would i get around that?

    Also, i get a weird error... when i ever i try and use 4 parameters in a MessageBox function, i recieve an error stating that the function can't handle 4 parameters, but in the Win32 API Reference, it does. What gives?

    And yes, i am new to windows programming

  2. #2
    You can do it like this:
    Code:
    char text[200];
    
    sprintf(text,"this is the number %i",10);
    MessageBox(hwnd,"Caption",text,MB_OK);

  3. #3
    Unregistered
    Guest
    Damn!

    I still keep getting this error stating that the MessageBox function doesn't take four parameters...

  4. #4
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    > I still keep getting this error stating that the MessageBox function doesn't take four parameters...

    Well, look up the definition of the function and you'll see that it is actually four parameters. I think maes mixed them up though. Where he has "caption", should be the text to be displayed, and then the next parameter should be the caption.

    --Garfield the Programmer
    1978 Silver Anniversary Corvette

  5. #5
    I think maes mixed them up though. Where he has "caption", should be the text to be displayed, and then the next parameter should be the caption
    yes, what was I thinking

    I guess I should try the code first before posting it

  6. #6
    Unregistered
    Guest
    I'll try it when i get back from work, thanks for all the help.

  7. #7
    I have tried the code and it works (except it says "caption" in the text area and "this is the number 10" in the caption

    if it still doesn't work:
    can you post the code that you use (MessageBox, sprintf an declarations)

  8. #8
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Yeah, the functio is right. maes is right. You might not be implementing it right or you just have a stupid typo or something you can't see. Post away!

    --Garfield the Programmer
    1978 Silver Anniversary Corvette

  9. #9
    Unregistered
    Guest
    DAMN! I still get the same error about the MessageBox not being able to handle 4 parameters. Ok, here's my code, this is very basic stuff, be kind

    Code:
    void CWinCubeDlg::OnCube() 
    {
    	// TODO: Add your control notification handler code here
    	char buff[1024];
    	int answer;
    	 
    	answer = Cube(m_value);
    	
    	sprintf(buff, "The value of %i is: %i", m_value, answer);
    
    	MessageBox(NULL, buff, "The results...", MB_OK);
    }
    
    int Cube(int x)
    {
    	int	x_cubed;
    
    	x_cubed = x * x * x;
    
    	return x_cubed;
    }
    Once again, it states that, "error C2660: 'MessageBoxA' : function does not take 4 parameters."

  10. #10
    Registered User -leech-'s Avatar
    Join Date
    Nov 2001
    Posts
    54

    Post

    Just like to say that i'm registered now so no one will get confused as to who "unregistered" is

    Would just like to clarify some stuff:

    - m_value is the variable to the number that the user inputs.
    - i know my array is too big
    Not yet, have to think of one...

  11. #11
    Registered User ski6ski's Avatar
    Join Date
    Aug 2001
    Posts
    133
    From your code it looks like you are using Visual C++ and made this with AppWizard. In that case take the NULL out. That should work.
    C++ Is Powerful
    I use C++
    There fore I am Powerful

  12. #12
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    sprintf uses %d for int's not %i.

    NULL for the HWND will display to the main window.

    (But I use just VC no ++.)
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  13. #13
    Registered User -leech-'s Avatar
    Join Date
    Nov 2001
    Posts
    54
    Took out the NULL, added an UpdateData(TRUE) and everything's peachy
    Last edited by -leech-; 11-11-2001 at 10:18 PM.
    Not yet, have to think of one...

  14. #14
    ‡ †hë Ö†hÈr sîÐè ‡ Nor's Avatar
    Join Date
    Nov 2001
    Posts
    299
    try changing
    MessageBox(NULL, buff, "The results...", MB_OK);
    to something like
    MessageBox(NULL, buff, "The results...", MB_OK | MB_ICONINFORMATION);

    And if that doesn't work then its got me to.
    Try to help all less knowledgeable than yourself, within
    the limits provided by time, complexity and tolerance.
    - Nor

  15. #15
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Why would performing a bitwise operation help anything? I don't see the sense in that.

    --Garfield
    1978 Silver Anniversary Corvette

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. questions....so many questions about random numbers....
    By face_master in forum C++ Programming
    Replies: 2
    Last Post: 07-30-2009, 08:47 AM
  2. A very long list of questions... maybe to long...
    By Ravens'sWrath in forum C Programming
    Replies: 16
    Last Post: 05-16-2007, 05:36 AM
  3. Delete files that are used
    By Yuri in forum C++ Programming
    Replies: 8
    Last Post: 10-18-2005, 01:48 PM
  4. Trivial questions - what to do?
    By Aerie in forum A Brief History of Cprogramming.com
    Replies: 23
    Last Post: 12-26-2004, 09:44 AM
  5. EnterCriticalSection and MessageBox
    By novacain in forum Windows Programming
    Replies: 13
    Last Post: 01-30-2003, 08:48 AM