C++ MessageBoxes

I want to make a message box show a few fixed strings and a few class members but when i tried the following code i got told .dwHeight and .dwWidth need a type or something on the left which is really confusing me..

MessageBox(NULL, "Width: " && ddsDesc.dwWidth & "
Height: " && ddsDesc.dwHeight, "Compatible display mode", MB_OK);

The program is a simple test program to enumerate display modes using direct draw 7. The .dwWidth and .dwHeight are both DWORDs.

If anyone can tell me what i've done wrong then please do! If you need more code to work out whats wrong ask for it and i'll tell you

Thanks!

Comments

  • [b][red]This message was edited by stober at 2003-3-6 7:12:33[/red][/b][hr]
    : MessageBox(NULL, "Width: " && ddsDesc.dwWidth & "
    Height: " && ddsDesc.dwHeight, "Compatible display mode", MB_OK);
    :

    [red] I know this is a REALLY old thread, but I'll answer it anyway just in case someone else has stumbled across the same problem.

    You can't concantinate strings that way -- C/C++ does not work like VB or other languages. You have to format the string before sending it to MessageBox(). There are a couple ways to do that. I'll illustrate the simplest, C, method.

    [code]
    char buffer[126];
    sprintf(buffer,"Width: %d
    Height: %d",ddsDesc.dwWidth, ddsDesc.dwHeight);

    MessageBox(NULL,buffer,"Compatible display mode", MB_OK);
    [/code]





Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion