[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c++

C++ Message Box>.

jdk0118

9/30/2008 1:53:00 AM

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;
}
4 Answers

asm23

9/30/2008 3:06:00 AM

0

jdk0118@gmail.com wrote:
> 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.

Ole Nielsby

10/1/2008 10:38:00 AM

0

asm23 wrote:

> jdk0118@gmail.com wrote:
>> So I am making some code that shows your mouses X and Y coordinates.
>> [...]
>> How would I got about putting it in a MessageBox() ?
>
> It's a platform related topic. You'd better try some *windows*
> related group.

Or, if you don't want your apps to be MS Windows only, look
here: http://en.wikipedia.org/wiki/List_of_widge...


Ioannis Vranos

10/1/2008 10:41:00 AM

0

Ole Nielsby wrote:
> asm23 wrote:
>
>> jdk0118@gmail.com wrote:
>>> So I am making some code that shows your mouses X and Y coordinates.
>>> [...]
>>> How would I got about putting it in a MessageBox() ?
>> It's a platform related topic. You'd better try some *windows*
>> related group.
>
> Or, if you don't want your apps to be MS Windows only, look
> here: http://en.wikipedia.org/wiki/List_of_widge...


One can also use QT.

Thomas J. Gritzan

10/1/2008 8:33:00 PM

0

> jdk0118@gmail.com wrote:
>> 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..

asm23 wrote:
> 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::ostringstream 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::ostringstream 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() );
}

--
Thomas