• Welcome to Dark Bit Factory & Gravity.
 

Message / Error Boxes

Started by Clyde, September 20, 2009

Previous topic - Next topic

0 Members and 0 Guests are viewing this topic.

Clyde

How would I use messagebox to display an error message when using TinyPTC_Ext for C / C++ ? As I dont have a window handle / or window instance; meaning the lib takes care of setting up the window stuff.

Thanks,
Clyde.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won:

Rbz

No need for window handle to display a message box, even though tinyptc_ext have a function to retrieve it, just use "ptc_getwindow();"

MessageBox(NULL,"Hello","Caption",MB_OK);
Challenge Trophies Won:

rain_storm


Challenge Trophies Won:

Clyde

In a little confused:

Should I use:

1/ MessageBox( ptc_getwindow(), "Boo!","Something went tits up");
2/ MessageBox( hwnd_desktop, "Boo!","Something went tits up");
3/ MessageBox( Null, "Boo!","Something went tits up"); // and null is the quivalent of hwnd_desktop?
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won:

Jim

#4
2 and 3 would need to be

MessageBox(HWND_DESKTOP, "Boo!","Something went tits up");
MessageBox(NULL, "Boo!","Something went tits up");

and you need a 4th parameter of MB_OK on all 3.

It doesn't matter which you use.  The difference is which window ends up being the parent of the message box, but you don't really care.

Jim
Challenge Trophies Won:

Clyde

Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won:

Clyde

ive noticed with using MSVCRTS.lib that it now changes that command to MessageBoxW and the need for (LPSCRT) before messages.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won:

Jim

I don't think that's the reason, I think you need to go to Project->Properties
Configuration Properties->General->Character Set
and change
Use Unicode Character Set
to
Use Multi-Byte Character Set

Visual Studio these days defaults to a mode where all strings instead of having a single byte for every character it has 2.  That means that it can better deal with foreign languages and all the variety of alphabets that requires.  This is a good thing for real-life applications, in my opinion.  Not so good for tiny-code demos though.

That means that almost every Windows API call that used to take a byte string needs another version that takes a double-byte string.  One is called eg. MessageBoxA the other is called MessageBoxW.
When you include windows.h, it checks to see if you have chosen to build for unicode or not, and does something like this

#ifdef _UNICODE
  #define MessageBox MessageBoxW
#else
  #define MessageBox MessageBoxA
#endif

That makes a 'normal' MessageBox call hook up to the right routine.  I think you've got a mix of ascii (multibyte) and unicode in your app due to mismatch between these two settings.

Jim
Challenge Trophies Won:

Clyde

Thanks for the heads up dude!

Im also a bit stuck wether or not break; is needed if an error occurs as it tells me I cant use it in the following instance.

for example:

if (sound ==0 )
{
   MessageBox( Null, "Boo!", "Something went tits up", MB_OK);
   break;
}
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won:

Jim

If you want to quit the program then you need to use
exit(0);
If you use exit, you should #include <stdlib.h>

break is used to jump out of while/do/for loops and to control the drop-through in switch/case statements.
e.g.
for (x=0; x<5; x++)
{  if (x==2) break; }
will only count 0,1,2, but the program will continue.

Do you not have a book that tells you what break does?

Jim








Challenge Trophies Won: