C++ Message Box>.

J

jdk0118

So I am making some code that shows your mouses X and Y coordinates.
As of now I am doing it via command line and I have to press enter.

How would I got about putting it in a MessageBox() ?
I tried it but I can't put the variable in..

Any help would be appreciated.
This is what I have so far..

#include <iostream>
#include <windows.h>

int main()
{
while(1)
{


POINT cursorPos;
GetCursorPos(&cursorPos);
float x = 0;
x = cursorPos.x;
float y = 0;
y = cursorPos.y;






system("cls");
std::cout << "X: ";
std::cout << x;
std::cout << "\n";
std::cout << "Y: ";
std::cout << y;
std::cin.get();


}

return 0;
}
 
A

asm23

So I am making some code that shows your mouses X and Y coordinates.
As of now I am doing it via command line and I have to press enter.

How would I got about putting it in a MessageBox() ?
I tried it but I can't put the variable in..

Any help would be appreciated.
This is what I have so far..

#include <iostream>
#include <windows.h>

int main()
{
while(1)
{


POINT cursorPos;
GetCursorPos(&cursorPos);
float x = 0;
x = cursorPos.x;
float y = 0;
y = cursorPos.y;






system("cls");
std::cout << "X: ";
std::cout << x;
std::cout << "\n";
std::cout << "Y: ";
std::cout << y;
std::cin.get();


}

return 0;
}
It's a platform related topic. You'd better try some *windows* related
group.
 
T

Thomas J. Gritzan

It's a platform related topic. You'd better try some *windows* related
group.

How to call MessageBox is platform specific, but the OP obviously
wanted to build a string and pass the string to MessageBox().

Let's assume that MessageBox takes a const char*, you could use a
std::eek:stringstream like this:

#include <sstream>
#include <string>

// a function that takes a C-style string
void SomeFunction(const char*);

int main()
{
float x = 0;
float y = 0;

std::eek:stringstream message;
message << "X: " << x;
message << "\n";
message << "Y: " << y;

// build temporary std::string from stringstream,
// get const char* from std::string,
// then call your function:
SomeFunction( message.str().c_str() );
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,169
Messages
2,570,919
Members
47,460
Latest member
eibafima

Latest Threads

Top