How do I create a message box that lets me display a variable? I also need to know how to display variables with text. Here is the code in the switch(message) statement that I have at the moment that doesn't work.

case WM_CREATE:
            CreateWindow(
                TEXT("button"), TEXT("Click"),
                WS_VISIBLE | WS_CHILD | WS_BORDER,
                10, 30, 55, 20,
                hwnd, (HMENU) 1, NULL, NULL
            );
            break;
        case WM_COMMAND:
            if(LOWORD(wParam) == 1){
                money--; //this has already been declared at 50.
                MessageBox(hwnd, money, "New money value", MB_OK); //also tried money.toString() but that doesn't work either.
            }
            break;

Recommended Answers

All 4 Replies

case WM_CREATE:
  CreateWindow(
     TEXT("button"), TEXT("Click"),
     WS_VISIBLE | WS_CHILD | WS_BORDER,
     10, 30, 55, 20,
     hwnd, (HMENU) 1, NULL, NULL
   );
   break;
case WM_COMMAND:
   if(LOWORD(wParam) == 1)
   {
      TCHAR szBuffer[16];
      money--; //this has already been declared at 50.
      _stprintf(szBuffer,_T("%d"),money);
      MessageBox(hwnd, szBuffer, _T("New money value"), MB_OK); //also tried money.toString() but that doesn't work either.
   }
   break;

.ToString is .NET stuff. Won't work in Win32.

I like to start control ids at 1500, so they don't interfere too badly with MS defined values. Also, use equates...

#define IDC_BUTTON1 1500

Also, for that to compile you should include....

#include <windows.h>
#include <tchar.h>
#include <cstdio>

Let me know if it doesn't work. Maybe I missed something else...

case WM_CREATE:
  CreateWindow(
     TEXT("button"), TEXT("Click"),
     WS_VISIBLE | WS_CHILD | WS_BORDER,
     10, 30, 55, 20,
     hwnd, (HMENU) 1, NULL, NULL
   );
   break;
case WM_COMMAND:
   if(LOWORD(wParam) == 1)
   {
      TCHAR szBuffer[16];
      money--; //this has already been declared at 50.
      _stprintf(szBuffer,_T("%d"),money);
      MessageBox(hwnd, szBuffer, _T("New money value"), MB_OK); //also tried money.toString() but that doesn't work either.
   }
   break;

.ToString is .NET stuff. Won't work in Win32.

I like to start control ids at 1500, so they don't interfere too badly with MS defined values. Also, use equates...

#define IDC_BUTTON1 1500

Also, for that to compile you should include....

#include <windows.h>
#include <tchar.h>
#include <cstdio>

Let me know if it doesn't work. Maybe I missed something else...

Thanks. Also, how would I print some text and a variable?

Although the short answer is TextOut(). But, having said that, since you were unsure how to represent an integral value within a character string buffer and output it with MessageBox, it likely wouldn't hurt you to examine the link above.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.