Dark Bit Factory & Gravity

PROGRAMMING => C / C++ /C# => Topic started by: Clyde on September 21, 2009

Title: Message / Error Boxes
Post by: Clyde on September 21, 2009
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.
Title: Re: Message / Error Boxes
Post by: Rbz on September 21, 2009
No need for window handle to display a message box, even though tinyptc_ext have a function to retrieve it, just use "ptc_getwindow();"

Code: [Select]
MessageBox(NULL,"Hello","Caption",MB_OK);
Title: Re: Message / Error Boxes
Post by: rain_storm on September 22, 2009
NULL == HWND_DESKTOP
Title: Re: Message / Error Boxes
Post by: Clyde on September 22, 2009
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?
Title: Re: Message / Error Boxes
Post by: Jim on September 22, 2009
2 and 3 would need to be
Code: [Select]
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
Title: Re: Message / Error Boxes
Post by: Clyde on September 22, 2009
Cheers :)
Title: Re: Message / Error Boxes
Post by: Clyde on November 02, 2009
ive noticed with using MSVCRTS.lib that it now changes that command to MessageBoxW and the need for (LPSCRT) before messages.
Title: Re: Message / Error Boxes
Post by: Jim on November 02, 2009
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
Title: Re: Message / Error Boxes
Post by: Clyde on November 06, 2009
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;
}
Title: Re: Message / Error Boxes
Post by: Jim on November 06, 2009
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